From a60a85d1561cc11d07be67923e9baf036b48d40d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 5 Aug 2020 14:12:36 +0300 Subject: [PATCH] Add aidl getAppInfo --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 4 + .../osmand/aidlapi/info/AppInfoParams.aidl | 3 + .../osmand/aidlapi/info/AppInfoParams.java | 86 +++++++++++++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 47 ++++++++-- .../net/osmand/aidl/OsmandAidlServiceV2.java | 12 +++ .../osmand/plus/activities/MapActivity.java | 10 ++- 6 files changed, 152 insertions(+), 10 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index c9974dd2c9..475093644e 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -100,6 +100,8 @@ import net.osmand.aidlapi.lock.SetLockStateParams; import net.osmand.aidlapi.events.AKeyEventsParams; +import net.osmand.aidlapi.info.AppInfoParams; + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -860,4 +862,6 @@ interface IOsmAndAidlInterface { * @params keyEventList (List) - list of requested key events */ long registerForKeyEvents(in AKeyEventsParams params, IOsmAndAidlCallback callback); + + AppInfoParams getAppInfo(); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.aidl new file mode 100644 index 0000000000..0030d5376c --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.info; + +parcelable AppInfoParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java new file mode 100644 index 0000000000..13eb6f2292 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java @@ -0,0 +1,86 @@ +package net.osmand.aidlapi.info; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; +import net.osmand.aidlapi.map.ALatLon; + +public class AppInfoParams extends AidlParams { + + private ALatLon lastKnownLocation; + private ALatLon mapLocation; + private int time; + private long eta; + private int leftDistance; + private boolean mapVisible; + + public AppInfoParams(ALatLon lastKnownLocation, ALatLon mapLocation, int time, long eta, int leftDistance, boolean mapVisible) { + this.lastKnownLocation = lastKnownLocation; + this.mapLocation = mapLocation; + this.time = time; + this.eta = eta; + this.leftDistance = leftDistance; + this.mapVisible = mapVisible; + } + + public AppInfoParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AppInfoParams createFromParcel(Parcel in) { + return new AppInfoParams(in); + } + + @Override + public AppInfoParams[] newArray(int size) { + return new AppInfoParams[size]; + } + }; + + public ALatLon getLastKnownLocation() { + return lastKnownLocation; + } + + public ALatLon getMapLocation() { + return mapLocation; + } + + public int getTime() { + return time; + } + + public long getEta() { + return eta; + } + + public int getLeftDistance() { + return leftDistance; + } + + public boolean isMapVisible() { + return mapVisible; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putParcelable("location", lastKnownLocation); + bundle.putParcelable("mapLocation", mapLocation); + bundle.putInt("time", time); + bundle.putLong("eta", eta); + bundle.putInt("leftDistance", leftDistance); + bundle.putBoolean("mapVisible", mapVisible); + } + + @Override + protected void readFromBundle(Bundle bundle) { + lastKnownLocation = bundle.getParcelable("location"); + mapLocation = bundle.getParcelable("mapLocation"); + time = bundle.getInt("time"); + eta = bundle.getLong("eta"); + leftDistance = bundle.getInt("leftDistance"); + mapVisible = bundle.getBoolean("mapVisible"); + } +} \ 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 3f8ccb9447..f36cbad0ea 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -30,6 +30,7 @@ import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.gpx.AGpxFile; import net.osmand.aidl.gpx.AGpxFileDetails; @@ -38,6 +39,8 @@ import net.osmand.aidl.navigation.ADirectionInfo; import net.osmand.aidl.navigation.OnVoiceNavigationParams; import net.osmand.aidl.quickaction.QuickActionInfoParams; import net.osmand.aidl.tiles.ASqliteDbFile; +import net.osmand.aidlapi.info.AppInfoParams; +import net.osmand.aidlapi.map.ALatLon; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -76,10 +79,10 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.SettingsHelper; -import net.osmand.plus.views.layers.AidlMapLayer; -import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.layers.AidlMapLayer; +import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; import net.osmand.router.TurnType; import net.osmand.util.Algorithms; @@ -202,7 +205,7 @@ public class OsmandAidlApi { private Map contextMenuButtonsParams = new ConcurrentHashMap<>(); private Map voiceRouterMessageCallbacks = new ConcurrentHashMap<>(); - private AMapPointUpdateListener aMapPointUpdateListener; + private MapActivity mapActivity; private boolean mapActivityActive = false; @@ -238,12 +241,12 @@ public class OsmandAidlApi { registerLockStateReceiver(mapActivity); initOsmandTelegram(); app.getAppCustomization().addListener(mapActivity); - aMapPointUpdateListener = mapActivity; + this.mapActivity = mapActivity; } public void onDestroyMapActivity(MapActivity mapActivity) { app.getAppCustomization().removeListener(mapActivity); - aMapPointUpdateListener = null; + this.mapActivity = null; mapActivityActive = false; for (BroadcastReceiver b : receivers.values()) { if (b == null) { @@ -263,7 +266,7 @@ public class OsmandAidlApi { } AMapPointUpdateListener getAMapPointUpdateListener() { - return aMapPointUpdateListener; + return mapActivity; } private void initOsmandTelegram() { @@ -309,7 +312,7 @@ public class OsmandAidlApi { zoom = zoom > mapView.getMaxZoom() ? mapView.getMaxZoom() : zoom; zoom = zoom < mapView.getMinZoom() ? mapView.getMinZoom() : zoom; } - if(!Float.isNaN(rotation)) { + if (!Float.isNaN(rotation)) { mapView.setRotate(rotation, false); } if (animated) { @@ -1714,6 +1717,36 @@ public class OsmandAidlApi { return true; } + AppInfoParams getAppInfo() { + ALatLon lastKnownLocation = null; + Location location = app.getLocationProvider().getLastKnownLocation(); + if (location != null) { + lastKnownLocation = new ALatLon(location.getLatitude(), location.getLongitude()); + } + + boolean mapVisible = false; + ALatLon mapLocation = null; + if (mapActivity != null) { + LatLon mapLoc = mapActivity.getMapLocation(); + if (mapLoc != null) { + mapLocation = new ALatLon(mapLoc.getLatitude(), mapLoc.getLongitude()); + } + mapVisible = mapActivity.isMapVisible(); + } + + int time = 0; + long eta = 0; + int leftDistance = 0; + + RoutingHelper routingHelper = app.getRoutingHelper(); + if (routingHelper.isRouteCalculated()) { + time = routingHelper.getLeftTime(); + eta = time + System.currentTimeMillis() / 1000; + leftDistance = routingHelper.getLeftDistance(); + } + return new AppInfoParams(lastKnownLocation, mapLocation, time, eta, leftDistance, mapVisible); + } + boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude, final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index e8ca7291c2..1a4f675d52 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -22,6 +22,7 @@ import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams; import net.osmand.aidlapi.copyfile.CopyFileParams; +import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.customization.CustomizationInfoParams; import net.osmand.aidlapi.customization.OsmandSettingsInfoParams; import net.osmand.aidlapi.customization.OsmandSettingsParams; @@ -1295,6 +1296,17 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public AppInfoParams getAppInfo() { + try { + OsmandAidlApi api = getApi("getAppInfo"); + return api != null ? api.getAppInfo() : null; + } catch (Exception e) { + handleException(e); + return null; + } + } }; 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 87fb588e9d..80d6a9bf72 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -147,15 +147,15 @@ import net.osmand.plus.settings.fragments.ProfileAppearanceFragment; import net.osmand.plus.track.TrackAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; -import net.osmand.plus.views.layers.MapControlsLayer; -import net.osmand.plus.views.layers.MapInfoLayer; -import net.osmand.plus.views.layers.MapQuickActionLayer; import net.osmand.plus.views.OsmAndMapLayersView; import net.osmand.plus.views.OsmAndMapSurfaceView; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView.OnDrawMapListener; import net.osmand.plus.views.corenative.NativeCoreContext; +import net.osmand.plus.views.layers.MapControlsLayer; +import net.osmand.plus.views.layers.MapInfoLayer; +import net.osmand.plus.views.layers.MapQuickActionLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.render.RenderingRulesStorage; @@ -1119,6 +1119,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return mIsDestroyed; } + public boolean isMapVisible() { + return AndroidUtils.isActivityNotDestroyed(this) && settings.MAP_ACTIVITY_ENABLED.get(); + } + private void restartApp() { AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setMessage(R.string.storage_permission_restart_is_required);