From 524eb9b53639ae8a2827b798784d9839d830e80b Mon Sep 17 00:00:00 2001 From: Pranav Vashi Date: Sun, 27 Dec 2020 17:29:21 +0530 Subject: [PATCH] Cherish:Pulse initial checkin for Android 12 [2/2] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pranav Vashi Signed-off-by: Hưng Phan --- res/values/cherish_arrays.xml | 23 ++ res/values/cherish_strings.xml | 34 ++- res/xml/cherish_settings_lockscreen.xml | 7 + res/xml/pulse_settings.xml | 156 +++++++++++++ .../fragments/sound/PulseSettings.java | 221 ++++++++++++++++++ .../SecureSettingColorPickerPreference.java | 43 ++++ .../SystemSettingColorPickerPreference.java | 43 ++++ 7 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 res/xml/pulse_settings.xml create mode 100644 src/com/cherish/settings/fragments/sound/PulseSettings.java create mode 100644 src/net/margaritov/preference/colorpicker/SecureSettingColorPickerPreference.java create mode 100644 src/net/margaritov/preference/colorpicker/SystemSettingColorPickerPreference.java diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index b91d437..d9bce1b 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -537,6 +537,29 @@ @string/qs_tile_animation_duration_quite_fast @string/qs_tile_animation_duration_super_fast + + + + @string/pulse_render_mode_fading_bars + @string/pulse_render_mode_solid_lines + + + + 0 + 1 + + + + @string/pulse_color_accent + @string/pulse_color_custom + @string/pulse_color_lava_lamp + + + + 0 + 1 + 2 + 2500 diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index b51e357..399a874 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -665,7 +665,7 @@ Simple3 Icon Vivo Icon Margaritov Icon - + Mic and camera privacy indicator Show indicator when any app uses mic or camera @@ -766,5 +766,37 @@ Black Clear Vivid(Monet) + + + About Pulse + Pulse is a brilliant audio graphic equalizer when music plays on the device + Pulse + Audio graphic equalizer for navigation bar and lockscreen + Navbar Pulse + Audio graphic equalizer on the navigation bar + Lockscreen Pulse + Audio graphic equalizer on the lockscreen + Ambient Pulse + Audio graphic equalizer on the ambient screen + Render mode + Fading blocks + Solid lines + Fading blocks mode settings + Sanity level + Lava lamp speed + Solid lines count + Solid lines opacity + Solid lines mode settings + Color + Accent + Custom + Lava lamp + Choose color + Turn on smoothing + Each bar is animated more smoothly + Bar width + Bar spacing + Block size + Block spacing diff --git a/res/xml/cherish_settings_lockscreen.xml b/res/xml/cherish_settings_lockscreen.xml index 77ba272..bc96433 100644 --- a/res/xml/cherish_settings_lockscreen.xml +++ b/res/xml/cherish_settings_lockscreen.xml @@ -112,6 +112,13 @@ android:entryValues="@array/lockscreen_albumart_filter_values" android:dependency="lockscreen_media_metadata" android:defaultValue="0" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/cherish/settings/fragments/sound/PulseSettings.java b/src/com/cherish/settings/fragments/sound/PulseSettings.java new file mode 100644 index 0000000..a85c7d6 --- /dev/null +++ b/src/com/cherish/settings/fragments/sound/PulseSettings.java @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2016-2021 crDroid Android 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.sound; + +import android.content.Context; +import android.content.ContentResolver; +import android.content.DialogInterface; +import android.content.res.Resources; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.os.UserHandle; +import android.provider.Settings; + +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; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +import net.margaritov.preference.colorpicker.ColorPickerPreference; + +public class PulseSettings extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener { + + private static final String TAG = PulseSettings.class.getSimpleName(); + + private static final String NAVBAR_PULSE_ENABLED_KEY = "navbar_pulse_enabled"; + private static final String LOCKSCREEN_PULSE_ENABLED_KEY = "lockscreen_pulse_enabled"; + private static final String AMBIENT_PULSE_ENABLED_KEY = "ambient_pulse_enabled"; + private static final String PULSE_SMOOTHING_KEY = "pulse_smoothing_enabled"; + private static final String PULSE_COLOR_MODE_KEY = "pulse_color_mode"; + private static final String PULSE_COLOR_MODE_CHOOSER_KEY = "pulse_color_user"; + private static final String PULSE_COLOR_MODE_LAVA_SPEED_KEY = "pulse_lavalamp_speed"; + private static final String PULSE_RENDER_CATEGORY_SOLID = "pulse_2"; + private static final String PULSE_RENDER_CATEGORY_FADING = "pulse_fading_bars_category"; + private static final String PULSE_RENDER_MODE_KEY = "pulse_render_style"; + private static final int RENDER_STYLE_FADING_BARS = 0; + private static final int RENDER_STYLE_SOLID_LINES = 1; + private static final int COLOR_TYPE_ACCENT = 0; + private static final int COLOR_TYPE_USER = 1; + private static final int COLOR_TYPE_LAVALAMP = 2; + private static final int COLOR_TYPE_AUTO = 3; + + private static final String PULSE_SETTINGS_FOOTER = "pulse_settings_footer"; + + private SwitchPreference mNavbarPulse; + private SwitchPreference mLockscreenPulse; + private SwitchPreference mAmbientPulse; + private SwitchPreference mPulseSmoothing; + private Preference mRenderMode; + private ListPreference mColorModePref; + private ColorPickerPreference mColorPickerPref; + private Preference mLavaSpeedPref; + private Preference mFooterPref; + + private PreferenceCategory mFadingBarsCat; + private PreferenceCategory mSolidBarsCat; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.pulse_settings); + + ContentResolver resolver = getContext().getContentResolver(); + + mNavbarPulse = (SwitchPreference) findPreference(NAVBAR_PULSE_ENABLED_KEY); + boolean navbarPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.NAVBAR_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0; + mNavbarPulse.setChecked(navbarPulse); + mNavbarPulse.setOnPreferenceChangeListener(this); + + mLockscreenPulse = (SwitchPreference) findPreference(LOCKSCREEN_PULSE_ENABLED_KEY); + boolean lockscreenPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.LOCKSCREEN_PULSE_ENABLED, 1, UserHandle.USER_CURRENT) != 0; + mLockscreenPulse.setChecked(lockscreenPulse); + mLockscreenPulse.setOnPreferenceChangeListener(this); + + mAmbientPulse = (SwitchPreference) findPreference(AMBIENT_PULSE_ENABLED_KEY); + boolean ambientPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.AMBIENT_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0; + mAmbientPulse.setChecked(ambientPulse); + mAmbientPulse.setOnPreferenceChangeListener(this); + + mColorModePref = (ListPreference) findPreference(PULSE_COLOR_MODE_KEY); + mColorPickerPref = (ColorPickerPreference) findPreference(PULSE_COLOR_MODE_CHOOSER_KEY); + mLavaSpeedPref = findPreference(PULSE_COLOR_MODE_LAVA_SPEED_KEY); + mColorModePref.setOnPreferenceChangeListener(this); + + mRenderMode = findPreference(PULSE_RENDER_MODE_KEY); + mRenderMode.setOnPreferenceChangeListener(this); + + mFadingBarsCat = (PreferenceCategory) findPreference( + PULSE_RENDER_CATEGORY_FADING); + mSolidBarsCat = (PreferenceCategory) findPreference( + PULSE_RENDER_CATEGORY_SOLID); + + mPulseSmoothing = (SwitchPreference) findPreference(PULSE_SMOOTHING_KEY); + + mFooterPref = findPreference(PULSE_SETTINGS_FOOTER); + mFooterPref.setTitle(R.string.pulse_help_policy_notice_summary); + + updateAllPrefs(); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + ContentResolver resolver = getContext().getContentResolver(); + if (preference == mNavbarPulse) { + boolean val = (Boolean) newValue; + Settings.Secure.putIntForUser(resolver, + Settings.Secure.NAVBAR_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT); + updateAllPrefs(); + return true; + } else if (preference == mLockscreenPulse) { + boolean val = (Boolean) newValue; + Settings.Secure.putIntForUser(resolver, + Settings.Secure.LOCKSCREEN_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT); + updateAllPrefs(); + return true; + } else if (preference == mAmbientPulse) { + boolean val = (Boolean) newValue; + Settings.Secure.putIntForUser(resolver, + Settings.Secure.AMBIENT_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT); + updateAllPrefs(); + return true; + } else if (preference == mColorModePref) { + updateColorPrefs(Integer.valueOf(String.valueOf(newValue))); + return true; + } else if (preference == mRenderMode) { + updateRenderCategories(Integer.valueOf(String.valueOf(newValue))); + return true; + } + return false; + } + + private void updateAllPrefs() { + ContentResolver resolver = getContext().getContentResolver(); + + boolean navbarPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.NAVBAR_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0; + boolean lockscreenPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.LOCKSCREEN_PULSE_ENABLED, 1, UserHandle.USER_CURRENT) != 0; + + boolean ambientPulse = Settings.Secure.getIntForUser(resolver, + Settings.Secure.AMBIENT_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0; + + mPulseSmoothing.setEnabled(navbarPulse || lockscreenPulse || ambientPulse); + + mColorModePref.setEnabled(navbarPulse || lockscreenPulse || ambientPulse); + if (navbarPulse || lockscreenPulse) { + int colorMode = Settings.Secure.getIntForUser(resolver, + Settings.Secure.PULSE_COLOR_MODE, COLOR_TYPE_LAVALAMP, UserHandle.USER_CURRENT); + updateColorPrefs(colorMode); + } else { + mColorPickerPref.setEnabled(false); + mLavaSpeedPref.setEnabled(false); + } + + mRenderMode.setEnabled(navbarPulse || lockscreenPulse || ambientPulse); + if (navbarPulse || lockscreenPulse || ambientPulse) { + int renderMode = Settings.Secure.getIntForUser(resolver, + Settings.Secure.PULSE_RENDER_STYLE, RENDER_STYLE_SOLID_LINES, UserHandle.USER_CURRENT); + updateRenderCategories(renderMode); + } else { + mFadingBarsCat.setEnabled(false); + mSolidBarsCat.setEnabled(false); + } + + mFooterPref.setEnabled(navbarPulse || lockscreenPulse); + } + + private void updateColorPrefs(int val) { + switch (val) { + case COLOR_TYPE_ACCENT: + mColorPickerPref.setEnabled(false); + mLavaSpeedPref.setEnabled(false); + break; + case COLOR_TYPE_USER: + mColorPickerPref.setEnabled(true); + mLavaSpeedPref.setEnabled(false); + break; + case COLOR_TYPE_LAVALAMP: + mColorPickerPref.setEnabled(false); + mLavaSpeedPref.setEnabled(true); + break; + case COLOR_TYPE_AUTO: + mColorPickerPref.setEnabled(false); + mLavaSpeedPref.setEnabled(false); + break; + } + } + + private void updateRenderCategories(int mode) { + mFadingBarsCat.setEnabled(mode == RENDER_STYLE_FADING_BARS); + mSolidBarsCat.setEnabled(mode == RENDER_STYLE_SOLID_LINES); + } + + @Override + public int getMetricsCategory() { + return MetricsProto.MetricsEvent.CHERISH_SETTINGS; + } +} diff --git a/src/net/margaritov/preference/colorpicker/SecureSettingColorPickerPreference.java b/src/net/margaritov/preference/colorpicker/SecureSettingColorPickerPreference.java new file mode 100644 index 0000000..ee3ad1c --- /dev/null +++ b/src/net/margaritov/preference/colorpicker/SecureSettingColorPickerPreference.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 crDroid Android 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 net.margaritov.preference.colorpicker; + +import android.content.Context; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.provider.Settings; + +import com.cherish.settings.preferences.SecureSettingsStore; + +import net.margaritov.preference.colorpicker.ColorPickerPreference; + +public class SecureSettingColorPickerPreference extends ColorPickerPreference { + + public SecureSettingColorPickerPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver())); + } + + public SecureSettingColorPickerPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver())); + } + + public SecureSettingColorPickerPreference(Context context) { + super(context, null); + setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver())); + } +} \ No newline at end of file diff --git a/src/net/margaritov/preference/colorpicker/SystemSettingColorPickerPreference.java b/src/net/margaritov/preference/colorpicker/SystemSettingColorPickerPreference.java new file mode 100644 index 0000000..693716a --- /dev/null +++ b/src/net/margaritov/preference/colorpicker/SystemSettingColorPickerPreference.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 crDroid Android 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 net.margaritov.preference.colorpicker; + +import android.content.Context; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.provider.Settings; + +import com.cherish.settings.preferences.SystemSettingsStore; + +import net.margaritov.preference.colorpicker.ColorPickerPreference; + +public class SystemSettingColorPickerPreference extends ColorPickerPreference { + + public SystemSettingColorPickerPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setPreferenceDataStore(new SystemSettingsStore(context.getContentResolver())); + } + + public SystemSettingColorPickerPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setPreferenceDataStore(new SystemSettingsStore(context.getContentResolver())); + } + + public SystemSettingColorPickerPreference(Context context) { + super(context, null); + setPreferenceDataStore(new SystemSettingsStore(context.getContentResolver())); + } +} \ No newline at end of file