Cherish: Keyguard Batterybar & Color Modes [2/2]

- 0: Gradient.
- 1: Accent.
- 2: Random.
- 3: Custom.

Signed-off-by: Aston-Martinn <advaithbhat9@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Advaith Bhat
2021-04-07 13:21:14 +00:00
committed by Hưng Phan
parent ed4be90966
commit 36218a35f4
5 changed files with 203 additions and 0 deletions

View File

@@ -1389,4 +1389,19 @@
<item>2</item> <item>2</item>
<item>3</item> <item>3</item>
</string-array> </string-array>
<!-- Keygaurd batterybar color modes -->
<string-array name="keygaurd_battery_bar_color_modes_entries" translatable="false">
<item>@string/keyguard_battery_bar_color_gradient</item>
<item>@string/keyguard_battery_bar_color_accent</item>
<item>@string/keyguard_battery_bar_color_random</item>
<item>@string/keyguard_battery_bar_color_custom</item>
</string-array>
<string-array name="keygaurd_battery_bar_color_modes_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources> </resources>

View File

@@ -1185,4 +1185,17 @@
<string name="flashlight_on_call_not_dnd">Only in ringer mode</string> <string name="flashlight_on_call_not_dnd">Only in ringer mode</string>
<string name="flashlight_on_call_dnd">Only in DND mode</string> <string name="flashlight_on_call_dnd">Only in DND mode</string>
<string name="flashlight_on_call_always">Always</string> <string name="flashlight_on_call_always">Always</string>
<!-- Keygaurd battery bar & color modes -->
<string name="keyguard_show_battery_title">Battery bar</string>
<string name="keyguard_show_battery_summary">Show a battery bar on the ambient display when charging</string>
<string name="keyguard_show_battery_always_title">Always show battery bar</string>
<string name="keyguard_show_battery_always_summary">Always show a battery bar on the ambient display</string>
<string name="keygaurd_battery_bar_color_title">Color</string>
<string name="on_aod_title">AOD</string>
<string name="keyguard_battery_bar_color_modes_title">Color mode</string>
<string name="keyguard_battery_bar_color_gradient">Gradient</string>
<string name="keyguard_battery_bar_color_accent">Accent</string>
<string name="keyguard_battery_bar_color_random">Random</string>
<string name="keyguard_battery_bar_color_custom">Custom</string>
</resources> </resources>

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 TenX-OS
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.
-->
<PreferenceScreen
android:title="@string/keyguard_show_battery_title"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ionionizer="http://schemas.android.com/apk/res-auto"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<PreferenceCategory
android:title="@string/on_aod_title">
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="sysui_keyguard_show_battery_bar"
android:title="@string/keyguard_show_battery_title"
android:summary="@string/keyguard_show_battery_summary"
android:defaultValue="false" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="sysui_keyguard_show_battery_bar_always"
android:title="@string/keyguard_show_battery_always_title"
android:summary="@string/keyguard_show_battery_always_summary"
android:defaultValue="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/keygaurd_battery_bar_color_title">
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="keygaurd_battery_bar_color_mode"
android:title="@string/keyguard_battery_bar_color_modes_title"
android:entries="@array/keygaurd_battery_bar_color_modes_entries"
android:entryValues="@array/keygaurd_battery_bar_color_modes_values"
android:dependency="sysui_keyguard_show_battery_bar"
android:defaultValue="0" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="keygaurd_battery_bar_color_custom"
android:title="@string/keyguard_battery_bar_color_custom"
android:defaultValue="0xffffffff"
android:persistent="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -283,6 +283,12 @@
android:defaultValue="25" android:defaultValue="25"
settings:units="dp"/> settings:units="dp"/>
<Preference
android:key="keygaurd_batterybar"
android:title="@string/keyguard_show_battery_title"
android:summary="@string/keyguard_show_battery_summary"
android:fragment="com.cherish.settings.fragments.KeygaurdBatteryBar" />
</PreferenceCategory> </PreferenceCategory>
<!-- FOD icon picker --> <!-- FOD icon picker -->

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2021 TenX-OS
*
* 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.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.*;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.SystemSettingListPreference;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class KeygaurdBatteryBar extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
private static final String BATTERY_BAR_COLOR_MODE = "keygaurd_battery_bar_color_mode";
private static final String BATTERY_BAR_COLOR_CUSTOM = "keygaurd_battery_bar_color_custom";
private SystemSettingListPreference mColor;
private ColorPickerPreference mColorCustom;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.cherish_keyguard_battery_bar);
PreferenceScreen prefScreen = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
mColor = (SystemSettingListPreference) findPreference(BATTERY_BAR_COLOR_MODE);
mColor.setOnPreferenceChangeListener(this);
int color = Settings.System.getIntForUser(resolver,
Settings.System.KEYGAURD_BATTERY_BAR_COLOR_MODE, 0, UserHandle.USER_CURRENT);
mColor.setValue(String.valueOf(color));
mColor.setSummary(mColor.getEntry());
mColorCustom = (ColorPickerPreference) findPreference(BATTERY_BAR_COLOR_CUSTOM);
mColorCustom.setOnPreferenceChangeListener(this);
int custom = Settings.System.getInt(getContentResolver(),
Settings.System.KEYGAURD_BATTERY_BAR_COLOR_CUSTOM, 0xFFFFFFFF);
String hex = String.format("#%08x", (0xFFFFFFFF & custom));
if (hex.equals("#ffffffff")) {
mColorCustom.setSummary(R.string.default_string);
} else {
mColorCustom.setSummary(hex);
}
mColorCustom.setNewPreviewColor(custom);
updateColorPrefs(color);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mColor) {
int color = Integer.parseInt(((String) newValue).toString());
Settings.System.putIntForUser(resolver,
Settings.System.KEYGAURD_BATTERY_BAR_COLOR_MODE, color, UserHandle.USER_CURRENT);
int index = mColor.findIndexOfValue((String) newValue);
mColor.setSummary(
mColor.getEntries()[index]);
updateColorPrefs(color);
return true;
} else if (preference == mColorCustom) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#ffffffff")) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getContentResolver(),
Settings.System.KEYGAURD_BATTERY_BAR_COLOR_CUSTOM, intHex);
return true;
}
return false;
}
private void updateColorPrefs(int color) {
if (color == 3) {
mColorCustom.setEnabled(true);
} else {
mColorCustom.setEnabled(false);
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}