do not merge: cherry-pick e9f4f5dd39
from master branch
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothError;
|
||||
import android.bluetooth.BluetoothIntent;
|
||||
@@ -24,15 +26,18 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* BluetoothNamePreference is the preference type for editing the device's
|
||||
* Bluetooth name. It asks the user for a name, and persists it via the
|
||||
* Bluetooth API.
|
||||
*/
|
||||
public class BluetoothNamePreference extends EditTextPreference {
|
||||
public class BluetoothNamePreference extends EditTextPreference implements TextWatcher {
|
||||
private static final String TAG = "BluetoothNamePreference";
|
||||
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
@@ -64,9 +69,24 @@ public class BluetoothNamePreference extends EditTextPreference {
|
||||
filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
|
||||
filter.addAction(BluetoothIntent.NAME_CHANGED_ACTION);
|
||||
getContext().registerReceiver(mReceiver, filter);
|
||||
|
||||
// Make sure the OK button is disabled (if necessary) after rotation
|
||||
EditText et = getEditText();
|
||||
if (et != null) {
|
||||
et.addTextChangedListener(this);
|
||||
Dialog d = getDialog();
|
||||
if (d instanceof AlertDialog) {
|
||||
Button b = ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
b.setEnabled(et.getText().length() > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
EditText et = getEditText();
|
||||
if (et != null) {
|
||||
et.removeTextChangedListener(this);
|
||||
}
|
||||
getContext().unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@@ -84,4 +104,32 @@ public class BluetoothNamePreference extends EditTextPreference {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
||||
// The dialog should be created by now
|
||||
EditText et = getEditText();
|
||||
if (et != null) {
|
||||
et.setText(mLocalManager.getBluetoothManager().getName());
|
||||
}
|
||||
}
|
||||
|
||||
// TextWatcher interface
|
||||
public void afterTextChanged(Editable s) {
|
||||
Dialog d = getDialog();
|
||||
if (d instanceof AlertDialog) {
|
||||
((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
// TextWatcher interface
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// not used
|
||||
}
|
||||
|
||||
// TextWatcher interface
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// not used
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user