auto import from //branches/cupcake/...@127436
This commit is contained in:
242
src/com/android/settings/UserDictionarySettings.java
Normal file
242
src/com/android/settings/UserDictionarySettings.java
Normal file
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* Copyright (C) 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.UserDictionary;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.AlphabetIndexer;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SectionIndexer;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class UserDictionarySettings extends ListActivity {
|
||||
|
||||
private static final String INSTANCE_KEY_DIALOG_EDITING_WORD = "DIALOG_EDITING_WORD";
|
||||
|
||||
private static final String[] QUERY_PROJECTION = {
|
||||
UserDictionary.Words._ID, UserDictionary.Words.WORD
|
||||
};
|
||||
|
||||
// Either the locale is empty (means the word is applicable to all locales)
|
||||
// or the word equals our current locale
|
||||
private static final String QUERY_SELECTION = UserDictionary.Words.LOCALE + "=? OR "
|
||||
+ UserDictionary.Words.LOCALE + " is null";
|
||||
|
||||
private static final String DELETE_SELECTION = UserDictionary.Words.WORD + "=?";
|
||||
|
||||
private static final int CONTEXT_MENU_EDIT = Menu.FIRST;
|
||||
private static final int CONTEXT_MENU_DELETE = Menu.FIRST + 1;
|
||||
|
||||
private static final int OPTIONS_MENU_ADD = Menu.FIRST;
|
||||
|
||||
private static final int DIALOG_ADD_OR_EDIT = 0;
|
||||
|
||||
/** The word being edited in the dialog (null means the user is adding a word). */
|
||||
private String mDialogEditingWord;
|
||||
|
||||
private Cursor mCursor;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.list_content_with_empty_view);
|
||||
|
||||
mCursor = createCursor();
|
||||
setListAdapter(createAdapter());
|
||||
|
||||
TextView emptyView = (TextView) findViewById(R.id.empty);
|
||||
emptyView.setText(R.string.user_dict_settings_empty_text);
|
||||
|
||||
ListView listView = getListView();
|
||||
listView.setFastScrollEnabled(true);
|
||||
listView.setEmptyView(emptyView);
|
||||
|
||||
registerForContextMenu(listView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle state) {
|
||||
super.onRestoreInstanceState(state);
|
||||
mDialogEditingWord = state.getString(INSTANCE_KEY_DIALOG_EDITING_WORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(INSTANCE_KEY_DIALOG_EDITING_WORD, mDialogEditingWord);
|
||||
}
|
||||
|
||||
private Cursor createCursor() {
|
||||
String currentLocale = Locale.getDefault().toString();
|
||||
// Case-insensitive sort
|
||||
return managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
|
||||
QUERY_SELECTION, new String[] { currentLocale },
|
||||
"UPPER(" + UserDictionary.Words.WORD + ")");
|
||||
}
|
||||
|
||||
private ListAdapter createAdapter() {
|
||||
return new MyAdapter(this,
|
||||
android.R.layout.simple_list_item_1, mCursor,
|
||||
new String[] { UserDictionary.Words.WORD },
|
||||
new int[] { android.R.id.text1 });
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
showAddOrEditDialog(getWord(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
if (!(menuInfo instanceof AdapterContextMenuInfo)) return;
|
||||
|
||||
AdapterContextMenuInfo adapterMenuInfo = (AdapterContextMenuInfo) menuInfo;
|
||||
menu.setHeaderTitle(getWord(adapterMenuInfo.position));
|
||||
menu.add(0, CONTEXT_MENU_EDIT, 0, R.string.user_dict_settings_context_menu_edit_title);
|
||||
menu.add(0, CONTEXT_MENU_DELETE, 0, R.string.user_dict_settings_context_menu_delete_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
ContextMenuInfo menuInfo = item.getMenuInfo();
|
||||
if (!(menuInfo instanceof AdapterContextMenuInfo)) return false;
|
||||
|
||||
AdapterContextMenuInfo adapterMenuInfo = (AdapterContextMenuInfo) menuInfo;
|
||||
String word = getWord(adapterMenuInfo.position);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case CONTEXT_MENU_DELETE:
|
||||
deleteWord(word);
|
||||
return true;
|
||||
|
||||
case CONTEXT_MENU_EDIT:
|
||||
showAddOrEditDialog(word);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title)
|
||||
.setIcon(R.drawable.ic_menu_add);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
showAddOrEditDialog(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showAddOrEditDialog(String editingWord) {
|
||||
mDialogEditingWord = editingWord;
|
||||
showDialog(DIALOG_ADD_OR_EDIT);
|
||||
}
|
||||
|
||||
private String getWord(int position) {
|
||||
mCursor.moveToPosition(position);
|
||||
return mCursor.getString(
|
||||
mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
View content = getLayoutInflater().inflate(R.layout.dialog_edittext, null);
|
||||
final EditText editText = (EditText) content.findViewById(R.id.edittext);
|
||||
|
||||
return new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.user_dict_settings_add_dialog_title)
|
||||
.setView(content)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onAddOrEditFinished(editText.getText().toString());
|
||||
}})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog d) {
|
||||
AlertDialog dialog = (AlertDialog) d;
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.edittext);
|
||||
editText.setText(mDialogEditingWord);
|
||||
}
|
||||
|
||||
private void onAddOrEditFinished(String word) {
|
||||
if (mDialogEditingWord != null) {
|
||||
// The user was editing a word, so do a delete/add
|
||||
deleteWord(mDialogEditingWord);
|
||||
}
|
||||
|
||||
// Disallow duplicates
|
||||
deleteWord(word);
|
||||
|
||||
// TODO: present UI for picking whether to add word to all locales, or current.
|
||||
UserDictionary.Words.addWord(this, word.toString(),
|
||||
1, UserDictionary.Words.LOCALE_TYPE_ALL);
|
||||
mCursor.requery();
|
||||
}
|
||||
|
||||
private void deleteWord(String word) {
|
||||
getContentResolver().delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION,
|
||||
new String[] { word });
|
||||
}
|
||||
|
||||
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
|
||||
private AlphabetIndexer mIndexer;
|
||||
|
||||
public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
|
||||
super(context, layout, c, from, to);
|
||||
|
||||
int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD);
|
||||
String alphabet = context.getString(com.android.internal.R.string.fast_scroll_alphabet);
|
||||
mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet);
|
||||
}
|
||||
|
||||
public int getPositionForSection(int section) {
|
||||
return mIndexer.getPositionForSection(section);
|
||||
}
|
||||
|
||||
public int getSectionForPosition(int position) {
|
||||
return mIndexer.getSectionForPosition(position);
|
||||
}
|
||||
|
||||
public Object[] getSections() {
|
||||
return mIndexer.getSections();
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,13 +21,12 @@ import com.android.settings.bluetooth.LocalBluetoothManager.ExtendedBluetoothSta
|
||||
import android.bluetooth.BluetoothA2dp;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.bluetooth.BluetoothError;
|
||||
import android.bluetooth.BluetoothIntent;
|
||||
import android.bluetooth.IBluetoothDeviceCallback;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -40,29 +39,6 @@ public class BluetoothEventRedirector {
|
||||
private static final boolean V = LocalBluetoothManager.V;
|
||||
|
||||
private LocalBluetoothManager mManager;
|
||||
private Handler mUiHandler = new Handler();
|
||||
|
||||
private IBluetoothDeviceCallback mBtDevCallback = new IBluetoothDeviceCallback.Stub() {
|
||||
public void onCreateBondingResult(final String address, final int result) {
|
||||
if (V) {
|
||||
Log.v(TAG, "onCreateBondingResult(" + address + ", " + result + ")");
|
||||
}
|
||||
|
||||
mUiHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
boolean wasSuccess = result == BluetoothDevice.RESULT_SUCCESS;
|
||||
LocalBluetoothDeviceManager deviceManager = mManager.getLocalDeviceManager();
|
||||
deviceManager.onBondingStateChanged(address, wasSuccess);
|
||||
if (!wasSuccess) {
|
||||
deviceManager.onBondingError(address);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEnableResult(int result) { }
|
||||
public void onGetRemoteServiceChannelResult(String address, int channel) { }
|
||||
};
|
||||
|
||||
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -86,17 +62,21 @@ public class BluetoothEventRedirector {
|
||||
|
||||
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION)) {
|
||||
short rssi = intent.getShortExtra(BluetoothIntent.RSSI, Short.MIN_VALUE);
|
||||
mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi);
|
||||
mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi);
|
||||
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onDeviceDisappeared(address);
|
||||
} else if (action.equals(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onDeviceNameUpdated(address);
|
||||
|
||||
} else if (action.equals(BluetoothIntent.BONDING_CREATED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onBondingStateChanged(address, true);
|
||||
} else if (action.equals(BluetoothIntent.BONDING_REMOVED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onBondingStateChanged(address, false);
|
||||
|
||||
} else if (action.equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)) {
|
||||
int bondState = intent.getIntExtra(BluetoothIntent.BOND_STATE,
|
||||
BluetoothError.ERROR);
|
||||
mManager.getLocalDeviceManager().onBondingStateChanged(address, bondState);
|
||||
if (bondState == BluetoothDevice.BOND_NOT_BONDED) {
|
||||
int reason = intent.getIntExtra(BluetoothIntent.REASON, BluetoothError.ERROR);
|
||||
Log.w(TAG, address + " unbonded with reason " + reason +
|
||||
", TODO: handle this nicely in the UI"); //TODO
|
||||
mManager.getLocalDeviceManager().onBondingError(address);
|
||||
}
|
||||
} else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onProfileStateChanged(address);
|
||||
|
||||
@@ -139,8 +119,7 @@ public class BluetoothEventRedirector {
|
||||
filter.addAction(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION);
|
||||
|
||||
// Pairing broadcasts
|
||||
filter.addAction(BluetoothIntent.BONDING_CREATED_ACTION);
|
||||
filter.addAction(BluetoothIntent.BONDING_REMOVED_ACTION);
|
||||
filter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
|
||||
|
||||
// Fine-grained state broadcasts
|
||||
filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
|
||||
@@ -152,8 +131,4 @@ public class BluetoothEventRedirector {
|
||||
public void stop() {
|
||||
mManager.getContext().unregisterReceiver(mBroadcastReceiver);
|
||||
}
|
||||
|
||||
public IBluetoothDeviceCallback getBluetoothDeviceCallback() {
|
||||
return mBtDevCallback;
|
||||
}
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
|
||||
private boolean mVisible;
|
||||
|
||||
private int mPairingStatus;
|
||||
private int mBondState;
|
||||
|
||||
private final LocalBluetoothManager mLocalManager;
|
||||
|
||||
@@ -85,13 +85,13 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
}
|
||||
|
||||
public void onClicked() {
|
||||
int pairingStatus = getPairingStatus();
|
||||
int bondState = getBondState();
|
||||
|
||||
if (isConnected()) {
|
||||
askDisconnect();
|
||||
} else if (pairingStatus == SettingsBtStatus.PAIRING_STATUS_PAIRED) {
|
||||
} else if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
connect();
|
||||
} else if (pairingStatus == SettingsBtStatus.PAIRING_STATUS_UNPAIRED) {
|
||||
} else if (bondState == BluetoothDevice.BOND_NOT_BONDED) {
|
||||
pair();
|
||||
}
|
||||
}
|
||||
@@ -195,55 +195,54 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
}
|
||||
|
||||
private boolean ensurePaired() {
|
||||
if (getPairingStatus() == SettingsBtStatus.PAIRING_STATUS_UNPAIRED) {
|
||||
if (getBondState() == BluetoothDevice.BOND_NOT_BONDED) {
|
||||
pair();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void pair() {
|
||||
BluetoothDevice manager = mLocalManager.getBluetoothManager();
|
||||
|
||||
// Pairing doesn't work if scanning, so cancel
|
||||
|
||||
// Pairing is unreliable while scanning, so cancel discovery
|
||||
if (manager.isDiscovering()) {
|
||||
manager.cancelDiscovery();
|
||||
}
|
||||
|
||||
|
||||
if (mLocalManager.createBonding(mAddress)) {
|
||||
setPairingStatus(SettingsBtStatus.PAIRING_STATUS_PAIRING);
|
||||
//TODO: consider removing this line - UI will update through Intent
|
||||
setBondState(BluetoothDevice.BOND_BONDING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void unpair() {
|
||||
BluetoothDevice manager = mLocalManager.getBluetoothManager();
|
||||
|
||||
switch (getPairingStatus()) {
|
||||
case SettingsBtStatus.PAIRING_STATUS_PAIRED:
|
||||
manager.removeBonding(mAddress);
|
||||
break;
|
||||
|
||||
case SettingsBtStatus.PAIRING_STATUS_PAIRING:
|
||||
manager.cancelBondingProcess(mAddress);
|
||||
break;
|
||||
|
||||
switch (getBondState()) {
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
manager.removeBond(mAddress);
|
||||
break;
|
||||
|
||||
case BluetoothDevice.BOND_BONDING:
|
||||
manager.cancelBondProcess(mAddress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void fillData() {
|
||||
BluetoothDevice manager = mLocalManager.getBluetoothManager();
|
||||
|
||||
fetchName();
|
||||
|
||||
fetchName();
|
||||
mBtClass = manager.getRemoteClass(mAddress);
|
||||
|
||||
LocalBluetoothProfileManager.fill(mBtClass, mProfiles);
|
||||
|
||||
mPairingStatus = manager.hasBonding(mAddress)
|
||||
? SettingsBtStatus.PAIRING_STATUS_PAIRED
|
||||
: SettingsBtStatus.PAIRING_STATUS_UNPAIRED;
|
||||
|
||||
|
||||
mBondState = manager.getBondState(mAddress);
|
||||
|
||||
mVisible = false;
|
||||
|
||||
|
||||
dispatchAttributesChanged();
|
||||
}
|
||||
|
||||
@@ -283,17 +282,17 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
public int getPairingStatus() {
|
||||
return mPairingStatus;
|
||||
public int getBondState() {
|
||||
return mBondState;
|
||||
}
|
||||
|
||||
void setPairingStatus(int pairingStatus) {
|
||||
if (mPairingStatus != pairingStatus) {
|
||||
mPairingStatus = pairingStatus;
|
||||
void setBondState(int bondState) {
|
||||
if (mBondState != bondState) {
|
||||
mBondState = bondState;
|
||||
dispatchAttributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setRssi(short rssi) {
|
||||
if (mRssi != rssi) {
|
||||
mRssi = rssi;
|
||||
@@ -327,7 +326,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
if (getPairingStatus() == SettingsBtStatus.PAIRING_STATUS_PAIRING) {
|
||||
if (getBondState() == BluetoothDevice.BOND_BONDING) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -374,9 +373,8 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
return SettingsBtStatus.getConnectionStatusSummary(connectionStatus);
|
||||
}
|
||||
}
|
||||
|
||||
int pairingStatus = getPairingStatus();
|
||||
return SettingsBtStatus.getPairingStatusSummary(pairingStatus);
|
||||
|
||||
return SettingsBtStatus.getPairingStatusSummary(getBondState());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,7 +428,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
// No context menu if there are no profiles
|
||||
if (mProfiles.size() == 0) return;
|
||||
|
||||
int pairingStatus = getPairingStatus();
|
||||
int bondState = getBondState();
|
||||
boolean isConnected = isConnected();
|
||||
|
||||
menu.setHeaderTitle(getName());
|
||||
@@ -439,13 +437,13 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
menu.add(0, CONTEXT_ITEM_DISCONNECT, 0, R.string.bluetooth_device_context_disconnect);
|
||||
} else {
|
||||
// For connection action, show either "Connect" or "Pair & connect"
|
||||
int connectString = pairingStatus == SettingsBtStatus.PAIRING_STATUS_UNPAIRED
|
||||
int connectString = (bondState == BluetoothDevice.BOND_NOT_BONDED)
|
||||
? R.string.bluetooth_device_context_pair_connect
|
||||
: R.string.bluetooth_device_context_connect;
|
||||
menu.add(0, CONTEXT_ITEM_CONNECT, 0, connectString);
|
||||
}
|
||||
|
||||
if (pairingStatus == SettingsBtStatus.PAIRING_STATUS_PAIRED) {
|
||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
// For unpair action, show either "Unpair" or "Disconnect & unpair"
|
||||
int unpairString = isConnected
|
||||
? R.string.bluetooth_device_context_disconnect_unpair
|
||||
@@ -540,8 +538,8 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
// Paired above not paired
|
||||
comparison = (another.mPairingStatus == SettingsBtStatus.PAIRING_STATUS_PAIRED ? 1 : 0) -
|
||||
(mPairingStatus == SettingsBtStatus.PAIRING_STATUS_PAIRED ? 1 : 0);
|
||||
comparison = (another.mBondState == BluetoothDevice.BOND_BONDED ? 1 : 0) -
|
||||
(mBondState == BluetoothDevice.BOND_BONDED ? 1 : 0);
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
// Visible above not visible
|
||||
|
@@ -47,7 +47,7 @@ public class LocalBluetoothDeviceManager {
|
||||
|
||||
private synchronized void readPairedDevices() {
|
||||
BluetoothDevice manager = mLocalManager.getBluetoothManager();
|
||||
String[] bondedAddresses = manager.listBondings();
|
||||
String[] bondedAddresses = manager.listBonds();
|
||||
if (bondedAddresses == null) return;
|
||||
|
||||
for (String address : bondedAddresses) {
|
||||
@@ -97,7 +97,7 @@ public class LocalBluetoothDeviceManager {
|
||||
}
|
||||
|
||||
private void checkForDeviceRemoval(LocalBluetoothDevice device) {
|
||||
if (device.getPairingStatus() == SettingsBtStatus.PAIRING_STATUS_UNPAIRED &&
|
||||
if (device.getBondState() == BluetoothDevice.BOND_NOT_BONDED &&
|
||||
!device.isVisible()) {
|
||||
// If device isn't paired, remove it altogether
|
||||
mDevices.remove(device);
|
||||
@@ -154,19 +154,18 @@ public class LocalBluetoothDeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void onBondingStateChanged(String address, boolean created) {
|
||||
public synchronized void onBondingStateChanged(String address, int bondState) {
|
||||
LocalBluetoothDevice device = findDevice(address);
|
||||
if (device == null) {
|
||||
Log.e(TAG, "Got bonding state changed for " + address +
|
||||
", but we have no record of that device.");
|
||||
return;
|
||||
}
|
||||
|
||||
device.setPairingStatus(created ? SettingsBtStatus.PAIRING_STATUS_PAIRED
|
||||
: SettingsBtStatus.PAIRING_STATUS_UNPAIRED);
|
||||
|
||||
device.setBondState(bondState); //TODO: might be unecessary
|
||||
checkForDeviceRemoval(device);
|
||||
|
||||
if (created) {
|
||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
// Auto-connect after pairing
|
||||
device.connect();
|
||||
}
|
||||
|
@@ -227,7 +227,7 @@ public class LocalBluetoothManager {
|
||||
}
|
||||
|
||||
public boolean createBonding(String address) {
|
||||
return mManager.createBonding(address, mEventRedirector.getBluetoothDeviceCallback());
|
||||
return mManager.createBond(address);
|
||||
}
|
||||
|
||||
public void showError(String address, int titleResId, int messageResId) {
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
@@ -64,19 +66,13 @@ public class SettingsBtStatus {
|
||||
|| connectionStatus == CONNECTION_STATUS_DISCONNECTING;
|
||||
}
|
||||
|
||||
// Pairing status
|
||||
|
||||
public static final int PAIRING_STATUS_UNPAIRED = 0;
|
||||
public static final int PAIRING_STATUS_PAIRED = 1;
|
||||
public static final int PAIRING_STATUS_PAIRING = 2;
|
||||
|
||||
public static final int getPairingStatusSummary(int pairingStatus) {
|
||||
switch (pairingStatus) {
|
||||
case PAIRING_STATUS_PAIRED:
|
||||
public static final int getPairingStatusSummary(int bondState) {
|
||||
switch (bondState) {
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
return R.string.bluetooth_paired;
|
||||
case PAIRING_STATUS_PAIRING:
|
||||
case BluetoothDevice.BOND_BONDING:
|
||||
return R.string.bluetooth_pairing;
|
||||
case PAIRING_STATUS_UNPAIRED:
|
||||
case BluetoothDevice.BOND_NOT_BONDED:
|
||||
return R.string.bluetooth_not_connected;
|
||||
default:
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user