Merge "Split loading process for battery header"
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.BatteryInfo;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
/**
|
||||
* Controller that update the battery header view
|
||||
*/
|
||||
public class BatteryHeaderPreferenceController extends PreferenceController {
|
||||
@VisibleForTesting
|
||||
static final String KEY_BATTERY_HEADER = "battery_header";
|
||||
@VisibleForTesting
|
||||
BatteryMeterView mBatteryMeterView;
|
||||
@VisibleForTesting
|
||||
TextView mTimeText;
|
||||
@VisibleForTesting
|
||||
TextView mSummary;
|
||||
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
|
||||
public BatteryHeaderPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mBatteryLayoutPref = (LayoutPreference) screen.findPreference(KEY_BATTERY_HEADER);
|
||||
mBatteryMeterView = (BatteryMeterView) mBatteryLayoutPref
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
mTimeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
mSummary = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
|
||||
Intent batteryBroadcast = mContext.registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
final int batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
||||
|
||||
mBatteryMeterView.setBatteryLevel(batteryLevel);
|
||||
mTimeText.setText(Utils.formatPercentage(batteryLevel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BATTERY_HEADER;
|
||||
}
|
||||
|
||||
public void updateHeaderPreference(BatteryInfo info) {
|
||||
mTimeText.setText(Utils.formatPercentage(info.batteryLevel));
|
||||
if (info.remainingLabel == null) {
|
||||
mSummary.setText(info.statusLabel);
|
||||
} else {
|
||||
mSummary.setText(info.remainingLabel);
|
||||
}
|
||||
|
||||
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
|
||||
mBatteryMeterView.setCharging(!info.discharging);
|
||||
}
|
||||
}
|
@@ -72,6 +72,10 @@ public class BatteryMeterView extends ImageView {
|
||||
}
|
||||
}
|
||||
|
||||
public int getBatteryLevel() {
|
||||
return mDrawable.getBatteryLevel();
|
||||
}
|
||||
|
||||
public void setCharging(boolean charging) {
|
||||
mDrawable.setCharging(charging);
|
||||
}
|
||||
|
@@ -139,6 +139,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
@VisibleForTesting
|
||||
SparseArray<List<Anomaly>> mAnomalySparseArray;
|
||||
|
||||
private BatteryHeaderPreferenceController mBatteryHeaderPreferenceController;
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
private PreferenceGroup mAppListGroup;
|
||||
private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
|
||||
@@ -192,7 +193,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
Intent batteryBroadcast = getContext().registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
BatteryInfo batteryInfo = getBatteryInfo(elapsedRealtimeUs, batteryBroadcast);
|
||||
updateHeaderPreference(batteryInfo);
|
||||
mBatteryHeaderPreferenceController.updateHeaderPreference(batteryInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -226,11 +227,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
BatteryEntry.stopRequestQueue();
|
||||
@@ -277,6 +273,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
mBatteryHeaderPreferenceController = new BatteryHeaderPreferenceController(context);
|
||||
controllers.add(mBatteryHeaderPreferenceController);
|
||||
controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
|
||||
controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
|
||||
controllers.add(new BatterySaverController(context, getLifecycle()));
|
||||
@@ -497,7 +495,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
Intent batteryBroadcast = context.registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
BatteryInfo batteryInfo = getBatteryInfo(elapsedRealtimeUs, batteryBroadcast);
|
||||
updateHeaderPreference(batteryInfo);
|
||||
mBatteryHeaderPreferenceController.updateHeaderPreference(batteryInfo);
|
||||
|
||||
final long runningTime = mBatteryUtils.calculateRunningTimeBasedOnStatsType(mStatsHelper,
|
||||
mStatsType);
|
||||
@@ -656,27 +654,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
timeSequence));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateHeaderPreference(BatteryInfo info) {
|
||||
final Context context = getContext();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
timeText.setText(Utils.formatPercentage(info.batteryLevel));
|
||||
if (info.remainingLabel == null ) {
|
||||
summary1.setText(info.statusLabel);
|
||||
} else {
|
||||
summary1.setText(info.remainingLabel);
|
||||
}
|
||||
|
||||
batteryView.setBatteryLevel(info.batteryLevel);
|
||||
batteryView.setCharging(!info.discharging);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
double calculatePercentage(double powerUsage, double dischargeAmount) {
|
||||
final double totalPower = mStatsHelper.getTotalPower();
|
||||
|
Reference in New Issue
Block a user