Merge "Implement the battery tips cards.(1/2)" into udc-qpr-dev am: 270b7ef18d
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24124246 Change-Id: I657cab61453b5f7708fcf305d1a9611d3022c4d6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -37,6 +37,16 @@ public interface PowerUsageFeatureProvider {
|
||||
*/
|
||||
boolean isBatteryUsageEnabled();
|
||||
|
||||
/**
|
||||
* Check whether the battery tips card is enabled in the battery usage page
|
||||
*/
|
||||
boolean isBatteryTipsEnabled();
|
||||
|
||||
/**
|
||||
* Check whether the feedback card is enabled in the battery tips card
|
||||
*/
|
||||
boolean isBatteryTipsFeedbackEnabled();
|
||||
|
||||
/**
|
||||
* Returns a threshold (in milliseconds) for the minimal screen on time in battery usage list
|
||||
*/
|
||||
|
@@ -75,6 +75,16 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryTipsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryTipsFeedbackEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBatteryUsageListScreenOnTimeThresholdInMs() {
|
||||
return 0;
|
||||
|
@@ -98,6 +98,20 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
void onScreenOnTimeUpdated(Long screenOnTime, String slotTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback listener for the battery tips card is updated.
|
||||
* This happens when battery tips card is ready.
|
||||
*/
|
||||
public interface OnBatteryTipsUpdatedListener {
|
||||
/**
|
||||
* The callback function for the battery tips card is updated.
|
||||
* @param title the title of the battery tip card
|
||||
* @param summary the summary of the battery tip card
|
||||
*/
|
||||
void onBatteryTipsUpdated(String title, String summary);
|
||||
}
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
Context mPrefContext;
|
||||
@VisibleForTesting
|
||||
@@ -119,6 +133,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
private List<BatteryChartViewModel> mHourlyViewModels;
|
||||
private OnBatteryUsageUpdatedListener mOnBatteryUsageUpdatedListener;
|
||||
private OnScreenOnTimeUpdatedListener mOnScreenOnTimeUpdatedListener;
|
||||
private OnBatteryTipsUpdatedListener mOnBatteryTipsUpdatedListener;
|
||||
|
||||
private final SettingsActivity mActivity;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -209,6 +224,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
mOnScreenOnTimeUpdatedListener = listener;
|
||||
}
|
||||
|
||||
void setOnBatteryTipsUpdatedListener(OnBatteryTipsUpdatedListener listener) {
|
||||
mOnBatteryTipsUpdatedListener = listener;
|
||||
}
|
||||
|
||||
void setBatteryHistoryMap(
|
||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
|
||||
Log.d(TAG, "setBatteryHistoryMap() " + (batteryHistoryMap == null ? "null"
|
||||
@@ -344,6 +363,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
}
|
||||
mOnBatteryUsageUpdatedListener.onBatteryUsageUpdated(
|
||||
slotUsageData, getSlotInformation(), isBatteryUsageMapNullOrEmpty());
|
||||
|
||||
if (mOnBatteryTipsUpdatedListener != null) {
|
||||
mOnBatteryTipsUpdatedListener.onBatteryTipsUpdated(null, null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
/**
|
||||
* A preference for displaying the battery tips card view.
|
||||
*/
|
||||
public class BatteryTipsCardPreference extends Preference implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = "BatteryTipsCardPreference";
|
||||
|
||||
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
|
||||
private MaterialButton mActionButton;
|
||||
private ImageButton mDismissButton;
|
||||
private ImageButton mThumbUpButton;
|
||||
private ImageButton mThumbDownButton;
|
||||
private CharSequence mTitle;
|
||||
private CharSequence mSummary;
|
||||
|
||||
public BatteryTipsCardPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.battery_tips_card);
|
||||
setSelectable(false);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
mSummary = summary;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// TODO: replace with the settings anomaly obtained from detectSettingsAnomaly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
((TextView) view.findViewById(R.id.title)).setText(mTitle);
|
||||
((TextView) view.findViewById(R.id.summary)).setText(mSummary);
|
||||
|
||||
mActionButton = (MaterialButton) view.findViewById(R.id.action_button);
|
||||
mActionButton.setOnClickListener(this);
|
||||
mDismissButton = (ImageButton) view.findViewById(R.id.dismiss_button);
|
||||
mDismissButton.setOnClickListener(this);
|
||||
|
||||
if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) {
|
||||
return;
|
||||
}
|
||||
view.findViewById(R.id.tips_card)
|
||||
.setBackgroundResource(R.drawable.battery_tips_half_rounded_top_bg);
|
||||
view.findViewById(R.id.feedback_card).setVisibility(View.VISIBLE);
|
||||
|
||||
mThumbUpButton = (ImageButton) view.findViewById(R.id.thumb_up);
|
||||
mThumbUpButton.setOnClickListener(this);
|
||||
mThumbDownButton = (ImageButton) view.findViewById(R.id.thumb_down);
|
||||
mThumbDownButton.setOnClickListener(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/** Controls the update for battery tips card */
|
||||
public class BatteryTipsController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "BatteryTipsController";
|
||||
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
||||
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
||||
|
||||
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
|
||||
private Context mPrefContext;
|
||||
private BatteryTipsCardPreference mCardPreference;
|
||||
|
||||
public BatteryTipsController(Context context) {
|
||||
super(context, ROOT_PREFERENCE_KEY);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPrefContext = screen.getContext();
|
||||
mCardPreference = screen.findPreference(CARD_PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the card visibility and contents.
|
||||
* @param title a string not extend 2 lines.
|
||||
* @param summary a string not extend 10 lines.
|
||||
*/
|
||||
// TODO: replace parameters with SettingsAnomaly Data Proto
|
||||
public void handleBatteryTipsCardUpdated(String title, String summary) {
|
||||
if (!mPowerUsageFeatureProvider.isBatteryTipsEnabled()) {
|
||||
mCardPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
if (title == null || summary == null) {
|
||||
mCardPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
mCardPreference.setTitle(title);
|
||||
mCardPreference.setSummary(summary);
|
||||
mCardPreference.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
@@ -34,6 +34,8 @@ import androidx.loader.content.Loader;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
@@ -143,6 +145,16 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
controllers.add(screenOnTimeController);
|
||||
controllers.add(batteryUsageBreakdownController);
|
||||
setBatteryChartPreferenceController();
|
||||
|
||||
final PowerUsageFeatureProvider powerUsageFeatureProvider =
|
||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||
if (powerUsageFeatureProvider.isBatteryTipsEnabled()) {
|
||||
BatteryTipsController batteryTipsController = new BatteryTipsController(context);
|
||||
mBatteryChartPreferenceController.setOnBatteryTipsUpdatedListener(
|
||||
batteryTipsController::handleBatteryTipsCardUpdated);
|
||||
controllers.add(batteryTipsController);
|
||||
}
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user