Files
app_Settings/src/com/android/settings/accessibility/DaltonizerPreference.kt
Chun-Ku Lin 0f84b652cc Make ColorAndMotionFragment fully in Catalyst
Bug: 392190782
Test: manual (verify the navigation and the search still works the same)
Test: atest
Flag: com.android.settings.flags.catalyst_accessibility_color_and_motion

Change-Id: I7717390c70246503aec545991fd9a40be5152373
2025-02-17 03:01:36 +00:00

82 lines
3.1 KiB
Kotlin

/*
* Copyright (C) 2025 The Android Open Source 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.android.settings.accessibility
import android.app.settings.SettingsEnums
import android.content.Context
import android.provider.Settings
import com.android.settings.R
import com.android.settings.core.SubSettingLauncher
import com.android.settingslib.datastore.HandlerExecutor
import com.android.settingslib.datastore.KeyedObserver
import com.android.settingslib.datastore.SettingsSecureStore
import com.android.settingslib.metadata.PreferenceLifecycleContext
import com.android.settingslib.metadata.PreferenceLifecycleProvider
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.PreferenceSummaryProvider
class DaltonizerPreference : PreferenceMetadata, PreferenceSummaryProvider,
PreferenceLifecycleProvider {
override val key: String
get() = PREFERENCE_KEY
override val title: Int
get() = com.android.settingslib.R.string.accessibility_display_daltonizer_preference_title
override val icon: Int
get() = R.drawable.ic_daltonizer
override val keywords: Int
get() = R.string.keywords_color_correction
private var mSettingsKeyedObserver: KeyedObserver<String>? = null
override fun intent(context: Context) =
SubSettingLauncher(context)
.setDestination(ToggleDaltonizerPreferenceFragment::class.java.name)
.setSourceMetricsCategory(SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION)
.toIntent()
override fun getSummary(context: Context): CharSequence? {
return AccessibilityUtil.getSummary(
context,
SETTING_KEY,
R.string.daltonizer_state_on, R.string.daltonizer_state_off
)
}
override fun onStart(context: PreferenceLifecycleContext) {
val observer =
KeyedObserver<String> { _, _ -> context.notifyPreferenceChange(PREFERENCE_KEY) }
mSettingsKeyedObserver = observer
val storage = SettingsSecureStore.get(context)
storage.addObserver(SETTING_KEY, observer, HandlerExecutor.main)
}
override fun onStop(context: PreferenceLifecycleContext) {
mSettingsKeyedObserver?.let {
val storage = SettingsSecureStore.get(context)
storage.removeObserver(SETTING_KEY, it)
mSettingsKeyedObserver = null
}
}
companion object {
const val PREFERENCE_KEY = "daltonizer_preference"
const val SETTING_KEY = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED
}
}