Merge "Fixed battery tips card UI." into udc-qpr-dev am: 646c676ff6

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24457990

Change-Id: I410f00abe1785cca6a45ac63abd3e89a818c2a10
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-08-25 09:36:12 +00:00
committed by Automerger Merge Worker
8 changed files with 45 additions and 31 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge.batteryusage;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@@ -30,6 +31,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
@@ -56,6 +58,8 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
@VisibleForTesting
String mDestinationComponentName;
@VisibleForTesting
String mPreferenceHighlightKey;
@VisibleForTesting
Integer mSourceMetricsCategory;
public BatteryTipsCardPreference(Context context, AttributeSet attrs) {
@@ -98,9 +102,10 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
* Sets the info of target fragment launched by main button.
*/
public void setMainButtonLauncherInfo(final String destinationClassName,
final Integer sourceMetricsCategory) {
final Integer sourceMetricsCategory, final String highlightKey) {
mDestinationComponentName = destinationClassName;
mSourceMetricsCategory = sourceMetricsCategory;
mPreferenceHighlightKey = highlightKey;
}
@Override
@@ -110,9 +115,16 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
if (TextUtils.isEmpty(mDestinationComponentName)) {
return;
}
Bundle arguments = Bundle.EMPTY;
if (!TextUtils.isEmpty(mPreferenceHighlightKey)) {
arguments = new Bundle(1);
arguments.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
mPreferenceHighlightKey);
}
new SubSettingLauncher(getContext())
.setDestination(mDestinationComponentName)
.setSourceMetricsCategory(mSourceMetricsCategory)
.setArguments(arguments)
.launch();
setVisible(false);
mMetricsFeatureProvider.action(

View File

@@ -69,9 +69,9 @@ public class BatteryTipsController extends BasePreferenceController {
private <T> T getInfo(PowerAnomalyEvent powerAnomalyEvent,
Function<WarningBannerInfo, T> warningBannerInfoSupplier,
Function<WarningItemInfo, T> warningItemInfoSupplier) {
if (powerAnomalyEvent.hasWarningBannerInfo() && warningBannerInfoSupplier != null) {
if (warningBannerInfoSupplier != null && powerAnomalyEvent.hasWarningBannerInfo()) {
return warningBannerInfoSupplier.apply(powerAnomalyEvent.getWarningBannerInfo());
} else if (powerAnomalyEvent.hasWarningItemInfo() && warningItemInfoSupplier != null) {
} else if (warningItemInfoSupplier != null && powerAnomalyEvent.hasWarningItemInfo()) {
return warningItemInfoSupplier.apply(powerAnomalyEvent.getWarningItemInfo());
}
return null;
@@ -125,20 +125,20 @@ public class BatteryTipsController extends BasePreferenceController {
WarningBannerInfo::getCancelButtonString, WarningItemInfo::getCancelButtonString,
R.array.power_anomaly_dismiss_btn_strings, resourceIndex);
String destinationClassName = getString(powerAnomalyEvent,
WarningBannerInfo::getMainButtonDestination,
WarningItemInfo::getMainButtonDestination,
-1, -1);
String destinationClassName = getInfo(powerAnomalyEvent,
WarningBannerInfo::getMainButtonDestination, null);
Integer sourceMetricsCategory = getInfo(powerAnomalyEvent,
WarningBannerInfo::getMainButtonSourceMetricsCategory,
WarningItemInfo::getMainButtonSourceMetricsCategory);
WarningBannerInfo::getMainButtonSourceMetricsCategory, null);
String preferenceHighlightKey = getInfo(powerAnomalyEvent,
WarningBannerInfo::getMainButtonSourceHighlightKey, null);
// Updated card preference and main button fragment launcher
mCardPreference.setAnomalyEventId(powerAnomalyEvent.getEventId());
mCardPreference.setTitle(titleString);
mCardPreference.setMainButtonLabel(mainBtnString);
mCardPreference.setDismissButtonLabel(dismissBtnString);
mCardPreference.setMainButtonLauncherInfo(destinationClassName, sourceMetricsCategory);
mCardPreference.setMainButtonLauncherInfo(
destinationClassName, sourceMetricsCategory, preferenceHighlightKey);
mCardPreference.setVisible(true);
mMetricsFeatureProvider.action(mContext,

View File

@@ -47,7 +47,9 @@ message WarningBannerInfo {
optional string main_button_destination = 4;
// Used in the SubSettingLauncher.setSourceMetricsCategory().
optional int32 main_button_source_metrics_category = 5;
optional string cancel_button_string = 6;
// Used in the SubSettingLauncher.setArguments().
optional string main_button_source_highlight_key = 6;
optional string cancel_button_string = 7;
}
message WarningItemInfo {
@@ -57,9 +59,5 @@ message WarningItemInfo {
optional string title_string = 4;
optional string description_string = 5;
optional string main_button_string = 6;
// Used in the SubSettingLauncher.setDestination().
optional string main_button_destination = 7;
// Used in the SubSettingLauncher.setSourceMetricsCategory().
optional int32 main_button_source_metrics_category = 8;
optional string cancel_button_string = 9;
optional string cancel_button_string = 7;
}

View File

@@ -33,8 +33,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settingslib.widget.CandidateInfo;
@@ -46,7 +46,10 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFragment implements
/**
* A fragment to handle general radio button picker
*/
public abstract class RadioButtonPickerFragment extends SettingsPreferenceFragment implements
SelectorWithWidgetPreference.OnClickListener {
@VisibleForTesting