Fix osmand plugins updates and improve settings bottom sheets
This commit is contained in:
parent
fc44cb8506
commit
0275b22aaa
13 changed files with 233 additions and 280 deletions
|
@ -377,7 +377,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerReceiver(BroadcastReceiver rec, MapActivity ma,
|
private void registerReceiver(BroadcastReceiver rec, MapActivity ma,
|
||||||
String filter) {
|
String filter) {
|
||||||
receivers.put(filter, rec);
|
receivers.put(filter, rec);
|
||||||
ma.registerReceiver(rec, new IntentFilter(filter));
|
ma.registerReceiver(rec, new IntentFilter(filter));
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1254,7 @@ public class OsmandAidlApi {
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
|
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
|
||||||
int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(
|
int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(
|
||||||
app.getRendererRegistry().getCurrentSelectedRenderer(), color);
|
app.getRendererRegistry().getCurrentSelectedRenderer(), color);
|
||||||
if (!destinationExists) {
|
if (!destinationExists) {
|
||||||
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
|
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
|
||||||
gpxDataItem.setApiImported(true);
|
gpxDataItem.setApiImported(true);
|
||||||
|
@ -1472,19 +1472,19 @@ public class OsmandAidlApi {
|
||||||
List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems();
|
List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems();
|
||||||
for (GpxDataItem dataItem : gpxDataItems) {
|
for (GpxDataItem dataItem : gpxDataItems) {
|
||||||
//if (dataItem.isApiImported()) {
|
//if (dataItem.isApiImported()) {
|
||||||
File file = dataItem.getFile();
|
File file = dataItem.getFile();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
|
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
|
||||||
long modifiedTime = dataItem.getFileLastModifiedTime();
|
long modifiedTime = dataItem.getFileLastModifiedTime();
|
||||||
long fileSize = file.length();
|
long fileSize = file.length();
|
||||||
AGpxFileDetails details = null;
|
AGpxFileDetails details = null;
|
||||||
GPXTrackAnalysis analysis = dataItem.getAnalysis();
|
GPXTrackAnalysis analysis = dataItem.getAnalysis();
|
||||||
if (analysis != null) {
|
if (analysis != null) {
|
||||||
details = createGpxFileDetails(analysis);
|
details = createGpxFileDetails(analysis);
|
||||||
|
}
|
||||||
|
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
|
||||||
}
|
}
|
||||||
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
|
|
||||||
}
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1661,8 +1661,8 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean navigate(String startName, double startLat, double startLon,
|
boolean navigate(String startName, double startLat, double startLon,
|
||||||
String destName, double destLat, double destLon,
|
String destName, double destLat, double destLon,
|
||||||
String profile, boolean force) {
|
String profile, boolean force) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(AIDL_NAVIGATE);
|
intent.setAction(AIDL_NAVIGATE);
|
||||||
intent.putExtra(AIDL_START_NAME, startName);
|
intent.putExtra(AIDL_START_NAME, startName);
|
||||||
|
@ -1678,8 +1678,8 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean navigateSearch(String startName, double startLat, double startLon,
|
boolean navigateSearch(String startName, double startLat, double startLon,
|
||||||
String searchQuery, double searchLat, double searchLon,
|
String searchQuery, double searchLat, double searchLon,
|
||||||
String profile, boolean force) {
|
String profile, boolean force) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(AIDL_NAVIGATE_SEARCH);
|
intent.setAction(AIDL_NAVIGATE_SEARCH);
|
||||||
intent.putExtra(AIDL_START_NAME, startName);
|
intent.putExtra(AIDL_START_NAME, startName);
|
||||||
|
@ -1740,7 +1740,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,
|
boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,
|
||||||
final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) {
|
final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) {
|
||||||
if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) {
|
if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1762,7 +1762,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean registerForOsmandInitialization(final OsmandAppInitCallback callback)
|
boolean registerForOsmandInitialization(final OsmandAppInitCallback callback)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
if (app.isApplicationInitializing()) {
|
if (app.isApplicationInitializing()) {
|
||||||
app.getAppInitializer().addListener(new AppInitializeListener() {
|
app.getAppInitializer().addListener(new AppInitializeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1819,22 +1819,6 @@ public class OsmandAidlApi {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConnectedApps() {
|
|
||||||
try {
|
|
||||||
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
|
|
||||||
for (int i = 0; i < array.length(); i++) {
|
|
||||||
JSONObject obj = array.getJSONObject(i);
|
|
||||||
String pack = obj.optString(ConnectedApp.PACK_KEY, "");
|
|
||||||
ConnectedApp connectedApp = connectedApps.get(pack);
|
|
||||||
if (connectedApp != null) {
|
|
||||||
connectedApp.enabled = obj.optBoolean(ConnectedApp.ENABLED_KEY, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean switchEnabled(@NonNull ConnectedApp app) {
|
public boolean switchEnabled(@NonNull ConnectedApp app) {
|
||||||
app.enabled = !app.enabled;
|
app.enabled = !app.enabled;
|
||||||
return saveConnectedApps();
|
return saveConnectedApps();
|
||||||
|
@ -1866,7 +1850,7 @@ public class OsmandAidlApi {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConnectedApps() {
|
public void loadConnectedApps() {
|
||||||
try {
|
try {
|
||||||
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
|
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
|
@ -2090,7 +2074,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels,
|
boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels,
|
||||||
final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) {
|
final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) {
|
||||||
if (gpxUri == null || callback == null) {
|
if (gpxUri == null || callback == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,19 +156,6 @@ public abstract class OsmandPlugin {
|
||||||
activatePlugins(app, enabledPlugins);
|
activatePlugins(app, enabledPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateActivatedPlugins(@NonNull OsmandApplication app) {
|
|
||||||
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
|
|
||||||
for (OsmandPlugin plugin : allPlugins) {
|
|
||||||
try {
|
|
||||||
if (plugin.init(app, null)) {
|
|
||||||
plugin.setActive(enabledPlugins.contains(plugin.getId()));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Plugin initialization failed " + plugin.getId(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void activatePlugins(OsmandApplication app, Set<String> enabledPlugins) {
|
private static void activatePlugins(OsmandApplication app, Set<String> enabledPlugins) {
|
||||||
for (OsmandPlugin plugin : allPlugins) {
|
for (OsmandPlugin plugin : allPlugins) {
|
||||||
if (enabledPlugins.contains(plugin.getId()) || plugin.isActive()) {
|
if (enabledPlugins.contains(plugin.getId()) || plugin.isActive()) {
|
||||||
|
|
|
@ -8,8 +8,6 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.media.AudioAttributes;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -21,9 +19,9 @@ import android.support.v4.util.Pair;
|
||||||
import android.support.v7.preference.PreferenceDataStore;
|
import android.support.v7.preference.PreferenceDataStore;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
|
import net.osmand.aidl.OsmandAidlApi;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
@ -44,8 +42,6 @@ import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -247,30 +243,45 @@ public class OsmandSettings {
|
||||||
DEFAULT_APPLICATION_MODE.set(appMode);
|
DEFAULT_APPLICATION_MODE.set(appMode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (value instanceof ApplicationMode) {
|
}
|
||||||
DEFAULT_APPLICATION_MODE.set((ApplicationMode) value);
|
} 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.set(metricSystem);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (preference == METRIC_SYSTEM && value instanceof String) {
|
} else if (preference == SPEED_SYSTEM) {
|
||||||
String metricSystemName = (String) value;
|
SpeedConstants speedSystem = null;
|
||||||
MetricsConstants metricSystem;
|
if (value instanceof String) {
|
||||||
try {
|
String speedSystemName = (String) value;
|
||||||
metricSystem = MetricsConstants.valueOf(metricSystemName);
|
try {
|
||||||
} catch (IllegalArgumentException e) {
|
speedSystem = SpeedConstants.valueOf(speedSystemName);
|
||||||
return false;
|
} 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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
METRIC_SYSTEM.setModeValue(mode, metricSystem);
|
if (speedSystem != null) {
|
||||||
return true;
|
SPEED_SYSTEM.set(speedSystem);
|
||||||
} else if (preference == SPEED_SYSTEM && value instanceof String) {
|
return true;
|
||||||
String speedSystemName = (String) value;
|
|
||||||
SpeedConstants speedSystem;
|
|
||||||
try {
|
|
||||||
speedSystem = SpeedConstants.valueOf(speedSystemName);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
SPEED_SYSTEM.setModeValue(mode, speedSystem);
|
|
||||||
return true;
|
|
||||||
} else if (preference instanceof BooleanPreference) {
|
} else if (preference instanceof BooleanPreference) {
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
((BooleanPreference) preference).setModeValue(mode, (Boolean) value);
|
((BooleanPreference) preference).setModeValue(mode, (Boolean) value);
|
||||||
|
@ -349,13 +360,20 @@ public class OsmandSettings {
|
||||||
@Override
|
@Override
|
||||||
public boolean set(ApplicationMode val) {
|
public boolean set(ApplicationMode val) {
|
||||||
ApplicationMode oldMode = currentMode;
|
ApplicationMode oldMode = currentMode;
|
||||||
boolean changed = settingsAPI.edit(globalPreferences).putString(getId(), val.getStringKey()).commit();
|
boolean valueSaved = settingsAPI.edit(globalPreferences).putString(getId(), val.getStringKey()).commit();
|
||||||
if (changed) {
|
if (valueSaved) {
|
||||||
currentMode = val;
|
currentMode = val;
|
||||||
profilePreferences = getProfilePreferences(currentMode);
|
profilePreferences = getProfilePreferences(currentMode);
|
||||||
|
|
||||||
|
OsmandAidlApi aidlApi = ctx.getAidlApi();
|
||||||
|
if (aidlApi != null) {
|
||||||
|
aidlApi.loadConnectedApps();
|
||||||
|
OsmandPlugin.initPlugins(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
fireEvent(oldMode);
|
fireEvent(oldMode);
|
||||||
}
|
}
|
||||||
return changed;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -475,15 +493,15 @@ public class OsmandSettings {
|
||||||
if (global) {
|
if (global) {
|
||||||
return set(obj);
|
return set(obj);
|
||||||
}
|
}
|
||||||
Object profilePrefs = getProfilePreferences(mode);
|
|
||||||
boolean changed = setValue(profilePrefs, obj);
|
|
||||||
|
|
||||||
if (changed && cache && cachedPreference == profilePrefs) {
|
Object profilePrefs = getProfilePreferences(mode);
|
||||||
|
boolean valueSaved = setValue(profilePrefs, obj);
|
||||||
|
if (valueSaved && cache && cachedPreference == profilePrefs) {
|
||||||
cachedValue = obj;
|
cachedValue = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
fireEvent(obj);
|
fireEvent(obj);
|
||||||
return changed;
|
|
||||||
|
return valueSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getProfileDefaultValue(ApplicationMode mode) {
|
public T getProfileDefaultValue(ApplicationMode mode) {
|
||||||
|
@ -1241,11 +1259,11 @@ public class OsmandSettings {
|
||||||
public final CommonPreference<Boolean> ENABLE_PROXY = new BooleanPreference("enable_proxy", false) {
|
public final CommonPreference<Boolean> ENABLE_PROXY = new BooleanPreference("enable_proxy", false) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Boolean val) {
|
protected boolean setValue(Object prefs, Boolean val) {
|
||||||
boolean valueSet = super.setValue(prefs, val);
|
boolean valueSaved = super.setValue(prefs, val);
|
||||||
if (valueSet) {
|
if (valueSaved) {
|
||||||
NetworkUtils.setProxy(val ? PROXY_HOST.get() : null, val ? PROXY_PORT.get() : 0);
|
NetworkUtils.setProxy(val ? PROXY_HOST.get() : null, val ? PROXY_PORT.get() : 0);
|
||||||
}
|
}
|
||||||
return valueSet;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
}.makeGlobal();
|
}.makeGlobal();
|
||||||
|
|
||||||
|
@ -1327,36 +1345,36 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<Boolean> ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) {
|
public final OsmandPreference<Boolean> ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Boolean val) {
|
protected boolean setValue(Object prefs, Boolean val) {
|
||||||
boolean changed = super.setValue(prefs, val);
|
boolean valueSaved = super.setValue(prefs, val);
|
||||||
if (changed) {
|
if (valueSaved) {
|
||||||
SHOW_WPT.set(val);
|
SHOW_WPT.set(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
}.makeProfile().cache();
|
}.makeProfile().cache();
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_FAVORITES = new BooleanPreference("announce_nearby_favorites", false) {
|
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_FAVORITES = new BooleanPreference("announce_nearby_favorites", false) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Boolean val) {
|
protected boolean setValue(Object prefs, Boolean val) {
|
||||||
boolean changed = super.setValue(prefs, val);
|
boolean valueSaved = super.setValue(prefs, val);
|
||||||
if (changed) {
|
if (valueSaved) {
|
||||||
SHOW_NEARBY_FAVORITES.set(val);
|
SHOW_NEARBY_FAVORITES.set(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
}.makeProfile().cache();
|
}.makeProfile().cache();
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_POI = new BooleanPreference("announce_nearby_poi", false) {
|
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_POI = new BooleanPreference("announce_nearby_poi", false) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Boolean val) {
|
protected boolean setValue(Object prefs, Boolean val) {
|
||||||
boolean changed = super.setValue(prefs, val);
|
boolean valueSaved = super.setValue(prefs, val);
|
||||||
if (changed) {
|
if (valueSaved) {
|
||||||
SHOW_NEARBY_POI.set(val);
|
SHOW_NEARBY_POI.set(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
}.makeProfile().cache();
|
}.makeProfile().cache();
|
||||||
|
|
||||||
|
@ -1537,25 +1555,25 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<Integer> AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream", 3/*AudioManager.STREAM_MUSIC*/) {
|
public final OsmandPreference<Integer> AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream", 3/*AudioManager.STREAM_MUSIC*/) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Integer stream) {
|
protected boolean setValue(Object prefs, Integer stream) {
|
||||||
boolean valueSet = super.setValue(prefs, stream);
|
boolean valueSaved = super.setValue(prefs, stream);
|
||||||
|
|
||||||
if (valueSet) {
|
if (valueSaved) {
|
||||||
CommandPlayer player = ctx.getPlayer();
|
CommandPlayer player = ctx.getPlayer();
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.updateAudioStream(get());
|
player.updateAudioStream(get());
|
||||||
}
|
}
|
||||||
// Sync corresponding AUDIO_USAGE value
|
// Sync corresponding AUDIO_USAGE value
|
||||||
ApplicationMode mode = APPLICATION_MODE.get();
|
ApplicationMode mode = APPLICATION_MODE.get();
|
||||||
if (stream == AudioManager.STREAM_MUSIC) {
|
if (stream == 3 /*AudioManager.STREAM_MUSIC*/) {
|
||||||
AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE);
|
AUDIO_USAGE.setModeValue(mode, 12 /*AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE*/);
|
||||||
} else if (stream == AudioManager.STREAM_NOTIFICATION) {
|
} else if (stream == 5 /*AudioManager.STREAM_NOTIFICATION*/) {
|
||||||
AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_NOTIFICATION);
|
AUDIO_USAGE.setModeValue(mode, 5 /*AudioAttributes.USAGE_NOTIFICATION*/);
|
||||||
} else if (stream == AudioManager.STREAM_VOICE_CALL) {
|
} else if (stream == 0 /*AudioManager.STREAM_VOICE_CALL*/) {
|
||||||
AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_VOICE_COMMUNICATION);
|
AUDIO_USAGE.setModeValue(mode, 2 /*AudioAttributes.USAGE_VOICE_COMMUNICATION*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueSet;
|
return valueSaved;
|
||||||
}
|
}
|
||||||
}.makeProfile();
|
}.makeProfile();
|
||||||
|
|
||||||
|
@ -3176,47 +3194,38 @@ public class OsmandSettings {
|
||||||
|
|
||||||
public class PreferencesDataStore extends PreferenceDataStore {
|
public class PreferencesDataStore extends PreferenceDataStore {
|
||||||
|
|
||||||
private final Log log = PlatformUtil.getLog(PreferencesDataStore.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putString(String key, @Nullable String value) {
|
public void putString(String key, @Nullable String value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putString key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putStringSet(String key, @Nullable Set<String> values) {
|
public void putStringSet(String key, @Nullable Set<String> values) {
|
||||||
setPreference(key, values);
|
setPreference(key, values);
|
||||||
log.debug("putStringSet key " + key + " value " + values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putInt(String key, int value) {
|
public void putInt(String key, int value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putInt key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putLong(String key, long value) {
|
public void putLong(String key, long value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putLong key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putFloat(String key, float value) {
|
public void putFloat(String key, float value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putFloat key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putBoolean(String key, boolean value) {
|
public void putBoolean(String key, boolean value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putBoolean key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putValue(String key, Object value) {
|
public void putValue(String key, Object value) {
|
||||||
setPreference(key, value);
|
setPreference(key, value);
|
||||||
log.debug("putValue key " + key + " value " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
private boolean stopped = true;
|
private boolean stopped = true;
|
||||||
|
|
||||||
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
private LockHelper lockHelper;
|
private LockHelper lockHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -351,7 +351,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
registerReceiver(screenOffReceiver, filter);
|
registerReceiver(screenOffReceiver, filter);
|
||||||
|
|
||||||
app.getAidlApi().onCreateMapActivity(this);
|
app.getAidlApi().onCreateMapActivity(this);
|
||||||
|
|
||||||
lockHelper.setLockUIAdapter(this);
|
lockHelper.setLockUIAdapter(this);
|
||||||
|
|
||||||
mIsDestroyed = false;
|
mIsDestroyed = false;
|
||||||
|
@ -1415,8 +1415,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
public void updateApplicationModeSettings() {
|
public void updateApplicationModeSettings() {
|
||||||
changeKeyguardFlags();
|
changeKeyguardFlags();
|
||||||
updateMapSettings();
|
updateMapSettings();
|
||||||
OsmandPlugin.updateActivatedPlugins(app);
|
|
||||||
getMyApplication().getAidlApi().updateConnectedApps();
|
|
||||||
mapViewTrackingUtilities.updateSettings();
|
mapViewTrackingUtilities.updateSettings();
|
||||||
//app.getRoutingHelper().setAppMode(settings.getApplicationMode());
|
//app.getRoutingHelper().setAppMode(settings.getApplicationMode());
|
||||||
if (mapLayers.getMapInfoLayer() != null) {
|
if (mapLayers.getMapInfoLayer() != null) {
|
||||||
|
@ -2080,7 +2078,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, boolean showCategories,
|
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, boolean showCategories,
|
||||||
@NonNull String searchQuery, @Nullable LatLon searchLocation) {
|
@NonNull String searchQuery, @Nullable LatLon searchLocation) {
|
||||||
if (mode == ShowQuickSearchMode.CURRENT) {
|
if (mode == ShowQuickSearchMode.CURRENT) {
|
||||||
mapContextMenu.close();
|
mapContextMenu.close();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2133,7 +2131,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, QuickSearchTab showSearchTab,
|
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, QuickSearchTab showSearchTab,
|
||||||
@NonNull String searchQuery, @Nullable LatLon searchLocation) {
|
@NonNull String searchQuery, @Nullable LatLon searchLocation) {
|
||||||
if (mode == ShowQuickSearchMode.CURRENT) {
|
if (mode == ShowQuickSearchMode.CURRENT) {
|
||||||
mapContextMenu.close();
|
mapContextMenu.close();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,6 +39,10 @@ import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||||
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
|
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
|
||||||
import net.osmand.plus.profiles.AppProfileArrayAdapter;
|
import net.osmand.plus.profiles.AppProfileArrayAdapter;
|
||||||
import net.osmand.plus.profiles.ProfileDataObject;
|
import net.osmand.plus.profiles.ProfileDataObject;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.EditTextPreferenceBottomSheet;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.MultiSelectPreferencesBottomSheet;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet;
|
||||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||||
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.preference.CheckBoxPreference;
|
import android.support.v7.preference.CheckBoxPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
@ -23,6 +23,7 @@ import net.osmand.Location;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
|
||||||
|
|
||||||
|
|
||||||
public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
||||||
|
@ -158,8 +159,6 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
||||||
spannableBuilder.append(" ");
|
spannableBuilder.append(" ");
|
||||||
spannableBuilder.append(getString(R.string.shared_string_read_more));
|
spannableBuilder.append(getString(R.string.shared_string_read_more));
|
||||||
|
|
||||||
final int color = ContextCompat.getColor(app, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
|
|
||||||
|
|
||||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NonNull View widget) {
|
public void onClick(@NonNull View widget) {
|
||||||
|
@ -168,7 +167,7 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDrawState(@NonNull TextPaint ds) {
|
public void updateDrawState(@NonNull TextPaint ds) {
|
||||||
ds.setColor(color);
|
super.updateDrawState(ds);
|
||||||
ds.setUnderlineText(false);
|
ds.setUnderlineText(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -180,18 +179,19 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String key = preference.getKey();
|
String key = preference.getKey();
|
||||||
|
|
||||||
updateSelectedFormatPrefs(key);
|
|
||||||
|
|
||||||
int newFormat = getCoordinatesFormatForKey(key);
|
int newFormat = getCoordinatesFormatForKey(key);
|
||||||
if (newFormat != -1) {
|
if (newFormat != -1) {
|
||||||
settings.COORDINATES_FORMAT.set(newFormat);
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
return true;
|
if (fragmentManager != null) {
|
||||||
|
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, settings.COORDINATES_FORMAT.getId(), newFormat, this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPreferenceClick(preference);
|
return super.onPreferenceChange(preference, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectedFormatPrefs(String key) {
|
private void updateSelectedFormatPrefs(String key) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
|
||||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.preference.DialogPreference.TargetFragment;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
|
||||||
|
public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public static final String PREFERENCE_ID = "preference_id";
|
||||||
|
|
||||||
|
private Preference preference;
|
||||||
|
|
||||||
|
public Preference getPreference() {
|
||||||
|
if (preference == null) {
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args != null && args.containsKey(PREFERENCE_ID)) {
|
||||||
|
String prefId = args.getString(PREFERENCE_ID);
|
||||||
|
TargetFragment targetFragment = (TargetFragment) getTargetFragment();
|
||||||
|
|
||||||
|
if (targetFragment != null) {
|
||||||
|
preference = targetFragment.findPreference(prefId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.preference.DialogPreference;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -13,7 +12,6 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.BooleanPreference;
|
import net.osmand.plus.OsmandSettings.BooleanPreference;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||||
|
@ -22,37 +20,28 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
public class BooleanPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = BooleanPreferenceBottomSheet.class.getSimpleName();
|
public static final String TAG = BooleanPreferenceBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
private static final String PREFERENCE_ID = "preference_id";
|
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(BooleanPreferenceBottomSheet.class);
|
private static final Log LOG = PlatformUtil.getLog(BooleanPreferenceBottomSheet.class);
|
||||||
|
|
||||||
private SwitchPreferenceEx switchPreference;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
switchPreference = getListPreference();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
Bundle args = getArguments();
|
if (app == null) {
|
||||||
if (app == null || args == null || switchPreference == null) {
|
return;
|
||||||
|
}
|
||||||
|
final SwitchPreferenceEx switchPreference = getSwitchPreferenceEx();
|
||||||
|
if (switchPreference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String title = switchPreference.getTitle().toString();
|
|
||||||
String description = switchPreference.getDescription();
|
|
||||||
|
|
||||||
OsmandPreference preference = app.getSettings().getPreference(switchPreference.getKey());
|
OsmandPreference preference = app.getSettings().getPreference(switchPreference.getKey());
|
||||||
if (!(preference instanceof BooleanPreference)) {
|
if (!(preference instanceof BooleanPreference)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String title = switchPreference.getTitle().toString();
|
||||||
items.add(new TitleItem(title));
|
items.add(new TitleItem(title));
|
||||||
|
|
||||||
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
|
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
|
||||||
|
@ -79,6 +68,7 @@ public class BooleanPreferenceBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
.create();
|
.create();
|
||||||
items.add(preferenceBtn[0]);
|
items.add(preferenceBtn[0]);
|
||||||
|
|
||||||
|
String description = switchPreference.getDescription();
|
||||||
if (description != null) {
|
if (description != null) {
|
||||||
BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
|
@ -88,20 +78,15 @@ public class BooleanPreferenceBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SwitchPreferenceEx getListPreference() {
|
|
||||||
if (switchPreference == null) {
|
|
||||||
final String key = getArguments().getString(PREFERENCE_ID);
|
|
||||||
final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) getTargetFragment();
|
|
||||||
switchPreference = (SwitchPreferenceEx) fragment.findPreference(key);
|
|
||||||
}
|
|
||||||
return switchPreference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getDismissButtonTextId() {
|
protected int getDismissButtonTextId() {
|
||||||
return R.string.shared_string_close;
|
return R.string.shared_string_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SwitchPreferenceEx getSwitchPreferenceEx() {
|
||||||
|
return (SwitchPreferenceEx) getPreference();
|
||||||
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target) {
|
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target) {
|
||||||
try {
|
try {
|
||||||
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
|
@ -1,4 +1,4 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -14,11 +14,11 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -26,12 +26,10 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChangeGeneralProfilesPrefBottomSheet extends MenuBottomSheetDialogFragment {
|
public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = "ChangeGeneralProfilesPrefBottomSheet";
|
public static final String TAG = "ChangeGeneralProfilesPrefBottomSheet";
|
||||||
|
|
||||||
private static final String PREFERENCE_ID = "preference_id";
|
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(ChangeGeneralProfilesPrefBottomSheet.class);
|
private static final Log LOG = PlatformUtil.getLog(ChangeGeneralProfilesPrefBottomSheet.class);
|
||||||
|
|
||||||
private Object newValue;
|
private Object newValue;
|
|
@ -1,54 +1,44 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.preference.DialogPreference;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
|
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class EditTextPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = EditTextPreferenceBottomSheet.class.getSimpleName();
|
public static final String TAG = EditTextPreferenceBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
private static final String PREFERENCE_ID = "preference_id";
|
|
||||||
private static final String EDIT_TEXT_PREFERENCE_KEY = "edit_text_preference_key";
|
private static final String EDIT_TEXT_PREFERENCE_KEY = "edit_text_preference_key";
|
||||||
|
|
||||||
private EditTextPreferenceEx editTextPreference;
|
|
||||||
|
|
||||||
private EditText editText;
|
private EditText editText;
|
||||||
private String text;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
editTextPreference = getEditTextPreference();
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
text = getEditTextPreference().getText();
|
|
||||||
} else {
|
|
||||||
text = savedInstanceState.getString(EDIT_TEXT_PREFERENCE_KEY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
final Context context = getContext();
|
Context ctx = getContext();
|
||||||
if (context == null || editTextPreference == null) {
|
EditTextPreferenceEx editTextPreference = getEditTextPreference();
|
||||||
|
if (ctx == null || editTextPreference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.add(new TitleItem(editTextPreference.getDialogTitle().toString()));
|
items.add(new TitleItem(editTextPreference.getDialogTitle().toString()));
|
||||||
|
String text;
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
text = savedInstanceState.getString(EDIT_TEXT_PREFERENCE_KEY);
|
||||||
|
} else {
|
||||||
|
text = editTextPreference.getText();
|
||||||
|
}
|
||||||
|
|
||||||
editText = new EditText(context);
|
editText = new EditText(ctx);
|
||||||
editText.setText(text);
|
editText.setText(text);
|
||||||
items.add(new SimpleBottomSheetItem.Builder().setCustomView(editText).create());
|
items.add(new SimpleBottomSheetItem.Builder().setCustomView(editText).create());
|
||||||
|
|
||||||
|
@ -61,7 +51,7 @@ public class EditTextPreferenceBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putString(EDIT_TEXT_PREFERENCE_KEY, text);
|
outState.putString(EDIT_TEXT_PREFERENCE_KEY, editText.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,26 +66,19 @@ public class EditTextPreferenceBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
String value = editText.getText().toString();
|
EditTextPreferenceEx editTextPreference = getEditTextPreference();
|
||||||
if (editTextPreference.callChangeListener(value)) {
|
if (editTextPreference != null) {
|
||||||
editTextPreference.setText(value);
|
String value = editText.getText().toString();
|
||||||
|
if (editTextPreference.callChangeListener(value)) {
|
||||||
|
editTextPreference.setText(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditTextPreferenceEx getEditTextPreference() {
|
private EditTextPreferenceEx getEditTextPreference() {
|
||||||
if (editTextPreference == null) {
|
return (EditTextPreferenceEx) getPreference();
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args != null) {
|
|
||||||
final String key = args.getString(PREFERENCE_ID);
|
|
||||||
Fragment targetFragment = getTargetFragment();
|
|
||||||
if (targetFragment instanceof DialogPreference.TargetFragment) {
|
|
||||||
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) targetFragment;
|
|
||||||
editTextPreference = (EditTextPreferenceEx) fragment.findPreference(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return editTextPreference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
|
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
|
|
@ -1,15 +1,14 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.preference.DialogPreference;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||||
|
@ -17,15 +16,18 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFragment {
|
public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = MultiSelectPreferencesBottomSheet.class.getSimpleName();
|
public static final String TAG = MultiSelectPreferencesBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
private static final String PREFERENCE_ID = "preference_id";
|
private static final Log LOG = PlatformUtil.getLog(MultiSelectPreferencesBottomSheet.class);
|
||||||
|
|
||||||
private static final String PREFERENCES_IDS = "preferences_ids";
|
private static final String PREFERENCES_IDS = "preferences_ids";
|
||||||
private static final String PREFERENCE_CHANGED = "preference_changed";
|
private static final String PREFERENCE_CHANGED = "preference_changed";
|
||||||
private static final String PREFERENCES_ENTRIES = "preferences_entries";
|
private static final String PREFERENCES_ENTRIES = "preferences_entries";
|
||||||
|
@ -37,27 +39,27 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
private CharSequence[] entries;
|
private CharSequence[] entries;
|
||||||
private Set<String> enabledPrefs = new HashSet<>();
|
private Set<String> enabledPrefs = new HashSet<>();
|
||||||
|
|
||||||
private boolean preferenceChanged;
|
private boolean prefChanged;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
multiSelectBooleanPreference = getListPreference();
|
multiSelectBooleanPreference = getListPreference();
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) {
|
if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) {
|
||||||
throw new IllegalStateException("MultiSelectListPreference requires an entries array and an entryValues array.");
|
LOG.error("MultiSelectListPreference requires an entries array and an entryValues array.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
enabledPrefs.clear();
|
enabledPrefs.clear();
|
||||||
enabledPrefs.addAll(multiSelectBooleanPreference.getValues());
|
enabledPrefs.addAll(multiSelectBooleanPreference.getValues());
|
||||||
preferenceChanged = false;
|
prefChanged = false;
|
||||||
entries = multiSelectBooleanPreference.getEntries();
|
entries = multiSelectBooleanPreference.getEntries();
|
||||||
prefsIds = multiSelectBooleanPreference.getPrefsIds();
|
prefsIds = multiSelectBooleanPreference.getPrefsIds();
|
||||||
} else {
|
} else {
|
||||||
enabledPrefs.clear();
|
enabledPrefs.clear();
|
||||||
enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS));
|
enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS));
|
||||||
preferenceChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false);
|
prefChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false);
|
||||||
entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES);
|
entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES);
|
||||||
prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS);
|
prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +68,7 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
if (app == null || multiSelectBooleanPreference == null) {
|
if (app == null || multiSelectBooleanPreference == null || prefsIds == null || entries == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +97,9 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
boolean checked = !item[0].isChecked();
|
boolean checked = !item[0].isChecked();
|
||||||
if (checked) {
|
if (checked) {
|
||||||
preferenceChanged |= enabledPrefs.add(prefsIds[index]);
|
prefChanged |= enabledPrefs.add(prefsIds[index]);
|
||||||
} else {
|
} else {
|
||||||
preferenceChanged |= enabledPrefs.remove(prefsIds[index]);
|
prefChanged |= enabledPrefs.remove(prefsIds[index]);
|
||||||
}
|
}
|
||||||
item[0].setChecked(checked);
|
item[0].setChecked(checked);
|
||||||
}
|
}
|
||||||
|
@ -122,10 +124,10 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putStringArrayList(ENABLED_PREFERENCES_IDS, new ArrayList<>(enabledPrefs));
|
outState.putBoolean(PREFERENCE_CHANGED, prefChanged);
|
||||||
outState.putBoolean(PREFERENCE_CHANGED, preferenceChanged);
|
|
||||||
outState.putCharSequenceArray(PREFERENCES_ENTRIES, entries);
|
|
||||||
outState.putStringArray(PREFERENCES_IDS, prefsIds);
|
outState.putStringArray(PREFERENCES_IDS, prefsIds);
|
||||||
|
outState.putStringArrayList(ENABLED_PREFERENCES_IDS, new ArrayList<>(enabledPrefs));
|
||||||
|
outState.putCharSequenceArray(PREFERENCES_ENTRIES, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,13 +137,13 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
if (preferenceChanged) {
|
if (prefChanged) {
|
||||||
final Set<String> values = enabledPrefs;
|
final Set<String> values = enabledPrefs;
|
||||||
if (multiSelectBooleanPreference.callChangeListener(values)) {
|
if (multiSelectBooleanPreference.callChangeListener(values)) {
|
||||||
multiSelectBooleanPreference.setValues(values);
|
multiSelectBooleanPreference.setValues(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preferenceChanged = false;
|
prefChanged = false;
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,18 +151,6 @@ public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
return (MultiSelectBooleanPreference) getPreference();
|
return (MultiSelectBooleanPreference) getPreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DialogPreference getPreference() {
|
|
||||||
Bundle args = getArguments();
|
|
||||||
if (multiSelectBooleanPreference == null && args != null) {
|
|
||||||
final String key = args.getString(PREFERENCE_ID);
|
|
||||||
final DialogPreference.TargetFragment targetFragment = (DialogPreference.TargetFragment) getTargetFragment();
|
|
||||||
if (targetFragment != null) {
|
|
||||||
multiSelectBooleanPreference = (MultiSelectBooleanPreference) targetFragment.findPreference(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return multiSelectBooleanPreference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target) {
|
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target) {
|
||||||
try {
|
try {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
|
@ -1,71 +1,65 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.preference.DialogPreference;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.settings.OnPreferenceChanged;
|
||||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class SingleSelectPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
|
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
private static final String PREFERENCE_ID = "preference_id";
|
|
||||||
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
|
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
|
||||||
|
|
||||||
private ListPreferenceEx listPreference;
|
private ListPreferenceEx listPreference;
|
||||||
|
|
||||||
private String[] entries;
|
|
||||||
private Object[] entryValues;
|
|
||||||
private int selectedEntryIndex = -1;
|
private int selectedEntryIndex = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
listPreference = getListPreference();
|
listPreference = getListPreference();
|
||||||
if (listPreference != null) {
|
if (savedInstanceState != null) {
|
||||||
entries = listPreference.getEntries();
|
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
|
||||||
entryValues = listPreference.getEntryValues();
|
} else if (listPreference != null) {
|
||||||
|
selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue());
|
||||||
if (savedInstanceState != null) {
|
|
||||||
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
|
|
||||||
} else {
|
|
||||||
selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
final Context context = getContext();
|
Context ctx = getContext();
|
||||||
if (context == null || listPreference == null || entries == null || entryValues == null) {
|
if (ctx == null || listPreference == null || listPreference.getEntries() == null || listPreference.getEntryValues() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.add(new TitleItem(listPreference.getDialogTitle().toString()));
|
String title = listPreference.getDialogTitle().toString();
|
||||||
|
items.add(new TitleItem(title));
|
||||||
|
|
||||||
String description = listPreference.getDescription();
|
String description = listPreference.getDescription();
|
||||||
if (!Algorithms.isEmpty(description)) {
|
if (!Algorithms.isEmpty(description)) {
|
||||||
items.add(new LongDescriptionItem(description));
|
items.add(new LongDescriptionItem(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] entries = listPreference.getEntries();
|
||||||
|
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
final BaseBottomSheetItem[] preferenceItem = new BottomSheetItemWithCompoundButton[1];
|
final BaseBottomSheetItem[] preferenceItem = new BottomSheetItemWithCompoundButton[1];
|
||||||
preferenceItem[0] = new BottomSheetItemWithCompoundButton.Builder()
|
preferenceItem[0] = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
.setChecked(i == selectedEntryIndex)
|
.setChecked(i == selectedEntryIndex)
|
||||||
.setButtonTintList(AndroidUtils.createCheckedColorStateList(context, R.color.icon_color_default_light, getActiveColorId()))
|
.setButtonTintList(AndroidUtils.createCheckedColorStateList(ctx, R.color.icon_color_default_light, getActiveColorId()))
|
||||||
.setTitle(entries[i])
|
.setTitle(entries[i])
|
||||||
.setTag(i)
|
.setTag(i)
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left)
|
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left)
|
||||||
|
@ -93,30 +87,6 @@ public class SingleSelectPreferenceBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
outState.putInt(SELECTED_ENTRY_INDEX_KEY, selectedEntryIndex);
|
outState.putInt(SELECTED_ENTRY_INDEX_KEY, selectedEntryIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateItems() {
|
|
||||||
for (BaseBottomSheetItem item : items) {
|
|
||||||
if (item instanceof BottomSheetItemWithCompoundButton) {
|
|
||||||
boolean checked = item.getTag().equals(selectedEntryIndex);
|
|
||||||
((BottomSheetItemWithCompoundButton) item).setChecked(checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ListPreferenceEx getListPreference() {
|
|
||||||
if (listPreference == null) {
|
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args != null) {
|
|
||||||
final String key = args.getString(PREFERENCE_ID);
|
|
||||||
Fragment targetFragment = getTargetFragment();
|
|
||||||
if (targetFragment instanceof DialogPreference.TargetFragment) {
|
|
||||||
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) targetFragment;
|
|
||||||
listPreference = (ListPreferenceEx) fragment.findPreference(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return listPreference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getDismissButtonTextId() {
|
protected int getDismissButtonTextId() {
|
||||||
return R.string.shared_string_close;
|
return R.string.shared_string_close;
|
||||||
|
@ -129,19 +99,34 @@ public class SingleSelectPreferenceBottomSheet extends MenuBottomSheetDialogFrag
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
if (selectedEntryIndex >= 0) {
|
Object[] entryValues = listPreference.getEntryValues();
|
||||||
|
if (entryValues != null && selectedEntryIndex >= 0) {
|
||||||
Object value = entryValues[selectedEntryIndex];
|
Object value = entryValues[selectedEntryIndex];
|
||||||
if (listPreference.callChangeListener(value)) {
|
if (listPreference.callChangeListener(value)) {
|
||||||
listPreference.setValue(value);
|
listPreference.setValue(value);
|
||||||
}
|
}
|
||||||
|
Fragment target = getTargetFragment();
|
||||||
|
if (target instanceof OnPreferenceChanged) {
|
||||||
|
((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Fragment target = getTargetFragment();
|
|
||||||
if (target instanceof OnPreferenceChanged) {
|
|
||||||
((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey());
|
|
||||||
}
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateItems() {
|
||||||
|
for (BaseBottomSheetItem item : items) {
|
||||||
|
if (item instanceof BottomSheetItemWithCompoundButton) {
|
||||||
|
boolean checked = item.getTag().equals(selectedEntryIndex);
|
||||||
|
((BottomSheetItemWithCompoundButton) item).setChecked(checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ListPreferenceEx getListPreference() {
|
||||||
|
return (ListPreferenceEx) getPreference();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
|
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
|
||||||
try {
|
try {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
Loading…
Reference in a new issue