Merge pull request #11258 from osmandapp/Displayed-tracks

Displayed tracks
This commit is contained in:
Vitaliy 2021-03-29 12:52:36 +03:00 committed by GitHub
commit adbcb141a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 33 deletions

View file

@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -23,11 +24,16 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routing.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import net.osmand.plus.widgets.TextViewExProgress; import net.osmand.plus.widgets.TextViewExProgress;
public class MapRouteInfoMenuFragment extends ContextMenuFragment { import static net.osmand.plus.track.TrackMenuFragment.startNavigationForGPX;
public class MapRouteInfoMenuFragment extends ContextMenuFragment implements TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
public static final String TAG = MapRouteInfoMenuFragment.class.getName(); public static final String TAG = MapRouteInfoMenuFragment.class.getName();
@Nullable @Nullable
@ -101,7 +107,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) { if (view != null) {
bottomContainer = (FrameLayout) view.findViewById(R.id.bottom_container); bottomContainer = view.findViewById(R.id.bottom_container);
modesLayoutToolbar = view.findViewById(R.id.modes_layout_toolbar); modesLayoutToolbar = view.findViewById(R.id.modes_layout_toolbar);
modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container); modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container);
modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container); modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container);
@ -121,7 +127,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
int widthNoShadow = getLandscapeNoShadowWidth(); int widthNoShadow = getLandscapeNoShadowWidth();
modesLayoutToolbar.setLayoutParams(new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT)); modesLayoutToolbar.setLayoutParams(new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM|Gravity.START; params.gravity = Gravity.BOTTOM | Gravity.START;
view.findViewById(R.id.control_buttons).setLayoutParams(params); view.findViewById(R.id.control_buttons).setLayoutParams(params);
View appModesView = view.findViewById(R.id.app_modes); View appModesView = view.findViewById(R.id.app_modes);
AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0); AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0);
@ -182,10 +188,10 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
@Override @Override
protected void updateMenuState(int currentMenuState, int newMenuState) { protected void updateMenuState(int currentMenuState, int newMenuState) {
if(getMyApplication().getRoutingHelper().isRouteCalculated() ) { if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode(); ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode();
if (newMenuState == MenuState.HEADER_ONLY && currentMenuState == MenuState.HALF_SCREEN) { if (newMenuState == MenuState.HEADER_ONLY && currentMenuState == MenuState.HALF_SCREEN) {
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.setModeValue(mV,true); getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.setModeValue(mV, true);
} else if (currentMenuState == MenuState.HEADER_ONLY && newMenuState == MenuState.HALF_SCREEN) { } else if (currentMenuState == MenuState.HEADER_ONLY && newMenuState == MenuState.HALF_SCREEN) {
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV); getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV);
} }
@ -356,7 +362,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return; return;
} }
boolean indeterminate = isPublicTransportMode() || !isOsmandRouting(); boolean indeterminate = isPublicTransportMode() || !isOsmandRouting();
ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar); ProgressBar progressBar = mainView.findViewById(R.id.progress_bar);
if (progressBar != null) { if (progressBar != null) {
if (progress == 0) { if (progress == 0) {
progressBar.setIndeterminate(indeterminate); progressBar.setIndeterminate(indeterminate);
@ -366,14 +372,14 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
} }
progressBar.setProgress(progress); progressBar.setProgress(progress);
} }
ProgressBar progressBarButton = (ProgressBar) view.findViewById(R.id.progress_bar_button); ProgressBar progressBarButton = view.findViewById(R.id.progress_bar_button);
if (progressBarButton != null) { if (progressBarButton != null) {
if (progressBarButton.getVisibility() != View.VISIBLE) { if (progressBarButton.getVisibility() != View.VISIBLE) {
progressBarButton.setVisibility(View.VISIBLE); progressBarButton.setVisibility(View.VISIBLE);
} }
progressBarButton.setProgress(indeterminate ? 0 : progress); progressBarButton.setProgress(indeterminate ? 0 : progress);
} }
TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr); TextViewExProgress textViewExProgress = view.findViewById(R.id.start_button_descr);
textViewExProgress.percent = indeterminate ? 0 : progress / 100f; textViewExProgress.percent = indeterminate ? 0 : progress / 100f;
textViewExProgress.invalidate(); textViewExProgress.invalidate();
} }
@ -390,11 +396,11 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
if (progressBar != null) { if (progressBar != null) {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
ProgressBar progressBarButton = (ProgressBar) view.findViewById(R.id.progress_bar_button); ProgressBar progressBarButton = view.findViewById(R.id.progress_bar_button);
if (progressBarButton != null) { if (progressBarButton != null) {
progressBarButton.setProgress(0); progressBarButton.setProgress(0);
} }
TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr); TextViewExProgress textViewExProgress = view.findViewById(R.id.start_button_descr);
textViewExProgress.percent = 0; textViewExProgress.percent = 0;
} }
@ -501,4 +507,19 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return false; return false;
} }
} }
@Override
public void onSegmentSelect(GPXUtilities.GPXFile gpxFile, int selectedSegment) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment);
getMyApplication().getRoutingHelper().onSettingsChanged(true);
}
dismiss();
}
}
} }

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
@ -20,7 +21,9 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,7 +33,7 @@ import java.util.List;
public class TracksCard extends BaseCard { public class TracksCard extends BaseCard {
private List<GPXFile> gpxFiles; private final List<GPXFile> gpxFiles;
private boolean showLimited = true; private boolean showLimited = true;
private static class GpxItem { private static class GpxItem {
@ -76,7 +79,7 @@ public class TracksCard extends BaseCard {
} }
}); });
LinearLayout tracks = (LinearLayout) view.findViewById(R.id.items); LinearLayout tracks = view.findViewById(R.id.items);
tracks.removeAllViews(); tracks.removeAllViews();
int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.route_info_card_item_height); int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.route_info_card_item_height);
@ -110,10 +113,10 @@ public class TracksCard extends BaseCard {
((TextView) v.findViewById(R.id.points_count)).setTextColor(descriptionColor); ((TextView) v.findViewById(R.id.points_count)).setTextColor(descriptionColor);
((TextView) v.findViewById(R.id.time)).setTextColor(descriptionColor); ((TextView) v.findViewById(R.id.time)).setTextColor(descriptionColor);
ImageView img = (ImageView) v.findViewById(R.id.icon); ImageView img = v.findViewById(R.id.icon);
img.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark)); img.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
img.setVisibility(View.VISIBLE); img.setVisibility(View.VISIBLE);
LinearLayout container = (LinearLayout) v.findViewById(R.id.container); LinearLayout container = v.findViewById(R.id.container);
container.setMinimumHeight(minCardHeight); container.setMinimumHeight(minCardHeight);
AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0); AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);
v.setOnClickListener(new View.OnClickListener() { v.setOnClickListener(new View.OnClickListener() {
@ -127,9 +130,14 @@ public class TracksCard extends BaseCard {
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true); app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true);
} }
} }
if (item.file.getNonEmptySegmentsCount() > 1) {
Fragment targetFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapRouteInfoMenuFragment.TAG);
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), item.file, targetFragment);
} else {
mapActivity.getMapActions().setGPXRouteParams(item.file); mapActivity.getMapActions().setGPXRouteParams(item.file);
app.getTargetPointsHelper().updateRouteAndRefresh(true); app.getTargetPointsHelper().updateRouteAndRefresh(true);
} }
}
}); });
tracks.addView(v); tracks.addView(v);
i++; i++;

