Added api for osmand settings customization
This commit is contained in:
parent
3d7df19a7b
commit
e6066ef551
22 changed files with 582 additions and 103 deletions
|
@ -67,6 +67,9 @@ import net.osmand.aidl.search.SearchResult;
|
|||
import net.osmand.aidl.search.SearchParams;
|
||||
import net.osmand.aidl.navigation.NavigateSearchParams;
|
||||
|
||||
import net.osmand.aidl.customization.SetWidgetsParams;
|
||||
import net.osmand.aidl.customization.OsmandSettingsParams;
|
||||
|
||||
// NOTE: Add new methods at the end of file!!!
|
||||
|
||||
interface IOsmAndAidlInterface {
|
||||
|
@ -140,4 +143,9 @@ interface IOsmAndAidlInterface {
|
|||
boolean setDisabledIds(in List<String> ids);
|
||||
boolean setEnabledPatterns(in List<String> patterns);
|
||||
boolean setDisabledPatterns(in List<String> patterns);
|
||||
|
||||
boolean regWidgetVisibility(in SetWidgetsParams params);
|
||||
boolean regWidgetAvailability(in SetWidgetsParams params);
|
||||
|
||||
boolean customizeOsmandSettings(in OsmandSettingsParams params);
|
||||
}
|
|
@ -14,6 +14,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -84,10 +85,12 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -1664,22 +1667,37 @@ public class OsmandAidlApi {
|
|||
}
|
||||
|
||||
boolean setEnabledIds(Collection<String> ids) {
|
||||
app.getAppCustomization().setEnabledIds(ids);
|
||||
app.getAppCustomization().setFeaturesEnabledIds(ids);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean setDisabledIds(Collection<String> ids) {
|
||||
app.getAppCustomization().setDisabledIds(ids);
|
||||
app.getAppCustomization().setFeaturesDisabledIds(ids);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean setEnabledPatterns(Collection<String> patterns) {
|
||||
app.getAppCustomization().setEnabledPatterns(patterns);
|
||||
app.getAppCustomization().setFeaturesEnabledPatterns(patterns);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean setDisabledPatterns(Collection<String> patterns) {
|
||||
app.getAppCustomization().setDisabledPatterns(patterns);
|
||||
app.getAppCustomization().setFeaturesDisabledPatterns(patterns);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean regWidgetVisibility(@NonNull String widgetId, @Nullable List<String> appModeKeys) {
|
||||
app.getAppCustomization().regWidgetVisibility(widgetId, appModeKeys);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean regWidgetAvailability(@NonNull String widgetId, @Nullable List<String> appModeKeys) {
|
||||
app.getAppCustomization().regWidgetAvailability(widgetId, appModeKeys);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean customizeOsmandSettings(@NonNull String sharedPreferencesName, @Nullable Bundle bundle) {
|
||||
app.getAppCustomization().customizeOsmandSettings(sharedPreferencesName, bundle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import android.support.annotation.Nullable;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback;
|
||||
import net.osmand.aidl.calculateroute.CalculateRouteParams;
|
||||
import net.osmand.aidl.customization.OsmandSettingsParams;
|
||||
import net.osmand.aidl.customization.SetWidgetsParams;
|
||||
import net.osmand.aidl.favorite.AddFavoriteParams;
|
||||
import net.osmand.aidl.favorite.RemoveFavoriteParams;
|
||||
import net.osmand.aidl.favorite.UpdateFavoriteParams;
|
||||
|
@ -679,25 +681,25 @@ public class OsmandAidlService extends Service {
|
|||
|
||||
@Override
|
||||
public boolean setEnabledIds(List<String> ids) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("setEnabledIds");
|
||||
OsmandAidlApi api = getApi("setFeaturesEnabledIds");
|
||||
return api != null && api.setEnabledIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisabledIds(List<String> ids) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("setDisabledIds");
|
||||
OsmandAidlApi api = getApi("setFeaturesDisabledIds");
|
||||
return api != null && api.setDisabledIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setEnabledPatterns(List<String> patterns) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("setEnabledPatterns");
|
||||
OsmandAidlApi api = getApi("setFeaturesEnabledPatterns");
|
||||
return api != null && api.setEnabledPatterns(patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisabledPatterns(List<String> patterns) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("setDisabledPatterns");
|
||||
OsmandAidlApi api = getApi("setFeaturesDisabledPatterns");
|
||||
return api != null && api.setDisabledPatterns(patterns);
|
||||
}
|
||||
|
||||
|
@ -719,5 +721,23 @@ public class OsmandAidlService extends Service {
|
|||
}
|
||||
}, updateTimeMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regWidgetVisibility(SetWidgetsParams params) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("regWidgetVisibility");
|
||||
return api != null && api.regWidgetVisibility(params.getWidgetKey(), params.getAppModesKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regWidgetAvailability(SetWidgetsParams params) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("regWidgetVisibility");
|
||||
return api != null && api.regWidgetAvailability(params.getWidgetKey(), params.getAppModesKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean customizeOsmandSettings(OsmandSettingsParams params) throws RemoteException {
|
||||
OsmandAidlApi api = getApi("customizeOsmandSettings");
|
||||
return api != null && api.customizeOsmandSettings(params.getSharedPreferencesName(), params.getBundle());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
parcelable OsmandSettingsParams;
|
|
@ -0,0 +1,60 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class OsmandSettingsParams implements Parcelable {
|
||||
|
||||
private String sharedPreferencesName;
|
||||
private Bundle bundle;
|
||||
|
||||
public OsmandSettingsParams(@NonNull String sharedPreferencesName, @Nullable Bundle bundle) {
|
||||
this.sharedPreferencesName = sharedPreferencesName;
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
public OsmandSettingsParams(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<OsmandSettingsParams> CREATOR = new Creator<OsmandSettingsParams>() {
|
||||
@Override
|
||||
public OsmandSettingsParams createFromParcel(Parcel in) {
|
||||
return new OsmandSettingsParams(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OsmandSettingsParams[] newArray(int size) {
|
||||
return new OsmandSettingsParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getSharedPreferencesName() {
|
||||
return sharedPreferencesName;
|
||||
}
|
||||
|
||||
public Bundle getBundle() {
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(sharedPreferencesName);
|
||||
out.writeBundle(bundle);
|
||||
}
|
||||
|
||||
@SuppressLint("ParcelClassLoader")
|
||||
private void readFromParcel(Parcel in) {
|
||||
sharedPreferencesName = in.readString();
|
||||
bundle = in.readBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
parcelable SetWidgetsParams;
|
|
@ -0,0 +1,93 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetWidgetsParams implements Parcelable {
|
||||
|
||||
private String widgetKey;
|
||||
private List<String> appModesKeys;
|
||||
|
||||
public SetWidgetsParams(String widgetKey, @Nullable List<String> appModesKeys) {
|
||||
this.widgetKey = widgetKey;
|
||||
this.appModesKeys = appModesKeys;
|
||||
}
|
||||
|
||||
public SetWidgetsParams(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<SetWidgetsParams> CREATOR = new Creator<SetWidgetsParams>() {
|
||||
@Override
|
||||
public SetWidgetsParams createFromParcel(Parcel in) {
|
||||
return new SetWidgetsParams(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetWidgetsParams[] newArray(int size) {
|
||||
return new SetWidgetsParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getWidgetKey() {
|
||||
return widgetKey;
|
||||
}
|
||||
|
||||
public List<String> getAppModesKeys() {
|
||||
return appModesKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(widgetKey);
|
||||
writeStringList(out, appModesKeys);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel in) {
|
||||
widgetKey = in.readString();
|
||||
appModesKeys = readStringList(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void writeStringList(Parcel out, List<String> val) {
|
||||
if (val == null) {
|
||||
out.writeInt(-1);
|
||||
return;
|
||||
}
|
||||
int N = val.size();
|
||||
int i = 0;
|
||||
out.writeInt(N);
|
||||
while (i < N) {
|
||||
out.writeString(val.get(i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> readStringList(Parcel in) {
|
||||
List<String> list = new ArrayList<>();
|
||||
int M = list.size();
|
||||
int N = in.readInt();
|
||||
if (N == -1) {
|
||||
return null;
|
||||
}
|
||||
int i = 0;
|
||||
for (; i < M && i < N; i++) {
|
||||
list.set(i, in.readString());
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
list.add(in.readString());
|
||||
}
|
||||
for (; i < M; i++) {
|
||||
list.remove(N);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -187,19 +187,29 @@ public class ApplicationMode {
|
|||
this.stringKey = stringKey;
|
||||
}
|
||||
|
||||
public static List<ApplicationMode> values(OsmandSettings settings) {
|
||||
public static List<ApplicationMode> values(OsmandApplication app) {
|
||||
if (customizationListener == null) {
|
||||
customizationListener = new OsmAndAppCustomization.OsmAndAppCustomizationListener() {
|
||||
@Override
|
||||
public void onOsmAndSettingsCustomized() {
|
||||
cachedFilteredValues = new ArrayList<>();
|
||||
}
|
||||
};
|
||||
app.getAppCustomization().addListener(customizationListener);
|
||||
}
|
||||
if (cachedFilteredValues.isEmpty()) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (listener == null) {
|
||||
listener = new StateChangedListener<String>() {
|
||||
@Override
|
||||
public void stateChanged(String change) {
|
||||
cachedFilteredValues = new ArrayList<ApplicationMode>();
|
||||
cachedFilteredValues = new ArrayList<>();
|
||||
}
|
||||
};
|
||||
settings.AVAILABLE_APP_MODES.addListener(listener);
|
||||
}
|
||||
String available = settings.AVAILABLE_APP_MODES.get();
|
||||
cachedFilteredValues = new ArrayList<ApplicationMode>();
|
||||
cachedFilteredValues = new ArrayList<>();
|
||||
for (ApplicationMode v : values) {
|
||||
if (available.indexOf(v.getStringKey() + ",") != -1 || v == DEFAULT) {
|
||||
cachedFilteredValues.add(v);
|
||||
|
@ -236,7 +246,10 @@ public class ApplicationMode {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean isWidgetVisible(String key) {
|
||||
public boolean isWidgetVisible(OsmandApplication app, String key) {
|
||||
if (app.getAppCustomization().areWidgetsCustomized()) {
|
||||
return app.getAppCustomization().isWidgetVisible(key, this);
|
||||
}
|
||||
Set<ApplicationMode> set = widgetsVisibilityMap.get(key);
|
||||
if (set == null) {
|
||||
return false;
|
||||
|
@ -261,7 +274,10 @@ public class ApplicationMode {
|
|||
return set;
|
||||
}
|
||||
|
||||
public boolean isWidgetAvailable(String key) {
|
||||
public boolean isWidgetAvailable(OsmandApplication app, String key) {
|
||||
if (app.getAppCustomization().areWidgetsCustomized()) {
|
||||
return app.getAppCustomization().isWidgetAvailable(key, this);
|
||||
}
|
||||
Set<ApplicationMode> set = widgetsAvailabilityMap.get(key);
|
||||
if (set == null) {
|
||||
return true;
|
||||
|
@ -393,4 +409,5 @@ public class ApplicationMode {
|
|||
private int locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
||||
private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
||||
private static StateChangedListener<String> listener;
|
||||
private static OsmAndAppCustomization.OsmAndAppCustomizationListener customizationListener;
|
||||
}
|
|
@ -4,6 +4,8 @@ import android.app.Activity;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
@ -25,9 +27,11 @@ import java.io.File;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -39,12 +43,43 @@ public class OsmAndAppCustomization {
|
|||
|
||||
private Bitmap navDrawerLogo;
|
||||
|
||||
private Set<String> enabledIds = new HashSet<>();
|
||||
private Set<String> disabledIds = new HashSet<>();
|
||||
private Set<String> enabledPatterns = new HashSet<>();
|
||||
private Set<String> disabledPatterns = new HashSet<>();
|
||||
private Set<String> featuresEnabledIds = new HashSet<>();
|
||||
private Set<String> featuresDisabledIds = new HashSet<>();
|
||||
private Set<String> featuresEnabledPatterns = new HashSet<>();
|
||||
private Set<String> featuresDisabledPatterns = new HashSet<>();
|
||||
private Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
|
||||
private Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
|
||||
private CustomOsmandSettings customOsmandSettings;
|
||||
|
||||
private boolean customizationEnabled;
|
||||
private boolean featuresCustomized;
|
||||
private boolean widgetsCustomized;
|
||||
|
||||
private List<OsmAndAppCustomizationListener> listeners = new ArrayList<>();
|
||||
|
||||
public interface OsmAndAppCustomizationListener {
|
||||
|
||||
void onOsmAndSettingsCustomized();
|
||||
}
|
||||
|
||||
public static class CustomOsmandSettings {
|
||||
private String sharedPreferencesName;
|
||||
private OsmandSettings settings;
|
||||
|
||||
CustomOsmandSettings(OsmandApplication app, String sharedPreferencesName, Bundle bundle) {
|
||||
this.sharedPreferencesName = sharedPreferencesName;
|
||||
this.settings = new OsmandSettings(app, new net.osmand.plus.api.SettingsAPIImpl(app), sharedPreferencesName);
|
||||
if (bundle != null) {
|
||||
for (String key : bundle.keySet()) {
|
||||
Object object = bundle.get(key);
|
||||
this.settings.setPreference(key, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OsmandSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
public void setup(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -52,7 +87,25 @@ public class OsmAndAppCustomization {
|
|||
}
|
||||
|
||||
public OsmandSettings getOsmandSettings() {
|
||||
return osmandSettings;
|
||||
return customOsmandSettings != null ? customOsmandSettings.getSettings() : osmandSettings;
|
||||
}
|
||||
|
||||
public void customizeOsmandSettings(@NonNull String sharedPreferencesName, @Nullable Bundle bundle) {
|
||||
customOsmandSettings = new CustomOsmandSettings(app, sharedPreferencesName, bundle);
|
||||
OsmandSettings newSettings = customOsmandSettings.getSettings();
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
if (osmandSettings.isExternalStorageDirectorySpecifiedPre19()) {
|
||||
File externalStorageDirectory = osmandSettings.getExternalStorageDirectoryPre19();
|
||||
newSettings.setExternalStorageDirectoryPre19(externalStorageDirectory.getAbsolutePath());
|
||||
}
|
||||
} else if (osmandSettings.isExternalStorageDirectoryTypeSpecifiedV19()
|
||||
&& osmandSettings.isExternalStorageDirectorySpecifiedV19()) {
|
||||
int type = osmandSettings.getExternalStorageDirectoryTypeV19();
|
||||
String directory = osmandSettings.getExternalStorageDirectoryV19();
|
||||
newSettings.setExternalStorageDirectoryV19(type, directory);
|
||||
}
|
||||
app.setOsmandSettings(newSettings);
|
||||
notifySettingsCustomized();
|
||||
}
|
||||
|
||||
// Activities
|
||||
|
@ -145,49 +198,109 @@ public class OsmAndAppCustomization {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void setEnabledIds(@NonNull Collection<String> ids) {
|
||||
enabledIds.clear();
|
||||
enabledIds.addAll(ids);
|
||||
updateCustomizationEnabled();
|
||||
public void setFeaturesEnabledIds(@NonNull Collection<String> ids) {
|
||||
featuresEnabledIds.clear();
|
||||
featuresEnabledIds.addAll(ids);
|
||||
setFeaturesCustomized();
|
||||
}
|
||||
|
||||
public void setDisabledIds(@NonNull Collection<String> ids) {
|
||||
disabledIds.clear();
|
||||
disabledIds.addAll(ids);
|
||||
updateCustomizationEnabled();
|
||||
public void setFeaturesDisabledIds(@NonNull Collection<String> ids) {
|
||||
featuresDisabledIds.clear();
|
||||
featuresDisabledIds.addAll(ids);
|
||||
setFeaturesCustomized();
|
||||
}
|
||||
|
||||
public void setEnabledPatterns(@NonNull Collection<String> patterns) {
|
||||
enabledPatterns.clear();
|
||||
enabledPatterns.addAll(patterns);
|
||||
updateCustomizationEnabled();
|
||||
public void setFeaturesEnabledPatterns(@NonNull Collection<String> patterns) {
|
||||
featuresEnabledPatterns.clear();
|
||||
featuresEnabledPatterns.addAll(patterns);
|
||||
setFeaturesCustomized();
|
||||
}
|
||||
|
||||
public void setDisabledPatterns(@NonNull Collection<String> patterns) {
|
||||
disabledPatterns.clear();
|
||||
disabledPatterns.addAll(patterns);
|
||||
updateCustomizationEnabled();
|
||||
public void setFeaturesDisabledPatterns(@NonNull Collection<String> patterns) {
|
||||
featuresDisabledPatterns.clear();
|
||||
featuresDisabledPatterns.addAll(patterns);
|
||||
setFeaturesCustomized();
|
||||
}
|
||||
|
||||
public Set<ApplicationMode> regWidgetVisibility(@NonNull String widgetId, @Nullable List<String> appModeKeys) {
|
||||
HashSet<ApplicationMode> set = getAppModesSet(appModeKeys);
|
||||
widgetsVisibilityMap.put(widgetId, set);
|
||||
setWidgetsCustomized();
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<ApplicationMode> regWidgetAvailability(@NonNull String widgetId, @Nullable List<String> appModeKeys) {
|
||||
HashSet<ApplicationMode> set = getAppModesSet(appModeKeys);
|
||||
widgetsAvailabilityMap.put(widgetId, set);
|
||||
setWidgetsCustomized();
|
||||
return set;
|
||||
}
|
||||
|
||||
public boolean isWidgetVisible(@NonNull String key, ApplicationMode appMode) {
|
||||
Set<ApplicationMode> set = widgetsVisibilityMap.get(key);
|
||||
if (set == null) {
|
||||
return false;
|
||||
}
|
||||
return set.contains(appMode);
|
||||
}
|
||||
|
||||
public boolean isWidgetAvailable(@NonNull String key, ApplicationMode appMode) {
|
||||
Set<ApplicationMode> set = widgetsAvailabilityMap.get(key);
|
||||
if (set == null) {
|
||||
return true;
|
||||
}
|
||||
return set.contains(appMode);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private HashSet<ApplicationMode> getAppModesSet(@Nullable List<String> appModeKeys) {
|
||||
HashSet<ApplicationMode> set = new HashSet<>();
|
||||
List<ApplicationMode> values = ApplicationMode.allPossibleValues();
|
||||
if (appModeKeys == null) {
|
||||
set.addAll(values);
|
||||
} else {
|
||||
for (String key : appModeKeys) {
|
||||
ApplicationMode am = ApplicationMode.valueOfStringKey(key, null);
|
||||
if (am != null) {
|
||||
set.add(am);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ApplicationMode m : values) {
|
||||
// add derived modes
|
||||
if (set.contains(m.getParent())) {
|
||||
set.add(m);
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public boolean isFeatureEnabled(@NonNull String id) {
|
||||
if (!customizationEnabled) {
|
||||
if (!featuresCustomized) {
|
||||
return true;
|
||||
}
|
||||
if (enabledIds.contains(id)) {
|
||||
if (featuresEnabledIds.contains(id)) {
|
||||
return true;
|
||||
}
|
||||
if (disabledIds.contains(id)) {
|
||||
if (featuresDisabledIds.contains(id)) {
|
||||
return false;
|
||||
}
|
||||
if (isMatchesPattern(id, enabledPatterns)) {
|
||||
if (isMatchesPattern(id, featuresEnabledPatterns)) {
|
||||
return true;
|
||||
}
|
||||
return !isMatchesPattern(id, disabledPatterns);
|
||||
return !isMatchesPattern(id, featuresDisabledPatterns);
|
||||
}
|
||||
|
||||
private void updateCustomizationEnabled() {
|
||||
customizationEnabled = !enabledIds.isEmpty() || !disabledIds.isEmpty()
|
||||
|| !enabledPatterns.isEmpty() || !disabledPatterns.isEmpty();
|
||||
public boolean areWidgetsCustomized() {
|
||||
return widgetsCustomized;
|
||||
}
|
||||
|
||||
private void setFeaturesCustomized() {
|
||||
featuresCustomized = true;
|
||||
}
|
||||
|
||||
private void setWidgetsCustomized() {
|
||||
widgetsCustomized = true;
|
||||
}
|
||||
|
||||
private boolean isMatchesPattern(@NonNull String id, @NonNull Set<String> patterns) {
|
||||
|
@ -198,4 +311,24 @@ public class OsmAndAppCustomization {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void notifySettingsCustomized() {
|
||||
app.uiHandler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (OsmAndAppCustomizationListener l : listeners) {
|
||||
l.onOsmAndSettingsCustomized();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addListener(OsmAndAppCustomizationListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(OsmAndAppCustomizationListener listener) {
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import android.app.Application;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -25,6 +25,7 @@ import android.view.accessibility.AccessibilityManager;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibilityPlugin;
|
||||
|
@ -271,6 +272,12 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return osmandSettings;
|
||||
}
|
||||
|
||||
public void setOsmandSettings(OsmandSettings osmandSettings) {
|
||||
//android.os.Process.killProcess(android.os.Process.myPid());
|
||||
this.osmandSettings = osmandSettings;
|
||||
OsmandPlugin.initPlugins(this);
|
||||
}
|
||||
|
||||
public SavingTrackHelper getSavingTrackHelper() {
|
||||
return savingTrackHelper;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ public abstract class OsmandPlugin {
|
|||
OsmandSettings settings = app.getSettings();
|
||||
Set<String> enabledPlugins = settings.getEnabledPlugins();
|
||||
|
||||
allPlugins.clear();
|
||||
allPlugins.add(new MapillaryPlugin(app));
|
||||
enabledPlugins.add(MapillaryPlugin.ID);
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
|
|||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -119,7 +121,8 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
// These settings are stored in SharedPreferences
|
||||
private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$
|
||||
private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings";
|
||||
private static String CUSTOM_SHARED_PREFERENCES_NAME;
|
||||
|
||||
|
||||
/// Settings variables
|
||||
|
@ -143,11 +146,19 @@ public class OsmandSettings {
|
|||
initPrefs();
|
||||
}
|
||||
|
||||
protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI, String sharedPreferencesName) {
|
||||
ctx = clientContext;
|
||||
this.settingsAPI = settinsAPI;
|
||||
CUSTOM_SHARED_PREFERENCES_NAME = "net.osmand.customsettings." + sharedPreferencesName;
|
||||
initPrefs();
|
||||
}
|
||||
|
||||
private void initPrefs() {
|
||||
globalPreferences = settingsAPI.getPreferenceObject(SHARED_PREFERENCES_NAME);
|
||||
globalPreferences = settingsAPI.getPreferenceObject(getSharedPreferencesName(null));
|
||||
defaultProfilePreferences = getProfilePreferences(ApplicationMode.DEFAULT);
|
||||
currentMode = readApplicationMode();
|
||||
profilePreferences = getProfilePreferences(currentMode);
|
||||
registeredPreferences.put(APPLICATION_MODE.getId(), APPLICATION_MODE);
|
||||
}
|
||||
|
||||
public OsmandApplication getContext() {
|
||||
|
@ -164,10 +175,11 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
public static String getSharedPreferencesName(ApplicationMode mode) {
|
||||
String sharedPreferencesName = !Algorithms.isEmpty(CUSTOM_SHARED_PREFERENCES_NAME) ? CUSTOM_SHARED_PREFERENCES_NAME : SHARED_PREFERENCES_NAME;
|
||||
if (mode == null) {
|
||||
return SHARED_PREFERENCES_NAME;
|
||||
return sharedPreferencesName;
|
||||
} else {
|
||||
return SHARED_PREFERENCES_NAME + "." + mode.getStringKey().toLowerCase();
|
||||
return sharedPreferencesName + "." + mode.getStringKey().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,6 +187,81 @@ public class OsmandSettings {
|
|||
return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode));
|
||||
}
|
||||
|
||||
public boolean setPreference(String key, Object value) {
|
||||
OsmandPreference<?> preference = registeredPreferences.get(key);
|
||||
if (preference != null) {
|
||||
if (preference == APPLICATION_MODE) {
|
||||
if (value instanceof String) {
|
||||
String appModeKey = (String) value;
|
||||
ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null);
|
||||
if (appMode != null) {
|
||||
APPLICATION_MODE.set(appMode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (preference == DEFAULT_APPLICATION_MODE) {
|
||||
if (value instanceof String) {
|
||||
String appModeKey = (String) value;
|
||||
ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null);
|
||||
if (appMode != null) {
|
||||
DEFAULT_APPLICATION_MODE.set(appMode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (preference == METRIC_SYSTEM) {
|
||||
if (value instanceof String) {
|
||||
String metricSystemName = (String) value;
|
||||
MetricsConstants metricSystem;
|
||||
try {
|
||||
metricSystem = MetricsConstants.valueOf(metricSystemName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
METRIC_SYSTEM.set(metricSystem);
|
||||
return true;
|
||||
}
|
||||
} else if (preference == SPEED_SYSTEM) {
|
||||
if (value instanceof String) {
|
||||
String speedSystemName = (String) value;
|
||||
SpeedConstants speedSystem;
|
||||
try {
|
||||
speedSystem = SpeedConstants.valueOf(speedSystemName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
SPEED_SYSTEM.set(speedSystem);
|
||||
return true;
|
||||
}
|
||||
} else if (preference instanceof BooleanPreference) {
|
||||
if (value instanceof Boolean) {
|
||||
((BooleanPreference) preference).set((Boolean) value);
|
||||
return true;
|
||||
}
|
||||
} else if (preference instanceof StringPreference) {
|
||||
if (value instanceof String) {
|
||||
((StringPreference) preference).set((String) value);
|
||||
return true;
|
||||
}
|
||||
} else if (preference instanceof FloatPreference) {
|
||||
if (value instanceof Float) {
|
||||
((FloatPreference) preference).set((Float) value);
|
||||
return true;
|
||||
}
|
||||
} else if (preference instanceof IntPreference) {
|
||||
if (value instanceof Integer) {
|
||||
((IntPreference) preference).set((Integer) value);
|
||||
return true;
|
||||
}
|
||||
} else if (preference instanceof LongPreference) {
|
||||
if (value instanceof Long) {
|
||||
((LongPreference) preference).set((Long) value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null;
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
@ -297,6 +384,7 @@ public class OsmandSettings {
|
|||
public CommonPreference(String id, T defaultValue) {
|
||||
this.id = id;
|
||||
this.defaultValue = defaultValue;
|
||||
registeredPreferences.put(id, this);
|
||||
}
|
||||
|
||||
public CommonPreference<T> makeGlobal() {
|
||||
|
@ -1596,7 +1684,7 @@ public class OsmandSettings {
|
|||
return isWriteable;
|
||||
}
|
||||
|
||||
public boolean isExternalStorageDirectorySpecifiedV19() {
|
||||
public boolean isExternalStorageDirectoryTypeSpecifiedV19() {
|
||||
return settingsAPI.contains(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19);
|
||||
}
|
||||
|
||||
|
@ -1604,6 +1692,14 @@ public class OsmandSettings {
|
|||
return settingsAPI.getInt(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19, -1);
|
||||
}
|
||||
|
||||
public boolean isExternalStorageDirectorySpecifiedV19() {
|
||||
return settingsAPI.contains(globalPreferences, EXTERNAL_STORAGE_DIR_V19);
|
||||
}
|
||||
|
||||
public String getExternalStorageDirectoryV19() {
|
||||
return settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR_V19, null);
|
||||
}
|
||||
|
||||
public File getExternalStorageDirectoryPre19() {
|
||||
String defaultLocation = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
File rootFolder = new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR,
|
||||
|
|
|
@ -65,6 +65,7 @@ import net.osmand.plus.MapMarkersHelper;
|
|||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
|
||||
import net.osmand.plus.OnDismissDialogFragmentListener;
|
||||
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -149,7 +150,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
|
||||
OnRequestPermissionsResultCallback, IRouteInformationListener,
|
||||
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener {
|
||||
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener, OsmAndAppCustomizationListener {
|
||||
public static final String INTENT_KEY_PARENT_MAP_ACTIVITY = "intent_parent_map_activity_key";
|
||||
|
||||
private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1;
|
||||
|
@ -207,6 +208,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
private boolean mIsDestroyed = false;
|
||||
private boolean pendingPause = false;
|
||||
private Timer splashScreenTimer;
|
||||
private boolean activityRestartNeeded = false;
|
||||
|
||||
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
|
@ -325,6 +327,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
registerReceiver(screenOffReceiver, filter);
|
||||
|
||||
app.getAidlApi().onCreateMapActivity(this);
|
||||
app.getAppCustomization().addListener(this);
|
||||
|
||||
mIsDestroyed = false;
|
||||
}
|
||||
|
@ -466,7 +469,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) {
|
||||
final OsmandSettings.CommonPreference<Boolean> allowPrivate
|
||||
= settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false);
|
||||
final List<ApplicationMode> modes = ApplicationMode.values(settings);
|
||||
final List<ApplicationMode> modes = ApplicationMode.values(app);
|
||||
for (ApplicationMode mode : modes) {
|
||||
if (!allowPrivate.getModeValue(mode)) {
|
||||
settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, true);
|
||||
|
@ -633,6 +636,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (activityRestartNeeded) {
|
||||
activityRestartNeeded = false;
|
||||
recreate();
|
||||
return;
|
||||
}
|
||||
|
||||
long tm = System.currentTimeMillis();
|
||||
|
||||
if (app.getMapMarkersHelper().getPlanRouteContext().isFragmentVisible()) {
|
||||
|
@ -1946,6 +1956,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
activityResultListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOsmAndSettingsCustomized() {
|
||||
activityRestartNeeded = true;
|
||||
}
|
||||
|
||||
public enum ShowQuickSearchMode {
|
||||
NEW,
|
||||
NEW_IF_EXPIRED,
|
||||
|
|
|
@ -940,7 +940,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
getMyApplication().stopNavigation();
|
||||
mapActivity.updateApplicationModeSettings();
|
||||
mapActivity.getDashboard().clearDeletedPoints();
|
||||
List<ApplicationMode> modes = ApplicationMode.values(settings);
|
||||
List<ApplicationMode> modes = ApplicationMode.values(getMyApplication());
|
||||
for (ApplicationMode mode : modes) {
|
||||
if (settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(mode)) {
|
||||
settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, false);
|
||||
|
|
|
@ -96,7 +96,7 @@ public class MapActivityLayers {
|
|||
|
||||
public MapActivityLayers(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
this.mapWidgetRegistry = new MapWidgetRegistry(activity.getMyApplication().getSettings());
|
||||
this.mapWidgetRegistry = new MapWidgetRegistry(activity.getMyApplication());
|
||||
this.quickActionRegistry = new QuickActionRegistry(activity.getMyApplication().getSettings());
|
||||
}
|
||||
|
||||
|
|
|
@ -324,20 +324,21 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
settings = getMyApplication().getSettings();
|
||||
OsmandApplication app = getMyApplication();
|
||||
settings = app.getSettings();
|
||||
getToolbar().setTitle(R.string.shared_string_settings);
|
||||
|
||||
|
||||
if (profileSettings) {
|
||||
modes.clear();
|
||||
for (ApplicationMode a : ApplicationMode.values(settings)) {
|
||||
for (ApplicationMode a : ApplicationMode.values(app)) {
|
||||
if (a != ApplicationMode.DEFAULT) {
|
||||
modes.add(a);
|
||||
}
|
||||
}
|
||||
List<String> s = new ArrayList<String>();
|
||||
for (ApplicationMode a : modes) {
|
||||
s.add(a.toHumanString(getMyApplication()));
|
||||
s.add(a.toHumanString(app));
|
||||
}
|
||||
SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this,
|
||||
R.layout.spinner_item, s);
|
||||
|
|
|
@ -1,30 +1,6 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.DrivingRegion;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
|
@ -55,6 +31,31 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.DrivingRegion;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback {
|
||||
|
||||
|
@ -80,13 +81,13 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
|||
String[] entries;
|
||||
String[] entrieValues;
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
settings = getMyApplication().getSettings();
|
||||
OsmandApplication app = getMyApplication();
|
||||
settings = app.getSettings();
|
||||
|
||||
|
||||
ApplicationMode[] appModes = ApplicationMode.values(settings).toArray(new ApplicationMode[0]);
|
||||
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
|
||||
entries = new String[appModes.length];
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
entries[i] = appModes[i].toHumanString(getMyApplication());
|
||||
entries[i] = appModes[i].toHumanString(app);
|
||||
}
|
||||
registerListPreference(settings.DEFAULT_APPLICATION_MODE, screen, entries, appModes);
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ public class AppModeDialog {
|
|||
|
||||
public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault,
|
||||
ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
|
||||
OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
|
||||
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
|
||||
OsmandApplication app = (OsmandApplication) a.getApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
final List<ApplicationMode> values = new ArrayList<>(ApplicationMode.values(app));
|
||||
if(!showDefault) {
|
||||
values.remove(ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
@ -38,8 +39,9 @@ public class AppModeDialog {
|
|||
//needed because if there's more than 4 items - the don't fit in drawer
|
||||
public static View prepareAppModeDrawerView(Activity a, final Set<ApplicationMode> selected,
|
||||
boolean useMapTheme, final View.OnClickListener onClickListener) {
|
||||
OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
|
||||
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
|
||||
OsmandApplication app = (OsmandApplication) a.getApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
final List<ApplicationMode> values = new ArrayList<>(ApplicationMode.values(app));
|
||||
selected.add(settings.getApplicationMode());
|
||||
return prepareAppModeView(a, values, selected, null, true, true, useMapTheme, onClickListener);
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||
final List<ApplicationMode> modes = ApplicationMode.allPossibleValues();
|
||||
modes.remove(ApplicationMode.DEFAULT);
|
||||
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>(ApplicationMode.values(settings));
|
||||
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>(ApplicationMode.values(getMyApplication()));
|
||||
selected.remove(ApplicationMode.DEFAULT);
|
||||
View v = AppModeDialog.prepareAppModeView(this, modes, selected, null, false, true, false,
|
||||
new View.OnClickListener() {
|
||||
|
|
|
@ -48,13 +48,13 @@ public class SnapToRoadBottomSheetDialogFragment extends android.support.design.
|
|||
@Override
|
||||
public void setupDialog(Dialog dialog, int style) {
|
||||
super.setupDialog(dialog, style);
|
||||
if (getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app.getSettings().DO_NOT_USE_ANIMATIONS.get()) {
|
||||
dialog.getWindow().setWindowAnimations(R.style.Animations_NoAnimation);
|
||||
}
|
||||
|
||||
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
final OsmandSettings settings = getMyApplication().getSettings();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, null);
|
||||
|
@ -76,7 +76,7 @@ public class SnapToRoadBottomSheetDialogFragment extends android.support.design.
|
|||
}
|
||||
|
||||
LinearLayout container = (LinearLayout) mainView.findViewById(R.id.navigation_types_container);
|
||||
final List<ApplicationMode> modes = new ArrayList<>(ApplicationMode.values(settings));
|
||||
final List<ApplicationMode> modes = new ArrayList<>(ApplicationMode.values(app));
|
||||
if (removeDefaultMode) {
|
||||
modes.remove(ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class NauticalMapsPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
public void addBoatProfile(boolean flag) {
|
||||
Set<ApplicationMode> selectedProfiles = new LinkedHashSet<>(ApplicationMode.values(app.getSettings()));
|
||||
Set<ApplicationMode> selectedProfiles = new LinkedHashSet<>(ApplicationMode.values(app));
|
||||
boolean isBoatEnabled = selectedProfiles.contains(ApplicationMode.BOAT);
|
||||
if((!isBoatEnabled && flag) || (isBoatEnabled && !flag)) {
|
||||
String s = app.getSettings().AVAILABLE_APP_MODES.get();
|
||||
|
|
|
@ -45,13 +45,14 @@ public class MapWidgetRegistry {
|
|||
private Set<MapWidgetRegInfo> leftWidgetSet = new TreeSet<>();
|
||||
private Set<MapWidgetRegInfo> rightWidgetSet = new TreeSet<>();
|
||||
private Map<ApplicationMode, Set<String>> visibleElementsFromSettings = new LinkedHashMap<>();
|
||||
private final OsmandApplication app;
|
||||
private final OsmandSettings settings;
|
||||
|
||||
public MapWidgetRegistry(OsmandApplication app) {
|
||||
this.app = app;
|
||||
this.settings = app.getSettings();
|
||||
|
||||
public MapWidgetRegistry(OsmandSettings settings) {
|
||||
this.settings = settings;
|
||||
|
||||
for (ApplicationMode ms : ApplicationMode.values(settings)) {
|
||||
for (ApplicationMode ms : ApplicationMode.values(app)) {
|
||||
String mpf = settings.MAP_INFO_CONTROLS.getModeValue(ms);
|
||||
if (mpf.equals(SHOW_PREFIX)) {
|
||||
visibleElementsFromSettings.put(ms, null);
|
||||
|
@ -193,9 +194,9 @@ public class MapWidgetRegistry {
|
|||
}
|
||||
|
||||
private void processVisibleModes(String key, MapWidgetRegInfo ii) {
|
||||
for (ApplicationMode ms : ApplicationMode.values(settings)) {
|
||||
for (ApplicationMode ms : ApplicationMode.values(app)) {
|
||||
boolean collapse = ms.isWidgetCollapsible(key);
|
||||
boolean def = ms.isWidgetVisible(key);
|
||||
boolean def = ms.isWidgetVisible(app, key);
|
||||
Set<String> set = visibleElementsFromSettings.get(ms);
|
||||
if (set != null) {
|
||||
if (set.contains(key)) {
|
||||
|
@ -288,7 +289,7 @@ public class MapWidgetRegistry {
|
|||
for (MapWidgetRegInfo ri : set) {
|
||||
ri.visibleCollapsible.remove(mode);
|
||||
ri.visibleModes.remove(mode);
|
||||
if (mode.isWidgetVisible(ri.key)) {
|
||||
if (mode.isWidgetVisible(app, ri.key)) {
|
||||
if (mode.isWidgetCollapsible(ri.key)) {
|
||||
ri.visibleCollapsible.add(mode);
|
||||
} else {
|
||||
|
@ -457,7 +458,7 @@ public class MapWidgetRegistry {
|
|||
private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter,
|
||||
Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
|
||||
for (final MapWidgetRegInfo r : groupTitle) {
|
||||
if (!mode.isWidgetAvailable(r.key)) {
|
||||
if (!mode.isWidgetAvailable(app, r.key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -484,7 +485,7 @@ public class MapWidgetRegistry {
|
|||
MenuInflater inflater = popup.getMenuInflater();
|
||||
final Menu menu = popup.getMenu();
|
||||
inflater.inflate(R.menu.widget_visibility_menu, menu);
|
||||
UiUtilities ic = mapActivity.getMyApplication().getUIUtilities();
|
||||
UiUtilities ic = app.getUIUtilities();
|
||||
menu.findItem(R.id.action_show).setIcon(ic.getThemedIcon(R.drawable.ic_action_view));
|
||||
menu.findItem(R.id.action_hide).setIcon(ic.getThemedIcon(R.drawable.ic_action_hide));
|
||||
menu.findItem(R.id.action_collapse).setIcon(ic.getThemedIcon(R.drawable.ic_action_widget_collapse));
|
||||
|
|
Loading…
Reference in a new issue