Cherish: Bring Back LsClock settings
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -59,6 +59,8 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String AOD_SCHEDULE_KEY = "always_on_display_schedule";
|
||||
private static final String CUSTOM_CLOCK_FACE = Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE;
|
||||
private static final String DEFAULT_CLOCK = "com.android.keyguard.clock.DefaultClockController";
|
||||
|
||||
static final int MODE_DISABLED = 0;
|
||||
static final int MODE_NIGHT = 1;
|
||||
@@ -66,6 +68,9 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
static final int MODE_MIXED_SUNSET = 3;
|
||||
static final int MODE_MIXED_SUNRISE = 4;
|
||||
|
||||
private ListPreference mLockClockStyles;
|
||||
private Context mContext;
|
||||
|
||||
Preference mAODPref;
|
||||
|
||||
@Override
|
||||
@@ -89,6 +94,12 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
mAODPref = findPreference(AOD_SCHEDULE_KEY);
|
||||
updateAlwaysOnSummary();
|
||||
|
||||
mLockClockStyles = (ListPreference) findPreference(CUSTOM_CLOCK_FACE);
|
||||
String mLockClockStylesValue = getLockScreenCustomClockFace();
|
||||
mLockClockStyles.setValue(mLockClockStylesValue);
|
||||
mLockClockStyles.setSummary(mLockClockStyles.getEntry());
|
||||
mLockClockStyles.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,8 +134,39 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mLockClockStyles) {
|
||||
setLockScreenCustomClockFace((String) newValue);
|
||||
int index = mLockClockStyles.findIndexOfValue((String) newValue);
|
||||
mLockClockStyles.setSummary(mLockClockStyles.getEntries()[index]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getLockScreenCustomClockFace() {
|
||||
mContext = getActivity();
|
||||
String value = Settings.Secure.getStringForUser(mContext.getContentResolver(),
|
||||
CUSTOM_CLOCK_FACE, USER_CURRENT);
|
||||
|
||||
if (value == null || value.isEmpty()) value = DEFAULT_CLOCK;
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(value);
|
||||
return json.getString("clock");
|
||||
} catch (JSONException ex) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void setLockScreenCustomClockFace(String value) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("clock", value);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(), CUSTOM_CLOCK_FACE,
|
||||
json.toString(), USER_CURRENT);
|
||||
} catch (JSONException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
|
||||
Reference in New Issue
Block a user