Revert "Add animation for battery asyncLoader."
This reverts commit a3c528f64d
.
Test: Build
Change-Id: Ib50221873e39dee40c5cf8e4b41dcf7aa13f6134
Merged-In: Ib50221873e39dee40c5cf8e4b41dcf7aa13f6134
This commit is contained in:
@@ -38,8 +38,6 @@ public class BatteryMeterView extends ImageView {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
ColorFilter mAccentColorFilter;
|
ColorFilter mAccentColorFilter;
|
||||||
|
|
||||||
private int mLevel;
|
|
||||||
|
|
||||||
public BatteryMeterView(Context context) {
|
public BatteryMeterView(Context context) {
|
||||||
this(context, null, 0);
|
this(context, null, 0);
|
||||||
}
|
}
|
||||||
@@ -66,7 +64,6 @@ public class BatteryMeterView extends ImageView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBatteryLevel(int level) {
|
public void setBatteryLevel(int level) {
|
||||||
mLevel = level;
|
|
||||||
mDrawable.setBatteryLevel(level);
|
mDrawable.setBatteryLevel(level);
|
||||||
if (level < mDrawable.getCriticalLevel()) {
|
if (level < mDrawable.getCriticalLevel()) {
|
||||||
mDrawable.setBatteryColorFilter(mErrorColorFilter);
|
mDrawable.setBatteryColorFilter(mErrorColorFilter);
|
||||||
@@ -75,10 +72,6 @@ public class BatteryMeterView extends ImageView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBatteryLevel() {
|
|
||||||
return mLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCharging(boolean charging) {
|
public void setCharging(boolean charging) {
|
||||||
mDrawable.setCharging(charging);
|
mDrawable.setCharging(charging);
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.fuelgauge;
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.animation.ValueAnimator;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -43,7 +41,6 @@ import android.util.TypedValue;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -87,10 +84,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
private static final String KEY_BATTERY_HEADER = "battery_header";
|
private static final String KEY_BATTERY_HEADER = "battery_header";
|
||||||
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
|
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
|
||||||
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
||||||
private static final int BATTERY_ANIMATION_DURATION_MS_PER_LEVEL = 30;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String ARG_BATTERY_LEVEL = "key_battery_level";
|
|
||||||
|
|
||||||
private static final String KEY_SCREEN_USAGE = "screen_usage";
|
private static final String KEY_SCREEN_USAGE = "screen_usage";
|
||||||
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
|
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
|
||||||
@@ -111,8 +104,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
private final FooterPreferenceMixin mFooterPreferenceMixin =
|
private final FooterPreferenceMixin mFooterPreferenceMixin =
|
||||||
new FooterPreferenceMixin(this, getLifecycle());
|
new FooterPreferenceMixin(this, getLifecycle());
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
int mBatteryLevel;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mShowAllApps = false;
|
boolean mShowAllApps = false;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -133,8 +124,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
setAnimationAllowed(true);
|
setAnimationAllowed(true);
|
||||||
|
|
||||||
mBatteryLevel = getContext().getResources().getInteger(
|
|
||||||
com.android.internal.R.integer.config_criticalBatteryWarningLevel) + 1;
|
|
||||||
mBatteryLayoutPref = (LayoutPreference) findPreference(KEY_BATTERY_HEADER);
|
mBatteryLayoutPref = (LayoutPreference) findPreference(KEY_BATTERY_HEADER);
|
||||||
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
|
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
|
||||||
mScreenUsagePref = (PowerGaugePreference) findPreference(KEY_SCREEN_USAGE);
|
mScreenUsagePref = (PowerGaugePreference) findPreference(KEY_SCREEN_USAGE);
|
||||||
@@ -147,14 +136,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
initFeatureProvider();
|
initFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
mBatteryLevel = savedInstanceState.getInt(ARG_BATTERY_LEVEL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY;
|
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY;
|
||||||
@@ -163,8 +144,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
initHeaderPreference();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -182,12 +161,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putInt(ARG_BATTERY_LEVEL, mBatteryLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
if (KEY_BATTERY_HEADER.equals(preference.getKey())) {
|
if (KEY_BATTERY_HEADER.equals(preference.getKey())) {
|
||||||
@@ -596,46 +569,15 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
.findViewById(R.id.battery_header_icon);
|
.findViewById(R.id.battery_header_icon);
|
||||||
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||||
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||||
|
timeText.setText(Utils.formatPercentage(info.batteryLevel));
|
||||||
if (info.remainingLabel == null ) {
|
if (info.remainingLabel == null ) {
|
||||||
summary1.setText(info.statusLabel);
|
summary1.setText(info.statusLabel);
|
||||||
} else {
|
} else {
|
||||||
summary1.setText(info.remainingLabel);
|
summary1.setText(info.remainingLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
batteryView.setBatteryLevel(info.batteryLevel);
|
||||||
batteryView.setCharging(!info.discharging);
|
batteryView.setCharging(!info.discharging);
|
||||||
startBatteryHeaderAnimationIfNecessary(batteryView, timeText, mBatteryLevel,
|
|
||||||
info.batteryLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void initHeaderPreference() {
|
|
||||||
final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref
|
|
||||||
.findViewById(R.id.battery_header_icon);
|
|
||||||
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
|
||||||
|
|
||||||
batteryView.setBatteryLevel(mBatteryLevel);
|
|
||||||
timeText.setText(Utils.formatPercentage(mBatteryLevel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void startBatteryHeaderAnimationIfNecessary(BatteryMeterView batteryView, TextView timeTextView,
|
|
||||||
int prevLevel, int currentLevel) {
|
|
||||||
mBatteryLevel = currentLevel;
|
|
||||||
final int diff = Math.abs(prevLevel - currentLevel);
|
|
||||||
if (diff != 0) {
|
|
||||||
final ValueAnimator animator = ValueAnimator.ofInt(prevLevel, currentLevel);
|
|
||||||
animator.setDuration(BATTERY_ANIMATION_DURATION_MS_PER_LEVEL * diff);
|
|
||||||
animator.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
|
|
||||||
android.R.interpolator.fast_out_slow_in));
|
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
|
||||||
final Integer level = (Integer) animation.getAnimatedValue();
|
|
||||||
batteryView.setBatteryLevel(level);
|
|
||||||
timeTextView.setText(Utils.formatPercentage(level));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
animator.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -17,7 +17,6 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -129,6 +128,8 @@ public class PowerUsageSummaryTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private LayoutPreference mBatteryLayoutPref;
|
private LayoutPreference mBatteryLayoutPref;
|
||||||
@Mock
|
@Mock
|
||||||
|
private TextView mBatteryPercentText;
|
||||||
|
@Mock
|
||||||
private TextView mSummary1;
|
private TextView mSummary1;
|
||||||
@Mock
|
@Mock
|
||||||
private BatteryInfo mBatteryInfo;
|
private BatteryInfo mBatteryInfo;
|
||||||
@@ -139,7 +140,6 @@ public class PowerUsageSummaryTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SettingsActivity mSettingsActivity;
|
private SettingsActivity mSettingsActivity;
|
||||||
|
|
||||||
private TextView mBatteryPercentText;
|
|
||||||
private List<BatterySipper> mUsageList;
|
private List<BatterySipper> mUsageList;
|
||||||
private Context mRealContext;
|
private Context mRealContext;
|
||||||
private TestFragment mFragment;
|
private TestFragment mFragment;
|
||||||
@@ -163,7 +163,7 @@ public class PowerUsageSummaryTest {
|
|||||||
mLastFullChargePref = new PowerGaugePreference(mRealContext);
|
mLastFullChargePref = new PowerGaugePreference(mRealContext);
|
||||||
mFragment = spy(new TestFragment(mContext));
|
mFragment = spy(new TestFragment(mContext));
|
||||||
mFragment.initFeatureProvider();
|
mFragment.initFeatureProvider();
|
||||||
mBatteryMeterView = spy(new BatteryMeterView(mRealContext));
|
mBatteryMeterView = new BatteryMeterView(mRealContext);
|
||||||
mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
|
mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
|
||||||
|
|
||||||
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
||||||
@@ -185,7 +185,6 @@ public class PowerUsageSummaryTest {
|
|||||||
mCellBatterySipper.drainType = BatterySipper.DrainType.CELL;
|
mCellBatterySipper.drainType = BatterySipper.DrainType.CELL;
|
||||||
mCellBatterySipper.totalPowerMah = POWER_MAH;
|
mCellBatterySipper.totalPowerMah = POWER_MAH;
|
||||||
|
|
||||||
mBatteryPercentText = new TextView(mRealContext);
|
|
||||||
when(mBatteryLayoutPref.findViewById(R.id.summary1)).thenReturn(mSummary1);
|
when(mBatteryLayoutPref.findViewById(R.id.summary1)).thenReturn(mSummary1);
|
||||||
when(mBatteryLayoutPref.findViewById(R.id.battery_percent)).thenReturn(mBatteryPercentText);
|
when(mBatteryLayoutPref.findViewById(R.id.battery_percent)).thenReturn(mBatteryPercentText);
|
||||||
when(mBatteryLayoutPref.findViewById(R.id.battery_header_icon))
|
when(mBatteryLayoutPref.findViewById(R.id.battery_header_icon))
|
||||||
@@ -278,50 +277,6 @@ public class PowerUsageSummaryTest {
|
|||||||
testToggleAllApps(false);
|
testToggleAllApps(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInitHeaderPreference_initCorrectly() {
|
|
||||||
mFragment.mBatteryLevel = 100;
|
|
||||||
|
|
||||||
mFragment.initHeaderPreference();
|
|
||||||
|
|
||||||
assertThat(mBatteryMeterView.getBatteryLevel()).isEqualTo(100);
|
|
||||||
assertThat(mBatteryPercentText.getText().toString()).isEqualTo("100%");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStartBatteryHeaderAnimationIfNecessary_batteryLevelChanged_animationStarted() {
|
|
||||||
final int prevLevel = 100;
|
|
||||||
final int curLevel = 80;
|
|
||||||
|
|
||||||
mFragment.startBatteryHeaderAnimationIfNecessary(mBatteryMeterView, mBatteryPercentText,
|
|
||||||
prevLevel, curLevel);
|
|
||||||
|
|
||||||
assertThat(mBatteryMeterView.getBatteryLevel()).isEqualTo(curLevel);
|
|
||||||
assertThat(mBatteryPercentText.getText().toString()).isEqualTo("80%");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnSaveInstanceState_saveBatteryLevel() {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
mFragment.mBatteryLevel = BATTERY_LEVEL;
|
|
||||||
// mock it to stop crash in getPreferenceScreen
|
|
||||||
doReturn(null).when(mFragment).getPreferenceScreen();
|
|
||||||
|
|
||||||
mFragment.onSaveInstanceState(bundle);
|
|
||||||
|
|
||||||
assertThat(bundle.getInt(PowerUsageSummary.ARG_BATTERY_LEVEL)).isEqualTo(BATTERY_LEVEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnActivityCreated_setBatteryLevel() {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putInt(PowerUsageSummary.ARG_BATTERY_LEVEL, BATTERY_LEVEL);
|
|
||||||
|
|
||||||
mFragment.onActivityCreated(bundle);
|
|
||||||
|
|
||||||
assertThat(mFragment.mBatteryLevel).isEqualTo(BATTERY_LEVEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractKeyFromSipper_typeAPPUidObjectNull_returnPackageNames() {
|
public void testExtractKeyFromSipper_typeAPPUidObjectNull_returnPackageNames() {
|
||||||
mNormalBatterySipper.uidObj = null;
|
mNormalBatterySipper.uidObj = null;
|
||||||
|
Reference in New Issue
Block a user