Files
app_Settings/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
ykhung 1599313caf Remove the current battery usage chart and replace it with new one
Bug: 183921876
Test: make SettingsRoboTests
Test: make SettingsGoogleRoboTests
Change-Id: I06f0eb5c09d07a9db0d1a93cda751e8fad672c79
2021-04-07 11:52:16 +00:00

71 lines
2.3 KiB
Java

/*
* Copyright (C) 2010 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.os.BatteryUsageStats;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
/**
* Custom preference for displaying the battery level as chart graph.
*/
public class BatteryHistoryPreference extends Preference {
private static final String TAG = "BatteryHistoryPreference";
@VisibleForTesting
BatteryInfo mBatteryInfo;
public BatteryHistoryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
final boolean isChartGraphEnabled =
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context)
.isChartGraphEnabled(context);
Log.i(TAG, "isChartGraphEnabled: " + isChartGraphEnabled);
if (isChartGraphEnabled) {
setLayoutResource(R.layout.battery_chart_graph);
}
setSelectable(false);
}
void setBatteryUsageStats(@NonNull BatteryUsageStats batteryUsageStats) {
BatteryInfo.getBatteryInfo(getContext(), info -> {
mBatteryInfo = info;
notifyChanged();
}, batteryUsageStats, false);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
final long startTime = System.currentTimeMillis();
if (mBatteryInfo == null) {
return;
}
BatteryUtils.logRuntime(TAG, "onBindViewHolder", startTime);
}
}