diff --git a/OsmAnd/res/layout/import_track_card.xml b/OsmAnd/res/layout/import_track_card.xml new file mode 100644 index 0000000000..50cb493196 --- /dev/null +++ b/OsmAnd/res/layout/import_track_card.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 90990a2b78..f3448fd00d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + Choose track file to follow or import it from device. + Choose track file to follow + Follow track In case of reverse direction Are you sure you want to close Plan route without saving? You will lose all changes. Street-level imagery diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index de3068cf5a..804d14f35c 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -1024,7 +1024,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { } } - protected static boolean showInstance(@NonNull MapActivity mapActivity, ContextMenuFragment fragment) { + public static boolean showInstance(@NonNull MapActivity mapActivity, ContextMenuFragment fragment) { try { mapActivity.getSupportFragmentManager() .beginTransaction() diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 477026fd57..d94e75846d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -627,15 +627,7 @@ public class ImportHelper { return; } final OsmandApplication app = mapActivity.getMyApplication(); - Intent intent = new Intent(); - String action; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - action = Intent.ACTION_OPEN_DOCUMENT; - } else { - action = Intent.ACTION_GET_CONTENT; - } - intent.setAction(action); - intent.setType("*/*"); + Intent intent = ImportHelper.getImportTrackIntent(); ActivityResultListener listener = new ActivityResultListener(IMPORT_FILE_REQUEST, new ActivityResultListener.OnActivityResultListener() { @Override @@ -675,6 +667,19 @@ public class ImportHelper { mapActivity.startActivityForResult(intent, IMPORT_FILE_REQUEST); } + public static Intent getImportTrackIntent() { + Intent intent = new Intent(); + String action; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + action = Intent.ACTION_OPEN_DOCUMENT; + } else { + action = Intent.ACTION_GET_CONTENT; + } + intent.setAction(action); + intent.setType("*/*"); + return intent; + } + private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject> callback) { if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) { int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index 7775d91119..78d1c75f32 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -34,7 +34,7 @@ import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; -import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.GpxLocalRoutingParameter; +import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.FollowTrackRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.InterruptMusicRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup; @@ -163,7 +163,7 @@ public class RoutePreferencesMenu { btn.performClick(); } else if (obj instanceof AvoidRoadsRoutingParameter) { routingOptionsHelper.selectRestrictedRoads(mapActivity); - } else if (obj instanceof GpxLocalRoutingParameter) { + } else if (obj instanceof FollowTrackRoutingParameter) { showOptionsMenu((TextView) view.findViewById(R.id.description)); } else { CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item); @@ -287,7 +287,7 @@ public class RoutePreferencesMenu { return v; } - if (parameter instanceof GpxLocalRoutingParameter) { + if (parameter instanceof FollowTrackRoutingParameter) { View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null); AndroidUtils.setListItemBackground(mapActivity, v, nightMode); AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.title), nightMode); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java index 409b7f875a..421eef5764 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java @@ -4,7 +4,6 @@ import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.view.View; @@ -150,15 +149,7 @@ public class StartPlanRouteBottomSheet extends MenuBottomSheetDialogFragment { } private void importTrack() { - Intent intent = new Intent(); - String action; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - action = Intent.ACTION_OPEN_DOCUMENT; - } else { - action = Intent.ACTION_GET_CONTENT; - } - intent.setAction(action); - intent.setType("*/*"); + Intent intent = ImportHelper.getImportTrackIntent(); try { startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST); } catch (ActivityNotFoundException e) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index 5022942bf8..502bd11212 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -6,7 +6,6 @@ import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.text.Spannable; import android.text.SpannableStringBuilder; @@ -23,16 +22,16 @@ import androidx.viewpager.widget.ViewPager; import net.osmand.PlatformUtil; import net.osmand.data.PointDescription; -import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.FavoritesTreeFragment; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.helpers.ImportHelper; +import net.osmand.plus.settings.backend.OsmAndAppCustomization; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.controls.PagerSlidingTabStrip; import org.apache.commons.logging.Log; @@ -98,7 +97,7 @@ public class FavoritesActivity extends TabActivity { } public void addTrack() { - Intent intent = getImportGpxIntent(); + Intent intent = ImportHelper.getImportTrackIntent(); try { startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST); } catch (ActivityNotFoundException e) { @@ -107,7 +106,7 @@ public class FavoritesActivity extends TabActivity { } public void importFavourites() { - Intent intent = getImportGpxIntent(); + Intent intent = ImportHelper.getImportTrackIntent(); try { startActivityForResult(intent, IMPORT_FAVOURITES_REQUEST); } catch (ActivityNotFoundException e) { @@ -115,19 +114,6 @@ public class FavoritesActivity extends TabActivity { } } - private Intent getImportGpxIntent() { - Intent intent = new Intent(); - String action; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - action = Intent.ACTION_OPEN_DOCUMENT; - } else { - action = Intent.ACTION_GET_CONTENT; - } - intent.setAction(action); - intent.setType("*/*"); - return intent; - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == OPEN_GPX_DOCUMENT_REQUEST && resultCode == Activity.RESULT_OK) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 808418aa05..23fcd3fe9c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -22,17 +22,17 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.StateChangedListener; -import net.osmand.plus.UiUtilities; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.actions.OsmAndDialogs; +import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerStartItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; @@ -40,7 +40,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DividerItem; -import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.GpxLocalRoutingParameter; +import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.FollowTrackRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter; @@ -50,6 +50,8 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRou import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditionalRoutingItem; import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.router.GeneralRouter; @@ -121,7 +123,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { items.add(createAvoidPTTypesItem(optionsItem)); } else if (optionsItem instanceof AvoidRoadsRoutingParameter) { items.add(createAvoidRoadsItem(optionsItem)); - } else if (optionsItem instanceof GpxLocalRoutingParameter) { + } else if (optionsItem instanceof FollowTrackRoutingParameter) { items.add(createGpxRoutingItem(optionsItem)); } else if (optionsItem instanceof TimeConditionalRoutingItem) { items.add(createTimeConditionalRoutingItem(optionsItem)); @@ -346,30 +348,32 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) { - View view = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null); - AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) view.findViewById(R.id.title), nightMode); - final TextView gpxDescription = (TextView) view.findViewById(R.id.description); - - ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(getContentIcon(optionsItem.getActiveIconId())); - ((ImageView) view.findViewById(R.id.dropDownIcon)).setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_drop_down)); - - RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - String gpxName; - if (rp == null) { - AndroidUtils.setTextSecondaryColor(mapActivity, gpxDescription, nightMode); - gpxName = mapActivity.getString(R.string.choose_track_file_to_follow); + RouteProvider.GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute(); + String description; + int descriptionColorId; + if (routeParamsBuilder == null) { + descriptionColorId = nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light; + description = mapActivity.getString(R.string.follow_track_descr); } else { - gpxDescription.setTextColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); - gpxName = new File(rp.getFile().path).getName(); + descriptionColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + description = new File(routeParamsBuilder.getFile().path).getName(); } - gpxDescription.setText(gpxName); - return new BaseBottomSheetItem.Builder().setCustomView(view).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - showOptionsMenu(gpxDescription); - } - }).create(); + return new BottomSheetItemWithDescription.Builder() + .setDescription(description) + .setDescriptionColorId(descriptionColorId) + .setIcon(getContentIcon(optionsItem.getActiveIconId())) + .setTitle(getString(R.string.follow_track)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + FollowTrackOptionsFragment trackOptionsFragment = new FollowTrackOptionsFragment(); + ContextMenuFragment.showInstance(mapActivity, trackOptionsFragment); + dismiss(); + } + }) + .create(); } private BaseBottomSheetItem createOtherSettingsRoutingItem(final LocalRoutingParameter optionsItem) { @@ -577,7 +581,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { GeneralRouter.USE_SHORTEST_WAY, TimeConditionalRoutingItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY), @@ -590,7 +594,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { ShowAlongTheRouteItem.KEY, TimeConditionalRoutingItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY), @@ -601,7 +605,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { ShowAlongTheRouteItem.KEY, TimeConditionalRoutingItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY), @@ -619,7 +623,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { ShowAlongTheRouteItem.KEY, TimeConditionalRoutingItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY), @@ -627,7 +631,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { DividerItem.KEY, ShowAlongTheRouteItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY), @@ -635,7 +639,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { DividerItem.KEY, ShowAlongTheRouteItem.KEY, DividerItem.KEY, - GpxLocalRoutingParameter.KEY, + FollowTrackRoutingParameter.KEY, OtherSettingsRoutingParameter.KEY, RouteSimulationItem.KEY); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 8357a606fe..42c7f7bd28 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -294,9 +294,7 @@ public class RoutingOptionsHelper { if (item != null) { updateRoutingParameterIcons(item); list.add(item); - if (item instanceof GpxLocalRoutingParameter) { - list.addAll(getGpxRouterParameters(am)); - } else if (item instanceof TimeConditionalRoutingItem) { + if (item instanceof TimeConditionalRoutingItem) { list.addAll(getOsmandRouterParameters(am)); } } @@ -395,8 +393,8 @@ public class RoutingOptionsHelper { return new AvoidPTTypesRoutingParameter(); case AvoidRoadsRoutingParameter.KEY: return new AvoidRoadsRoutingParameter(); - case GpxLocalRoutingParameter.KEY: - return new GpxLocalRoutingParameter(); + case FollowTrackRoutingParameter.KEY: + return new FollowTrackRoutingParameter(); case TimeConditionalRoutingItem.KEY: return new TimeConditionalRoutingItem(); case OtherSettingsRoutingParameter.KEY: @@ -443,7 +441,7 @@ public class RoutingOptionsHelper { list.add(2, new InterruptMusicRoutingParameter()); list.add(3, new AvoidRoadsRoutingParameter()); list.add(4, new TimeConditionalRoutingItem()); - list.add(new GpxLocalRoutingParameter()); + list.add(new FollowTrackRoutingParameter()); list.add(new OtherSettingsRoutingParameter()); return list; } @@ -900,9 +898,9 @@ public class RoutingOptionsHelper { } - public static class GpxLocalRoutingParameter extends LocalRoutingParameter { + public static class FollowTrackRoutingParameter extends LocalRoutingParameter { - public static final String KEY = "GpxLocalRoutingParameter"; + public static final String KEY = "FollowTrackRoutingParameter"; public String getKey() { return KEY; @@ -912,7 +910,7 @@ public class RoutingOptionsHelper { return false; } - public GpxLocalRoutingParameter() { + public FollowTrackRoutingParameter() { super(null); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java new file mode 100644 index 0000000000..78633b080e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java @@ -0,0 +1,54 @@ +package net.osmand.plus.routepreparationmenu.cards; + +import android.graphics.Typeface; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.ForegroundColorSpan; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.FontCache; + +public class ImportTrackCard extends BaseCard { + + public ImportTrackCard(@NonNull MapActivity mapActivity) { + super(mapActivity); + } + + @Override + public int getCardLayoutId() { + return R.layout.import_track_card; + } + + @Override + protected void updateContent() { + int color = ContextCompat.getColor(app, R.color.preference_category_title); + Typeface typeface = FontCache.getRobotoMedium(app); + String importTrack = app.getString(R.string.plan_route_import_track); + SpannableString spannable = UiUtilities.createCustomFontSpannable(typeface, importTrack, importTrack, importTrack); + spannable.setSpan(new ForegroundColorSpan(color), 0, importTrack.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + + TextView title = view.findViewById(R.id.title); + title.setText(spannable); + + ImageView icon = view.findViewById(R.id.icon); + icon.setImageDrawable(getContentIcon(R.drawable.ic_action_import_to)); + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CardListener listener = getListener(); + if (listener != null) { + listener.onCardPressed(ImportTrackCard.this); + } + } + }); + } +} \ No newline at end of file