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 net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
@ -23,11 +24,16 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routing.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper;
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;
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();
@Nullable
@ -95,13 +101,13 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
MapActivity mapActivity = requireMapActivity();
menu = mapActivity.getMapRouteInfoMenu();
View view = super.onCreateView(inflater, container, savedInstanceState);
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);
modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container);
modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container);
@ -121,7 +127,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
int widthNoShadow = getLandscapeNoShadowWidth();
modesLayoutToolbar.setLayoutParams(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 appModesView = view.findViewById(R.id.app_modes);
AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0);
@ -182,15 +188,15 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
@Override
protected void updateMenuState(int currentMenuState, int newMenuState) {
if(getMyApplication().getRoutingHelper().isRouteCalculated() ) {
if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode();
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) {
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV);
}
}
}
}
@Override
protected void setViewY(int y, boolean animated, boolean adjustMapPos) {
@ -347,7 +353,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
OsmandApplication app = getMyApplication();
return app != null && app.getRoutingHelper().isOsmandRouting();
}
public void updateRouteCalculationProgress(int progress) {
MapActivity mapActivity = getMapActivity();
View mainView = getMainView();
@ -356,7 +362,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return;
}
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 (progress == 0) {
progressBar.setIndeterminate(indeterminate);
@ -366,14 +372,14 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
}
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.getVisibility() != View.VISIBLE) {
progressBarButton.setVisibility(View.VISIBLE);
}
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.invalidate();
}
@ -390,11 +396,11 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
if (progressBar != null) {
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) {
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;
}
@ -501,4 +507,19 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
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.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
@ -20,7 +21,9 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import java.io.File;
import java.util.ArrayList;
@ -30,7 +33,7 @@ import java.util.List;
public class TracksCard extends BaseCard {
private List<GPXFile> gpxFiles;
private final List<GPXFile> gpxFiles;
private boolean showLimited = true;
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();
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.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.setVisibility(View.VISIBLE);
LinearLayout container = (LinearLayout) v.findViewById(R.id.container);
LinearLayout container = v.findViewById(R.id.container);
container.setMinimumHeight(minCardHeight);
AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);
v.setOnClickListener(new View.OnClickListener() {
@ -127,8 +130,13 @@ public class TracksCard extends BaseCard {
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true);
}
}
mapActivity.getMapActions().setGPXRouteParams(item.file);
app.getTargetPointsHelper().updateRouteAndRefresh(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);
app.getTargetPointsHelper().updateRouteAndRefresh(true);
}
}
});
tracks.addView(v);

View file

@ -82,8 +82,8 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
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.search.QuickSearchDialogFragment;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
@ -804,7 +804,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (gpxFile.getNonEmptySegmentsCount() > 1) {
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
} else {
startNavigationForGPX(gpxFile, mapActions);
startNavigationForGPX(gpxFile, mapActions, mapActivity);
dismiss();
}
}
@ -827,7 +827,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
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));
if (segment != null && !Algorithms.isEmpty(items)) {
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) {
if (app.getRoutingHelper().isFollowingMode()) {
public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) {
if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
final WeakReference<MapActivity> activityRef = new WeakReference<>(mapActivity);
mapActions.stopNavigationActionConfirm(null, new Runnable() {
@Override
public void run() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
MapActivity activity = activityRef.get();
if (activity != null) {
activity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
null, null, true, true, MenuState.HEADER_ONLY);
}
}
@ -1130,7 +1131,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
public boolean onMenuItemClick(MenuItem item) {
int i = item.getItemId();
if (i == R.id.action_edit) {
editSegment(segment);
editSegment();
return true;
} else if (i == R.id.action_delete) {
FragmentActivity activity = getActivity();
@ -1164,7 +1165,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
startNavigationForGPX(gpxFile, mapActivity.getMapActions());
startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
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();
openPlanRoute(new GpxData(gpxFile));
hide();
@ -1219,7 +1220,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override
public void gpxSavingFinished(Exception errorMessage) {
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.processPoints(app);
}
@ -1313,7 +1314,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
public static void showInstance(@NonNull MapActivity mapActivity,
@Nullable String path,
@Nullable String path,
boolean showCurrentTrack,
@Nullable final LatLon latLon,
@Nullable final String returnScreenName,
@ -1332,7 +1333,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
public static boolean showInstance(@NonNull MapActivity mapActivity,
@NonNull SelectedGpxFile selectedGpxFile,
@NonNull SelectedGpxFile selectedGpxFile,
@Nullable LatLon latLon,
@Nullable String returnScreenName,
@Nullable String callingFragmentTag) {