Move clear instant app dialog logic out of AppInfoDashboardFragment.
- refactor AppInfoDashboardFragment and move the clear instant app dialog handling into instant app button controller. - move the dialog fragment to be a stand-alone class instead of inner class. Change-Id: I51c045938f3fd1db73b4b9f7e0311a51df599a29 Fixes: 110102457 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.android.settings.applications.appinfo;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Fragment to show the dialog for clearing the instant app.
|
||||
*/
|
||||
public class InstantAppButtonDialogFragment extends InstrumentedDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
|
||||
private static final String ARG_PACKAGE_NAME = "packageName";
|
||||
|
||||
private String mPackageName;
|
||||
|
||||
public static InstantAppButtonDialogFragment newInstance(String packageName) {
|
||||
final InstantAppButtonDialogFragment dialogFragment = new InstantAppButtonDialogFragment();
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putString(ARG_PACKAGE_NAME, packageName);
|
||||
dialogFragment.setArguments(args);
|
||||
return dialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_APP_INFO_ACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Bundle arguments = getArguments();
|
||||
mPackageName = arguments.getString(ARG_PACKAGE_NAME);
|
||||
return createDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Context context = getContext();
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
.action(context, MetricsEvent.ACTION_SETTINGS_CLEAR_INSTANT_APP, mPackageName);
|
||||
packageManager.deletePackageAsUser(mPackageName, null, 0, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
private AlertDialog createDialog() {
|
||||
AlertDialog confirmDialog = new AlertDialog.Builder(getContext())
|
||||
.setPositiveButton(R.string.clear_instant_app_data, this)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setTitle(R.string.clear_instant_app_data)
|
||||
.setMessage(R.string.clear_instant_app_confirmation)
|
||||
.create();
|
||||
return confirmDialog;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user