Cherish: Clean hide clock
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -583,13 +583,6 @@
|
||||
<string name="status_bar_clock_position_left">Left</string>
|
||||
<string name="status_bar_clock_position_center">Center</string>
|
||||
<string name="status_bar_clock_position_hidden">Hidden</string>
|
||||
<string name="status_bar_clock_auto_hide_title">Auto hide</string>
|
||||
<string name="status_bar_clock_auto_hide_launcher_summary">Hide clock if launcher is visible</string>
|
||||
<string name="status_bar_clock_auto_hide_summary">Hide clock at regular interval</string>
|
||||
<string name="status_bar_clock_auto_hide_hdur_title">Hide duration</string>
|
||||
<string name="status_bar_clock_auto_hide_hdur_summary">Number of seconds to hide clock</string>
|
||||
<string name="status_bar_clock_auto_hide_sdur_title">Show duration</string>
|
||||
<string name="status_bar_clock_auto_hide_sdur_summary">Number of seconds to wait before hiding clock</string>
|
||||
<string name="status_bar_am_pm_title">AM/PM style</string>
|
||||
<string name="status_bar_am_pm_info">24-hour clock is enabled</string>
|
||||
<string name="status_bar_am_pm_normal">Normal</string>
|
||||
|
||||
@@ -8,40 +8,6 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/status_bar_clock_title">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="status_bar_clock_auto_hide_launcher"
|
||||
android:title="@string/status_bar_clock_auto_hide_title"
|
||||
android:summary="@string/status_bar_clock_auto_hide_launcher_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="status_bar_clock_auto_hide"
|
||||
android:title="@string/status_bar_clock_auto_hide_title"
|
||||
android:summary="@string/status_bar_clock_auto_hide_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="status_bar_clock_auto_hide_hduration"
|
||||
android:title="@string/status_bar_clock_auto_hide_hdur_title"
|
||||
android:summary="@string/status_bar_clock_auto_hide_hdur_summary"
|
||||
android:max="300"
|
||||
settings:min="5"
|
||||
settings:interval="5"
|
||||
android:dependency="status_bar_clock_auto_hide"
|
||||
android:defaultValue="60"
|
||||
settings:units="@string/unit_seconds" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="status_bar_clock_auto_hide_sduration"
|
||||
android:title="@string/status_bar_clock_auto_hide_sdur_title"
|
||||
android:summary="@string/status_bar_clock_auto_hide_sdur_summary"
|
||||
android:max="300"
|
||||
settings:min="5"
|
||||
settings:interval="5"
|
||||
android:dependency="status_bar_clock_auto_hide"
|
||||
android:defaultValue="5"
|
||||
settings:units="@string/unit_seconds" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="status_bar_clock_seconds"
|
||||
android:title="@string/status_bar_clock_seconds_title"
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
@@ -25,6 +28,7 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.DateFormat;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
@@ -39,11 +43,14 @@ import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.cherish.settings.fragments.Clock;
|
||||
import com.cherish.settings.preferences.SecureSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingSeekBarPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class Clock extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
@@ -51,13 +58,27 @@ public class Clock extends SettingsPreferenceFragment implements
|
||||
private static final String TAG = "Clock";
|
||||
|
||||
private static final String STATUS_BAR_AM_PM = "status_bar_am_pm";
|
||||
private static final String CLOCK_DATE_DISPLAY = "status_bar_clock_date_display";
|
||||
private static final String CLOCK_DATE_POSITION = "status_bar_clock_date_position";
|
||||
private static final String CLOCK_DATE_STYLE = "status_bar_clock_date_style";
|
||||
private static final String CLOCK_DATE_FORMAT = "status_bar_clock_date_format";
|
||||
|
||||
private static final int CLOCK_DATE_STYLE_LOWERCASE = 1;
|
||||
private static final int CLOCK_DATE_STYLE_UPPERCASE = 2;
|
||||
private static final int CUSTOM_CLOCK_DATE_FORMAT_INDEX = 18;
|
||||
|
||||
private SystemSettingListPreference mStatusBarAmPm;
|
||||
private SystemSettingListPreference mClockDateDisplay;
|
||||
private SystemSettingListPreference mClockDatePosition;
|
||||
private SystemSettingListPreference mClockDateStyle;
|
||||
private ListPreference mClockDateFormat;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_status_bar_clock);
|
||||
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final Context mContext = getActivity().getApplicationContext();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
@@ -69,14 +90,131 @@ public class Clock extends SettingsPreferenceFragment implements
|
||||
mStatusBarAmPm.setEnabled(false);
|
||||
mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
|
||||
}
|
||||
|
||||
int dateDisplay = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_DATE_DISPLAY, 0, UserHandle.USER_CURRENT);
|
||||
|
||||
mClockDateDisplay = (SystemSettingListPreference) findPreference(CLOCK_DATE_DISPLAY);
|
||||
mClockDateDisplay.setOnPreferenceChangeListener(this);
|
||||
|
||||
mClockDatePosition = (SystemSettingListPreference) findPreference(CLOCK_DATE_POSITION);
|
||||
mClockDatePosition.setEnabled(dateDisplay > 0);
|
||||
mClockDatePosition.setOnPreferenceChangeListener(this);
|
||||
|
||||
mClockDateStyle = (SystemSettingListPreference) findPreference(CLOCK_DATE_STYLE);
|
||||
mClockDateStyle.setEnabled(dateDisplay > 0);
|
||||
mClockDateStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mClockDateFormat = (ListPreference) findPreference(CLOCK_DATE_FORMAT);
|
||||
if (mClockDateFormat.getValue() == null) {
|
||||
mClockDateFormat.setValue("EEE");
|
||||
}
|
||||
parseClockDateFormats();
|
||||
mClockDateFormat.setEnabled(dateDisplay > 0);
|
||||
mClockDateFormat.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
AlertDialog dialog;
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mClockDateDisplay) {
|
||||
int val = Integer.parseInt((String) newValue);
|
||||
if (val == 0) {
|
||||
mClockDatePosition.setEnabled(false);
|
||||
mClockDateStyle.setEnabled(false);
|
||||
mClockDateFormat.setEnabled(false);
|
||||
} else {
|
||||
mClockDatePosition.setEnabled(true);
|
||||
mClockDateStyle.setEnabled(true);
|
||||
mClockDateFormat.setEnabled(true);
|
||||
}
|
||||
return true;
|
||||
} else if (preference == mClockDatePosition) {
|
||||
parseClockDateFormats();
|
||||
return true;
|
||||
} else if (preference == mClockDateStyle) {
|
||||
parseClockDateFormats();
|
||||
return true;
|
||||
} else if (preference == mClockDateFormat) {
|
||||
int index = mClockDateFormat.findIndexOfValue((String) newValue);
|
||||
|
||||
if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setTitle(R.string.status_bar_date_string_edittext_title);
|
||||
alert.setMessage(R.string.status_bar_date_string_edittext_summary);
|
||||
|
||||
final EditText input = new EditText(getActivity());
|
||||
String oldText = Settings.System.getString(
|
||||
resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_DATE_FORMAT);
|
||||
if (oldText != null) {
|
||||
input.setText(oldText);
|
||||
}
|
||||
alert.setView(input);
|
||||
|
||||
alert.setPositiveButton(R.string.menu_save, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogInterface, int whichButton) {
|
||||
String value = input.getText().toString();
|
||||
if (value.equals("")) {
|
||||
return;
|
||||
}
|
||||
Settings.System.putString(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_DATE_FORMAT, value);
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
alert.setNegativeButton(R.string.menu_cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogInterface, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
dialog = alert.create();
|
||||
dialog.show();
|
||||
} else {
|
||||
if ((String) newValue != null) {
|
||||
Settings.System.putString(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_DATE_FORMAT, (String) newValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parseClockDateFormats() {
|
||||
String[] dateEntries = getResources().getStringArray(
|
||||
R.array.status_bar_date_format_entries_values);
|
||||
CharSequence parsedDateEntries[];
|
||||
parsedDateEntries = new String[dateEntries.length];
|
||||
Date now = new Date();
|
||||
|
||||
int lastEntry = dateEntries.length - 1;
|
||||
int dateFormat = Settings.System.getIntForUser(getActivity()
|
||||
.getContentResolver(), Settings.System.STATUS_BAR_CLOCK_DATE_STYLE, 0, UserHandle.USER_CURRENT);
|
||||
for (int i = 0; i < dateEntries.length; i++) {
|
||||
if (i == lastEntry) {
|
||||
parsedDateEntries[i] = dateEntries[i];
|
||||
} else {
|
||||
String newDate;
|
||||
CharSequence dateString = DateFormat.format(dateEntries[i], now);
|
||||
if (dateFormat == CLOCK_DATE_STYLE_LOWERCASE) {
|
||||
newDate = dateString.toString().toLowerCase();
|
||||
} else if (dateFormat == CLOCK_DATE_STYLE_UPPERCASE) {
|
||||
newDate = dateString.toString().toUpperCase();
|
||||
} else {
|
||||
newDate = dateString.toString();
|
||||
}
|
||||
|
||||
parsedDateEntries[i] = newDate;
|
||||
}
|
||||
}
|
||||
mClockDateFormat.setEntries(parsedDateEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
@@ -87,4 +225,4 @@ public class Clock extends SettingsPreferenceFragment implements
|
||||
*/
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.cherish_settings_status_bar_clock);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user