diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 45b4e8c105..7b152c5ec5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -657,14 +657,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven closeDrawer(); return; } - if (getQuickSearchDialogFragment() != null) { - showQuickSearch(ShowQuickSearchMode.CURRENT, false); - return; - } if (getMapLayers().getContextMenuLayer().isInAddGpxPointMode()) { quitAddGpxPointMode(); } - if (launchPrevActivityIntent()) { + if (!getOnBackPressedDispatcher().hasEnabledCallbacks() && launchPrevActivityIntent()) { return; } super.onBackPressed(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 7a53629f4d..5f88a13607 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -168,17 +168,21 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { - public void handleOnBackPressed() { - if (menu.isVisible() && menu.isClosable()) { - if (menu.getCurrentMenuState() != MenuState.HEADER_ONLY && !menu.isLandscapeLayout()) { - menu.openMenuHeaderOnly(); - } else { - menu.close(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + boolean enabled = mapActivity.getQuickSearchDialogFragment() == null; + mapActivity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(enabled) { + public void handleOnBackPressed() { + if (menu.isVisible() && menu.isClosable()) { + if (menu.getCurrentMenuState() != MenuState.HEADER_ONLY && !menu.isLandscapeLayout()) { + menu.openMenuHeaderOnly(); + } else { + menu.close(); + } } } - } - }); + }); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 0e34a4ca35..3c55261668 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -34,6 +34,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -41,6 +42,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentTransaction; @@ -232,13 +234,24 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + FragmentActivity activity = requireActivity(); app = getMyApplication(); nightMode = !app.getSettings().isLightContent(); navigationInfo = new NavigationInfo(app); - accessibilityAssistant = new AccessibilityAssistant(getActivity()); + accessibilityAssistant = new AccessibilityAssistant(activity); + boolean isLightTheme = app.getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); + + activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { + public void handleOnBackPressed() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false); + } + } + }); } @Override