Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a98a8e3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Create PreferenceControllers and xml for ExtraDim screen" into main

parents a280dc5b 0c7a1458
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ 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.
  -->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:persistent="false"
    android:title="@string/reduce_bright_colors_preference_title">

    <com.android.settingslib.widget.TopIntroPreference
        android:key="top_intro"
        android:title="@string/reduce_bright_colors_preference_intro_text"
        settings:searchable="false" />

    <com.android.settingslib.widget.IllustrationPreference
        android:key="animated_image"
        settings:controller="com.android.settings.accessibility.detail.extradim.ExtraDimIllustrationPreferenceController"
        settings:searchable="false" />

    <com.android.settingslib.widget.MainSwitchPreference
        android:key="rbc_switch"
        android:title="@string/reduce_bright_colors_switch_title"
        settings:controller="com.android.settings.accessibility.detail.extradim.ExtraDimMainSwitchPreferenceController" />

    <PreferenceCategory
        android:title="@string/accessibility_screen_option"
        settings:searchable="false">

        <com.android.settingslib.widget.SliderPreference
            android:key="rbc_intensity"
            android:persistent="false"
            android:title="@string/reduce_bright_colors_intensity_preference_title"
            settings:textEnd="@string/reduce_bright_colors_intensity_end_label"
            settings:textStart="@string/reduce_bright_colors_intensity_start_label"
            settings:controller="com.android.settings.accessibility.detail.extradim.IntensityPreferenceController"/>

        <!-- The term `restarts` is usually used for indicating restarting devices.
             Therefore, We wouldn't want `Keep on after device restarts` preference in the Extra Dim
             shows up as the search result when the user searches `restart`-->
        <SwitchPreferenceCompat
            android:key="rbc_persist"
            android:persistent="false"
            android:title="@string/reduce_bright_colors_persist_preference_title"
            settings:searchable="false"
            settings:controller="com.android.settings.accessibility.detail.extradim.PersistentAfterRestartsPreferenceController"/>

        <com.android.settings.accessibility.ShortcutPreference
            android:key="rbc_shortcut"
            android:persistent="false"
            android:title="@string/reduce_bright_colors_shortcut_title"
            settings:controller="com.android.settings.accessibility.ToggleShortcutPreferenceController" />

    </PreferenceCategory>

    <com.android.settings.accessibility.AccessibilityFooterPreference
        android:key="html_description"
        settings:controller="com.android.settings.accessibility.detail.extradim.FooterPreferenceController"
        settings:searchable="false" />

</PreferenceScreen>
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
@@ -80,10 +80,6 @@ abstract class SimpleSettingSwitchPreferenceController(context: Context, prefKey
    }

    private fun setChecked(preference: TwoStatePreference, checked: Boolean) {
        val isEnabled = isChecked()
        if (checked == isEnabled) {
            return
        }
        AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(getComponentName(), checked)
        Settings.Secure.putInt(
            mContext.contentResolver,
+41 −0
Original line number Diff line number Diff line
/*
 * 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.detail.extradim

import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import com.android.settings.R
import com.android.settings.accessibility.IllustrationPreferenceController

class ExtraDimIllustrationPreferenceController(context: Context, prefKey: String) :
    IllustrationPreferenceController(context, prefKey) {
    init {
        val imageUri =
            Uri.Builder()
                .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
                .authority(context.packageName)
                .appendPath(R.raw.extra_dim_banner.toString())
                .build()
        val contentDescription =
            context.getString(
                R.string.accessibility_illustration_content_description,
                context.getText(R.string.reduce_bright_colors_preference_title),
            )
        initialize(imageUri, contentDescription)
    }
}
+79 −0
Original line number Diff line number Diff line
/*
 * 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.detail.extradim

import android.content.Context
import android.database.ContentObserver
import android.hardware.display.ColorDisplayManager
import android.os.Handler
import android.os.Looper
import androidx.preference.Preference
import androidx.preference.PreferenceScreen
import androidx.preference.TwoStatePreference
import com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME
import com.android.settings.accessibility.AccessibilityStatsLogUtils
import com.android.settings.core.BasePreferenceController

class ExtraDimMainSwitchPreferenceController(override val context: Context, prefKey: String) :
    BasePreferenceController(context, prefKey),
    ExtraDimSettingDependent,
    Preference.OnPreferenceChangeListener {

    private val colorDisplayManager: ColorDisplayManager? =
        context.getSystemService(ColorDisplayManager::class.java)
    private var preference: TwoStatePreference? = null
    override val contentObserver: ContentObserver =
        object : ContentObserver(Looper.myLooper()?.run { Handler(/* async= */ false) }) {
            override fun onChange(selfChange: Boolean) {
                preference?.let { updateState(it) }
            }
        }

    override fun getAvailabilityStatus(): Int = AVAILABLE

    override fun displayPreference(screen: PreferenceScreen?) {
        super.displayPreference(screen)
        preference = screen?.findPreference(preferenceKey)
    }

    override fun updateState(preference: Preference?) {
        super.updateState(preference)
        if (preference is TwoStatePreference) {
            preference.isChecked = isChecked()
        }
    }

    private fun setChecked(preference: TwoStatePreference, checked: Boolean) {
        AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(
            REDUCE_BRIGHT_COLORS_COMPONENT_NAME,
            checked,
        )
        colorDisplayManager?.setReduceBrightColorsActivated(checked)
        updateState(preference)
    }

    private fun isChecked(): Boolean {
        return colorDisplayManager?.isReduceBrightColorsActivated == true
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (preference is TwoStatePreference && newValue is Boolean) {
            setChecked(preference, newValue)
        }
        return false
    }
}
+41 −0
Original line number Diff line number Diff line
/*
 * 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.detail.extradim

import android.content.Context
import android.database.ContentObserver
import android.provider.Settings
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

const val EXTRA_DIM_SETTING = Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED
interface ExtraDimSettingDependent: DefaultLifecycleObserver {
    val context: Context
    val contentObserver: ContentObserver

    override fun onCreate(owner: LifecycleOwner) {
        context.contentResolver.registerContentObserver(
            Settings.Secure.getUriFor(EXTRA_DIM_SETTING),
            /* notifyForDescendants= */ false,
            contentObserver,
        )
    }

    override fun onDestroy(owner: LifecycleOwner) {
        context.contentResolver.unregisterContentObserver(contentObserver)
    }
}
Loading