Merge "Add dialog when restrict apps are more than 5" into pi-dev

This commit is contained in:
Lei Yu
2018-03-15 18:01:58 +00:00
committed by Android (Google) Code Review
4 changed files with 78 additions and 20 deletions

View File

@@ -107,21 +107,30 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
final List<AppInfo> restrictedAppList = restrictAppTip.getRestrictAppList();
final int num = restrictedAppList.size();
final CharSequence appLabel = Utils.getApplicationLabel(context,
restrictedAppList.get(0).packageName);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle(context.getResources().getQuantityString(
R.plurals.battery_tip_restrict_app_dialog_title, num, num))
.setMessage(getString(R.string.battery_tip_restrict_app_dialog_message))
.setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this)
.setNegativeButton(android.R.string.cancel, null);
// TODO(b/72385333): consider building dialog with 5+ apps when strings are done
if (num > 1) {
if (num == 1) {
builder.setMessage(
getString(R.string.battery_tip_restrict_app_dialog_message, appLabel));
} else if (num <= 5) {
builder.setMessage(
getString(
R.string.battery_tip_restrict_apps_less_than_5_dialog_message));
final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(
context).inflate(R.layout.recycler_view, null);
restrictionView.setLayoutManager(new LinearLayoutManager(context));
restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
builder.setView(restrictionView);
} else {
builder.setMessage(context.getString(
R.string.battery_tip_restrict_apps_more_than_5_dialog_message,
restrictAppTip.getRestrictAppsString(context)));
}
return builder.create();

View File

@@ -17,8 +17,9 @@
package com.android.settings.fuelgauge.batterytip.tips;
import android.content.Context;
import android.content.res.Resources;
import android.icu.text.ListFormatter;
import android.os.Parcel;
import android.text.TextUtils;
import android.util.Pair;
import com.android.internal.annotations.VisibleForTesting;
@@ -72,7 +73,7 @@ public class RestrictAppTip extends BatteryTip {
return mState == StateType.HANDLED
? context.getString(R.string.battery_tip_restrict_handled_summary)
: context.getResources().getQuantityString(R.plurals.battery_tip_restrict_summary,
num, appLabel, num);
num, appLabel, num);
}
@Override
@@ -118,6 +119,19 @@ public class RestrictAppTip extends BatteryTip {
return mRestrictAppList;
}
/**
* Construct the app list string(e.g. app1, app2, and app3)
*/
public CharSequence getRestrictAppsString(Context context) {
final List<CharSequence> appLabels = new ArrayList<>();
for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
appLabels.add(Utils.getApplicationLabel(context,
mRestrictAppList.get(i).packageName));
}
return ListFormatter.getInstance().format(appLabels);
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(super.toString());