diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index f628f6804a..095b92d241 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -93,6 +93,8 @@ import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidlapi.mapmarker.RemoveMapMarkersParams; +import net.osmand.aidlapi.quickaction.QuickActionParams; + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -834,4 +836,6 @@ interface IOsmAndAidlInterface { boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); boolean importProfile(in ProfileSettingsParams params); + + boolean executeQuickAction(in QuickActionParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.aidl new file mode 100644 index 0000000000..fa32216ce0 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.quickaction; + +parcelable QuickActionParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.java b/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.java new file mode 100644 index 0000000000..927ba128c0 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/quickaction/QuickActionParams.java @@ -0,0 +1,45 @@ +package net.osmand.aidlapi.quickaction; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class QuickActionParams extends AidlParams { + + private int actionNumber; + + public QuickActionParams(int actionNumber) { + this.actionNumber = actionNumber; + } + + public QuickActionParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public QuickActionParams createFromParcel(Parcel in) { + return new QuickActionParams(in); + } + + @Override + public QuickActionParams[] newArray(int size) { + return new QuickActionParams[size]; + } + }; + + public int getActionNumber() { + return actionNumber; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putInt("actionNumber", actionNumber); + } + + @Override + protected void readFromBundle(Bundle bundle) { + actionNumber = bundle.getInt("actionNumber"); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index d01667b04d..c5603a5914 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -94,6 +94,8 @@ import net.osmand.aidl.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidl.mapmarker.RemoveMapMarkersParams; +import net.osmand.aidl.quickaction.QuickActionParams; + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -849,4 +851,6 @@ interface IOsmAndAidlInterface { boolean getGpxColor(inout GpxColorParams params); boolean importProfile(in ProfileSettingsParams params); + + boolean executeQuickAction(in QuickActionParams params); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 9404442c1d..e2b91edc81 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -63,6 +63,8 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.IContextMenuButtonListener; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.TrackBitmapDrawer; +import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.routing.IRoutingDataUpdateListener; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; @@ -167,6 +169,9 @@ public class OsmandAidlApi { private static final String AIDL_HIDE_SQLITEDB_FILE = "aidl_hide_sqlitedb_file"; private static final String AIDL_FILE_NAME = "aidl_file_name"; + private static final String AIDL_EXECUTE_QUICK_ACTION = "aidl_execute_quick_action"; + private static final String AIDL_QUICK_ACTION_NUMBER = "aidl_quick_action_number"; + private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; @@ -216,6 +221,7 @@ public class OsmandAidlApi { registerUnmuteNavigationReceiver(mapActivity); registerShowSqliteDbFileReceiver(mapActivity); registerHideSqliteDbFileReceiver(mapActivity); + registerExecuteQuickActionReceiver(mapActivity); initOsmandTelegram(); app.getAppCustomization().addListener(mapActivity); aMapPointUpdateListener = mapActivity; @@ -824,6 +830,24 @@ public class OsmandAidlApi { registerReceiver(hideSqliteDbFileReceiver, mapActivity, AIDL_HIDE_SQLITEDB_FILE); } + private void registerExecuteQuickActionReceiver(MapActivity mapActivity) { + final WeakReference mapActivityRef = new WeakReference<>(mapActivity); + BroadcastReceiver executeQuickActionReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int actionNumber = intent.getIntExtra(AIDL_QUICK_ACTION_NUMBER, -1); + MapActivity mapActivity = mapActivityRef.get(); + if (actionNumber != -1 && mapActivity != null) { + List actionsList = app.getQuickActionRegistry().getFilteredQuickActions(); + if (actionNumber < actionsList.size()) { + QuickActionRegistry.produceAction(actionsList.get(actionNumber)).execute(mapActivity); + } + } + } + }; + registerReceiver(executeQuickActionReceiver, mapActivity, AIDL_EXECUTE_QUICK_ACTION); + } + public void registerMapLayers(@NonNull MapActivity mapActivity) { for (ConnectedApp connectedApp : connectedApps.values()) { connectedApp.registerMapLayers(mapActivity); @@ -2110,6 +2134,14 @@ public class OsmandAidlApi { } } + public boolean executeQuickAction(int actionNumber) { + Intent intent = new Intent(); + intent.setAction(AIDL_EXECUTE_QUICK_ACTION); + intent.putExtra(AIDL_QUICK_ACTION_NUMBER, actionNumber); + app.sendBroadcast(intent); + return true; + } + private class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 6fc69f9328..69c46c0db6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -80,6 +80,7 @@ import net.osmand.aidl.note.StartVideoRecordingParams; import net.osmand.aidl.note.StopRecordingParams; import net.osmand.aidl.note.TakePhotoNoteParams; import net.osmand.aidl.plugins.PluginParams; +import net.osmand.aidl.quickaction.QuickActionParams; import net.osmand.aidl.search.SearchParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -1302,6 +1303,17 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return false; } } + + @Override + public boolean executeQuickAction(QuickActionParams params) { + try { + OsmandAidlApi api = getApi("executeQuickAction"); + return api != null && api.executeQuickAction(params.getActionNumber()); + } catch (Exception e) { + handleException(e); + return false; + } + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 21b80c229d..6d0f545d34 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -81,6 +81,7 @@ import net.osmand.aidlapi.note.StartVideoRecordingParams; import net.osmand.aidlapi.note.StopRecordingParams; import net.osmand.aidlapi.note.TakePhotoNoteParams; import net.osmand.aidlapi.plugins.PluginParams; +import net.osmand.aidlapi.quickaction.QuickActionParams; import net.osmand.aidlapi.search.SearchParams; import net.osmand.aidlapi.search.SearchResult; import net.osmand.aidlapi.tiles.ASqliteDbFile; @@ -1235,6 +1236,17 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public boolean executeQuickAction(QuickActionParams params) { + try { + OsmandAidlApi api = getApi("executeQuickAction"); + return api != null && api.executeQuickAction(params.getActionNumber()); + } catch (Exception e) { + handleException(e); + return false; + } + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.aidl b/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.aidl new file mode 100644 index 0000000000..2a2fca38d8 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.quickaction; + +parcelable QuickActionParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.java b/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.java new file mode 100644 index 0000000000..b9fd262600 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/quickaction/QuickActionParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.quickaction; + +import android.os.Parcel; +import android.os.Parcelable; + +public class QuickActionParams implements Parcelable { + + private int actionNumber; + + public QuickActionParams(int actionNumber) { + this.actionNumber = actionNumber; + } + + public QuickActionParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public QuickActionParams createFromParcel(Parcel in) { + return new QuickActionParams(in); + } + + @Override + public QuickActionParams[] newArray(int size) { + return new QuickActionParams[size]; + } + }; + + public int getActionNumber() { + return actionNumber; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(actionNumber); + } + + private void readFromParcel(Parcel in) { + actionNumber = in.readInt(); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file