Update battery percentage column to UsageProgressBarPref (1/2)

- Change battery percentage column to new design
 - Remove debug info case
 Screenshots:
   https://screenshot.googleplex.com/9rvRfK3wBtpnarZ.png
   https://screenshot.googleplex.com/5iAjNXTptDechAm.png

Bug: 177407113
Test: make RunSettingsRoboTests -j40
Change-Id: I5d046be29a036910036e72edb677b69bc2c0a03f
This commit is contained in:
Wesley.CW Wang
2021-02-04 16:44:55 +08:00
committed by Wesley Wang
parent 2e47875c06
commit f4bc35333b
5 changed files with 39 additions and 285 deletions

View File

@@ -25,14 +25,9 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Global;
import android.text.format.Formatter;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.Loader;
import com.android.settings.R;
@@ -44,7 +39,6 @@ import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.utils.PowerUtil;
import com.android.settingslib.widget.LayoutPreference;
import java.util.List;
@@ -54,18 +48,15 @@ import java.util.List;
* since the last time it was unplugged.
*/
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class PowerUsageSummary extends PowerUsageBase implements OnLongClickListener,
public class PowerUsageSummary extends PowerUsageBase implements
BatteryTipPreferenceController.BatteryTipListener {
static final String TAG = "PowerUsageSummary";
private static final String KEY_BATTERY_HEADER = "battery_header";
@VisibleForTesting
static final int BATTERY_INFO_LOADER = 1;
@VisibleForTesting
static final int BATTERY_TIP_LOADER = 2;
public static final int DEBUG_INFO_LOADER = 3;
@VisibleForTesting
PowerUsageFeatureProvider mPowerFeatureProvider;
@@ -112,49 +103,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
};
LoaderManager.LoaderCallbacks<List<BatteryInfo>> mBatteryInfoDebugLoaderCallbacks =
new LoaderCallbacks<List<BatteryInfo>>() {
@Override
public Loader<List<BatteryInfo>> onCreateLoader(int i, Bundle bundle) {
return new DebugEstimatesLoader(getContext(), mStatsHelper);
}
@Override
public void onLoadFinished(Loader<List<BatteryInfo>> loader,
List<BatteryInfo> batteryInfos) {
updateViews(batteryInfos);
}
@Override
public void onLoaderReset(Loader<List<BatteryInfo>> loader) {
}
};
protected void updateViews(List<BatteryInfo> batteryInfos) {
final BatteryMeterView batteryView = mBatteryLayoutPref
.findViewById(R.id.battery_header_icon);
final TextView percentRemaining =
mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
BatteryInfo oldInfo = batteryInfos.get(0);
BatteryInfo newInfo = batteryInfos.get(1);
percentRemaining.setText(Utils.formatPercentage(oldInfo.batteryLevel));
// set the text to the old estimate (copied from battery info). Note that this
// can sometimes say 0 time remaining because battery stats requires the phone
// be unplugged for a period of time before being willing ot make an estimate.
final String OldEstimateString = mPowerFeatureProvider.getOldEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(oldInfo.remainingTimeUs)));
final String NewEstimateString = mPowerFeatureProvider.getEnhancedEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(newInfo.remainingTimeUs)));
summary1.setText(OldEstimateString + "\n" + NewEstimateString);
batteryView.setBatteryLevel(oldInfo.batteryLevel);
batteryView.setCharging(!oldInfo.discharging);
}
private LoaderManager.LoaderCallbacks<List<BatteryTip>> mBatteryTipsCallbacks =
new LoaderManager.LoaderCallbacks<List<BatteryTip>>() {
@@ -197,7 +145,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
setAnimationAllowed(true);
initFeatureProvider();
mBatteryLayoutPref = (LayoutPreference) findPreference(KEY_BATTERY_HEADER);
mBatteryUtils = BatteryUtils.getInstance(getContext());
@@ -274,17 +221,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
mBatteryLayoutPref = layoutPreference;
}
@VisibleForTesting
void showBothEstimates() {
final Context context = getContext();
if (context == null
|| !mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
return;
}
getLoaderManager().restartLoader(DEBUG_INFO_LOADER, Bundle.EMPTY,
mBatteryInfoDebugLoaderCallbacks);
}
@VisibleForTesting
void initFeatureProvider() {
final Context context = getContext();
@@ -303,11 +239,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
mBatteryInfoLoaderCallbacks);
if (mPowerFeatureProvider.isEstimateDebugEnabled()) {
// Set long click action for summary to show debug info
View header = mBatteryLayoutPref.findViewById(R.id.summary1);
header.setOnLongClickListener(this);
}
}
@VisibleForTesting
@@ -315,13 +246,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
mNeedUpdateBatteryTip = icicle == null || mBatteryTipPreferenceController.needUpdate();
}
@Override
public boolean onLongClick(View view) {
showBothEstimates();
view.setOnLongClickListener(null);
return true;
}
@Override
protected void restartBatteryStatsLoader(@BatteryUpdateType int refreshType) {
super.restartBatteryStatsLoader(refreshType);