This repository has been archived on 2025-09-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
android_packages_apps_Cherish/src/com/cherish/settings/fragments/Clock.java
Hưng Phan d24ab995b4 Cherish:Cherish:[SQUASH]Add tunables for clock position
Cherish: Add tunables for clock position
Author: Hendrik Hagendorn <git@finnq.de>
Date:   Sun Jan 15 10:00:12 2017 +0100
    Tuner: Move clock seconds option to status bar settings

    Change-Id: I532c179f06b934009d48433e50b69660247ee295

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Sun Jul 29 14:19:08 2018 +0200
    SystemUI: Fix default clock blacklist value

    Change-Id: Ibdc4f6a707569ddb417854760cf579daca989ebb

Author: LuK1337 <priv.luk@gmail.com>
Date:   Wed Aug 1 18:10:39 2018 +0200
    SystemUI: Initialize mClockVisibleByUser to android:visibility

    * Fixes ~ triple clock ~ after leaving from Google SUW.

    Change-Id: I3ceea4400b3057e2b6b1f221f9074b1d451133ea

Author: LuK1337 <priv.luk@gmail.com>
Date:   Thu Sep 27 12:24:19 2018 +0200
    SystemUI: Fix clock icon blacklist handling

    * This makes sure clock isn't on blacklist before
      calling showClock(animate);

    Change-Id: I7f77a83aa6c109e1682d764fb22701375ae5ba1e

Author: LuK1337 <priv.luk@gmail.com>
Date:   Tue Apr 2 20:56:25 2019 +0200
    SystemUI: Don't hide right clock when heads up is visible

    * https://gitlab.com/LineageOS/issues/android/issues/436

    Change-Id: I85a6cd2dff79e6b97d8a7db552c22d611bf25dbd

Author: LuK1337 <priv.luk@gmail.com>
Date:   Wed Oct 30 15:48:38 2019 +0100
    SystemUI: Fix up right clock handling when showing heads up

    * Oops, we somehow forgot to import this code from 16.0 ;-;

    Change-Id: Ic4195a30da2870f569f07fc323e4b939320ab6c8

Author: Michael W <baddaemon87@gmail.com>
Date:   Mon Jun 1 14:43:31 2020 +0200
    SystemUI: Make clock truly invisible

    * When the clock is set to left and then hidden, the notification
      icons, which would appear on the left first transition to the
      right to make place for the clock then finally snap into place
    * The same happens when the clock was set to show right and then
      is hidden: The battery, wifi, etc. icons do leave space for the
      (not displayed) clock and then snap to the right
    * This patch fixes the behavior

    Change-Id: Ic68b1001becb91da6f1aeaca95a7312b36e1d2a1

Author: LuK1337 <priv.luk@gmail.com>
Date:   Sat Apr 10 22:52:25 2021 +0200
    SystemUI: Make center clock layout safe insets aware

    This effectively fixes wrongly centered clock layout on
    devices with side notch / hole punch.

    Change-Id: I7cb8cbbe628397c50d37e23ba1853368e61a1fc9

Author: LuK1337 <priv.luk@gmail.com>
Date:   Sun Apr 11 09:47:17 2021 +0200
    SystemUI: Move network traffic monitor under same layout as clock

    This effectively fixes wrongly network monitor layout on
    devices with side notch / hole punch.

    Change-Id: I217b886d8da75eab7636066f4822f5fd6dbc9aff

Author: Volodymyr Zhdanov <wight554@gmail.com>
Date:   Tue Nov 9 20:53:56 2021 +0200
    SystemUI: fix clock dark/light mode switching

    * move ClockController init to PhoneStatusBarView
    * move add/remove dark receiver logic to ClockController

    Change-Id: I6464af6e8aa130ea54fe7bfa19858c8930a29b1e

Change-Id: Icdc039d13fd2676c1eb979a81fb77f9a6ec59b4a
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>

Cherish:Add tunables for clock AM/PM style
Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java

Cherish: Add support for clock auto-hiding
Hide statusbar clock when launcher is visible. Useful when you already have a clock as widget.

Change-Id: I03dfc81bc055f2f865ac704e3bf9d9d104fac272
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>

CherishAdd separate tunable for clock seconds
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
Co-authored-by: LuK1337 <priv.luk@gmail.com>
Co-authored-by: Michael Bestas <mkbestas@lineageos.org>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
2023-03-20 02:16:50 +07:00

229 lines
9.4 KiB
Java

/*
* Copyright (C) 2019-2022 The CherishOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.res.Resources;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.EditText;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
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 {
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();
mStatusBarAmPm =
(SystemSettingListPreference) findPreference(STATUS_BAR_AM_PM);
if (DateFormat.is24HourFormat(getActivity())) {
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;
}
/**
* For Search.
*/
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.cherish_settings_status_bar_clock);
}