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

Commit 1bd55059 authored by Xinyi Mao's avatar Xinyi Mao Committed by Android (Google) Code Review
Browse files

Merge changes from topic "warning_selector" into main

* changes:
  [UR] Pass warning chip arguments to Allow background usage screen.
  [Expressive Battery] Support warning chip for selector pref in Allow background usage.
parents c465112f 759761a5
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"/>
+19 −1
Original line number Diff line number Diff line
@@ -45,13 +45,19 @@ public class BatteryOptimizationModePreferenceController extends BasePreferenceC
    @Nullable @VisibleForTesting MainSwitchPreference mBackgroundUsageAllowabilityPreference;
    @Nullable @VisibleForTesting SelectorWithWidgetPreference mOptimizedPreference;
    @Nullable @VisibleForTesting SelectorWithWidgetPreference mUnrestrictedPreference;
    @Nullable @VisibleForTesting String mHintPrefKey;
    @Nullable @VisibleForTesting String mHintText;

    public BatteryOptimizationModePreferenceController(
            @NonNull Context context,
            @NonNull String preferenceKey,
            @NonNull BatteryOptimizeUtils batteryOptimizeUtils) {
            @NonNull BatteryOptimizeUtils batteryOptimizeUtils,
            @Nullable String hintPrefKey,
            @Nullable String hintText) {
        super(context, preferenceKey);
        mBatteryOptimizeUtils = batteryOptimizeUtils;
        mHintPrefKey = hintPrefKey;
        mHintText = hintText;
    }

    @Override
@@ -72,6 +78,7 @@ public class BatteryOptimizationModePreferenceController extends BasePreferenceC
        mOptimizedPreference = screen.findPreference(KEY_OPTIMIZED_PREF);
        mUnrestrictedPreference = screen.findPreference(KEY_UNRESTRICTED_PREF);
        initPreferences();
        initPreferenceHint(screen);
    }

    @VisibleForTesting
@@ -107,6 +114,17 @@ public class BatteryOptimizationModePreferenceController extends BasePreferenceC
        }
    }

    @VisibleForTesting
    void initPreferenceHint(@NonNull PreferenceScreen screen) {
        if (mHintPrefKey == null || mHintText == null) {
            return;
        }
        final Preference preference = screen.findPreference(mHintPrefKey);
        if (preference instanceof WarningFrameSelectorPreference) {
            ((WarningFrameSelectorPreference) preference).setHint(mHintText);
        }
    }

    @VisibleForTesting
    void updatePreferences(int optimizationMode) {
        if (mBackgroundUsageAllowabilityPreference == null
+11 −1
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ public class PowerBackgroundUsageDetail extends DashboardFragment {
    public static final String EXTRA_POWER_USAGE_AMOUNT = "extra_power_usage_amount";
    public static final String EXTRA_ICON_ID = "extra_icon_id";
    public static final String EXTRA_LAUNCH_SOURCE = "extra_launch_source";
    public static final String EXTRA_HINT_PREF_KEY = "extra_hint_pref_key";
    public static final String EXTRA_HINT_TEXT = "extra_hint_text";

    /** Launch Source type of current fragment. */
    public enum LaunchSourceType {
@@ -145,10 +147,18 @@ public class PowerBackgroundUsageDetail extends DashboardFragment {

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        final Bundle bundle = getArguments();
        final String hintPrefKey = bundle.getString(EXTRA_HINT_PREF_KEY);
        final String hintText = bundle.getString(EXTRA_HINT_TEXT);

        final List<AbstractPreferenceController> controllers = new ArrayList<>(1);
        controllers.add(
                new BatteryOptimizationModePreferenceController(
                        context, KEY_BATTERY_OPTIMIZATION_MODE_CATEGORY, mBatteryOptimizeUtils));
                        context,
                        KEY_BATTERY_OPTIMIZATION_MODE_CATEGORY,
                        mBatteryOptimizeUtils,
                        hintPrefKey,
                        hintText));

        return controllers;
    }
Loading