View file

@ -82,8 +82,8 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener; import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
@ -804,7 +804,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (gpxFile.getNonEmptySegmentsCount() > 1) { if (gpxFile.getNonEmptySegmentsCount() > 1) {
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this); TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
} else { } else {
startNavigationForGPX(gpxFile, mapActions); startNavigationForGPX(gpxFile, mapActions, mapActivity);
dismiss(); dismiss();
} }
} }
@ -827,7 +827,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
segment = segments.get(0); segment = segments.get(0);
} }
} }
GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT};
List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)); List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
if (segment != null && !Algorithms.isEmpty(items)) { if (segment != null && !Algorithms.isEmpty(items)) {
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment); SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
@ -904,14 +904,15 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
} }
} }
private void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions) { public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) {
if (app.getRoutingHelper().isFollowingMode()) { if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
final WeakReference<MapActivity> activityRef = new WeakReference<>(mapActivity);
mapActions.stopNavigationActionConfirm(null, new Runnable() { mapActions.stopNavigationActionConfirm(null, new Runnable() {
@Override @Override
public void run() { public void run() {
MapActivity mapActivity = getMapActivity(); MapActivity activity = activityRef.get();
if (mapActivity != null) { if (activity != null) {
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null, activity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
null, null, true, true, MenuState.HEADER_ONLY); null, null, true, true, MenuState.HEADER_ONLY);
} }
} }
@ -1130,7 +1131,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
int i = item.getItemId(); int i = item.getItemId();
if (i == R.id.action_edit) { if (i == R.id.action_edit) {
editSegment(segment); editSegment();
return true; return true;
} else if (i == R.id.action_delete) { } else if (i == R.id.action_delete) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
@ -1164,7 +1165,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment); app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
startNavigationForGPX(gpxFile, mapActivity.getMapActions()); startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) { if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment); paramsBuilder.setSelectedSegment(selectedSegment);
@ -1174,7 +1175,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
} }
} }
private void editSegment(TrkSegment segment) { private void editSegment() {
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
openPlanRoute(new GpxData(gpxFile)); openPlanRoute(new GpxData(gpxFile));
hide(); hide();
@ -1219,7 +1220,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override @Override
public void gpxSavingFinished(Exception errorMessage) { public void gpxSavingFinished(Exception errorMessage) {
if (selectedGpxFile != null) { if (selectedGpxFile != null) {
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}); List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT});
selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.setDisplayGroups(groups, app);
selectedGpxFile.processPoints(app); selectedGpxFile.processPoints(app);
} }