Fixed battery tips card UI.
- Add highlight effect after navigate to new page. - Update text format inside button. Screenshot: https://screenshot.googleplex.com/8ib66dWzn6PZmhy Fix: 296001546 Fix: 296339767 Bug: 291689623 Test: manual Change-Id: Ic789e5feb684a109582477c553963a9a3f9936b8
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user