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
@@ -1014,6 +1014,8 @@
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.development" />
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/summary_empty" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.applications.ProcessStatsSummary" />
|
||||
</activity>
|
||||
|
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2006 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<!-- Details button -->
|
||||
<ImageView
|
||||
android:id="@+id/deviceDetails"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="8dip"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_settings"
|
||||
android:contentDescription="@string/bluetooth_device_details" />
|
||||
|
||||
</LinearLayout>
|
@@ -1,90 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<!-- Based off preference_material_settings.xml except that ripple on only on the left side. -->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:background="@android:color/transparent"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="60dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="10"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Preference should place its actual preference widget here. -->
|
||||
<LinearLayout
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="vertical"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"/>
|
||||
|
||||
</LinearLayout>
|
@@ -35,7 +35,6 @@
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:tint="?android:attr/textColorPrimary"
|
||||
android:maxWidth="18dp"
|
||||
android:maxHeight="18dp"/>
|
||||
</LinearLayout>
|
||||
@@ -47,7 +46,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="start|center"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Body2"/>
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Body2"
|
||||
android:textColor="?android:attr/colorAccent"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/scanning_progress"
|
||||
|
30
res/layout/preference_widget_gear.xml
Normal file
30
res/layout/preference_widget_gear.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<!-- Settings button -->
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/settings_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_settings"
|
||||
android:contentDescription="@string/settings_button" />
|
||||
|
@@ -15,28 +15,12 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="20dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/dividerVertical"/>
|
||||
</LinearLayout>
|
||||
|
||||
<Switch android:id="@+id/switchWidget"
|
||||
android:layout_width="wrap_content"
|
||||
<Switch
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/switchWidget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:clickable="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingEnd="?android:attr/scrollbarSize">
|
||||
|
||||
<!-- Settings button -->
|
||||
<ImageView
|
||||
android:id="@+id/settings_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="8dip"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_settings"
|
||||
android:contentDescription="@string/settings_button" />
|
||||
|
||||
</LinearLayout>
|
@@ -222,8 +222,6 @@
|
||||
<string name="bluetooth_devices">Bluetooth devices</string>
|
||||
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
|
||||
<string name="bluetooth_device_name">Device name</string>
|
||||
<!-- Bluetooth settings screen, image description for device details button. This opens the screen to rename, unpair, etc. a single device. -->
|
||||
<string name="bluetooth_device_details">Device settings</string>
|
||||
<!-- Bluetooth settings screen, image description for profile of a device details button. -->
|
||||
<string name="bluetooth_profile_details">Profile settings</string>
|
||||
<!-- Bluetooth settings screen, summary text when there isn't a name set (for the name setting) -->
|
||||
@@ -7598,7 +7596,7 @@
|
||||
<!-- Summary of condition that battery saver is on [CHAR LIMIT=NONE] -->
|
||||
<string name="condition_battery_summary">Performance is reduced. Location services and background data are turned off.</string>
|
||||
|
||||
<!-- Title of condition that cellular data is off [CHAR LIMIT=30] -->
|
||||
<!-- Title of condition that cellular data is off [CHAR LIMIT=50] -->
|
||||
<string name="condition_cellular_title">Mobile data is off</string>
|
||||
|
||||
<!-- Summary of condition that cellular data is off [CHAR LIMIT=NONE] -->
|
||||
|
@@ -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)) {
|
||||
|
@@ -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) {
|
||||
private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
|
||||
// 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);
|
||||
if (!(pref instanceof BluetoothDevicePreference)) {
|
||||
Log.w(TAG, "onClick() called for other View: " + pref);
|
||||
return;
|
||||
}
|
||||
|
||||
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||
Bundle args = new Bundle();
|
||||
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());
|
||||
DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
|
||||
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,7 +77,7 @@ 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,8 +17,10 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -32,7 +34,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -91,4 +96,44 @@ public class BluetoothDevicePreferenceTest {
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSecondTargetResource_shouldBeGearIconLayout() {
|
||||
assertThat(mPreference.getSecondTargetResId()).isEqualTo(R.layout.preference_widget_gear);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHideSecondTarget_noDevice_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mPreference, "mCachedDevice", null);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHideSecondTarget_notBond_shouldReturnTrue() {
|
||||
when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHideSecondTarget_hasUserRestriction_shouldReturnTrue() {
|
||||
final UserManager um = mock(UserManager.class);
|
||||
ReflectionHelpers.setField(mPreference, "mUserManager", um);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHideSecondTarget_hasBoundDeviceAndNoRestriction_shouldReturnFalse() {
|
||||
when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
final UserManager um = mock(UserManager.class);
|
||||
ReflectionHelpers.setField(mPreference, "mUserManager", um);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -17,13 +17,10 @@
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Switch;
|
||||
|
||||
@@ -35,14 +32,11 @@ import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -53,15 +47,15 @@ public class MasterSwitchPreferenceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewPreference_shouldSetLayout() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
|
||||
assertThat(preference.getWidgetLayoutResource()).isEqualTo(
|
||||
R.layout.preference_widget_master_switch);
|
||||
assertThat(preference.getWidgetLayoutResource())
|
||||
.isEqualTo(R.layout.preference_widget_master_switch);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +63,7 @@ public class MasterSwitchPreferenceTest {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
preference.setChecked(true);
|
||||
@@ -82,9 +76,9 @@ public class MasterSwitchPreferenceTest {
|
||||
@Test
|
||||
public void setSwitchEnabled_shouldUpdateButtonEnabledState() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
preference.setSwitchEnabled(true);
|
||||
@@ -99,10 +93,10 @@ public class MasterSwitchPreferenceTest {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
inflater.inflate(R.layout.preference_master_switch, null));
|
||||
inflater.inflate(R.layout.preference_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
|
||||
inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
|
||||
final Switch toggle = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
widgetView.performClick();
|
||||
@@ -116,8 +110,8 @@ public class MasterSwitchPreferenceTest {
|
||||
public void clickWidgetView_shouldNotifyPreferenceChanged() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_master_switch, null));
|
||||
final View widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_two_target, null));
|
||||
final View widgetView = holder.findViewById(android.R.id.widget_frame);
|
||||
final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
preference.onBindViewHolder(holder);
|
||||
@@ -134,9 +128,9 @@ public class MasterSwitchPreferenceTest {
|
||||
@Test
|
||||
public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
toggle.setEnabled(true);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
@@ -147,9 +141,9 @@ public class MasterSwitchPreferenceTest {
|
||||
@Test
|
||||
public void setDisabledByAdmin_noEnforcedAdmin_shouldEnableButton() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.itemView.findViewById(R.id.switchWidget);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
toggle.setEnabled(false);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
|
Reference in New Issue
Block a user