diff --git a/OsmAnd/res/layout-land/empty_state_favourites.xml b/OsmAnd/res/layout-land/empty_state_favourites.xml
new file mode 100644
index 0000000000..e3a77b04ab
--- /dev/null
+++ b/OsmAnd/res/layout-land/empty_state_favourites.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout-land/empty_state_my_tracks.xml b/OsmAnd/res/layout-land/empty_state_my_tracks.xml
new file mode 100644
index 0000000000..80863986be
--- /dev/null
+++ b/OsmAnd/res/layout-land/empty_state_my_tracks.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/available_gpx.xml b/OsmAnd/res/layout/available_gpx.xml
index 56f9dc4bf5..227b73b025 100644
--- a/OsmAnd/res/layout/available_gpx.xml
+++ b/OsmAnd/res/layout/available_gpx.xml
@@ -1,8 +1,9 @@
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="?attr/ctx_menu_info_view_bg"
+ android:orientation="vertical">
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/empty_state_favourites.xml b/OsmAnd/res/layout/empty_state_favourites.xml
new file mode 100644
index 0000000000..ca57095bbc
--- /dev/null
+++ b/OsmAnd/res/layout/empty_state_favourites.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/empty_state_my_tracks.xml b/OsmAnd/res/layout/empty_state_my_tracks.xml
new file mode 100644
index 0000000000..b3da13be38
--- /dev/null
+++ b/OsmAnd/res/layout/empty_state_my_tracks.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/favorites_tree.xml b/OsmAnd/res/layout/favorites_tree.xml
index 22324a0e79..b7e0d85994 100644
--- a/OsmAnd/res/layout/favorites_tree.xml
+++ b/OsmAnd/res/layout/favorites_tree.xml
@@ -1,9 +1,10 @@
+ android:id="@+id/MainLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:background="?attr/ctx_menu_info_view_bg">
+ android:groupIndicator="@android:color/transparent"/>
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values-land/sizes.xml b/OsmAnd/res/values-land/sizes.xml
index 7cf56d5d90..4e116e39e1 100644
--- a/OsmAnd/res/values-land/sizes.xml
+++ b/OsmAnd/res/values-land/sizes.xml
@@ -4,4 +4,7 @@
24dp
48dp
+
+ 39dp
+ 39dp
\ No newline at end of file
diff --git a/OsmAnd/res/values-large-land/sizes.xml b/OsmAnd/res/values-large-land/sizes.xml
new file mode 100644
index 0000000000..2d48ca5083
--- /dev/null
+++ b/OsmAnd/res/values-large-land/sizes.xml
@@ -0,0 +1,5 @@
+
+
+ 59dp
+ 59dp
+
\ No newline at end of file
diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml
index 375e91283d..2de1e4ff3d 100644
--- a/OsmAnd/res/values-large/sizes.xml
+++ b/OsmAnd/res/values-large/sizes.xml
@@ -78,5 +78,17 @@
15sp
15sp
12sp
+
+ 63dp
+ 45dp
+ 12dp
+ 30dp
+ 20sp
+ 18sp
+ 68dp
+ 138dp
+ 72dp
+ 90dp
+ 96dp
\ No newline at end of file
diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml
index 5860d32a21..aa41eae132 100644
--- a/OsmAnd/res/values/sizes.xml
+++ b/OsmAnd/res/values/sizes.xml
@@ -143,4 +143,16 @@
150dp
128dp
+
+ 42dp
+ 30dp
+ 8dp
+ 20dp
+ 18sp
+ 16sp
+ 45dp
+ 92dp
+ 48dp
+ 60dp
+ 64dp
\ No newline at end of file
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 5430b54d9f..a32a2ac34c 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -2669,4 +2669,10 @@
Save Route Point
Waypoint 1
Route Point 1
+ Add and Record Tracks
+ Record or import tracks to view
+ Add Favorites
+ Add favorites on map or import them from filesystem
+ Import track
+ File %1$s does not contain waypoints, import it as a track?
diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
index 9d305cb72c..d038d93105 100644
--- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
@@ -21,6 +21,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.Filter;
@@ -71,11 +72,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
public static final int SHARE_ID = 4;
public static final int SELECT_MAP_MARKERS_ID = 5;
public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6;
+ public static final int IMPORT_FAVOURITES_ID = 7;
public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded";
private FavouritesAdapter favouritesAdapter = new FavouritesAdapter();
private FavouritesDbHelper helper;
+ private OsmandApplication app;
private boolean selectionMode = false;
private Set favoritesSelected = new LinkedHashSet<>();
private Set groupsToDelete = new LinkedHashSet<>();
@@ -88,6 +91,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ this.app = (OsmandApplication) getActivity().getApplication();
helper = getMyApplication().getFavorites();
favouritesAdapter.synchronizeGroups();
@@ -156,6 +160,17 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
}
+ View emptyView = view.findViewById(android.R.id.empty);
+ ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
+ emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_favorites_day_result : R.drawable.ic_empty_state_favorites_night_result);
+ Button importButton = (Button) emptyView.findViewById(R.id.import_button);
+ importButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ importFavourites();
+ }
+ });
+ listView.setEmptyView(emptyView);
listView.setAdapter(favouritesAdapter);
setListView(listView);
setHasOptionsMenu(true);
@@ -237,6 +252,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
} else if (item.getItemId() == DELETE_ACTION_ID) {
deleteFavoritesAction();
return true;
+ } else if (item.getItemId() == IMPORT_FAVOURITES_ID) {
+ importFavourites();
+ return true;
} else {
return super.onOptionsItemSelected(item);
}
@@ -268,6 +286,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
if (!MenuItemCompat.isActionViewExpanded(mi)) {
+ createMenuItem(menu, IMPORT_FAVOURITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_plus,
+ R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (getSettings().USE_MAP_MARKERS.get()) {
@@ -467,6 +487,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
}
}
+ private void importFavourites() {
+ ((FavoritesActivity) getActivity()).importFavourites();
+ }
+
public void shareFavorites(final FavoriteGroup group) {
final AsyncTask exportTask = new AsyncTask() {
diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java
index 26c75ebd4b..1cae32b6bc 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java
@@ -21,6 +21,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.views.OsmandMapTileView;
import java.io.ByteArrayInputStream;
@@ -88,6 +89,21 @@ public class GpxImportHelper {
return false;
}
+ public void handleFavouritesImport(Uri uri) {
+ String scheme = uri.getScheme();
+ boolean isFileIntent = "file".equals(scheme);
+ boolean isContentIntent = "content".equals(scheme);
+ boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(uri.getPath()));
+ final boolean saveFile = !isFileIntent || !isOsmandSubdir;
+ String fileName = "";
+ if (isFileIntent) {
+ fileName = new File(uri.getPath()).getName();
+ } else if (isContentIntent) {
+ fileName = getNameFromContentUri(uri);
+ }
+ handleFavouritesImport(uri, fileName, saveFile, false, true);
+ }
+
public void handleFileImport(final Uri intentUri, final String fileName, final boolean useImportDir) {
final boolean isFileIntent = "file".equals(intentUri.getScheme());
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
@@ -99,7 +115,7 @@ public class GpxImportHelper {
} else if (fileName != null && fileName.endsWith(KMZ_SUFFIX)) {
handleKmzImport(intentUri, fileName, saveFile, useImportDir);
} else {
- handleFavouritesImport(intentUri, fileName, saveFile, useImportDir);
+ handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
}
}
@@ -155,12 +171,12 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(GPXFile result) {
progress.dismiss();
- handleResult(result, fileName, save, useImportDir);
+ handleResult(result, fileName, save, useImportDir, false);
}
}.execute();
}
- private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir) {
+ private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) {
new AsyncTask() {
ProgressDialog progress = null;
@@ -193,12 +209,12 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(final GPXFile result) {
progress.dismiss();
- importFavourites(result, fileName, save, useImportDir);
+ importFavourites(result, fileName, save, useImportDir, forceImportFavourites);
}
}.execute();
}
- private void importFavoritesImpl(final GPXFile gpxFile) {
+ private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
new AsyncTask() {
ProgressDialog progress = null;
@@ -209,7 +225,7 @@ public class GpxImportHelper {
@Override
protected GPXFile doInBackground(Void... nothing) {
- final List favourites = asFavourites(gpxFile.points);
+ final List favourites = asFavourites(gpxFile.points, fileName, forceImportFavourites);
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
@@ -225,6 +241,8 @@ public class GpxImportHelper {
progress.dismiss();
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
+ newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
activity.startActivity(newIntent);
}
}.execute();
@@ -277,7 +295,7 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(GPXFile result) {
progress.dismiss();
- handleResult(result, name, save, useImportDir);
+ handleResult(result, name, save, useImportDir, false);
}
}.execute();
@@ -322,13 +340,13 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(GPXFile result) {
progress.dismiss();
- handleResult(result, name, save, useImportDir);
+ handleResult(result, name, save, useImportDir, false);
}
}.execute();
}
private void handleResult(final GPXFile result, final String name, final boolean save,
- final boolean useImportDir) {
+ final boolean useImportDir, boolean forceImportFavourites) {
if (result != null) {
if (result.warning != null) {
Toast.makeText(activity, result.warning, Toast.LENGTH_LONG).show();
@@ -372,6 +390,12 @@ public class GpxImportHelper {
})
.show();
}
+ if (forceImportFavourites) {
+ final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
+ newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ newIntent.putExtra(FavoritesActivity.OPEN_MY_PLACES_TAB, true);
+ activity.startActivity(newIntent);
+ }
}
private String saveImport(final GPXFile gpxFile, final String fileName, final boolean useImportDir) {
@@ -467,38 +491,76 @@ public class GpxImportHelper {
}
private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save,
- final boolean useImportDir) {
+ final boolean useImportDir, final boolean forceImportFavourites) {
if (gpxFile == null || gpxFile.points == null || gpxFile.points.size() == 0) {
- handleResult(gpxFile, fileName, save, useImportDir);
- return;
- }
- final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case DialogInterface.BUTTON_POSITIVE:
- importFavoritesImpl(gpxFile);
- break;
- case DialogInterface.BUTTON_NEGATIVE:
- handleResult(gpxFile, fileName, save, useImportDir);
- break;
- }
- }
- };
+ if (forceImportFavourites) {
+ final DialogInterface.OnClickListener importAsTrackListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ switch (which) {
+ case DialogInterface.BUTTON_POSITIVE:
+ handleResult(gpxFile, fileName, save, useImportDir, true);
+ break;
+ case DialogInterface.BUTTON_NEGATIVE:
+ dialog.dismiss();
+ break;
+ }
+ }
+ };
- new AlertDialog.Builder(activity)
- .setTitle(R.string.shared_string_import2osmand)
- .setMessage(R.string.import_file_favourites)
- .setPositiveButton(R.string.shared_string_import, importFavouritesListener)
- .setNegativeButton(R.string.shared_string_save, importFavouritesListener)
- .show();
+ new AlertDialog.Builder(activity)
+ .setTitle(R.string.import_track)
+ .setMessage(activity.getString(R.string.import_track_desc, fileName))
+ .setPositiveButton(R.string.shared_string_import, importAsTrackListener)
+ .setNegativeButton(R.string.shared_string_cancel, importAsTrackListener)
+ .show();
+ return;
+ } else {
+ handleResult(gpxFile, fileName, save, useImportDir, false);
+ return;
+ }
+ }
+
+ if (forceImportFavourites) {
+ importFavoritesImpl(gpxFile, fileName, true);
+ } else {
+ final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ switch (which) {
+ case DialogInterface.BUTTON_POSITIVE:
+ importFavoritesImpl(gpxFile, fileName, false);
+ break;
+ case DialogInterface.BUTTON_NEGATIVE:
+ handleResult(gpxFile, fileName, save, useImportDir, false);
+ break;
+ }
+ }
+ };
+
+ new AlertDialog.Builder(activity)
+ .setTitle(R.string.shared_string_import2osmand)
+ .setMessage(R.string.import_file_favourites)
+ .setPositiveButton(R.string.shared_string_import, importFavouritesListener)
+ .setNegativeButton(R.string.shared_string_save, importFavouritesListener)
+ .show();
+ }
}
- private List asFavourites(final List wptPts) {
+ private List asFavourites(final List wptPts, String fileName, boolean forceImportFavourites) {
final List favourites = new ArrayList<>();
for (GPXUtilities.WptPt p : wptPts) {
if (p.name != null) {
- final String fpCat = (p.category != null) ? p.category : "";
+ final String fpCat;
+ if (p.category == null) {
+ if (forceImportFavourites) {
+ fpCat = fileName;
+ } else {
+ fpCat = "";
+ }
+ } else {
+ fpCat = p.category;
+ }
final FavouritePoint fp = new FavouritePoint(p.lat, p.lon, p.name, fpCat);
if (p.desc != null) {
fp.setDescription(p.desc);
diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
index 3fbf92947e..ed70f41a77 100644
--- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
+++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
@@ -327,6 +327,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
+ View emptyView = v.findViewById(android.R.id.empty);
+ ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
+ emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_trip_day_result : R.drawable.ic_empty_state_trip_night_result);
+ Button importButton = (Button) emptyView.findViewById(R.id.import_button);
+ importButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ addTrack();
+ }
+ });
+ listView.setEmptyView(emptyView);
if (this.adapter != null) {
listView.setAdapter(this.adapter);
}
diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java
index 54182345a1..f58fb91504 100644
--- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java
+++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java
@@ -41,6 +41,10 @@ import java.util.List;
public class FavoritesActivity extends TabActivity {
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
+ private static final int IMPORT_FAVOURITES_REQUEST = 1007;
+
+ public static final String OPEN_FAVOURITES_TAB = "open_favourites_tab";
+ public static final String OPEN_MY_PLACES_TAB = "open_my_places_tab";
public static final int GPX_TAB = R.string.shared_string_my_tracks;
public static final int FAV_TAB = R.string.shared_string_my_favorites;
@@ -67,6 +71,16 @@ public class FavoritesActivity extends TabActivity {
List mTabs = getTabItems();
setTabs(mTabs);
// setupHomeButton();
+
+ ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
+ Intent intent = getIntent();
+ if (intent != null) {
+ if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) {
+ mViewPager.setCurrentItem(0, false);
+ } else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) {
+ mViewPager.setCurrentItem(1, false);
+ }
+ }
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@@ -76,6 +90,13 @@ public class FavoritesActivity extends TabActivity {
startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);
}
+ @TargetApi(Build.VERSION_CODES.KITKAT)
+ public void importFavourites() {
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ intent.setType("*/*");
+ startActivityForResult(intent, IMPORT_FAVOURITES_REQUEST);
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OPEN_GPX_DOCUMENT_REQUEST && resultCode == Activity.RESULT_OK) {
@@ -101,6 +122,11 @@ public class FavoritesActivity extends TabActivity {
}
}
}
+ } else if (requestCode == IMPORT_FAVOURITES_REQUEST && resultCode == Activity.RESULT_OK) {
+ if (data != null) {
+ Uri uri = data.getData();
+ gpxImportHelper.handleFavouritesImport(uri);
+ }
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@@ -135,22 +161,9 @@ public class FavoritesActivity extends TabActivity {
}
private List getTabItems() {
- File[] lf = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.GPX_INDEX_DIR).listFiles();
- boolean hasGpx = false;
- if (lf != null) {
- for (File t : lf) {
- if (t.isDirectory() || (t.getName().toLowerCase().endsWith(".gpx"))) {
- hasGpx = true;
- break;
- }
- }
- }
-
List mTabs = new ArrayList<>();
mTabs.add(getTabIndicator(FAV_TAB, FavoritesTreeFragment.class));
- if (hasGpx) {
- mTabs.add(getTabIndicator(GPX_TAB, AvailableGPXFragment.class));
- }
+ mTabs.add(getTabIndicator(GPX_TAB, AvailableGPXFragment.class));
OsmandPlugin.addMyPlacesTabPlugins(this, mTabs, getIntent());
return mTabs;
}