From 2095f843bed3bbdea73ed5025c6c16bfdcba32e0 Mon Sep 17 00:00:00 2001 From: crimean Date: Mon, 6 Aug 2018 11:22:04 +0300 Subject: [PATCH] Fix possible npe --- .../plus/mapcontextmenu/MapContextMenu.java | 1 + .../other/MapMultiSelectionMenu.java | 1 + .../osmand/plus/views/MapQuickActionLayer.java | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index e850dd4db9..45e010bec5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -756,6 +756,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } + @Nullable public WeakReference findMenuFragment() { Fragment fragment = mapActivity != null ? mapActivity.getSupportFragmentManager().findFragmentByTag(MapContextMenuFragment.TAG) : null; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index e263e6ed5c..08f244b67a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -186,6 +186,7 @@ public class MapMultiSelectionMenu extends BaseMenuController { return fragment != null; } + @Nullable public Fragment getFragmentByTag() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 348e4fea0c..69a64a7687 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -10,6 +10,7 @@ import android.graphics.PointF; import android.os.Build; import android.os.Vibrator; import android.support.annotation.DimenRes; +import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v4.util.Pair; import android.view.MotionEvent; @@ -32,12 +33,15 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; +import net.osmand.plus.mapcontextmenu.MapContextMenuFragment; +import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.measurementtool.MeasurementToolLayer; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionsWidget; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -381,15 +385,20 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } private void setupQuickActionBtnVisibility() { + MapContextMenu contextMenu = mapActivity.getContextMenu(); + MapMultiSelectionMenu multiSelectionMenu = contextMenu.getMultiSelectionMenu(); + WeakReference contextMenuMenuFragmentRef = contextMenu.findMenuFragment(); + MapContextMenuFragment contextMenuMenuFragment = contextMenuMenuFragmentRef != null ? contextMenuMenuFragmentRef.get() : null; + Fragment multiMenuFragment = multiSelectionMenu.getFragmentByTag(); boolean hideQuickButton = !isLayerOn || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInGpxDetailsMode() || measurementToolLayer.isInMeasurementMode() || mapMarkersLayer.isInPlanRouteMode() || - mapActivity.getContextMenu().isVisible() && !mapActivity.getContextMenu().findMenuFragment().get().isRemoving() || - mapActivity.getContextMenu().isVisible() && mapActivity.getContextMenu().findMenuFragment().get().isAdded() || - mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isAdded() || - mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && !mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isRemoving(); + contextMenu.isVisible() && contextMenuMenuFragment != null && !contextMenuMenuFragment.isRemoving() || + contextMenu.isVisible() && contextMenuMenuFragment != null && contextMenuMenuFragment.isAdded() || + multiSelectionMenu.isVisible() && multiMenuFragment != null && multiMenuFragment.isAdded() || + multiSelectionMenu.isVisible() && multiMenuFragment != null && !multiMenuFragment.isRemoving(); quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE); }