Add restrict and unrestrict dialog
Add a fake unrestrict tip so we could reuse the BatteryTipDialogFragment to build the unrestrict dialog. After this cl, restrict dialog has two types: 1. dialog to only restrict one app 2. dialog to restrict more than one app Will add dialog to restrict more than 5 apps when strings are finalized. Bug: 72385333 Bug: 72227981 Test: RunSettingsRoboTests Change-Id: Ib0328f0386efad525b331fd713dd15d060a1a649
This commit is contained in:
@@ -35,6 +35,7 @@ import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -89,20 +90,36 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
|
||||
.create();
|
||||
case BatteryTip.TipType.APP_RESTRICTION:
|
||||
final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
|
||||
final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(
|
||||
context).inflate(R.layout.recycler_view, null);
|
||||
final List<AppInfo> restrictedAppList = restrictAppTip.getRestrictAppList();
|
||||
final int num = restrictedAppList.size();
|
||||
restrictionView.setLayoutManager(new LinearLayoutManager(context));
|
||||
restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
|
||||
final UnrestrictAppTip unrestrictAppTip = (UnrestrictAppTip) mBatteryTip;
|
||||
final CharSequence name = Utils.getApplicationLabel(context,
|
||||
unrestrictAppTip.getPackageName());
|
||||
|
||||
return new AlertDialog.Builder(context)
|
||||
.setTitle(context.getResources().getQuantityString(
|
||||
R.plurals.battery_tip_restrict_title, num, num))
|
||||
.setMessage(getString(R.string.battery_tip_restrict_app_dialog_message))
|
||||
.setView(restrictionView)
|
||||
.setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setTitle(getString(R.string.battery_tip_unrestrict_app_dialog_title, name))
|
||||
.setMessage(R.string.battery_tip_unrestrict_app_dialog_message)
|
||||
.setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this)
|
||||
.setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null)
|
||||
.create();
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
|
||||
|
Reference in New Issue
Block a user