From f51e75a73e7e7414c53b261f39ba112174d33d75 Mon Sep 17 00:00:00 2001 From: jhonboy121 Date: Thu, 12 Jan 2023 21:12:05 +0700 Subject: [PATCH] Cherish: Monet settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f547af0ea12dadee832ab6f0e545a89eb9f4bd82. Signed-off-by: Hưng Phan --- res/values/cherish_strings.xml | 14 +++++ res/xml/cherish_settings_theme.xml | 7 +++ res/xml/monet_engine_settings.xml | 55 +++++++++++++++++ .../MonetChromaFactorPreferenceController.kt | 61 +++++++++++++++++++ .../MonetCustomColorPreferenceController.kt | 49 +++++++++++++++ .../settings/fragments/MonetEngineSettings.kt | 37 +++++++++++ 6 files changed, 223 insertions(+) create mode 100644 res/xml/monet_engine_settings.xml create mode 100644 src/com/cherish/settings/fragments/MonetChromaFactorPreferenceController.kt create mode 100644 src/com/cherish/settings/fragments/MonetCustomColorPreferenceController.kt create mode 100644 src/com/cherish/settings/fragments/MonetEngineSettings.kt diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index 28fefb0..8ec98ac 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -653,6 +653,20 @@ Label text size Columns (portrait) Columns (landscape) + + + Monet engine + Custom color, colorfulness, brightness + Use accurate shades + Custom color picker + Using wallpaper color + + Choosen color: %1$s. Set an empty value to use wallpaper color. + + Invalid color input! + Colorfulness + Use custom lightness scale + Brightness Power menu animation diff --git a/res/xml/cherish_settings_theme.xml b/res/xml/cherish_settings_theme.xml index 918cfe1..a2ae307 100644 --- a/res/xml/cherish_settings_theme.xml +++ b/res/xml/cherish_settings_theme.xml @@ -109,6 +109,13 @@ android:summary="%s" android:defaultValue="0" /> + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/cherish/settings/fragments/MonetChromaFactorPreferenceController.kt b/src/com/cherish/settings/fragments/MonetChromaFactorPreferenceController.kt new file mode 100644 index 0000000..8d6b43c --- /dev/null +++ b/src/com/cherish/settings/fragments/MonetChromaFactorPreferenceController.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 FlamingoOS 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.content.Context +import android.os.UserHandle +import android.provider.Settings + +import androidx.preference.Preference + +import com.android.settings.core.BasePreferenceController +import com.cherish.settings.preferences.CustomSeekBarPreference + +class MonetChromaFactorPreferenceController( + context: Context, + key: String, +) : BasePreferenceController(context, key), + Preference.OnPreferenceChangeListener { + + override fun getAvailabilityStatus(): Int = AVAILABLE + + override fun updateState(preference: Preference) { + super.updateState(preference) + val chromaFactor = Settings.Secure.getFloatForUser( + mContext.contentResolver, + Settings.Secure.MONET_ENGINE_CHROMA_FACTOR, + CHROMA_DEFAULT, + UserHandle.USER_CURRENT + ) * 100 + (preference as CustomSeekBarPreference).apply { + setValue(chromaFactor.toInt()) + } + } + + override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { + return Settings.Secure.putFloatForUser( + mContext.contentResolver, + Settings.Secure.MONET_ENGINE_CHROMA_FACTOR, + (newValue as Int) / 100f, + UserHandle.USER_CURRENT + ) + } + + companion object { + private const val CHROMA_DEFAULT = 1f + } +} diff --git a/src/com/cherish/settings/fragments/MonetCustomColorPreferenceController.kt b/src/com/cherish/settings/fragments/MonetCustomColorPreferenceController.kt new file mode 100644 index 0000000..bc004eb --- /dev/null +++ b/src/com/cherish/settings/fragments/MonetCustomColorPreferenceController.kt @@ -0,0 +1,49 @@ + +/* + * Copyright (C) 2022 FlamingoOS 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.content.Context +import android.os.UserHandle +import android.provider.Settings + +import com.android.settings.R +import com.android.settings.core.BasePreferenceController + +class MonetCustomColorPreferenceController( + context: Context, + key: String, +) : BasePreferenceController(context, key) { + + override fun getAvailabilityStatus(): Int = AVAILABLE + + override fun getSummary(): CharSequence? { + val customColor = Settings.Secure.getStringForUser( + mContext.contentResolver, + Settings.Secure.MONET_ENGINE_COLOR_OVERRIDE, + UserHandle.USER_CURRENT, + ) + return if (customColor == null || customColor.isBlank()) { + mContext.getString(R.string.color_override_default_summary) + } else { + mContext.getString( + R.string.custom_color_override_summary_placeholder, + customColor + ) + } + } +} diff --git a/src/com/cherish/settings/fragments/MonetEngineSettings.kt b/src/com/cherish/settings/fragments/MonetEngineSettings.kt new file mode 100644 index 0000000..87cd9f1 --- /dev/null +++ b/src/com/cherish/settings/fragments/MonetEngineSettings.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 FlamingoOS 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 com.android.settings.R +import com.android.settings.search.BaseSearchIndexProvider +import com.android.settingslib.search.SearchIndexable +import com.cherish.settings.fragments.CherishDashboardFragment + +@SearchIndexable +class MonetEngineSettings : CherishDashboardFragment() { + + override protected fun getPreferenceScreenResId() = R.xml.monet_engine_settings + + override protected fun getLogTag() = TAG + + companion object { + private const val TAG = "MonetEngineSettings" + + @JvmField + val SEARCH_INDEX_DATA_PROVIDER = BaseSearchIndexProvider(R.xml.monet_engine_settings) + } +}