Impl app anomlay preference
[ScreenShot]: https://screenshot.googleplex.com/BBrHTQbwbFHxZE9 Bug: 291689623 Bug: 291689643 Test: manual Change-Id: Ia257f3ace4a2d71b2221f861be3e1238de6d791e
This commit is contained in:
@@ -23,6 +23,7 @@ import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -51,6 +52,8 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
|
||||
private String mAnomalyEventId;
|
||||
private PowerAnomalyKey mPowerAnomalyKey;
|
||||
private int mIconResourceId = 0;
|
||||
private int mMainButtonStrokeColorResourceId = 0;
|
||||
|
||||
@VisibleForTesting
|
||||
CharSequence mMainButtonLabel;
|
||||
@@ -73,6 +76,26 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
mPowerAnomalyKey = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the icon in tips card.
|
||||
*/
|
||||
public void setIconResourceId(int resourceId) {
|
||||
if (mIconResourceId != resourceId) {
|
||||
mIconResourceId = resourceId;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stroke color of main button in tips card.
|
||||
*/
|
||||
public void setMainButtonStrokeColorResourceId(int resourceId) {
|
||||
if (mMainButtonStrokeColorResourceId != resourceId) {
|
||||
mMainButtonStrokeColorResourceId = resourceId;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the anomaly event id which is used in metrics.
|
||||
*/
|
||||
@@ -159,9 +182,15 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
MaterialButton mainButton = (MaterialButton) view.findViewById(R.id.main_button);
|
||||
mainButton.setOnClickListener(this);
|
||||
mainButton.setText(mMainButtonLabel);
|
||||
if (mMainButtonStrokeColorResourceId != 0) {
|
||||
mainButton.setStrokeColorResource(mMainButtonStrokeColorResourceId);
|
||||
}
|
||||
MaterialButton dismissButton = (MaterialButton) view.findViewById(R.id.dismiss_button);
|
||||
dismissButton.setOnClickListener(this);
|
||||
dismissButton.setText(mDismissButtonLabel);
|
||||
if (mIconResourceId != 0) {
|
||||
((ImageView) view.findViewById(R.id.icon)).setImageResource(mIconResourceId);
|
||||
}
|
||||
|
||||
if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) {
|
||||
return;
|
||||
|
@@ -77,23 +77,29 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getStringFromResource(int resourceId, int resourceIndex) {
|
||||
if (resourceId < 0) {
|
||||
return null;
|
||||
}
|
||||
final String[] stringArray = mContext.getResources().getStringArray(resourceId);
|
||||
return (resourceIndex >= 0 && resourceIndex < stringArray.length)
|
||||
? stringArray[resourceIndex] : null;
|
||||
}
|
||||
|
||||
private int getResourceId(int resourceId, int resourceIndex, String defType) {
|
||||
final String key = getStringFromResource(resourceId, resourceIndex);
|
||||
return TextUtils.isEmpty(key) ? 0
|
||||
: mContext.getResources().getIdentifier(key, defType, mContext.getPackageName());
|
||||
}
|
||||
|
||||
private String getString(PowerAnomalyEvent powerAnomalyEvent,
|
||||
Function<WarningBannerInfo, String> warningBannerInfoSupplier,
|
||||
Function<WarningItemInfo, String> warningItemInfoSupplier,
|
||||
int resourceId, int resourceIndex) {
|
||||
String string =
|
||||
getInfo(powerAnomalyEvent, warningBannerInfoSupplier, warningItemInfoSupplier);
|
||||
|
||||
if (!TextUtils.isEmpty(string) || resourceId < 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
String[] stringArray = mContext.getResources().getStringArray(resourceId);
|
||||
if (resourceIndex >= 0 && resourceIndex < stringArray.length) {
|
||||
string = stringArray[resourceIndex];
|
||||
}
|
||||
|
||||
return string;
|
||||
return (!TextUtils.isEmpty(string) || resourceId < 0) ? string
|
||||
: getStringFromResource(resourceId, resourceIndex);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -107,6 +113,13 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get card icon and color styles
|
||||
final int cardStyleId = powerAnomalyEvent.getType().getNumber();
|
||||
final int iconResId = getResourceId(
|
||||
R.array.battery_tips_card_icons, cardStyleId, "drawable");
|
||||
final int colorResId = getResourceId(
|
||||
R.array.battery_tips_card_colors, cardStyleId, "color");
|
||||
|
||||
// Get card preference strings and navigate fragment info
|
||||
final PowerAnomalyKey powerAnomalyKey = powerAnomalyEvent.hasKey()
|
||||
? powerAnomalyEvent.getKey() : null;
|
||||
@@ -133,10 +146,12 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
String preferenceHighlightKey = getInfo(powerAnomalyEvent,
|
||||
WarningBannerInfo::getMainButtonSourceHighlightKey, null);
|
||||
|
||||
// Updated card preference and main button fragment launcher
|
||||
// Update card preference and main button fragment launcher
|
||||
mCardPreference.setAnomalyEventId(powerAnomalyEvent.getEventId());
|
||||
mCardPreference.setPowerAnomalyKey(powerAnomalyKey);
|
||||
mCardPreference.setTitle(titleString);
|
||||
mCardPreference.setIconResourceId(iconResId);
|
||||
mCardPreference.setMainButtonStrokeColorResourceId(colorResId);
|
||||
mCardPreference.setMainButtonLabel(mainBtnString);
|
||||
mCardPreference.setDismissButtonLabel(dismissBtnString);
|
||||
mCardPreference.setMainButtonLauncherInfo(
|
||||
|
Reference in New Issue
Block a user