Update Battery preference for Instant Hotspot
- Use the static battery full icon
- Show charging status in Battery preference summary
Bug: 300559036
Test: manual test
atest -c WifiNetworkDetailsFragmentTest
Merged-In: I89e811ba0d1b715d4fff23c96bc094cd4270fef7
Change-Id: I89e811ba0d1b715d4fff23c96bc094cd4270fef7
diff --git a/res/drawable/ic_battery_full.xml b/res/drawable/ic_battery_full.xml
new file mode 100644
index 0000000..8b1321f
--- /dev/null
+++ b/res/drawable/ic_battery_full.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2023 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M320,880Q303,880 291.5,868.5Q280,857 280,840L280,200Q280,183 291.5,171.5Q303,160 320,160L400,160L400,80L560,80L560,160L640,160Q657,160 668.5,171.5Q680,183 680,200L680,840Q680,857 668.5,868.5Q657,880 640,880L320,880Z"/>
+</vector>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f8b770f..8f8ea41 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2003,6 +2003,8 @@
<string name="internet_source_mobile_data">Mobile data</string>
<!-- Ethernet summary in Internet source preference [CHAR LIMIT=NONE]-->
<string name="internet_source_ethernet">Ethernet</string>
+ <!-- Hotspot device details battery charging summary [CHAR LIMIT=NONE]-->
+ <string name="hotspot_battery_charging_summary"><xliff:g id="battery_percentage" example="80%">%s</xliff:g> \u2011 Charging</string>
<!-- Hotspot device details preference category title in Network details [CHAR LIMIT=NONE]-->
<string name="hotspot_connection_category">Hotspot connection</string>
<!-- Connection strength preference in Hotspot connection preference category [CHAR LIMIT=NONE]-->
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
index e3464c2..0062474 100644
--- a/res/xml/wifi_network_details_fragment2.xml
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -52,6 +52,7 @@
settings:enableCopying="true"/>
<Preference
android:key="hotspot_device_details_battery"
+ android:icon="@drawable/ic_battery_full"
android:title="@string/power_usage_summary_title"
android:selectable="false"
settings:enableCopying="true"/>
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index a3feeca..e3812af 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -23,7 +23,6 @@
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
-import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
@@ -66,7 +65,6 @@
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
@@ -436,22 +434,8 @@
@VisibleForTesting
void updateBattery(boolean isChanging, int percentage) {
Preference battery = getPreferenceScreen().findPreference(KEY_HOTSPOT_DEVICE_BATTERY);
- battery.setSummary(formatPercentage(percentage));
- ThemedBatteryDrawable drawable = getBatteryDrawable();
- if (drawable != null) {
- drawable.setCharging(isChanging);
- drawable.setBatteryLevel(percentage);
- }
- battery.setIcon(drawable);
- }
-
- @VisibleForTesting
- ThemedBatteryDrawable getBatteryDrawable() {
- int frameColor = getContext().getColor(R.color.meter_background_color);
- ThemedBatteryDrawable drawable = new ThemedBatteryDrawable(getContext(), frameColor);
- ColorFilter colorFilter = Utils.getAlphaInvariantColorFilterForColor(
- Utils.getColorAttrDefaultColor(getContext(), android.R.attr.colorControlNormal));
- drawable.setColorFilter(colorFilter);
- return drawable;
+ battery.setSummary((isChanging)
+ ? getString(R.string.hotspot_battery_charging_summary, formatPercentage(percentage))
+ : formatPercentage(percentage));
}
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
index bd8b5be..52a1a6c 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
@@ -58,7 +58,6 @@
import com.android.settings.wifi.WifiUtils;
import com.android.settings.wifi.details2.WifiDetailPreferenceController2;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
@@ -67,7 +66,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
@@ -112,8 +110,6 @@
FakeFragment mFragment;
PreferenceScreen mScreen;
- ArgumentCaptor<ThemedBatteryDrawable> mThemedBatteryDrawableCaptor =
- ArgumentCaptor.forClass(ThemedBatteryDrawable.class);
@Before
public void setUp() {
@@ -290,25 +286,20 @@
}
@Test
- public void updateBattery_hiPercentageNoCharging_setResourceCorrect() {
+ public void updateBattery_hiPercentageNoCharging_setSummaryCorrect() {
mFragment.updateBattery(false /* isChanging */, BATTERY_PERCENTAGE_MAX);
verify(mBattery).setSummary(formatPercentage(BATTERY_PERCENTAGE_MAX));
- verify(mBattery).setIcon(mThemedBatteryDrawableCaptor.capture());
- ThemedBatteryDrawable drawable = mThemedBatteryDrawableCaptor.getValue();
- assertThat(drawable.getCharging()).isFalse();
- assertThat(drawable.getBatteryLevel()).isEqualTo(BATTERY_PERCENTAGE_MAX);
}
@Test
- public void updateBattery_lowPercentageWithCharging_setResourceCorrect() {
+ public void updateBattery_lowPercentageWithCharging_setSummaryCorrect() {
+ String summary = mContext.getString(R.string.hotspot_battery_charging_summary,
+ formatPercentage(0));
+
mFragment.updateBattery(true /* isChanging */, 0 /* percentage */);
- verify(mBattery).setSummary(formatPercentage(0));
- verify(mBattery).setIcon(mThemedBatteryDrawableCaptor.capture());
- ThemedBatteryDrawable drawable = mThemedBatteryDrawableCaptor.getValue();
- assertThat(drawable.getCharging()).isTrue();
- assertThat(drawable.getBatteryLevel()).isEqualTo(0);
+ verify(mBattery).setSummary(summary);
}
// Fake WifiNetworkDetailsFragment to override the protected method as public.