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

Commit 3eac1574 authored by Jacky Wang's avatar Jacky Wang
Browse files

[Supervision] Custom bottom CardPreference

Fix: 406565456
Flag: android.app.supervision.flags.enable_supervision_settings_screen
Test: manual
Change-Id: I8506d22ddcc7cfa96963da56486c7c8b435440db
parent 164a958a
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import android.widget.TextView
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.android.settings.supervision.ipc.PreferenceData
import com.android.settingslib.metadata.PreferenceLifecycleContext
import com.android.settingslib.metadata.PreferenceLifecycleProvider
@@ -30,6 +32,8 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import com.android.settingslib.widget.mainswitch.R as MainSwitchPreferenceR
import com.android.settingslib.widget.preference.card.R as CardPreferenceR

/** A bottom banner promoting other supervision features offered by the supervision app. */
class SupervisionPromoFooterPreference(
@@ -45,7 +49,7 @@ class SupervisionPromoFooterPreference(
    override val key: String
        get() = KEY

    override fun createWidget(context: Context) = CardPreference(context)
    override fun createWidget(context: Context): Preference = FooterPreference(context)

    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
@@ -113,3 +117,19 @@ class SupervisionPromoFooterPreference(
        const val KEY = "promo_footer"
    }
}

private class FooterPreference(context: Context) : CardPreference(context) {
    override fun onBindViewHolder(holder: PreferenceViewHolder) {
        super.onBindViewHolder(holder)
        // Make colors consistent with main switch preference
        holder.findViewById(CardPreferenceR.id.card_container)?.background =
            context.getDrawable(MainSwitchPreferenceR.drawable.settingslib_expressive_switch_bar_bg)
        val textColor =
            context.resources.getColor(
                MainSwitchPreferenceR.color.settingslib_main_switch_text_color,
                context.theme,
            )
        (holder.findViewById(android.R.id.title) as? TextView)?.setTextColor(textColor)
        (holder.findViewById(android.R.id.summary) as? TextView)?.setTextColor(textColor)
    }
}