Merge "Remove the getSwitch() in SwitchWidgetController"
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index f95145d..87fa43d 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -23,7 +23,6 @@
import android.content.IntentFilter;
import android.os.UserManager;
import android.provider.Settings;
-import android.widget.Switch;
import android.widget.Toast;
import com.android.internal.annotations.VisibleForTesting;
@@ -41,8 +40,7 @@
* preference reflects the current state.
*/
public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchChangeListener {
- private final Switch mSwitch;
- private final SwitchWidgetController mSwitchWidget;
+ private final SwitchWidgetController mSwitchController;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private Context mContext;
private boolean mValidListener;
@@ -64,28 +62,27 @@
}
};
- public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent) {
- this(context, switchWidget, metricsFeatureProvider, manager, metricsEvent,
+ this(context, switchController, metricsFeatureProvider, manager, metricsEvent,
new RestrictionUtils());
}
- public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent, RestrictionUtils restrictionUtils) {
mContext = context;
mMetricsFeatureProvider = metricsFeatureProvider;
- mSwitchWidget = switchWidget;
- mSwitch = mSwitchWidget.getSwitch();
- mSwitchWidget.setListener(this);
+ mSwitchController = switchController;
+ mSwitchController.setListener(this);
mValidListener = false;
mMetricsEvent = metricsEvent;
if (manager == null) {
// Bluetooth is not supported
mLocalAdapter = null;
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
} else {
mLocalAdapter = manager.getBluetoothAdapter();
}
@@ -94,11 +91,11 @@
}
public void setupSwitchController() {
- mSwitchWidget.setupView();
+ mSwitchController.setupView();
}
public void teardownSwitchController() {
- mSwitchWidget.teardownView();
+ mSwitchController.teardownView();
}
public void resume(Context context) {
@@ -109,7 +106,7 @@
final boolean restricted = maybeEnforceRestrictions();
if (mLocalAdapter == null) {
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
return;
}
@@ -118,7 +115,7 @@
handleStateChanged(mLocalAdapter.getBluetoothState());
}
- mSwitchWidget.startListening();
+ mSwitchController.startListening();
mContext.registerReceiver(mReceiver, mIntentFilter);
mValidListener = true;
}
@@ -128,7 +125,7 @@
return;
}
if (mValidListener) {
- mSwitchWidget.stopListening();
+ mSwitchController.stopListening();
mContext.unregisterReceiver(mReceiver);
mValidListener = false;
}
@@ -137,37 +134,35 @@
void handleStateChanged(int state) {
switch (state) {
case BluetoothAdapter.STATE_TURNING_ON:
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
break;
case BluetoothAdapter.STATE_ON:
setChecked(true);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
break;
case BluetoothAdapter.STATE_OFF:
setChecked(false);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
break;
default:
setChecked(false);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
}
}
private void setChecked(boolean isChecked) {
- final boolean currentState =
- (mSwitchWidget.getSwitch() != null) && mSwitchWidget.getSwitch().isChecked();
- if (isChecked != currentState) {
+ if (isChecked != mSwitchController.isChecked()) {
// set listener to null, so onCheckedChanged won't be called
// if the checked status on Switch isn't changed by user click
if (mValidListener) {
- mSwitchWidget.stopListening();
+ mSwitchController.stopListening();
}
- mSwitchWidget.setChecked(isChecked);
+ mSwitchController.setChecked(isChecked);
if (mValidListener) {
- mSwitchWidget.startListening();
+ mSwitchController.startListening();
}
}
}
@@ -183,7 +178,7 @@
!WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
// Reset switch to off
- mSwitch.setChecked(false);
+ mSwitchController.setChecked(false);
return false;
}
@@ -195,13 +190,13 @@
// a) The switch should be OFF but it should still be togglable (enabled = True)
// b) The switch bar should have OFF text.
if (isChecked && !status) {
- mSwitch.setChecked(false);
- mSwitch.setEnabled(true);
- mSwitchWidget.updateTitle(false);
+ mSwitchController.setChecked(false);
+ mSwitchController.setEnabled(true);
+ mSwitchController.updateTitle(false);
return false;
}
}
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
return true;
}
@@ -213,13 +208,10 @@
@VisibleForTesting
boolean maybeEnforceRestrictions() {
EnforcedAdmin admin = getEnforcedAdmin(mRestrictionUtils, mContext);
- mSwitchWidget.setDisabledByAdmin(admin);
+ mSwitchController.setDisabledByAdmin(admin);
if (admin != null) {
- mSwitchWidget.setChecked(false);
- if (mSwitch != null) {
- mSwitch.setEnabled(false);
- mSwitch.setChecked(false);
- }
+ mSwitchController.setChecked(false);
+ mSwitchController.setEnabled(false);
}
return admin != null;
}
diff --git a/src/com/android/settings/widget/MasterSwitchController.java b/src/com/android/settings/widget/MasterSwitchController.java
index f7253fd..a22640c 100644
--- a/src/com/android/settings/widget/MasterSwitchController.java
+++ b/src/com/android/settings/widget/MasterSwitchController.java
@@ -74,9 +74,4 @@
public void setDisabledByAdmin(EnforcedAdmin admin) {
mPreference.setDisabledByAdmin(admin);
}
-
- @Override
- public Switch getSwitch() {
- return mPreference.getSwitch();
- }
}
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index 29bc17b..d47de88 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -90,7 +90,7 @@
}
public boolean isChecked() {
- return mSwitch != null && mSwitch.isEnabled() && mChecked;
+ return mSwitch != null && mChecked;
}
public void setChecked(boolean checked) {
diff --git a/src/com/android/settings/widget/SwitchBarController.java b/src/com/android/settings/widget/SwitchBarController.java
index 624db2a..cc4c8dc 100644
--- a/src/com/android/settings/widget/SwitchBarController.java
+++ b/src/com/android/settings/widget/SwitchBarController.java
@@ -82,10 +82,4 @@
public void setDisabledByAdmin(EnforcedAdmin admin) {
mSwitchBar.setDisabledByAdmin(admin);
}
-
- @Override
- public Switch getSwitch() {
- return mSwitchBar.getSwitch();
- }
-
}
diff --git a/src/com/android/settings/widget/SwitchWidgetController.java b/src/com/android/settings/widget/SwitchWidgetController.java
index 325a093..6c4f40a 100644
--- a/src/com/android/settings/widget/SwitchWidgetController.java
+++ b/src/com/android/settings/widget/SwitchWidgetController.java
@@ -16,7 +16,6 @@
package com.android.settings.widget;
-import android.widget.Switch;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/*
@@ -108,12 +107,4 @@
* is {@code null}, then this preference will be enabled. Otherwise, it will be disabled.
*/
public abstract void setDisabledByAdmin(EnforcedAdmin admin);
-
- /**
- * Get the underlying switch widget.
- *
- * @return the switch widget.
- */
- public abstract Switch getSwitch();
-
}
\ No newline at end of file