From 6f80a83e01068ea50c2d9f4e6bf4f06530c7b135 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 13 Oct 2020 19:27:32 +0300 Subject: [PATCH] Add AIDL isFragmentOpen isMenuOpen --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 10 +++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 8 +++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 22 +++++++++++++++++++ .../osmand/plus/activities/MapActivity.java | 17 ++++++++++---- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 72a3035b60..e25e4338de 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -873,4 +873,14 @@ interface IOsmAndAidlInterface { boolean setMapMargins(in MapMarginsParams params); boolean exportProfile(in ExportProfileParams params); + + /** + * Is any fragment open. + */ + boolean isFragmentOpen(); + + /** + * Is contect menu open. + */ + boolean isMenuOpen(); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 5801fc916d..bad1f3998e 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2317,6 +2317,14 @@ public class OsmandAidlApi { return false; } + public boolean isFragmentOpen() { + return mapActivity.isFragmentVisible(); + } + + public boolean isMenuOpen() { + return mapActivity.getContextMenu().isVisible(); + } + private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index b904ef0517..78e7875d24 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1334,6 +1334,28 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public boolean isFragmentOpen() { + try { + OsmandAidlApi api = getApi("isFragmentOpen"); + return api != null && api.isFragmentOpen(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean isMenuOpen() { + try { + OsmandAidlApi api = getApi("isMenuOpen"); + return api != null && api.isMenuOpen(); + } catch (Exception e) { + handleException(e); + return false; + } + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 3c63073d89..77acb11bf0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -74,6 +74,7 @@ import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.dashboard.DashBaseFragment; import net.osmand.plus.helpers.DayNightHelper; import net.osmand.plus.settings.backend.CommonPreference; import net.osmand.plus.settings.backend.OsmandSettings; @@ -1029,15 +1030,23 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public boolean isMapVisible() { - for (Fragment fragment : getSupportFragmentManager().getFragments()) { - if (fragment.isVisible()) { - return false; - } + if (isFragmentVisible()) { + return false; } return AndroidUtils.isActivityNotDestroyed(this) && settings.MAP_ACTIVITY_ENABLED.get() && !dashboardOnMap.isVisible(); } + public boolean isFragmentVisible() { + for (Fragment fragment : getSupportFragmentManager().getFragments()) { + if (!(fragment instanceof DashBaseFragment) && fragment.isVisible() + || dashboardOnMap.isVisible()) { + return true; + } + } + return false; + } + private void restartApp() { AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setMessage(R.string.storage_permission_restart_is_required);