Merge pull request #11354 from osmandapp/track_menu_fixes

Track menu fixes
This commit is contained in:
vshcherb 2021-04-06 09:29:01 +02:00 committed by GitHub
commit 336b2a8444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 54 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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);

View file

@ -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);
}
}
return isNightMode() ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
}
return -1;
}

View file

@ -268,14 +268,21 @@ 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();
} 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);
}
}
}
public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) {
this.selectOnMap = selectOnMap;
@ -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<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
List<Object> 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);