auto import from //branches/cupcake/...@130745

This commit is contained in:
The Android Open Source Project
2009-02-10 15:44:05 -08:00
parent 590c0a97ff
commit 1feaa85791
122 changed files with 5734 additions and 4925 deletions

View File

@@ -18,13 +18,19 @@ package com.android.settings.bluetooth;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.method.DigitsKeyListener;
import android.text.TextWatcher;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@@ -36,12 +42,31 @@ import com.android.settings.R;
* BluetoothPinDialog asks the user to enter a PIN for pairing with a remote
* Bluetooth device. It is an activity that appears as a dialog.
*/
public class BluetoothPinDialog extends AlertActivity implements DialogInterface.OnClickListener {
public class BluetoothPinDialog extends AlertActivity implements DialogInterface.OnClickListener,
TextWatcher {
private static final String TAG = "BluetoothPinDialog";
private LocalBluetoothManager mLocalManager;
private String mAddress;
private EditText mPinView;
private Button mOkButton;
private static final String INSTANCE_KEY_PAIRING_CANCELED = "received_pairing_canceled";
private boolean mReceivedPairingCanceled;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!BluetoothIntent.PAIRING_CANCEL_ACTION.equals(intent.getAction())) {
return;
}
String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
if (address == null || address.equals(mAddress)) {
onReceivedPairingCanceled();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -69,6 +94,39 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface
p.mNegativeButtonText = getString(android.R.string.cancel);
p.mNegativeButtonListener = this;
setupAlert();
mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
mOkButton.setEnabled(false);
/*
* Leave this registered through pause/resume since we still want to
* finish the activity in the background if pairing is canceled.
*/
registerReceiver(mReceiver, new IntentFilter(BluetoothIntent.PAIRING_CANCEL_ACTION));
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mReceivedPairingCanceled = savedInstanceState.getBoolean(INSTANCE_KEY_PAIRING_CANCELED);
if (mReceivedPairingCanceled) {
onReceivedPairingCanceled();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(INSTANCE_KEY_PAIRING_CANCELED, mReceivedPairingCanceled);
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mReceiver);
}
private View createView() {
@@ -79,9 +137,32 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface
messageView.setText(getString(R.string.bluetooth_enter_pin_msg, name));
mPinView = (EditText) view.findViewById(R.id.text);
mPinView.addTextChangedListener(this);
// Maximum of 10 characters in a PIN
mPinView.setFilters(new InputFilter[] { new LengthFilter(10) });
return view;
}
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
mOkButton.setEnabled(true);
}
}
private void onReceivedPairingCanceled() {
mReceivedPairingCanceled = true;
TextView messageView = (TextView) findViewById(R.id.message);
messageView.setText(getString(R.string.bluetooth_pairing_error_message,
mLocalManager.getLocalDeviceManager().getName(mAddress)));
mPinView.setEnabled(false);
mPinView.clearFocus();
mPinView.removeTextChangedListener(this);
mAlert.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}
private void onPair(String pin) {
byte[] pinBytes = BluetoothDevice.convertPinToBytes(pin);
@@ -94,7 +175,7 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface
}
private void onCancel() {
mLocalManager.getBluetoothManager().cancelPin(mAddress);
mLocalManager.getBluetoothManager().cancelBondProcess(mAddress);
}
public void onClick(DialogInterface dialog, int which) {
@@ -109,4 +190,12 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface
}
}
/* Not used */
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
/* Not used */
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}