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

Commit 756028aa authored by Wesley.CW Wang's avatar Wesley.CW Wang
Browse files

Support help message when battery is unavailable(1/2)

 - Present help preference when battery is unavailable

Bug: 179237551
Test: make SettingsRoboTests
Change-Id: If6e82210d831123cb1169d53a18d24cb2c576b10
parent b914ec91
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2021 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.
  -->
<!-- TODO(b/179237551): Refine the layout once the design been lock down. -->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <com.google.android.material.card.MaterialCardView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        style="@style/ContextualCardStyle">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="top|start"
            android:orientation="vertical"
            android:padding="16dp"
            android:background="@color/homepage_emergency_background">

            <ImageView
                android:id="@+id/battery_icon"
                android:src="@drawable/ic_battery_alert_24dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView android:id="@+id/summary_text"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="@string/battery_missing_message"
                      android:textAppearance="?android:attr/textAppearanceSmall"
                      android:textColor="?android:attr/textColorSecondary" />

            <TextView android:id="@+id/link_text"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="end"
                      android:text="@string/battery_missing_link_message"
                      android:textAppearance="?android:attr/textAppearanceSmall"
                      android:textColor="?android:attr/colorError" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>
</FrameLayout>
+3 −3
Original line number Diff line number Diff line
@@ -6051,9 +6051,9 @@
    <string name="battery_header_title_alternate"><xliff:g id="number" example="88">^1</xliff:g><small> <font size="20"><xliff:g id="unit" example="%">%</xliff:g></font></small></string>
    <!-- Summary for top level battery tile if battery is not present. [CHAR LIMIT=NONE] -->
    <string name="battery_missing_message">Problem reading your battery meter</string>
    <!-- Summary to battery page if battery is not present. [CHAR LIMIT=NONE] -->
    <string name="battery_missing_help_message">Problem reading your battery meter. Tap to <annotation id="url">learn more</annotation></string>
    <string name="battery_missing_message">Can’t update battery info</string>
    <!-- Help text if battery is not present. [CHAR LIMIT=NONE] -->
    <string name="battery_missing_link_message"></string>
    <!-- Title for force stop dialog [CHAR LIMIT=30] -->
    <string name="dialog_stop_title">Stop app?</string>
+11 −5
Original line number Diff line number Diff line
@@ -28,11 +28,10 @@
        android:selectable="false"
        settings:controller="com.android.settings.fuelgauge.BatteryHeaderPreferenceController" />

    <Preference
        android:fragment="com.android.settings.fuelgauge.PowerUsageAdvanced"
        android:key="battery_usage_summary"
        android:title="@string/advanced_battery_preference_title"
        app:iconSpaceReserved="false"
    <com.android.settingslib.widget.LayoutPreference
        android:key="battery_help_message"
        android:layout="@layout/preference_battery_error"
        android:selectable="false"
        settings:searchable="false" />

    <com.android.settings.widget.CardPreference
@@ -40,6 +39,13 @@
        android:title="@string/summary_placeholder"
        settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />

    <Preference
        android:fragment="com.android.settings.fuelgauge.PowerUsageAdvanced"
        android:key="battery_usage_summary"
        android:title="@string/advanced_battery_preference_title"
        app:iconSpaceReserved="false"
        settings:searchable="false" />

    <Preference
        android:fragment="com.android.settings.fuelgauge.batterysaver.BatterySaverSettings"
        android:key="battery_saver_summary"
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
        if (com.android.settings.Utils.isBatteryPresent(mContext)) {
            quickUpdateHeaderPreference();
        } else {
            //TODO(b/179237551): Make new progress bar widget support help message
            mBatteryUsageProgressBarPref.setVisible(false);
        }
    }

+12 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.provider.Settings.Global;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.SettingsActivity;
@@ -51,6 +52,8 @@ import java.util.List;
public class PowerUsageSummary extends PowerUsageBase implements
        BatteryTipPreferenceController.BatteryTipListener {

    private static final String KEY_BATTERY_ERROR = "battery_help_message";

    static final String TAG = "PowerUsageSummary";

    @VisibleForTesting
@@ -70,9 +73,11 @@ public class PowerUsageSummary extends PowerUsageBase implements
    @VisibleForTesting
    BatteryHeaderPreferenceController mBatteryHeaderPreferenceController;
    @VisibleForTesting
    BatteryTipPreferenceController mBatteryTipPreferenceController;
    @VisibleForTesting
    boolean mNeedUpdateBatteryTip;
    @VisibleForTesting
    BatteryTipPreferenceController mBatteryTipPreferenceController;
    Preference mHelpPreference;

    @VisibleForTesting
    final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
@@ -152,8 +157,14 @@ public class PowerUsageSummary extends PowerUsageBase implements

        mBatteryUtils = BatteryUtils.getInstance(getContext());

        mHelpPreference = findPreference(KEY_BATTERY_ERROR);
        mHelpPreference.setVisible(false);

        if (Utils.isBatteryPresent(getContext())) {
            restartBatteryInfoLoader();
        } else {
            // Present help preference when battery is unavailable.
            mHelpPreference.setVisible(true);
        }
        mBatteryTipPreferenceController.restoreInstanceState(icicle);
        updateBatteryTipFlag(icicle);
Loading