summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjhtop.kim <jhtop.kim@samsung.com>2011-07-20 14:03:07 +0900
committerJake Hamby <jhamby@google.com>2011-08-15 15:14:58 -0700
commite96f04c1ffaa99992f9ed4c2687db0b955ae0450 (patch)
treeff7cbb95d4046369f03963c46877dc5b7809a602 /src
parent2f6ea06a63aaa0a87ba9b5def4937108baea6138 (diff)
downloadpackages_apps_settings-e96f04c1ffaa99992f9ed4c2687db0b955ae0450.zip
packages_apps_settings-e96f04c1ffaa99992f9ed4c2687db0b955ae0450.tar.gz
packages_apps_settings-e96f04c1ffaa99992f9ed4c2687db0b955ae0450.tar.bz2
Bluetooth : fix for Settings crashes while rotating the screen.
- Add some codes preventing setting crash when rotating the screen when the Rename device or Visibility timeout dialogs are visible. Change-Id: I5e142a5d869a0d5c91c6ace80093d09178d79558 Signed-off-by: jhtop.kim <jhtop.kim@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java39
-rw-r--r--src/com/android/settings/bluetooth/BluetoothSettings.java6
-rw-r--r--src/com/android/settings/bluetooth/BluetoothVisibilityTimeoutFragment.java7
-rw-r--r--[-rwxr-xr-x]src/com/android/settings/bluetooth/LocalBluetoothManager.java10
4 files changed, 49 insertions, 13 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
index c00aff3..4996858 100644
--- a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
@@ -40,7 +40,7 @@ import com.android.settings.R;
/**
* Dialog fragment for renaming the local Bluetooth device.
*/
-final class BluetoothNameDialogFragment extends DialogFragment implements TextWatcher {
+public final class BluetoothNameDialogFragment extends DialogFragment implements TextWatcher {
private static final int BLUETOOTH_NAME_MAX_LENGTH_BYTES = 248;
private AlertDialog mAlertDialog;
@@ -54,6 +54,13 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
// This flag is set when the name is updated by code, to distinguish from user changes
private boolean mDeviceNameUpdated;
+ // This flag is set when the user edits the name (preserved on rotation)
+ private boolean mDeviceNameEdited;
+
+ // Key to save the edited name and edit status for restoring after rotation
+ private static final String KEY_NAME = "device_name";
+ private static final String KEY_NAME_EDITED = "device_name_edited";
+
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -68,16 +75,22 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
}
};
- public BluetoothNameDialogFragment(LocalBluetoothAdapter adapter) {
- mLocalAdapter = adapter;
+ public BluetoothNameDialogFragment() {
+ LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(getActivity());
+ mLocalAdapter = localManager.getBluetoothAdapter();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ String deviceName = mLocalAdapter.getName();
+ if (savedInstanceState != null) {
+ deviceName = savedInstanceState.getString(KEY_NAME, deviceName);
+ mDeviceNameEdited = savedInstanceState.getBoolean(KEY_NAME_EDITED, false);
+ }
mAlertDialog = new AlertDialog.Builder(getActivity())
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.bluetooth_rename_device)
- .setView(createDialogView())
+ .setView(createDialogView(deviceName))
.setPositiveButton(R.string.bluetooth_rename_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -94,7 +107,13 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
return mAlertDialog;
}
- private View createDialogView() {
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ outState.putString(KEY_NAME, mDeviceNameView.getText().toString());
+ outState.putBoolean(KEY_NAME_EDITED, mDeviceNameEdited);
+ }
+
+ private View createDialogView(String deviceName) {
final LayoutInflater layoutInflater = (LayoutInflater)getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.dialog_edittext, null);
@@ -102,6 +121,7 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
mDeviceNameView.setFilters(new InputFilter[] {
new Utf8ByteLengthFilter(BLUETOOTH_NAME_MAX_LENGTH_BYTES)
});
+ mDeviceNameView.setText(deviceName); // set initial value before adding listener
mDeviceNameView.addTextChangedListener(this);
return view;
}
@@ -119,13 +139,12 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
super.onResume();
if (mOkButton == null) {
mOkButton = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
- mOkButton.setEnabled(false); // Ok button is enabled when the user edits the name
+ mOkButton.setEnabled(mDeviceNameEdited); // Ok button enabled after user edits
}
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
getActivity().registerReceiver(mReceiver, filter);
- updateDeviceName();
}
@Override
@@ -137,6 +156,7 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
void updateDeviceName() {
if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
mDeviceNameUpdated = true;
+ mDeviceNameEdited = false;
mDeviceNameView.setText(mLocalAdapter.getName());
}
}
@@ -147,7 +167,10 @@ final class BluetoothNameDialogFragment extends DialogFragment implements TextWa
mDeviceNameUpdated = false;
mOkButton.setEnabled(false);
} else {
- mOkButton.setEnabled(s.length() != 0);
+ mDeviceNameEdited = true;
+ if (mOkButton != null) {
+ mOkButton.setEnabled(s.length() != 0);
+ }
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index af21149..91bcffd 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -194,12 +194,12 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
return true;
case MENU_ID_RENAME_DEVICE:
- new BluetoothNameDialogFragment(mLocalAdapter).show(
+ new BluetoothNameDialogFragment().show(
getFragmentManager(), "rename device");
return true;
case MENU_ID_VISIBILITY_TIMEOUT:
- new BluetoothVisibilityTimeoutFragment(mDiscoverableEnabler).show(
+ new BluetoothVisibilityTimeoutFragment().show(
getFragmentManager(), "visibility timeout");
return true;
@@ -261,6 +261,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
mLocalAdapter, mMyDevicePreference);
mDiscoverableEnabler.resume();
+ LocalBluetoothManager.getInstance(getActivity()).setDiscoverableEnabler(
+ mDiscoverableEnabler);
}
// Paired devices category
diff --git a/src/com/android/settings/bluetooth/BluetoothVisibilityTimeoutFragment.java b/src/com/android/settings/bluetooth/BluetoothVisibilityTimeoutFragment.java
index 7c518fb..a65c6c1 100644
--- a/src/com/android/settings/bluetooth/BluetoothVisibilityTimeoutFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothVisibilityTimeoutFragment.java
@@ -41,13 +41,14 @@ import com.android.settings.R;
/**
* Dialog fragment for setting the discoverability timeout.
*/
-final class BluetoothVisibilityTimeoutFragment extends DialogFragment
+public final class BluetoothVisibilityTimeoutFragment extends DialogFragment
implements DialogInterface.OnClickListener {
private final BluetoothDiscoverableEnabler mDiscoverableEnabler;
- public BluetoothVisibilityTimeoutFragment(BluetoothDiscoverableEnabler enabler) {
- mDiscoverableEnabler = enabler;
+ public BluetoothVisibilityTimeoutFragment() {
+ mDiscoverableEnabler = LocalBluetoothManager.getInstance(getActivity())
+ .getDiscoverableEnabler();
}
@Override
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index a1edca1..3357e59 100755..100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -36,6 +36,8 @@ public final class LocalBluetoothManager {
/** If a BT-related activity is in the foreground, this will be it. */
private Context mForegroundActivity;
+ private BluetoothDiscoverableEnabler mDiscoverableEnabler;
+
private final LocalBluetoothAdapter mLocalAdapter;
private final CachedBluetoothDeviceManager mCachedDeviceManager;
@@ -60,6 +62,14 @@ public final class LocalBluetoothManager {
return sInstance;
}
+ public void setDiscoverableEnabler(BluetoothDiscoverableEnabler discoverableEnabler) {
+ mDiscoverableEnabler = discoverableEnabler;
+ }
+
+ public BluetoothDiscoverableEnabler getDiscoverableEnabler() {
+ return mDiscoverableEnabler;
+ }
+
private LocalBluetoothManager(LocalBluetoothAdapter adapter, Context context) {
mContext = context;
mLocalAdapter = adapter;