Merge "Impl app anomlay preference" into udc-qpr-dev am: c51a3da148
am: 428b124bea
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24404174 Change-Id: I147d8496db00a770d8de45229813ae146e1e87cb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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