diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index c4c63e0376..50d7ea0b18 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -30,6 +30,21 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.core.app.ActivityCompat; +import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback; +import androidx.core.content.ContextCompat; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentManager.BackStackEntry; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback; + import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.Location; @@ -157,21 +172,6 @@ import java.util.TimerTask; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.core.app.ActivityCompat; -import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback; -import androidx.core.content.ContextCompat; -import androidx.drawerlayout.widget.DrawerLayout; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentManager.BackStackEntry; -import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback; - import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; public class MapActivity extends OsmandActionBarActivity implements DownloadEvents, @@ -2074,7 +2074,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void showQuickSearch(double latitude, double longitude) { - hideContextMenu(); + hideVisibleMenu(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); if (fragment != null) { fragment.dismiss(); @@ -2085,7 +2085,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void showQuickSearch(String searchQuery) { - hideContextMenu(); + hideVisibleMenu(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); if (fragment != null) { fragment.dismiss(); @@ -2096,7 +2096,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void showQuickSearch(Object object) { - hideContextMenu(); + hideVisibleMenu(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); if (fragment != null) { fragment.dismiss(); @@ -2119,7 +2119,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (mode == ShowQuickSearchMode.CURRENT) { mapContextMenu.close(); } else { - hideContextMenu(); + hideVisibleMenu(); } QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); if (mode.isPointSelection()) { @@ -2172,7 +2172,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (mode == ShowQuickSearchMode.CURRENT) { mapContextMenu.close(); } else { - hideContextMenu(); + hideVisibleMenu(); } QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); if (mode.isPointSelection()) { @@ -2221,11 +2221,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven BaseSettingsFragment.showInstance(this, SettingsScreenType.MAIN_SETTINGS); } - private void hideContextMenu() { + private void hideVisibleMenu() { if (mapContextMenu.isVisible()) { mapContextMenu.hide(); } else if (mapContextMenu.getMultiSelectionMenu().isVisible()) { mapContextMenu.getMultiSelectionMenu().hide(); + } else if (getTrackMenuFragment() != null) { + dismissTrackMenu(); } } @@ -2277,6 +2279,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(RouteLineAppearanceFragment.TAG); } + public void dismissTrackMenu() { + FragmentManager fragmentManager = getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(TrackMenuFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); + } + } + public void backToConfigureProfileFragment() { FragmentManager fragmentManager = getSupportFragmentManager(); int backStackEntryCount = fragmentManager.getBackStackEntryCount(); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index fc4bb84f0e..e6b761eabd 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -578,6 +578,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo if (visible) { mapActivity.dismissCardDialog(); + mapActivity.dismissTrackMenu(); mapActivity.getContextMenu().hideMenues(); mapViewLocation = mapActivity.getMapLocation(); mapRotation = mapActivity.getMapRotate(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index 5fc74c9db9..80dd39f959 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -42,7 +42,7 @@ public class SelectedGpxMenuController extends MenuController { leftTitleButtonController = new TitleButtonController() { @Override public void buttonPressed() { - mapContextMenu.hide(false); + mapContextMenu.close(); WptPt wptPt = selectedGpxPoint.selectedPoint; LatLon latLon = new LatLon(wptPt.lat, wptPt.lon); SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile(); diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 2822297f2e..c79638ec56 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -14,6 +14,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.Metadata; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; @@ -25,6 +26,7 @@ import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.util.Algorithms; +import static net.osmand.AndroidUtils.dpToPx; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; import static net.osmand.plus.track.OptionsCard.APPEARANCE_BUTTON_INDEX; @@ -39,6 +41,7 @@ public class OverviewCard extends BaseCard { private View appearanceButton; private View editButton; private View directionsButton; + private TextView description; private final SegmentActionsListener actionsListener; private final SelectedGpxFile selectedGpxFile; private final GpxBlockStatisticsBuilder blockStatisticsBuilder; @@ -70,6 +73,7 @@ public class OverviewCard extends BaseCard { appearanceButton = view.findViewById(R.id.appearance_button); editButton = view.findViewById(R.id.edit_button); directionsButton = view.findViewById(R.id.directions_button); + description = view.findViewById(R.id.description); RecyclerView blocksView = view.findViewById(R.id.recycler_overview); blockStatisticsBuilder.setBlocksView(blocksView); @@ -81,6 +85,10 @@ public class OverviewCard extends BaseCard { initDirectionsButton(iconColorDef, iconColorPres); } blockStatisticsBuilder.initStatBlocks(actionsListener, getActiveColor()); + + if (blocksView.getVisibility() == View.VISIBLE && description.getVisibility() == View.VISIBLE) { + AndroidUtils.setPadding(description, 0, 0, 0, dpToPx(app, 12)); + } } private GPXFile getGPXFile() { @@ -142,7 +150,6 @@ public class OverviewCard extends BaseCard { gpxFile.metadata = new Metadata(); } - TextView description = view.findViewById(R.id.description); final String descriptionHtml = gpxFile.metadata.getDescription(); if (Algorithms.isBlank(descriptionHtml)) { AndroidUiHelper.updateVisibility(description, false); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 18d35953a0..e1a620269d 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -7,7 +7,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.res.ColorStateList; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; @@ -270,8 +269,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { MapContextMenu contextMenu = mapActivity.getContextMenu(); - if (contextMenu.isActive() && contextMenu.getPointDescription() != null - && contextMenu.getPointDescription().isGpxPoint()) { + PointDescription pointDescription = contextMenu.getPointDescription(); + if (pointDescription != null && pointDescription.isGpxPoint()) { + contextMenu.init(contextMenu.getLatLon(), pointDescription, contextMenu.getObject()); contextMenu.show(); } else if (Algorithms.objectEquals(callingFragmentTag, QuickSearchDialogFragment.TAG)) { mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false); @@ -296,6 +296,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card : app.getResources().getString(R.string.shared_string_currently_recording_track); } + public LatLon getLatLon() { + return latLon; + } + public GPXFile getGpx() { return displayHelper.getGpx(); } @@ -746,19 +750,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public int getStatusBarColorId() { - View view = getView(); - if (view != null) { - boolean nightMode = isNightMode(); - if (getViewY() <= getFullScreenTopPosY() || !isPortrait()) { - if (Build.VERSION.SDK_INT >= 23 && !nightMode) { - view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } - return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; - } else { - if (Build.VERSION.SDK_INT >= 23 && !nightMode) { - view.setSystemUiVisibility(view.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } - } + if (getViewY() <= getFullScreenTopPosY() || !isPortrait()) { + return isNightMode() ? R.color.status_bar_color_dark : R.color.status_bar_color_light; } return -1; } @@ -827,7 +820,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 items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)); if (segment != null && !Algorithms.isEmpty(items)) { SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment); @@ -1220,7 +1213,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public void gpxSavingFinished(Exception errorMessage) { if (selectedGpxFile != null) { - List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}); + List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}); selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.processPoints(app); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index 0fa8db69fb..5acf8999ba 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -268,12 +268,19 @@ public class ContextMenuLayer extends OsmandMapLayer { canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight()); contextMarker.draw(canvas); mAddGpxPointBottomSheetHelper.onDraw(box); - } else if (menu.isActive() && !markerCustomized) { - LatLon latLon = menu.getLatLon(); - int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); - int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); - canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight()); - contextMarker.draw(canvas); + } else if (!markerCustomized) { + LatLon latLon = null; + if (menu.isActive()) { + latLon = menu.getLatLon(); + } else if (activity.getTrackMenuFragment() != null) { + latLon = activity.getTrackMenuFragment().getLatLon(); + } + if (latLon != null) { + int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight()); + contextMarker.draw(canvas); + } } } @@ -283,7 +290,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public void updateContextMenu() { for (OsmandMapLayer layer : view.getLayers()) { - if (layer instanceof ContextMenuLayer.IMoveObjectProvider && ((ContextMenuLayer.IMoveObjectProvider) layer).isObjectMovable(selectedObject)) { + if (layer instanceof IMoveObjectProvider && ((IMoveObjectProvider) layer).isObjectMovable(selectedObject)) { selectedObjectContextMenuProvider = (IContextMenuProvider) layer; break; } @@ -361,8 +368,8 @@ public class ContextMenuLayer extends OsmandMapLayer { public boolean isObjectMoveable(Object o) { if (o != null && selectedObjectContextMenuProvider != null - && selectedObjectContextMenuProvider instanceof ContextMenuLayer.IMoveObjectProvider) { - final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) selectedObjectContextMenuProvider; + && selectedObjectContextMenuProvider instanceof IMoveObjectProvider) { + final IMoveObjectProvider l = (IMoveObjectProvider) selectedObjectContextMenuProvider; if (l.isObjectMovable(o)) { return true; } @@ -860,7 +867,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } boolean res = false; for (OsmandMapLayer lt : view.getLayers()) { - if (lt instanceof ContextMenuLayer.IContextMenuProvider) { + if (lt instanceof IContextMenuProvider) { if (((IContextMenuProvider) lt).disableSingleTap()) { res = true; break; @@ -878,7 +885,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } boolean res = false; for (OsmandMapLayer lt : view.getLayers()) { - if (lt instanceof ContextMenuLayer.IContextMenuProvider) { + if (lt instanceof IContextMenuProvider) { if (((IContextMenuProvider) lt).disableLongPressOnMap()) { res = true; break; @@ -924,9 +931,9 @@ public class ContextMenuLayer extends OsmandMapLayer { Map selectedObjects = new HashMap<>(); List s = new ArrayList<>(); for (OsmandMapLayer lt : view.getLayers()) { - if (lt instanceof ContextMenuLayer.IContextMenuProvider) { + if (lt instanceof IContextMenuProvider) { s.clear(); - final IContextMenuProvider l = (ContextMenuLayer.IContextMenuProvider) lt; + final IContextMenuProvider l = (IContextMenuProvider) lt; l.collectObjectsFromPoint(point, tileBox, s, unknownLocation); for (Object o : s) { selectedObjects.put(o, l);