diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 770cc32418..a4bcc6ed1b 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -78,6 +78,7 @@ import net.osmand.aidlapi.customization.CustomizationInfoParams; import net.osmand.aidlapi.customization.ProfileSettingsParams; import net.osmand.aidlapi.customization.MapMarginsParams; import net.osmand.aidlapi.customization.CustomPluginParams; +import net.osmand.aidlapi.customization.SelectProfileParams; import net.osmand.aidlapi.gpx.AGpxFile; import net.osmand.aidlapi.gpx.AGpxFileDetails; @@ -886,4 +887,6 @@ interface IOsmAndAidlInterface { boolean isMenuOpen(); int getPluginVersion(in CustomPluginParams params); + + boolean selectProfile(in SelectProfileParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.aidl new file mode 100644 index 0000000000..5f0d089905 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.customization; + +parcelable SelectProfileParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.java new file mode 100644 index 0000000000..38d0e2abc7 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/SelectProfileParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidlapi.customization; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class SelectProfileParams extends AidlParams { + + public static final String PROFILE_ID_KEY = "profile_id"; + + private String appModeKey; + + public SelectProfileParams(String appModeKey) { + this.appModeKey = appModeKey; + } + + public SelectProfileParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public SelectProfileParams createFromParcel(Parcel in) { + return new SelectProfileParams(in); + } + + @Override + public SelectProfileParams[] newArray(int size) { + return new SelectProfileParams[size]; + } + }; + + public String getAppModeKey() { + return appModeKey; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putString(PROFILE_ID_KEY, appModeKey); + } + + @Override + protected void readFromBundle(Bundle bundle) { + appModeKey = bundle.getString(PROFILE_ID_KEY); + } +} \ 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 969e5bd135..87efbaaa1a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2337,6 +2337,16 @@ public class OsmandAidlApi { return CANNOT_ACCESS_API_ERROR; } + public boolean selectProfile(String appModeKey) { + ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null); + if (appMode != null) { +// ApplicationMode.changeProfileAvailability(appMode, true, app); + app.getSettings().APPLICATION_MODE.set(appMode); + return true; + } + return false; + } + 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 cac1426664..dc11891c3a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -28,6 +28,7 @@ import net.osmand.aidlapi.customization.MapMarginsParams; import net.osmand.aidlapi.customization.OsmandSettingsInfoParams; import net.osmand.aidlapi.customization.OsmandSettingsParams; import net.osmand.aidlapi.customization.ProfileSettingsParams; +import net.osmand.aidlapi.customization.SelectProfileParams; import net.osmand.aidlapi.customization.SetWidgetsParams; import net.osmand.aidlapi.events.AKeyEventsParams; import net.osmand.aidlapi.favorite.AFavorite; @@ -1372,6 +1373,17 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener } return CANNOT_ACCESS_API_ERROR; } + + @Override + public boolean selectProfile(SelectProfileParams params) { + try { + OsmandAidlApi api = getApi("selectProfile"); + return api != null && api.selectProfile(params.getAppModeKey()); + } catch (Exception e) { + handleException(e); + return false; + } + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) {