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 Change-Id: I89e811ba0d1b715d4fff23c96bc094cd4270fef7
This commit is contained in:
25
res/drawable/ic_battery_full.xml
Normal file
25
res/drawable/ic_battery_full.xml
Normal file
@@ -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>
|
@@ -2119,6 +2119,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%">%1$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]-->
|
||||
|
@@ -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"/>
|
||||
|
@@ -23,7 +23,6 @@ import android.app.Dialog;
|
||||
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;
|
||||
@@ -67,7 +66,6 @@ import com.android.settingslib.RestrictedLockUtils;
|
||||
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;
|
||||
|
||||
@@ -441,23 +439,8 @@ public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment impl
|
||||
@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(com.android.settingslib.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));
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,6 @@ import com.android.settings.core.BasePreferenceController;
|
||||
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.Rule;
|
||||
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 @@ public class WifiNetworkDetailsFragmentTest {
|
||||
|
||||
FakeFragment mFragment;
|
||||
PreferenceScreen mScreen;
|
||||
ArgumentCaptor<ThemedBatteryDrawable> mThemedBatteryDrawableCaptor =
|
||||
ArgumentCaptor.forClass(ThemedBatteryDrawable.class);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -290,25 +286,20 @@ public class WifiNetworkDetailsFragmentTest {
|
||||
}
|
||||
|
||||
@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.
|
||||
|
Reference in New Issue
Block a user