Change default settings bottom sheet initial commit
This commit is contained in:
parent
f7f29c5b0b
commit
56fb98cc56
7 changed files with 127 additions and 174 deletions
|
@ -11,6 +11,10 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="change_default_settings">Change default settings</string>
|
||||
<string name="discard_changes">Discard changes</string>
|
||||
<string name="apply_to_current_profile">Apply to current %1$s profile</string>
|
||||
<string name="apply_to_all_profiles">Apply to all profiles</string>
|
||||
<string name="start_up_message_pref">Start up message</string>
|
||||
<string name="analytics_pref_title">Analytics</string>
|
||||
<string name="turn_screen_on_info">Show map during navigation above the lock screen.</string>
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.access.AccessibilityMode;
|
||||
import net.osmand.plus.access.RelativeDirectionStyle;
|
||||
import net.osmand.plus.api.SettingsAPI;
|
||||
|
@ -1219,7 +1220,17 @@ public class OsmandSettings {
|
|||
|
||||
public final CommonPreference<Boolean> INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeProfile();
|
||||
|
||||
public final CommonPreference<Boolean> ENABLE_PROXY = new BooleanPreference("enable_proxy", false).makeGlobal();
|
||||
public final CommonPreference<Boolean> ENABLE_PROXY = new BooleanPreference("enable_proxy", false) {
|
||||
@Override
|
||||
protected boolean setValue(Object prefs, Boolean val) {
|
||||
boolean changed = super.setValue(prefs, val);
|
||||
if (changed) {
|
||||
NetworkUtils.setProxy(val ? PROXY_HOST.get() : null, val ? PROXY_PORT.get() : 0);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}.makeGlobal();
|
||||
|
||||
public final CommonPreference<String> PROXY_HOST = new StringPreference("proxy_host", "127.0.0.1").makeGlobal();
|
||||
public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal();
|
||||
public final CommonPreference<String> USER_ANDROID_ID = new StringPreference("user_android_id", "").makeGlobal();
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class ChangeProfilesPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "ChangeProfilesPreferenceBottomSheet";
|
||||
|
||||
private static final String PREFERENCE_ID = "preference_id";
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(ChangeProfilesPreferenceBottomSheet.class);
|
||||
|
||||
private Object newValue;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
Context context = getContext();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
items.add(new TitleItem(getString(R.string.change_default_settings)));
|
||||
|
||||
BaseBottomSheetItem applyToAllProfiles = new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(getString(R.string.apply_to_all_profiles))
|
||||
.setIcon(getActiveIcon(R.drawable.ic_action_copy))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getMyApplication().showShortToastMessage("applyToAllProfiles");
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(applyToAllProfiles);
|
||||
|
||||
ApplicationMode selectedAppMode = getMyApplication().getSettings().APPLICATION_MODE.get();
|
||||
|
||||
BaseBottomSheetItem applyToCurrentProfile = new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(getString(R.string.apply_to_current_profile, selectedAppMode.toHumanString(context)))
|
||||
.setIcon(getActiveIcon(selectedAppMode.getIconRes()))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getMyApplication().showShortToastMessage("applyToCurrentProfile");
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(applyToCurrentProfile);
|
||||
|
||||
BaseBottomSheetItem discardChanges = new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(getString(R.string.discard_changes))
|
||||
.setIcon(getActiveIcon(R.drawable.ic_action_copy))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(discardChanges);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hideButtonsContainer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, String prefId, Object newValue) {
|
||||
try {
|
||||
if (fm.findFragmentByTag(ChangeProfilesPreferenceBottomSheet.TAG) == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PREFERENCE_ID, prefId);
|
||||
|
||||
ChangeProfilesPreferenceBottomSheet fragment = new ChangeProfilesPreferenceBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.newValue = newValue;
|
||||
fragment.show(fm, ChangeProfilesPreferenceBottomSheet.TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,10 +42,12 @@ public class GeneralProfileSettings extends BaseSettingsFragment {
|
|||
return R.layout.profile_preference_toolbar_big;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getToolbarTitle() {
|
||||
return getString(R.string.general_settings_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
setupAppThemePref();
|
||||
setupRotateMapPref();
|
||||
|
@ -324,4 +326,13 @@ public class GeneralProfileSettings extends BaseSettingsFragment {
|
|||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
ChangeProfilesPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), newValue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
|
|||
String prefId = preference.getKey();
|
||||
|
||||
if (prefId.equals(settings.ENABLE_PROXY.getId())) {
|
||||
enableProxy((Boolean) newValue);
|
||||
return true;
|
||||
} else if (prefId.equals(settings.PROXY_HOST.getId())) {
|
||||
String ipAddress = (String) newValue;
|
||||
if (ipAddress.matches(IP_ADDRESS_PATTERN)) {
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class ListFloatPreference extends ListPreference {
|
||||
|
||||
public ListFloatPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public ListFloatPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public ListFloatPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ListFloatPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntries(CharSequence[] entries) {
|
||||
super.setEntries(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntries(int entriesResId) {
|
||||
super.setEntries(entriesResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntryValues(CharSequence[] entryValues) {
|
||||
super.setEntryValues(entryValues);
|
||||
}
|
||||
|
||||
public void setEntryValues(float[] entryValues) {
|
||||
String[] strings = new String[entryValues.length];
|
||||
for (int i = 0; i < entryValues.length; ++i) {
|
||||
strings[i] = Float.toString(entryValues[i]);
|
||||
}
|
||||
super.setEntryValues(strings);
|
||||
}
|
||||
|
||||
public void setEntryValues(int[] entryValues) {
|
||||
String[] strings = new String[entryValues.length];
|
||||
for (int i = 0; i < entryValues.length; ++i) {
|
||||
strings[i] = Float.toString(entryValues[i]);
|
||||
}
|
||||
super.setEntryValues(strings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntryValues(int entryValuesResId) {
|
||||
setEntryValues(getContext().getResources().getIntArray(entryValuesResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
} else {
|
||||
return persistFloat(Float.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPersistedString(String defaultReturnValue) {
|
||||
if (getSharedPreferences().contains(getKey())) {
|
||||
float floatValue = getPersistedFloat(0f);
|
||||
return String.valueOf(floatValue);
|
||||
} else {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return String.valueOf(a.getFloat(index, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callChangeListener(Object newValue) {
|
||||
return super.callChangeListener(Float.valueOf((String) newValue));
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class ListIntPreference extends ListPreference {
|
||||
|
||||
public ListIntPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public ListIntPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public ListIntPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ListIntPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntries(CharSequence[] entries) {
|
||||
super.setEntries(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntries(int entriesResId) {
|
||||
super.setEntries(entriesResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntryValues(CharSequence[] entryValues) {
|
||||
super.setEntryValues(entryValues);
|
||||
}
|
||||
|
||||
public void setEntryValues(int[] entryValues) {
|
||||
String[] strings = new String[entryValues.length];
|
||||
for (int i = 0; i < entryValues.length; ++i) {
|
||||
strings[i] = Integer.toString(entryValues[i]);
|
||||
}
|
||||
super.setEntryValues(strings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntryValues(int entryValuesResId) {
|
||||
setEntryValues(getContext().getResources().getIntArray(entryValuesResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
} else {
|
||||
return persistInt(Integer.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPersistedString(String defaultReturnValue) {
|
||||
if (getSharedPreferences().contains(getKey())) {
|
||||
int intValue = getPersistedInt(0);
|
||||
return String.valueOf(intValue);
|
||||
} else {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return String.valueOf(a.getInt(index, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callChangeListener(Object newValue) {
|
||||
return super.callChangeListener(Integer.valueOf((String) newValue));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue