Changed a Bluetooth device's settings from an activity to a dialog.
+ Replace the “Paired bluetooth device” screen with a “Pair device” dialog + Add device name text field at the top + Replace “Unpair” list item with a “Forget" button at bottom of dialog + Change “Profiles” section header to “Use for” + Remove status under profile titles + Move checkboxes to left side of labels Bug: 15719219 Change-Id: I3b0e8c82c761fae98f16508b9fd9c58aff651f80
This commit is contained in:
@@ -15,14 +15,38 @@
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout android:id="@+id/dialog_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bluetooth_dialog_padding"
|
||||
style="@style/wifi_item" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/bluetooth_preference_paired_dialog_name_label"
|
||||
android:textDirection="locale"
|
||||
style="@style/wifi_item_label" />
|
||||
|
||||
<EditText android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textNoSuggestions"
|
||||
android:maxLength="@integer/bluetooth_name_length"
|
||||
android:singleLine="true"
|
||||
style="@style/wifi_item_edit_content" />
|
||||
|
||||
<fragment android:id="@+id/bluetooth_fragment_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
class="com.android.settings.bluetooth.DeviceProfilesSettings" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/bluetooth_device_picker_fragment"
|
||||
android:name="com.android.settings.bluetooth.DevicePickerFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
@@ -204,4 +204,8 @@
|
||||
<dimen name="checkbox_widget_min_width">58dip</dimen>
|
||||
<dimen name="checkbox_layout_padding">16dip</dimen>
|
||||
|
||||
<!-- Bluetooth Preferences -->
|
||||
<dimen name="bluetooth_dialog_padding">8dip</dimen>
|
||||
<integer name="bluetooth_name_length">32</integer>
|
||||
|
||||
</resources>
|
||||
|
@@ -18,19 +18,6 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/bluetooth_device_advanced_title">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="rename_device"
|
||||
android:title="@string/bluetooth_device_advanced_rename_device"
|
||||
android:order="20"
|
||||
android:persistent="false" />
|
||||
|
||||
<Preference
|
||||
android:key="unpair"
|
||||
android:title="@string/bluetooth_device_context_unpair"
|
||||
android:order="40"
|
||||
android:persistent="false"
|
||||
/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="profile_container"
|
||||
android:order="100"
|
||||
|
@@ -18,28 +18,39 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
@@ -64,6 +75,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
|
||||
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
|
||||
|
||||
private static View mSettingsDialogView = null;
|
||||
|
||||
private BluetoothEnabler mBluetoothEnabler;
|
||||
|
||||
private PreferenceGroup mPairedDevicesCategory;
|
||||
@@ -371,20 +384,60 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// User clicked on advanced options icon for a device in the list
|
||||
if (v.getTag() instanceof CachedBluetoothDevice) {
|
||||
if (isUiRestricted()) return;
|
||||
|
||||
CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||
|
||||
Bundle args = new Bundle(1);
|
||||
args.putParcelable(DeviceProfilesSettings.EXTRA_DEVICE, device.getDevice());
|
||||
|
||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
||||
DeviceProfilesSettings.class.getName(), args,
|
||||
R.string.bluetooth_device_advanced_title, null, null, 0);
|
||||
} else {
|
||||
Log.w(TAG, "onClick() called for other View: " + v); // TODO remove
|
||||
if (!(v.getTag() instanceof CachedBluetoothDevice)) {
|
||||
Log.w(TAG, "onClick() called for other View: " + v);
|
||||
return;
|
||||
}
|
||||
|
||||
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||
final Activity activity = getActivity();
|
||||
DeviceProfilesSettings profileFrag = (DeviceProfilesSettings)activity.
|
||||
getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings);
|
||||
|
||||
if (mSettingsDialogView != null){
|
||||
ViewGroup parent = (ViewGroup) mSettingsDialogView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(mSettingsDialogView);
|
||||
}
|
||||
}
|
||||
if (profileFrag == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_picker, null);
|
||||
profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
|
||||
.findFragmentById(R.id.bluetooth_fragment_settings);
|
||||
}
|
||||
|
||||
final View dialogLayout = mSettingsDialogView;
|
||||
AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity);
|
||||
profileFrag.setDevice(device);
|
||||
final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
|
||||
deviceName.setText(device.getName(), TextView.BufferType.EDITABLE);
|
||||
settingsDialog.setView(dialogLayout);
|
||||
settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices);
|
||||
settingsDialog.setPositiveButton(R.string.okay,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
|
||||
device.setName(deviceName.getText().toString());
|
||||
}
|
||||
});
|
||||
final Context context = v.getContext();
|
||||
settingsDialog.setNegativeButton(R.string.forget,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
device.unpair();
|
||||
com.android.settings.bluetooth.Utils.updateSearchIndex(activity,
|
||||
BluetoothSettings.class.getName(), device.getName(),
|
||||
context.getResources().getString(R.string.bluetooth_settings),
|
||||
R.drawable.ic_settings_bluetooth2, false);
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = settingsDialog.create();
|
||||
dialog.create();
|
||||
dialog.show();
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
@@ -36,6 +37,7 @@ import android.text.TextWatcher;
|
||||
import android.app.Dialog;
|
||||
import android.widget.Button;
|
||||
import android.text.Editable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.Index;
|
||||
@@ -52,15 +54,14 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
implements CachedBluetoothDevice.Callback, Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "DeviceProfilesSettings";
|
||||
|
||||
private static final String KEY_RENAME_DEVICE = "rename_device";
|
||||
private static final String KEY_PROFILE_CONTAINER = "profile_container";
|
||||
private static final String KEY_UNPAIR = "unpair";
|
||||
private static final String KEY_PBAP_SERVER = "PBAP Server";
|
||||
|
||||
public static final String EXTRA_DEVICE = "device";
|
||||
private RenameEditTextPreference mRenameDeviceNamePref;
|
||||
private LocalBluetoothManager mManager;
|
||||
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
private LocalBluetoothManager mManager;
|
||||
private LocalBluetoothProfileManager mProfileManager;
|
||||
|
||||
private PreferenceGroup mProfileContainer;
|
||||
@@ -72,66 +73,18 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
private AlertDialog mDisconnectDialog;
|
||||
private boolean mProfileGroupIsRemoved;
|
||||
|
||||
private class RenameEditTextPreference implements TextWatcher{
|
||||
public void afterTextChanged(Editable s) {
|
||||
Dialog d = mDeviceNamePref.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
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
BluetoothDevice device;
|
||||
if (savedInstanceState != null) {
|
||||
device = savedInstanceState.getParcelable(EXTRA_DEVICE);
|
||||
} else {
|
||||
Bundle args = getArguments();
|
||||
device = args.getParcelable(EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
addPreferencesFromResource(R.xml.bluetooth_device_advanced);
|
||||
getPreferenceScreen().setOrderingAsAdded(false);
|
||||
mProfileContainer = (PreferenceGroup) findPreference(KEY_PROFILE_CONTAINER);
|
||||
mDeviceNamePref = (EditTextPreference) findPreference(KEY_RENAME_DEVICE);
|
||||
|
||||
if (device == null) {
|
||||
Log.w(TAG, "Activity started without a remote Bluetooth device");
|
||||
finish();
|
||||
return; // TODO: test this failure path
|
||||
}
|
||||
mRenameDeviceNamePref = new RenameEditTextPreference();
|
||||
mManager = LocalBluetoothManager.getInstance(getActivity());
|
||||
CachedBluetoothDeviceManager deviceManager =
|
||||
mManager.getCachedDeviceManager();
|
||||
mProfileManager = mManager.getProfileManager();
|
||||
mCachedDevice = deviceManager.findDevice(device);
|
||||
if (mCachedDevice == null) {
|
||||
Log.w(TAG, "Device not found, cannot connect to it");
|
||||
finish();
|
||||
return; // TODO: test this failure path
|
||||
}
|
||||
|
||||
String deviceName = mCachedDevice.getName();
|
||||
mDeviceNamePref.setSummary(deviceName);
|
||||
mDeviceNamePref.setText(deviceName);
|
||||
mDeviceNamePref.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Add a preference for each profile
|
||||
addPreferencesForProfiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,6 +94,9 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
mDisconnectDialog.dismiss();
|
||||
mDisconnectDialog = null;
|
||||
}
|
||||
if (mCachedDevice != null) {
|
||||
mCachedDevice.unregisterCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,18 +110,13 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
super.onResume();
|
||||
|
||||
mManager.setForegroundActivity(getActivity());
|
||||
mCachedDevice.registerCallback(this);
|
||||
if(mCachedDevice.getBondState() == BluetoothDevice.BOND_NONE)
|
||||
finish();
|
||||
refresh();
|
||||
EditText et = mDeviceNamePref.getEditText();
|
||||
if (et != null) {
|
||||
et.addTextChangedListener(mRenameDeviceNamePref);
|
||||
Dialog d = mDeviceNamePref.getDialog();
|
||||
if (d instanceof AlertDialog) {
|
||||
Button b = ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
b.setEnabled(et.getText().length() > 0);
|
||||
if (mCachedDevice != null) {
|
||||
mCachedDevice.registerCallback(this);
|
||||
if (mCachedDevice.getBondState() == BluetoothDevice.BOND_NONE) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,11 +124,23 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
mCachedDevice.unregisterCallback(this);
|
||||
if (mCachedDevice != null) {
|
||||
mCachedDevice.unregisterCallback(this);
|
||||
}
|
||||
|
||||
mManager.setForegroundActivity(null);
|
||||
}
|
||||
|
||||
public void setDevice(CachedBluetoothDevice cachedDevice) {
|
||||
mCachedDevice = cachedDevice;
|
||||
|
||||
mCachedDevice.registerCallback(this);
|
||||
addPreferencesForProfiles();
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void addPreferencesForProfiles() {
|
||||
mProfileContainer.removeAll();
|
||||
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
|
||||
Preference pref = createProfilePreference(profile);
|
||||
mProfileContainer.addPreference(pref);
|
||||
@@ -238,28 +201,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
return pref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||
String key = preference.getKey();
|
||||
if (key.equals(KEY_UNPAIR)) {
|
||||
unpairDevice();
|
||||
finish();
|
||||
final Context context = preference.getContext();
|
||||
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.className = BluetoothSettings.class.getName();
|
||||
data.title = mCachedDevice.getName();
|
||||
data.screenTitle = context.getResources().getString(R.string.bluetooth_settings);
|
||||
data.iconResId = R.drawable.ic_settings_bluetooth2;
|
||||
data.enabled = false;
|
||||
|
||||
Index.getInstance(context).updateFromSearchIndexableData(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mDeviceNamePref) {
|
||||
mCachedDevice.setName((String) newValue);
|
||||
@@ -331,14 +272,16 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
mDisconnectDialog, disconnectListener, title, Html.fromHtml(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceAttributesChanged() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
String deviceName = mCachedDevice.getName();
|
||||
mDeviceNamePref.setSummary(deviceName);
|
||||
mDeviceNamePref.setText(deviceName);
|
||||
final EditText deviceNameField = (EditText) getView().findViewById(R.id.name);
|
||||
if (deviceNameField != null) {
|
||||
deviceNameField.setText(mCachedDevice.getName());
|
||||
}
|
||||
|
||||
refreshProfiles();
|
||||
}
|
||||
@@ -391,8 +334,4 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
private int getProfilePreferenceIndex(int profIndex) {
|
||||
return mProfileContainer.getOrder() + profIndex * 10;
|
||||
}
|
||||
|
||||
private void unpairDevice() {
|
||||
mCachedDevice.unpair();
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import android.content.DialogInterface;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
|
||||
/**
|
||||
* Utils is a helper class that contains constants for various
|
||||
@@ -101,4 +103,19 @@ final class Utils {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the search Index for a specific class name and resources.
|
||||
*/
|
||||
public static void updateSearchIndex(Context context, String className, String title,
|
||||
String screenTitle, int iconResId, boolean enabled) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.className = className;
|
||||
data.title = title;
|
||||
data.screenTitle = screenTitle;
|
||||
data.iconResId = iconResId;
|
||||
data.enabled = enabled;
|
||||
|
||||
Index.getInstance(context).updateFromSearchIndexableData(data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user