Cherish: Pulse initial checkin for Android 11 [4/4]

Squashed in:
* Pulse navbar audio gfx visualizer for Android 10 [3/4] - bigrushdog
* Add automatic album art color mode for navbar pulse [3/3] - ezio84
* Extend NavBar Pulse to LockScreen [2/2] - neobuddy89

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
bigrushdog
2020-06-09 16:31:25 -07:00
committed by Hưng Phan
parent 87fd619a2a
commit b6685242ef
4 changed files with 415 additions and 0 deletions

View File

@@ -1330,4 +1330,29 @@
<item>5</item> <item>5</item>
<item>6</item> <item>6</item>
</string-array> </string-array>
<!-- Pulse -->
<string-array name="pulse_render_mode_entries">
<item>@string/pulse_render_mode_fading_bars</item>
<item>@string/pulse_render_mode_solid_lines</item>
</string-array>
<string-array name="pulse_render_mode_values" translatable="false">
<item>0</item>
<item>1</item>
</string-array>
<string-array name="pulse_color_mode_entries">
<item>@string/pulse_color_accent</item>
<item>@string/pulse_color_custom</item>
<item>@string/pulse_color_lava_lamp</item>
<item>@string/pulse_color_auto</item>
</string-array>
<string-array name="pulse_color_mode_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources> </resources>

View File

@@ -246,6 +246,13 @@
android:key="visualizer" android:key="visualizer"
android:title="@string/visualizer_title"> android:title="@string/visualizer_title">
<Preference
android:key="pulse_category"
android:icon="@drawable/ic_visualizer"
android:fragment="com.cherish.settings.fragments.PulseSettings"
android:title="@string/pulse_settings"
android:summary="@string/pulse_settings_summary" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference <com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="lockscreen_media_art" android:key="lockscreen_media_art"
android:icon="@drawable/ic_media" android:icon="@drawable/ic_media"

154
res/xml/pulse_settings.xml Normal file
View File

@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 CherishOS
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 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/pulse_settings" >
<SwitchPreference
android:key="navbar_pulse_enabled"
android:title="@string/show_navbar_pulse_title"
android:summary="@string/show_navbar_pulse_summary"/>
<SwitchPreference
android:key="lockscreen_pulse_enabled"
android:title="@string/show_lockscreen_pulse_title"
android:summary="@string/show_lockscreen_pulse_summary"/>
<com.cherish.settings.preferences.SecureSettingListPreference
android:key="pulse_render_style"
android:title="@string/pulse_render_mode_title"
android:entries="@array/pulse_render_mode_entries"
android:entryValues="@array/pulse_render_mode_values"
android:defaultValue="1"/>
<com.cherish.settings.preferences.SecureSettingSwitchPreference
android:key="pulse_smoothing_enabled"
android:title="@string/smoothing_enabled_title"
android:summary="@string/smoothing_enabled_summary"
android:defaultValue="false"/>
<PreferenceCategory
android:key="pulse_color_category"
android:title="@string/pulse_color">
<com.cherish.settings.preferences.SecureSettingListPreference
android:key="pulse_color_mode"
android:title="@string/pulse_color_mode"
android:entries="@array/pulse_color_mode_entries"
android:entryValues="@array/pulse_color_mode_values"
android:defaultValue="2"/>
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="pulse_color_user"
android:title="@string/pulse_color_chooser"
android:defaultValue="0xffffffff"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_lavalamp_speed"
android:title="@string/lavamp_speed_title"
android:max="30000"
android:defaultValue="10000"
settings:min="200"
settings:interval="200"
settings:units="ms"/>
</PreferenceCategory>
<PreferenceCategory
android:key="pulse_fading_bars_category"
android:title="@string/pulse_legacy_mode_advanced_category">
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_custom_dimen"
android:title="@string/pulse_custom_dimen"
android:max="30"
android:defaultValue="14"
settings:min="1"
settings:units="dp"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_custom_div"
android:title="@string/pulse_custom_div"
android:max="44"
android:defaultValue="16"
settings:min="2"
settings:interval="2"
settings:units="dp"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_filled_block_size"
android:title="@string/pulse_filled_block_size"
android:max="8"
android:defaultValue="4"
settings:min="4"
settings:units="dp"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_empty_block_size"
android:title="@string/pulse_empty_block_size"
android:max="4"
android:defaultValue="1"
settings:min="0"
settings:units="dp"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_custom_fudge_factor"
android:title="@string/pulse_custom_fudge_factor"
android:max="6"
android:defaultValue="4"
settings:min="2"
android:dependency="pulse_fading_bars_category"/>
</PreferenceCategory>
<PreferenceCategory
android:key="pulse_2"
android:title="@string/pulse_solid_dimen_category">
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_solid_units_opacity"
android:title="@string/pulse_solid_units_opacity"
android:max="255"
android:defaultValue="200"
settings:min="0"
android:dependency="pulse_2"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_solid_units_count"
android:title="@string/pulse_solid_units_count"
android:defaultValue="32"
android:max="128"
settings:interval="16"
settings:min="16"
android:dependency="pulse_2"/>
<com.cherish.settings.preferences.SecureSettingSeekBarPreference
android:key="pulse_solid_fudge_factor"
android:title="@string/pulse_custom_fudge_factor"
android:max="6"
android:defaultValue="4"
settings:min="2"
android:dependency="pulse_2"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference
android:key="pulse_footer_pref"
android:title="@string/pulse_help_policy_notice_summary"
android:selectable="false"
settings:searchable="false"
settings:allowDividerAbove="true"/>
</PreferenceScreen>

View File

@@ -0,0 +1,229 @@
/*
* Copyright (C) 2020 The Dirty Unicorns 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.ActionBar;
import android.content.Context;
import android.content.ContentResolver;
import android.graphics.Color;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
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 com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SearchIndexable
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 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 SwitchPreference mNavbarPulse;
private SwitchPreference mLockscreenPulse;
private SwitchPreference mPulseSmoothing;
private Preference mRenderMode;
private ListPreference mColorModePref;
private ColorPickerPreference mColorPickerPref;
private Preference mLavaSpeedPref;
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, 0, UserHandle.USER_CURRENT) != 0;
mLockscreenPulse.setChecked(lockscreenPulse);
mLockscreenPulse.setOnPreferenceChangeListener(this);
mColorModePref = (ListPreference) findPreference(PULSE_COLOR_MODE_KEY);
mColorPickerPref = (ColorPickerPreference) findPreference(PULSE_COLOR_MODE_CHOOSER_KEY);
int userColor = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.PULSE_COLOR_USER, 0xffffffff);
mColorPickerPref.setOnPreferenceChangeListener(this);
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);
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 == mColorPickerPref) {
int value = (Integer) newValue;
Settings.Secure.putInt(resolver,
Settings.Secure.PULSE_COLOR_USER, value);
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;
mPulseSmoothing.setEnabled(navbarPulse || lockscreenPulse);
mColorModePref.setEnabled(navbarPulse || lockscreenPulse);
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);
if (navbarPulse || lockscreenPulse) {
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);
}
}
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;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.pulse_settings;
return Arrays.asList(sir);
}
@Override
public List<String> getNonIndexableKeys(Context context) {
ArrayList<String> result = new ArrayList<String>();
return result;
}
};
}