From f170bda5093f320c7aea7ff38aaf3d5d20932689 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 11 Dec 2020 10:28:00 +0200 Subject: [PATCH] Add getProfiles method to aidl --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 3 + .../aidlapi/customization/AProfile.aidl | 3 + .../aidlapi/customization/AProfile.java | 129 ++++++++++++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 18 ++- .../net/osmand/aidl/OsmandAidlServiceV2.java | 12 ++ .../settings/backend/ApplicationMode.java | 2 +- 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index a4bcc6ed1b..ca19b48c83 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -79,6 +79,7 @@ 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.customization.AProfile; import net.osmand.aidlapi.gpx.AGpxFile; import net.osmand.aidlapi.gpx.AGpxFileDetails; @@ -889,4 +890,6 @@ interface IOsmAndAidlInterface { int getPluginVersion(in CustomPluginParams params); boolean selectProfile(in SelectProfileParams params); + + boolean getProfiles(out List profiles); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.aidl b/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.aidl new file mode 100644 index 0000000000..43e0fe47bf --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.customization; + +parcelable AProfile; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.java new file mode 100644 index 0000000000..6678e42967 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/AProfile.java @@ -0,0 +1,129 @@ +package net.osmand.aidlapi.customization; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class AProfile extends AidlParams { + + public static final String PROFILE_ID_KEY = "profile_id"; + public static final String USER_PROFILE_NAME_KEY = "user_profile_name"; + public static final String PARENT_KEY = "parent"; + public static final String ICON_NAME_KEY = "icon_name"; + public static final String ICON_COLOR_KEY = "icon_color"; + public static final String ROUTING_PROFILE_KEY = "routing_profile"; + public static final String ROUTE_SERVICE_KEY = "route_service"; + public static final String LOC_ICON_KEY = "loc_icon"; + public static final String NAV_ICON_KEY = "nav_icon"; + public static final String ORDER_KEY = "order"; + + private String appModeKey; + private String userProfileName; + private String parent; + private String iconName; + private String iconColor; + private String routingProfile; + private String routeService; + private String locIcon; + private String navIcon; + private int order = -1; + + public AProfile(String appModeKey, String userProfileName, String parent, String iconName, String iconColor, + String routingProfile, String routeService, String locIcon, String navIcon, int order) { + this.appModeKey = appModeKey; + this.userProfileName = userProfileName; + this.parent = parent; + this.iconName = iconName; + this.iconColor = iconColor; + this.routingProfile = routingProfile; + this.routeService = routeService; + this.locIcon = locIcon; + this.navIcon = navIcon; + this.order = order; + } + + public AProfile(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AProfile createFromParcel(Parcel in) { + return new AProfile(in); + } + + @Override + public AProfile[] newArray(int size) { + return new AProfile[size]; + } + }; + + public String getStringKey() { + return appModeKey; + } + + public String getUserProfileName() { + return userProfileName; + } + + public String getParent() { + return parent; + } + + public String getIconName() { + return iconName; + } + + public String getIconColor() { + return iconColor; + } + + public String getRoutingProfile() { + return routingProfile; + } + + public String getRouteService() { + return routeService; + } + + public String getLocIcon() { + return locIcon; + } + + public String getNavIcon() { + return navIcon; + } + + public int getOrder() { + return order; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putString(PROFILE_ID_KEY, appModeKey); + bundle.putString(USER_PROFILE_NAME_KEY, userProfileName); + bundle.putString(PARENT_KEY, parent); + bundle.putString(ICON_NAME_KEY, iconName); + bundle.putString(ICON_COLOR_KEY, iconColor); + bundle.putString(ROUTING_PROFILE_KEY, routingProfile); + bundle.putString(ROUTE_SERVICE_KEY, routeService); + bundle.putString(LOC_ICON_KEY, locIcon); + bundle.putString(NAV_ICON_KEY, navIcon); + bundle.putInt(ORDER_KEY, order); + } + + @Override + protected void readFromBundle(Bundle bundle) { + appModeKey = bundle.getString(PROFILE_ID_KEY); + userProfileName = bundle.getString(USER_PROFILE_NAME_KEY); + parent = bundle.getString(PARENT_KEY); + iconName = bundle.getString(ICON_NAME_KEY); + iconColor = bundle.getString(ICON_COLOR_KEY); + routingProfile = bundle.getString(ROUTING_PROFILE_KEY); + routeService = bundle.getString(ROUTE_SERVICE_KEY); + locIcon = bundle.getString(LOC_ICON_KEY); + navIcon = bundle.getString(NAV_ICON_KEY); + order = bundle.getInt(ORDER_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 87efbaaa1a..efafacf012 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -40,6 +40,7 @@ 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.customization.AProfile; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.map.ALatLon; import net.osmand.data.FavouritePoint; @@ -79,6 +80,7 @@ import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.VoiceRouter; import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.OsmandSettings; @@ -2340,13 +2342,27 @@ public class OsmandAidlApi { public boolean selectProfile(String appModeKey) { ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null); if (appMode != null) { -// ApplicationMode.changeProfileAvailability(appMode, true, app); + if (!ApplicationMode.values(app).contains(appMode)) { + ApplicationMode.changeProfileAvailability(appMode, true, app); + } app.getSettings().APPLICATION_MODE.set(appMode); return true; } return false; } + public boolean getProfiles(List profiles) { + for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { + ApplicationModeBean bean = mode.toModeBean(); + AProfile aProfile = new AProfile(bean.stringKey, bean.userProfileName, bean.parent, bean.iconName, + bean.iconColor.name(), bean.routingProfile, bean.routeService.name(), bean.locIcon.name(), + bean.navIcon.name(), bean.order); + + profiles.add(aProfile); + } + return true; + } + 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 dc11891c3a..9943257c03 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.customization.AProfile; import net.osmand.aidlapi.customization.CustomPluginParams; import net.osmand.aidlapi.customization.CustomizationInfoParams; import net.osmand.aidlapi.customization.MapMarginsParams; @@ -1384,6 +1385,17 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public boolean getProfiles(List profiles) { + try { + OsmandAidlApi api = getApi("getProfiles"); + return api != null && api.getProfiles(profiles); + } catch (Exception e) { + handleException(e); + return false; + } + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java index 8c64654b41..5db3ef44c7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java @@ -786,6 +786,6 @@ public class ApplicationMode { @Expose public NavigationIcon navIcon = null; @Expose - int order = -1; + public int order = -1; } } \ No newline at end of file