summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2010-04-28 11:10:40 -0700
committerMichael Chan <mchan@android.com>2010-04-28 11:24:00 -0700
commita0de1dcd1960181d9d8fd2e44f19dead16021e2b (patch)
treec5fb10fd6b88b8bc25aacee3fd1ca4a407485b69 /src
parent64ab5338cb0f90f8ee0787b0b98611670e6dee7e (diff)
downloadpackages_apps_Settings-a0de1dcd1960181d9d8fd2e44f19dead16021e2b.zip
packages_apps_Settings-a0de1dcd1960181d9d8fd2e44f19dead16021e2b.tar.gz
packages_apps_Settings-a0de1dcd1960181d9d8fd2e44f19dead16021e2b.tar.bz2
b/2630339 Fixed the crash when an app requests BT to be enabled
For AlertActivity, the dialog needs to display at onCreate() time. Otherwise, the decor view would be made. Trying to display the dialog afterward would crash. Changed to AlertDialog instead. Change-Id: I2ea8463b4c475b9b54746d0a722fa80eea3d4529
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/bluetooth/RequestPermissionActivity.java53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/com/android/settings/bluetooth/RequestPermissionActivity.java b/src/com/android/settings/bluetooth/RequestPermissionActivity.java
index 9fdb338..eca233c 100644
--- a/src/com/android/settings/bluetooth/RequestPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/RequestPermissionActivity.java
@@ -16,11 +16,10 @@
package com.android.settings.bluetooth;
-import com.android.internal.app.AlertActivity;
-import com.android.internal.app.AlertController;
import com.android.settings.R;
import android.app.Activity;
+import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
@@ -31,14 +30,12 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
-import android.view.View;
-import android.widget.TextView;
/**
* RequestPermissionActivity asks the user whether to enable discovery. This is
* usually started by an application wanted to start bluetooth and or discovery
*/
-public class RequestPermissionActivity extends AlertActivity implements
+public class RequestPermissionActivity extends Activity implements
DialogInterface.OnClickListener {
// Command line to test this
// adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
@@ -73,6 +70,8 @@ public class RequestPermissionActivity extends AlertActivity implements
private boolean mUserConfirmed = false;
+ private AlertDialog mDialog = null;
+
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@@ -84,7 +83,7 @@ public class RequestPermissionActivity extends AlertActivity implements
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR);
if (state == BluetoothAdapter.STATE_ON) {
if (mUserConfirmed) {
- proceedAndFinish(false);
+ proceedAndFinish();
}
}
}
@@ -136,7 +135,7 @@ public class RequestPermissionActivity extends AlertActivity implements
case BluetoothAdapter.STATE_ON:
if (mEnableOnly) {
// Nothing to do. Already enabled.
- proceedAndFinish(false);
+ proceedAndFinish();
return;
} else {
// Ask the user about enabling discovery mode
@@ -147,28 +146,24 @@ public class RequestPermissionActivity extends AlertActivity implements
}
private void createDialog() {
- final AlertController.AlertParams p = mAlertParams;
- p.mIconId = android.R.drawable.ic_dialog_info;
- p.mTitle = getString(R.string.bluetooth_permission_request);
-
- View view = getLayoutInflater().inflate(R.layout.bluetooth_discoverable, null);
- p.mView = view;
- TextView tv = (TextView) view.findViewById(R.id.message);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+ builder.setTitle(getString(R.string.bluetooth_permission_request));
if (mNeededToEnableBluetooth) {
// RequestPermissionHelperActivity has gotten confirmation from user
// to turn on BT
- tv.setText(getString(R.string.bluetooth_turning_on));
+ builder.setMessage(getString(R.string.bluetooth_turning_on));
+ builder.setCancelable(false);
} else {
// Ask the user whether to turn on discovery mode or not
- tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
- p.mPositiveButtonText = getString(R.string.yes);
- p.mPositiveButtonListener = this;
- p.mNegativeButtonText = getString(R.string.no);
- p.mNegativeButtonListener = this;
+ builder.setMessage(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
+ builder.setPositiveButton(getString(R.string.yes), this);
+ builder.setNegativeButton(getString(R.string.no), this);
}
- setupAlert();
+ mDialog = builder.create();
+ mDialog.show();
}
@Override
@@ -182,6 +177,7 @@ public class RequestPermissionActivity extends AlertActivity implements
if (resultCode != RESULT_BT_STARTING_OR_STARTED) {
setResult(resultCode);
finish();
+ return;
}
// Back from RequestPermissionHelperActivity. User confirmed to enable
@@ -189,7 +185,7 @@ public class RequestPermissionActivity extends AlertActivity implements
mUserConfirmed = true;
if (mLocalManager.getBluetoothState() == BluetoothAdapter.STATE_ON) {
- proceedAndFinish(false);
+ proceedAndFinish();
} else {
// If BT is not up yet, show "Turning on Bluetooth..."
createDialog();
@@ -199,16 +195,17 @@ public class RequestPermissionActivity extends AlertActivity implements
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
- proceedAndFinish(true);
+ proceedAndFinish();
break;
case DialogInterface.BUTTON_NEGATIVE:
setResult(Activity.RESULT_CANCELED);
+ finish();
break;
}
}
- private void proceedAndFinish(boolean buttonPressed) {
+ private void proceedAndFinish() {
int returnCode;
if (mEnableOnly) {
@@ -227,10 +224,12 @@ public class RequestPermissionActivity extends AlertActivity implements
returnCode = Activity.RESULT_CANCELED;
}
- setResult(returnCode);
- if (!buttonPressed) {
- finish();
+ if (mDialog != null) {
+ mDialog.dismiss();
}
+
+ setResult(returnCode);
+ finish();
}
private boolean parseIntent() {