Merge changes from topic 'two_target_preference'
* changes: Update string character limit Convert BT preference to use TwoTargetPreference Refactor the layout for MasterSwitch to a 2 target pref
This commit is contained in:
committed by
Android (Google) Code Review
commit
b0967c8287
@@ -30,14 +30,13 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.HidProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||
@@ -50,15 +49,14 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
* BluetoothDevicePreference is the preference type used to display each remote
|
||||
* Bluetooth device in the Bluetooth Settings screen.
|
||||
*/
|
||||
public final class BluetoothDevicePreference extends Preference implements
|
||||
CachedBluetoothDevice.Callback, OnClickListener {
|
||||
private static final String TAG = "BluetoothDevicePreference";
|
||||
public final class BluetoothDevicePreference extends GearPreference implements
|
||||
CachedBluetoothDevice.Callback {
|
||||
private static final String TAG = "BluetoothDevicePref";
|
||||
|
||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||
|
||||
private final CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
private OnClickListener mOnSettingsClickListener;
|
||||
private final UserManager mUserManager;
|
||||
|
||||
private AlertDialog mDisconnectDialog;
|
||||
|
||||
@@ -76,7 +74,8 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
public final String BLUETOOTH = r.getString(R.string.bluetooth_talkback_bluetooth);
|
||||
|
||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
|
||||
super(context);
|
||||
super(context, null);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
|
||||
if (sDimAlpha == Integer.MIN_VALUE) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
@@ -85,14 +84,6 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
|
||||
mCachedDevice = cachedDevice;
|
||||
|
||||
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
if (!um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
|
||||
setWidgetLayoutResource(R.layout.preference_bluetooth);
|
||||
}
|
||||
}
|
||||
|
||||
mCachedDevice.registerCallback(this);
|
||||
|
||||
onDeviceAttributesChanged();
|
||||
@@ -102,12 +93,20 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
CachedBluetoothDevice getCachedDevice() {
|
||||
return mCachedDevice;
|
||||
@Override
|
||||
protected boolean shouldHideSecondTarget() {
|
||||
return mCachedDevice == null
|
||||
|| mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
|
||||
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
|
||||
}
|
||||
|
||||
public void setOnSettingsClickListener(OnClickListener listener) {
|
||||
mOnSettingsClickListener = listener;
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.preference_widget_gear;
|
||||
}
|
||||
|
||||
CachedBluetoothDevice getCachedDevice() {
|
||||
return mCachedDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,6 +119,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
}
|
||||
|
||||
public CachedBluetoothDevice getBluetoothDevice() {
|
||||
return mCachedDevice;
|
||||
}
|
||||
|
||||
public void onDeviceAttributesChanged() {
|
||||
/*
|
||||
* The preference framework takes care of making sure the value has
|
||||
@@ -157,11 +160,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
|
||||
if (mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
ImageView deviceDetails = (ImageView) view.findViewById(R.id.deviceDetails);
|
||||
ImageView deviceDetails = (ImageView) view.findViewById(R.id.settings_button);
|
||||
|
||||
if (deviceDetails != null) {
|
||||
deviceDetails.setOnClickListener(this);
|
||||
deviceDetails.setTag(mCachedDevice);
|
||||
}
|
||||
}
|
||||
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
|
||||
@@ -171,13 +173,6 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
super.onBindViewHolder(view);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
// Should never be null by construction
|
||||
if (mOnSettingsClickListener != null) {
|
||||
mOnSettingsClickListener.onClick(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ((o == null) || !(o instanceof BluetoothDevicePreference)) {
|
||||
@@ -207,19 +202,19 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
int bondState = mCachedDevice.getBondState();
|
||||
|
||||
final MetricsFeatureProvider metricsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
|
||||
|
||||
if (mCachedDevice.isConnected()) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
askDisconnect();
|
||||
} else if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
mCachedDevice.connect(true);
|
||||
} else if (bondState == BluetoothDevice.BOND_NONE) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
pair();
|
||||
}
|
||||
}
|
||||
@@ -283,10 +278,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
}
|
||||
if (btClass != null) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
|
||||
return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
|
||||
}
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
|
||||
return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
|
||||
}
|
||||
}
|
||||
|
@@ -45,13 +45,14 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.LinkifyUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.location.ScanningSettings;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.widget.FooterPreference;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.SwitchBarController;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
@@ -476,24 +477,25 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
}
|
||||
}
|
||||
|
||||
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// User clicked on advanced options icon for a device in the list
|
||||
if (!(v.getTag() instanceof CachedBluetoothDevice)) {
|
||||
Log.w(TAG, "onClick() called for other View: " + v);
|
||||
return;
|
||||
}
|
||||
|
||||
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS,
|
||||
device.getDevice().getAddress());
|
||||
DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
|
||||
profileSettings.setArguments(args);
|
||||
profileSettings.show(getFragmentManager(),
|
||||
DeviceProfilesSettings.class.getSimpleName());
|
||||
private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
|
||||
// User clicked on advanced options icon for a device in the list
|
||||
if (!(pref instanceof BluetoothDevicePreference)) {
|
||||
Log.w(TAG, "onClick() called for other View: " + pref);
|
||||
return;
|
||||
}
|
||||
final CachedBluetoothDevice device =
|
||||
((BluetoothDevicePreference) pref).getBluetoothDevice();
|
||||
if (device == null) {
|
||||
Log.w(TAG, "No BT device attached with this pref: " + pref);
|
||||
return;
|
||||
}
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS,
|
||||
device.getDevice().getAddress());
|
||||
final DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
|
||||
profileSettings.setArguments(args);
|
||||
profileSettings.show(getFragmentManager(),
|
||||
DeviceProfilesSettings.class.getSimpleName());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -506,7 +508,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
CachedBluetoothDevice cachedDevice = preference.getCachedDevice();
|
||||
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
// Only paired device have an associated advanced settings screen
|
||||
preference.setOnSettingsClickListener(mDeviceProfilesListener);
|
||||
preference.setOnGearClickListener(mDeviceProfilesListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
@@ -46,7 +45,7 @@ class SpellCheckerPreference extends CustomListPreference {
|
||||
public SpellCheckerPreference(final Context context, final SpellCheckerInfo[] scis) {
|
||||
super(context, null);
|
||||
mScis = scis;
|
||||
setWidgetLayoutResource(R.layout.preference_widget_settings);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_gear);
|
||||
CharSequence[] labels = new CharSequence[scis.length];
|
||||
CharSequence[] values = new CharSequence[scis.length];
|
||||
for (int i = 0 ; i < scis.length; i++) {
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.nfc;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
@@ -33,7 +32,6 @@ import android.widget.RadioButton;
|
||||
|
||||
import com.android.settings.CustomDialogPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
|
||||
|
||||
import java.util.List;
|
||||
@@ -59,7 +57,7 @@ public class NfcPaymentPreference extends CustomDialogPreference implements
|
||||
mAdapter = new NfcPaymentAdapter();
|
||||
setDialogTitle(context.getString(R.string.nfc_payment_pay_with));
|
||||
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_settings);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_gear);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@ public class GearPreference extends RestrictedPreference implements View.OnClick
|
||||
|
||||
public GearPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_settings);
|
||||
}
|
||||
|
||||
public void setOnGearClickListener(OnGearClickListener l) {
|
||||
@@ -41,6 +40,16 @@ public class GearPreference extends RestrictedPreference implements View.OnClick
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.preference_widget_gear;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldHideSecondTarget() {
|
||||
return mOnGearClickListener == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -27,12 +26,13 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
|
||||
/**
|
||||
* A custom preference that provides inline switch toggle. It has a mandatory field for title, and
|
||||
* optional fields for icon and sub-text.
|
||||
*/
|
||||
public class MasterSwitchPreference extends Preference {
|
||||
public class MasterSwitchPreference extends TwoTargetPreference {
|
||||
|
||||
private Switch mSwitch;
|
||||
private boolean mChecked;
|
||||
@@ -41,28 +41,29 @@ public class MasterSwitchPreference extends Preference {
|
||||
public MasterSwitchPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
public MasterSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public MasterSwitchPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public MasterSwitchPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.preference_widget_master_switch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
final View widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
|
||||
final View widgetView = holder.findViewById(android.R.id.widget_frame);
|
||||
if (widgetView != null) {
|
||||
widgetView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
@@ -76,12 +77,12 @@ public class MasterSwitchPreference extends Preference {
|
||||
}
|
||||
});
|
||||
}
|
||||
mSwitch = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
mSwitch = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(mChecked);
|
||||
}
|
||||
if (mMultiLine) {
|
||||
TextView textView = (TextView)holder.findViewById(android.R.id.title);
|
||||
TextView textView = (TextView) holder.findViewById(android.R.id.title);
|
||||
if (textView != null) {
|
||||
textView.setSingleLine(false);
|
||||
}
|
||||
@@ -99,10 +100,6 @@ public class MasterSwitchPreference extends Preference {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSwitchEnabled() {
|
||||
return mSwitch != null && mSwitch.isEnabled();
|
||||
}
|
||||
|
||||
public void setSwitchEnabled(boolean enabled) {
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setEnabled(enabled);
|
||||
@@ -128,9 +125,4 @@ public class MasterSwitchPreference extends Preference {
|
||||
public Switch getSwitch() {
|
||||
return mSwitch;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayoutResource(R.layout.preference_master_switch);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_master_switch);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user