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

Commit b69c9488 authored by mxyyiyi's avatar mxyyiyi
Browse files

[Expressive Battery] Support warning chip for selector pref in Allow background usage.

Bug: 349652542
Bug: 350657779
Bug: 400626521
Test: visual
Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled
Change-Id: I52218f488c915cc5baf606f54118669dc8702cb7
parent 63f3ebd0
Loading
Loading
Loading
Loading
+45 −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.
  -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:orientation="vertical">

    <include layout="@layout/settingslib_preference_selector_with_widget"
        android:id="@+id/preference_frame"/>

    <LinearLayout
        android:id="@+id/warning_chip_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="@dimen/settingslib_expressive_space_small1"
        android:layout_marginTop="-8dp"
        android:visibility="gone"
        android:clickable="false">
        <Space
            android:id="@+id/warning_padding_placeholder"
            android:layout_width="@dimen/settingslib_expressive_space_medium3"
            android:layout_height="1px"
            android:layout_marginEnd="@dimen/settingslib_expressive_space_extrasmall6"/>

        <include layout="@layout/power_anomaly_hints"/>
    </LinearLayout>

</LinearLayout>
 No newline at end of file
+44 −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.
  -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include layout="@layout/settingslib_preference_selector_with_widget"/>

    <LinearLayout
        android:id="@+id/warning_chip_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:visibility="gone"
        android:clickable="false"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
        <Space
            android:id="@+id/warning_padding_placeholder"
            android:layout_width="@dimen/secondary_app_icon_size"
            android:layout_height="1px"
            android:layout_marginEnd="16dp"/>

        <include layout="@layout/power_anomaly_hints"/>
    </LinearLayout>
</LinearLayout>
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -32,12 +32,12 @@
            android:key="background_usage_allowability_switch"
            android:title="@string/manager_battery_usage_allow_background_usage_title"/>

        <com.android.settingslib.widget.SelectorWithWidgetPreference
        <com.android.settings.fuelgauge.WarningFrameSelectorPreference
            android:key="optimized_preference"
            android:title="@string/manager_battery_usage_optimized_title"
            android:summary="@string/manager_battery_usage_optimized_summary"/>

        <com.android.settingslib.widget.SelectorWithWidgetPreference
        <com.android.settings.fuelgauge.WarningFrameSelectorPreference
            android:key="unrestricted_preference"
            android:title="@string/manager_battery_usage_unrestricted_title"
            android:summary="@string/manager_battery_usage_unrestricted_summary"/>
+85 −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.fuelgauge;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import com.android.settingslib.widget.SettingsThemeHelper;

/**
 * Custom preference for displaying the {@link SelectorWithWidgetPreference}
 * with an optional hint chip
 */
public class WarningFrameSelectorPreference extends SelectorWithWidgetPreference {
    private final boolean mIsExpressiveTheme;
    private final int mWarningChipBackgroundResId;

    @Nullable private CharSequence mHintText;

    public WarningFrameSelectorPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        mIsExpressiveTheme = SettingsThemeHelper.isExpressiveTheme(context);
        int layoutResId =
                mIsExpressiveTheme
                        ? R.layout.expressive_warning_frame_selector_preference
                        : R.layout.warning_frame_selector_preference;
        setLayoutResource(layoutResId);
        mWarningChipBackgroundResId =
                mIsExpressiveTheme
                        ? R.drawable.expressive_battery_hints_chip_bg_ripple
                        : R.drawable.battery_hints_chip_bg_ripple;
    }

    /** Sets the text of hint to show. */
    public void setHint(@Nullable CharSequence hintText) {
        if (!TextUtils.equals(mHintText, hintText)) {
            mHintText = hintText;
            notifyChanged();
        }
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);

        if (mIsExpressiveTheme) {
            final View preferenceFrame = view.findViewById(R.id.preference_frame);
            preferenceFrame.setBackground(null);
            preferenceFrame.setPadding(0, 0, 0, 0);
        }

        final View warningChipFrame = view.findViewById(R.id.warning_chip_frame);
        if (!TextUtils.isEmpty(mHintText)) {
            ((TextView) warningChipFrame.findViewById(R.id.warning_info)).setText(mHintText);
            warningChipFrame.setVisibility(View.VISIBLE);
            warningChipFrame
                    .findViewById(R.id.warning_chip)
                    .setBackgroundResource(mWarningChipBackgroundResId);
        } else {
            warningChipFrame.setVisibility(View.GONE);
        }
    }
}