From 2fa4ad8141ed0cb686c7acab27f01e8c2bc2877a Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Mon, 2 Mar 2009 22:54:43 -0800 Subject: auto import from //depot/cupcake/@137055 --- .../packageinstaller/UninstallerActivity.java | 85 +++++++++++++++------- 1 file changed, 58 insertions(+), 27 deletions(-) (limited to 'src/com/android/packageinstaller/UninstallerActivity.java') diff --git a/src/com/android/packageinstaller/UninstallerActivity.java b/src/com/android/packageinstaller/UninstallerActivity.java index b80f8ef..f22cc28 100755 --- a/src/com/android/packageinstaller/UninstallerActivity.java +++ b/src/com/android/packageinstaller/UninstallerActivity.java @@ -19,6 +19,7 @@ package com.android.packageinstaller; import com.android.packageinstaller.R; import android.app.Activity; import android.app.AlertDialog; +import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -40,16 +41,59 @@ import android.content.pm.PackageManager.NameNotFoundException; public class UninstallerActivity extends Activity implements OnClickListener { private static final String TAG = "UninstallerActivity"; private boolean localLOGV = false; - //states indicating status of ui display when uninstalling application - private static final int UNINSTALL_CONFIRM=1; - private static final int UNINSTALL_PROGRESS=2; - private static final int UNINSTALL_DONE=3; + // States indicating status of ui display when uninstalling application + private static final int UNINSTALL_CONFIRM = 1; + private static final int UNINSTALL_PROGRESS = 2; + private static final int UNINSTALL_DONE = 3; private int mCurrentState = UNINSTALL_CONFIRM; PackageManager mPm; private ApplicationInfo mAppInfo; private Button mOk; private Button mCancel; + + // Dialog identifiers used in showDialog + private static final int DLG_BASE = 0; + private static final int DLG_APP_NOT_FOUND = DLG_BASE + 1; + private static final int DLG_UNINSTALL_FAILED = DLG_BASE + 2; + + private void showDialogInner(int id) { + showDialog(id); + } + @Override + public Dialog onCreateDialog(int id) { + switch (id) { + case DLG_APP_NOT_FOUND : + return new AlertDialog.Builder(this) + .setTitle(R.string.app_not_found_dlg_title) + .setIcon(com.android.internal.R.drawable.ic_dialog_alert) + .setMessage(R.string.app_not_found_dlg_text) + .setNeutralButton(getString(R.string.dlg_ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + finish(); + }}) + .create(); + case DLG_UNINSTALL_FAILED : + // Guaranteed not to be null. will default to package name if not set by app + CharSequence appTitle = mPm.getApplicationLabel(mAppInfo); + String dlgText = getString(R.string.uninstall_failed_msg, + appTitle.toString()); + // Display uninstall failed dialog + return new AlertDialog.Builder(this) + .setTitle(R.string.uninstall_failed) + .setIcon(com.android.internal.R.drawable.ic_dialog_alert) + .setMessage(dlgText) + .setNeutralButton(getString(R.string.dlg_ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + finish(); + }}) + .create(); + } + return null; + } + private void startUninstallProgress() { Intent newIntent = new Intent(Intent.ACTION_VIEW); newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, @@ -58,32 +102,15 @@ public class UninstallerActivity extends Activity implements OnClickListener { startActivityForResult(newIntent, UNINSTALL_PROGRESS); } - private void startUninstallDone(boolean result) { + private void startUninstallDone() { Intent newIntent = new Intent(Intent.ACTION_VIEW); newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, mAppInfo); - newIntent.putExtra(PackageUtil.INTENT_ATTR_INSTALL_STATUS, result); + newIntent.putExtra(PackageUtil.INTENT_ATTR_INSTALL_STATUS, true); newIntent.setClass(this, UninstallAppDone.class); startActivityForResult(newIntent, UNINSTALL_DONE); } - - private void displayErrorDialog(int msgId) { - //display confirmation dialog - new AlertDialog.Builder(this) - .setTitle(getString(R.string.app_not_found_dlg_title)) - .setIcon(com.android.internal.R.drawable.ic_dialog_alert) - .setMessage(getString(msgId)) - .setNeutralButton(getString(R.string.dlg_ok), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //force to recompute changed value - finish(); - } - } - ) - .show(); - } - + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -93,7 +120,7 @@ public class UninstallerActivity extends Activity implements OnClickListener { String packageName = packageURI.getEncodedSchemeSpecificPart(); if(packageName == null) { Log.e(TAG, "Invalid package name:"+packageName); - displayErrorDialog(R.string.app_not_found_dlg_text); + showDialog(DLG_APP_NOT_FOUND); return; } //initialize package manager @@ -106,7 +133,7 @@ public class UninstallerActivity extends Activity implements OnClickListener { } if(mAppInfo == null || errFlag) { Log.e(TAG, "Invalid application:"+packageName); - displayErrorDialog(R.string.app_not_found_dlg_text); + showDialog(DLG_APP_NOT_FOUND); } else { requestWindowFeature(Window.FEATURE_NO_TITLE); //set view @@ -128,7 +155,11 @@ public class UninstallerActivity extends Activity implements OnClickListener { finish = false; mCurrentState = UNINSTALL_DONE; //start the next screen to show final status of installation - startUninstallDone(resultCode==UninstallAppProgress.SUCCEEDED); + if (resultCode==UninstallAppProgress.SUCCEEDED) { + startUninstallDone(); + } else { + showDialogInner(DLG_UNINSTALL_FAILED); + } break; case UNINSTALL_DONE: //neednt check for result code here -- cgit v1.1