use of net.osmand.plus.settings.backend.preferences.LongPreference in project Osmand by osmandapp.
the class OsmandSettings method registerLongPreference.
@SuppressWarnings("unchecked")
public CommonPreference<Long> registerLongPreference(String id, long defValue) {
if (registeredPreferences.containsKey(id)) {
return (CommonPreference<Long>) registeredPreferences.get(id);
}
LongPreference p = new LongPreference(this, id, defValue);
registeredPreferences.put(id, p);
return p;
}
use of net.osmand.plus.settings.backend.preferences.LongPreference in project Osmand by osmandapp.
the class OsmandSettings method setPreference.
// TODO doesn't look correct
@SuppressWarnings("unchecked")
public boolean setPreference(String key, Object value, ApplicationMode mode) {
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) {
setApplicationMode(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) {
MetricsConstants metricSystem = null;
if (value instanceof String) {
String metricSystemName = (String) value;
try {
metricSystem = MetricsConstants.valueOf(metricSystemName);
} catch (IllegalArgumentException e) {
return false;
}
} else if (value instanceof Integer) {
int index = (Integer) value;
if (index >= 0 && index < MetricsConstants.values().length) {
metricSystem = MetricsConstants.values()[index];
}
}
if (metricSystem != null) {
METRIC_SYSTEM.setModeValue(mode, metricSystem);
return true;
}
} else if (preference == SPEED_SYSTEM) {
SpeedConstants speedSystem = null;
if (value instanceof String) {
String speedSystemName = (String) value;
try {
speedSystem = SpeedConstants.valueOf(speedSystemName);
} catch (IllegalArgumentException e) {
return false;
}
} else if (value instanceof Integer) {
int index = (Integer) value;
if (index >= 0 && index < SpeedConstants.values().length) {
speedSystem = SpeedConstants.values()[index];
}
}
if (speedSystem != null) {
SPEED_SYSTEM.setModeValue(mode, speedSystem);
return true;
}
} else if (preference instanceof BooleanPreference) {
if (value instanceof Boolean) {
((BooleanPreference) preference).setModeValue(mode, (Boolean) value);
return true;
}
} else if (preference instanceof StringPreference) {
if (value instanceof String) {
((StringPreference) preference).setModeValue(mode, (String) value);
return true;
}
} else if (preference instanceof FloatPreference) {
if (value instanceof Float) {
((FloatPreference) preference).setModeValue(mode, (Float) value);
return true;
}
} else if (preference instanceof IntPreference) {
if (value instanceof Integer) {
((IntPreference) preference).setModeValue(mode, (Integer) value);
return true;
}
} else if (preference instanceof LongPreference) {
if (value instanceof Long) {
((LongPreference) preference).setModeValue(mode, (Long) value);
return true;
}
} else if (preference instanceof EnumStringPreference) {
EnumStringPreference enumPref = (EnumStringPreference) preference;
if (value instanceof String) {
Enum<?> enumValue = enumPref.parseString((String) value);
if (enumValue != null) {
return enumPref.setModeValue(mode, enumValue);
}
return false;
} else if (value instanceof Enum) {
return enumPref.setModeValue(mode, value);
} else if (value instanceof Integer) {
int newVal = (Integer) value;
if (enumPref.getValues().length > newVal) {
Enum<?> enumValue = enumPref.getValues()[newVal];
return enumPref.setModeValue(mode, enumValue);
}
return false;
}
} else if (preference instanceof ContextMenuItemsPreference) {
if (value instanceof ContextMenuItemsSettings) {
((ContextMenuItemsPreference) preference).setModeValue(mode, (ContextMenuItemsSettings) value);
}
}
}
return false;
}
Aggregations