Cherish:update edge light preferences
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
<com.android.settingslib.widget.TopIntroPreference
|
<com.android.settingslib.widget.TopIntroPreference
|
||||||
android:key="edge_light_intro"
|
android:key="edge_light_intro"
|
||||||
android:title="@string/edge_light_intro_text"
|
android:title="@string/edge_light_intro_text" />
|
||||||
android:selectable="false"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<com.cherish.settings.preferences.SystemSettingMainSwitchPreference
|
<com.cherish.settings.preferences.SystemSettingMainSwitchPreference
|
||||||
android:key="edge_light_enabled"
|
android:key="edge_light_enabled"
|
||||||
@@ -46,9 +44,9 @@
|
|||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
android:defaultValue="0" />
|
android:defaultValue="0" />
|
||||||
|
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<com.cherish.settings.preferences.SystemSettingColorPickerPreference
|
||||||
android:key="edge_light_custom_color"
|
android:key="edge_light_custom_color"
|
||||||
android:title="@string/edge_light_custom_color_title"
|
android:title="@string/edge_light_custom_color_title"
|
||||||
android:defaultValue="0xffffff" />
|
android:defaultValue="#FFFFFF" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -34,10 +34,10 @@
|
|||||||
android:entryValues="@array/torch_power_button_gesture_values" />
|
android:entryValues="@array/torch_power_button_gesture_values" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="edge_light_enabled"
|
android:key="edge_light_enabled"
|
||||||
android:title="@string/edge_light_title"
|
android:title="@string/edge_light_title"
|
||||||
android:summary="@string/edge_light_intro_text"
|
android:summary="@string/edge_light_intro_text"
|
||||||
android:fragment="com.cherish.settings.fragments.EdgeLightSettings" />
|
android:fragment="com.cherish.settings.lockscreen.EdgeLightSettings"/>
|
||||||
|
|
||||||
<com.cherish.settings.preferences.SecureSettingSwitchPreference
|
<com.cherish.settings.preferences.SecureSettingSwitchPreference
|
||||||
android:key="power_menu_hide_on_secure"
|
android:key="power_menu_hide_on_secure"
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019-2022 The CherishOS Projects
|
|
||||||
*
|
|
||||||
* 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.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
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.view.View;
|
|
||||||
|
|
||||||
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 java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
|
||||||
public class EdgeLightSettings extends SettingsPreferenceFragment implements
|
|
||||||
Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
addPreferencesFromResource(R.xml.cherish_settings_edge_light);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.CHERISH_SETTINGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For Search.
|
|
||||||
*/
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider(R.xml.cherish_settings_edge_light);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* 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.lockscreen
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.database.ContentObserver
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.UserHandle
|
||||||
|
import android.provider.Settings
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle.Event
|
||||||
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import androidx.preference.PreferenceScreen
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle
|
||||||
|
|
||||||
|
class EdgeLightColorPickerPreferenceController(
|
||||||
|
context: Context,
|
||||||
|
preferenceKey: String,
|
||||||
|
lifecycle: Lifecycle?,
|
||||||
|
) : BasePreferenceController(context, preferenceKey),
|
||||||
|
LifecycleEventObserver {
|
||||||
|
|
||||||
|
private val settingsObserver = object : ContentObserver(
|
||||||
|
Handler(Looper.getMainLooper())
|
||||||
|
) {
|
||||||
|
override fun onChange(selfChange: Boolean) {
|
||||||
|
preference?.let {
|
||||||
|
updateState(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var preference: Preference? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
lifecycle?.addObserver(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStateChanged(owner: LifecycleOwner, event: Event) {
|
||||||
|
if (event == Event.ON_START) {
|
||||||
|
mContext.contentResolver.registerContentObserver(
|
||||||
|
Settings.System.getUriFor(Settings.System.EDGE_LIGHT_COLOR_MODE),
|
||||||
|
false /* notifyDescendants */,
|
||||||
|
settingsObserver,
|
||||||
|
)
|
||||||
|
} else if (event == Event.ON_STOP) {
|
||||||
|
mContext.contentResolver.unregisterContentObserver(settingsObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAvailabilityStatus(): Int {
|
||||||
|
val isCustomColorMode = Settings.System.getIntForUser(
|
||||||
|
mContext.contentResolver,
|
||||||
|
Settings.System.EDGE_LIGHT_COLOR_MODE,
|
||||||
|
0, UserHandle.USER_CURRENT
|
||||||
|
) == 3
|
||||||
|
return if (isCustomColorMode) {
|
||||||
|
AVAILABLE
|
||||||
|
} else {
|
||||||
|
DISABLED_DEPENDENT_SETTING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun displayPreference(screen: PreferenceScreen) {
|
||||||
|
super.displayPreference(screen)
|
||||||
|
preference = screen.findPreference(preferenceKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateState(preference: Preference) {
|
||||||
|
super.updateState(preference)
|
||||||
|
preference.setEnabled(getAvailabilityStatus() == AVAILABLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/com/cherish/settings/lockscreen/EdgeLightSettings.kt
Normal file
87
src/com/cherish/settings/lockscreen/EdgeLightSettings.kt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.lockscreen
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.Switch
|
||||||
|
|
||||||
|
import androidx.preference.forEachIndexed
|
||||||
|
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle
|
||||||
|
import com.android.settingslib.search.SearchIndexable
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener
|
||||||
|
import com.android.settingslib.widget.TopIntroPreference
|
||||||
|
import com.cherish.settings.fragments.CherishDashboardFragment
|
||||||
|
|
||||||
|
@SearchIndexable
|
||||||
|
class EdgeLightSettings : CherishDashboardFragment(), OnMainSwitchChangeListener {
|
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
|
super.onCreatePreferences(savedInstanceState, rootKey)
|
||||||
|
findPreference<MainSwitchPreference>(MAIN_SWITCH_KEY)?.also {
|
||||||
|
updatePreferences(it.isChecked)
|
||||||
|
it.addOnSwitchChangeListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected fun getPreferenceScreenResId() = R.xml.cherish_settings_edge_light
|
||||||
|
|
||||||
|
override protected fun getLogTag() = TAG
|
||||||
|
|
||||||
|
override protected fun createPreferenceControllers(
|
||||||
|
context: Context
|
||||||
|
): List<AbstractPreferenceController> = buildPreferenceControllers(context, settingsLifecycle)
|
||||||
|
|
||||||
|
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
|
||||||
|
updatePreferences(isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePreferences(isChecked: Boolean) {
|
||||||
|
preferenceScreen.forEachIndexed { _, preference ->
|
||||||
|
if (preference !is MainSwitchPreference &&
|
||||||
|
preference !is TopIntroPreference
|
||||||
|
) preference.isVisible = isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "EdgeLightSettingsFragment"
|
||||||
|
|
||||||
|
private const val MAIN_SWITCH_KEY = "edge_light_enabled"
|
||||||
|
private const val CUSTOM_COLOR_PREFERENCE_KEY = "edge_light_custom_color"
|
||||||
|
|
||||||
|
private fun buildPreferenceControllers(
|
||||||
|
context: Context,
|
||||||
|
lifecycle: Lifecycle?,
|
||||||
|
): List<AbstractPreferenceController> = listOf(
|
||||||
|
EdgeLightColorPickerPreferenceController(context, CUSTOM_COLOR_PREFERENCE_KEY, lifecycle)
|
||||||
|
)
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val SEARCH_INDEX_DATA_PROVIDER = object : BaseSearchIndexProvider(R.xml.cherish_settings_edge_light) {
|
||||||
|
override fun createPreferenceControllers(
|
||||||
|
context: Context
|
||||||
|
): List<AbstractPreferenceController> = buildPreferenceControllers(
|
||||||
|
context, null /* lifecycle */)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user