use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class AppVersionUpgradeOnInit method migratePreferences.
public void migratePreferences() {
OsmandSettings settings = app.getSettings();
migrateEnumPreferences();
SharedPreferences globalSharedPreferences = (SharedPreferences) settings.getGlobalPreferences();
Map<String, ?> globalPrefsMap = globalSharedPreferences.getAll();
for (Map.Entry<String, ?> entry : globalPrefsMap.entrySet()) {
String key = entry.getKey();
OsmandPreference<?> pref = settings.getPreference(key);
if (pref instanceof CommonPreference) {
CommonPreference<?> commonPreference = (CommonPreference<?>) pref;
if (!commonPreference.isGlobal()) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!commonPreference.isSetForMode(mode) && !commonPreference.hasDefaultValueForMode(mode)) {
settings.setPreference(key, entry.getValue(), mode);
}
}
}
}
}
SharedPreferences defaultProfilePreferences = (SharedPreferences) settings.getProfilePreferences(ApplicationMode.DEFAULT);
Map<String, ?> defaultPrefsMap = defaultProfilePreferences.getAll();
for (Map.Entry<String, ?> entry : defaultPrefsMap.entrySet()) {
String key = entry.getKey();
OsmandPreference<?> pref = settings.getPreference(key);
if (pref instanceof CommonPreference) {
CommonPreference<?> commonPreference = (CommonPreference<?>) pref;
if (commonPreference.isGlobal() && !commonPreference.isSet()) {
settings.setPreference(key, entry.getValue());
}
}
}
for (OsmandPreference<?> pref : getGeneralPrefs()) {
if (pref instanceof CommonPreference) {
CommonPreference<?> commonPref = (CommonPreference<?>) pref;
Object defaultVal = commonPref.getModeValue(ApplicationMode.DEFAULT);
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!commonPref.isSetForMode(mode) && !commonPref.hasDefaultValueForMode(mode)) {
settings.setPreference(commonPref.getId(), defaultVal, mode);
}
}
}
}
String json = settings.getSettingsAPI().getString(settings.getGlobalPreferences(), "custom_app_profiles", "");
if (!Algorithms.isEmpty(json)) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
Type t = new TypeToken<ArrayList<ApplicationMode.ApplicationModeBean>>() {
}.getType();
List<ApplicationMode.ApplicationModeBean> customProfiles = gson.fromJson(json, t);
if (!Algorithms.isEmpty(customProfiles)) {
for (ApplicationMode.ApplicationModeBean modeBean : customProfiles) {
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.fromModeBean(app, modeBean);
ApplicationMode.saveProfile(builder, app);
}
}
}
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class AppVersionUpgradeOnInit method upgradeVersion.
@SuppressLint("ApplySharedPref")
void upgradeVersion(SharedPreferences startPrefs, int lastVersion) {
if (!startPrefs.contains(NUMBER_OF_STARTS)) {
startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
} else {
startPrefs.edit().putInt(NUMBER_OF_STARTS, startPrefs.getInt(NUMBER_OF_STARTS, 0) + 1).commit();
}
if (!startPrefs.contains(FIRST_INSTALLED)) {
startPrefs.edit().putLong(FIRST_INSTALLED, System.currentTimeMillis()).commit();
}
if (!startPrefs.contains(FIRST_TIME_APP_RUN)) {
firstTime = true;
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
} else {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
if (needsUpgrade(startPrefs, lastVersion)) {
OsmandSettings settings = app.getSettings();
if (prevAppVersion < VERSION_2_2) {
settings.SHOW_DASHBOARD_ON_START.set(true);
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
}
if (prevAppVersion < VERSION_3_2) {
settings.BILLING_PURCHASE_TOKENS_SENT.set("");
}
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3") || Version.getAppVersion(app).equals("3.5.4")) {
migratePreferences();
app.getAppInitializer().addListener(new AppInitializeListener() {
@Override
public void onStart(AppInitializer init) {
}
@Override
public void onProgress(AppInitializer init, InitEvents event) {
if (event.equals(InitEvents.FAVORITES_INITIALIZED)) {
migrateHomeWorkParkingToFavorites();
}
}
@Override
public void onFinish(AppInitializer init) {
}
});
}
if (prevAppVersion < VERSION_3_6) {
migratePreferences();
}
if (prevAppVersion < VERSION_3_7) {
migrateEnumPreferences();
}
if (prevAppVersion < VERSION_3_7_01) {
app.getAppInitializer().addListener(new AppInitializeListener() {
@Override
public void onStart(AppInitializer init) {
}
@Override
public void onProgress(AppInitializer init, InitEvents event) {
if (event.equals(InitEvents.FAVORITES_INITIALIZED)) {
app.getFavoritesHelper().fixBlackBackground();
}
}
@Override
public void onFinish(AppInitializer init) {
}
});
}
if (prevAppVersion < VERSION_3_8_00) {
migrateQuickActionStates();
}
if (prevAppVersion < VERSION_4_0_00) {
app.getAppInitializer().addListener(new AppInitializeListener() {
@Override
public void onStart(AppInitializer init) {
new MarkersDb39HelperLegacy(app).migrateMarkersGroups();
}
@Override
public void onProgress(AppInitializer init, InitEvents event) {
}
@Override
public void onFinish(AppInitializer init) {
}
});
}
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true;
}
}
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class AppInitializer method initNativeCore.
private void initNativeCore() {
if (!"qnx".equals(System.getProperty("os.name"))) {
OsmandSettings osmandSettings = app.getSettings();
if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
osmandSettings.SAFE_MODE.set(true);
osmandSettings.NATIVE_RENDERING_FAILED.set(false);
warnings.add(app.getString(R.string.native_library_not_supported));
} else {
osmandSettings.SAFE_MODE.set(false);
osmandSettings.NATIVE_RENDERING_FAILED.set(true);
startTask(app.getString(R.string.init_native_library), -1);
RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
NativeOsmandLibrary lib = NativeOsmandLibrary.getLibrary(storage, app);
boolean initialized = lib != null;
osmandSettings.NATIVE_RENDERING_FAILED.set(false);
if (!initialized) {
LOG.info("Native library could not be loaded!");
} else {
File ls = app.getAppPath("fonts");
lib.loadFontData(ls);
}
}
app.getResourceManager().initMapBoundariesCacheNative();
}
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapMenu method createLayersItems.
private void createLayersItems(@NonNull List<RenderingRuleProperty> customRules, @NonNull ContextMenuAdapter adapter, @NonNull MapActivity activity, boolean nightMode) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
int selectedProfileColor = settings.getApplicationMode().getProfileColor(nightMode);
MapLayerMenuListener listener = new MapLayerMenuListener(activity, adapter);
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(SHOW_CATEGORY_ID).setTitleId(R.string.shared_string_show, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
boolean selected = settings.SHOW_FAVORITES.get();
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(FAVORITES_ID).setTitleId(R.string.shared_string_favorites, activity).setSelected(settings.SHOW_FAVORITES.get()).setColor(app, selected ? R.color.osmand_orange : INVALID_ID).setIcon(R.drawable.ic_action_favorite).setItemDeleteAction(makeDeleteAction(settings.SHOW_FAVORITES)).setListener(listener).createItem());
ResourceManager resourceManager = app.getResourceManager();
boolean hasPoiData = !Algorithms.isEmpty(resourceManager.getAmenityRepositories()) || !Algorithms.isEmpty(resourceManager.getTravelRepositories());
if (hasPoiData) {
PoiUIFilter wiki = app.getPoiFilters().getTopWikiPoiFilter();
selected = app.getPoiFilters().isShowingAnyPoi(wiki);
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(POI_OVERLAY_ID).setTitleId(R.string.layer_poi, activity).setSelected(selected).setDescription(app.getPoiFilters().getSelectedPoiFiltersName(wiki)).setColor(app, selected ? R.color.osmand_orange : INVALID_ID).setIcon(R.drawable.ic_action_info_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).createItem());
}
selected = settings.SHOW_POI_LABEL.get();
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(POI_OVERLAY_LABELS_ID).setTitleId(R.string.layer_amenity_label, activity).setSelected(settings.SHOW_POI_LABEL.get()).setColor(app, selected ? R.color.osmand_orange : INVALID_ID).setIcon(R.drawable.ic_action_text_dark).setItemDeleteAction(makeDeleteAction(settings.SHOW_POI_LABEL)).setListener(listener).createItem());
selected = TransportLinesMenu.isShowLines(app);
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(TRANSPORT_ID).setTitleId(R.string.rendering_category_transport, activity).setIcon(R.drawable.ic_action_transport_bus).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(selected).setColor(selected ? selectedProfileColor : null).setListener(listener).createItem());
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(GPX_FILES_ID).setTitleId(R.string.layer_gpx_layer, activity).setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()).setDescription(app.getSelectedGpxHelper().getGpxDescription()).setColor(app, selected ? R.color.osmand_orange : INVALID_ID).setIcon(R.drawable.ic_action_polygom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).createItem());
selected = settings.SHOW_MAP_MARKERS.get();
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(MAP_MARKERS_ID).setTitleId(R.string.map_markers, activity).setSelected(selected).setColor(app, selected ? R.color.osmand_orange : INVALID_ID).setIcon(R.drawable.ic_action_flag).setItemDeleteAction(makeDeleteAction(settings.SHOW_MAP_MARKERS)).setListener(listener).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setId(MAP_SOURCE_ID).setTitleId(R.string.layer_map, activity).setIcon(R.drawable.ic_world_globe_dark).setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get().replace(IndexConstants.SQLITE_EXT, "") : null).setItemDeleteAction(makeDeleteAction(settings.MAP_ONLINE_DATA, settings.MAP_TILE_SOURCES)).setListener(listener).createItem());
OsmandPlugin.registerLayerContextMenu(adapter, activity, customRules);
app.getAidlApi().registerLayerContextMenu(adapter, activity);
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapMenu method createRouteAttributeItems.
private void createRouteAttributeItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter, MapActivity activity, boolean nightMode) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_routes, activity).setId(ROUTES_ID).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
for (String attrName : getRoutesDefaultAttrs().keySet()) {
RenderingRuleProperty property = getPropertyForAttr(customRules, attrName);
if (SHOW_CYCLE_ROUTES_ATTR.equals(attrName)) {
adapter.addItem(createCycleRoutesItem(activity, attrName, property, nightMode));
customRules.remove(getPropertyForAttr(customRules, CYCLE_NODE_NETWORK_ROUTES_ATTR));
} else if (HIKING_ROUTES_OSMC_ATTR.equals(attrName)) {
adapter.addItem(createHikingRoutesItem(activity, attrName, property, nightMode));
} else {
String id = ROUTES_ID + attrName;
int drawableId = getIconIdForAttr(attrName);
String name = AndroidUtils.getRenderingStringPropertyName(activity, attrName, property != null ? property.getName() : attrName);
CommonPreference<Boolean> pref = settings.getCustomRenderBooleanProperty(attrName);
ContextMenuItem item = createBooleanRenderingProperty(activity, attrName, name, id, property, drawableId, nightMode, result -> {
if (property == null) {
showRendererSnackbarForAttr(activity, attrName, nightMode, pref);
}
return false;
});
if (item != null) {
adapter.addItem(item);
}
}
customRules.remove(property);
}
ResourceManager manager = app.getResourceManager();
if (OsmandPlugin.isDevelopment() && (!Algorithms.isEmpty(manager.getTravelMapRepositories()) || !Algorithms.isEmpty(manager.getTravelRepositories()))) {
adapter.addItem(createTravelRoutesItem(activity, nightMode));
}
}
Aggregations