Remove unused SwitchBar

Only used in tests, so also migrate the tests.

Bug: 306658346
Test: manual - on bluetooth
Test: m RunSettingsRoboTests
Change-Id: Id2b010c1d9c32abe21dcc8765e9446fc4f7a5b25
This commit is contained in:
Chaohui Wang
2023-10-25 10:37:20 +08:00
parent 03a064fcd1
commit e752f7214b
24 changed files with 59 additions and 855 deletions

View File

@@ -1,52 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2014, 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.
*/
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/switch_text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:maxLines="2"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.Switch"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textAlignment="viewStart"/>
<ImageView
android:id="@+id/restricted_icon"
android:layout_width="@dimen/restricted_icon_size"
android:layout_height="@dimen/restricted_icon_size"
android:tint="?android:attr/colorAccent"
android:theme="@android:style/Theme.Material"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/restricted_icon_margin_end"
android:visibility="gone" />
<com.android.settings.widget.ToggleSwitch
android:id="@+id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:theme="@style/Widget.SwitchBar.Switch"/>
</merge>

View File

@@ -16,8 +16,6 @@
<resources
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<color name="switchbar_switch_track_tint">#82000000</color>
<color name="switchbar_switch_thumb_tint">@android:color/black</color>
<color name="homepage_accessibility_background">#783BE5</color>
<color name="homepage_support_background">#3F5FBD</color>
<color name="contextual_card_background">@*android:color/material_grey_900</color>

View File

@@ -24,9 +24,6 @@
<dimen name="actionbar_contentInsetStart">24dp</dimen>
<dimen name="actionbar_subsettings_contentInsetStart">80dp</dimen>
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">80dp</dimen>
<dimen name="settings_panel_width">560dp</dimen>
<!-- Lock pattern view size, align sysui biometric_auth_pattern_view_size -->

View File

@@ -20,8 +20,4 @@
<dimen name="actionbar_contentInsetStart">128dp</dimen>
<dimen name="actionbar_subsettings_contentInsetStart">128dp</dimen>
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">128dp</dimen>
<dimen name="switchbar_subsettings_margin_end">128dp</dimen>
</resources>

View File

@@ -19,10 +19,6 @@
<dimen name="actionbar_contentInsetStart">80dp</dimen>
<dimen name="actionbar_subsettings_contentInsetStart">80dp</dimen>
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">80dp</dimen>
<dimen name="switchbar_subsettings_margin_end">80dp</dimen>
<!-- Lock pattern view size, align sysui biometric_auth_pattern_view_size -->
<dimen name="biometric_auth_pattern_view_size">348dp</dimen>
</resources>

View File

@@ -112,12 +112,8 @@
<attr name="appCount" format="integer" />
</declare-styleable>
<!-- TODO: Clean up this -->
<attr name="switchBarTheme" format="reference" />
<attr name="switchBarMarginStart" format="dimension" />
<attr name="switchBarMarginEnd" format="dimension" />
<attr name="switchBarBackgroundColor" format="color" />
<attr name="switchBarBackgroundActivatedColor" format="color" />
<attr name="switchBarRestrictionIcon" format="reference" />
<attr name="preferenceBackgroundColor" format="color" />

View File

@@ -72,10 +72,6 @@
<color name="contextual_card_background">@*android:color/background_device_default_light</color>
<!-- End of dashboard/homepage icon background colors -->
<color name="switchbar_background_color">@*android:color/material_grey_600</color>
<color name="switchbar_switch_track_tint">#BFFFFFFF</color>
<color name="switchbar_switch_thumb_tint">@android:color/white</color>
<color name="battery_good_color_light">#43a047</color> <!-- Material Green 600 -->
<color name="battery_bad_color_light">#f44336</color> <!-- Material Red 500 -->

View File

@@ -75,10 +75,6 @@
<!-- Preference icon foreground image inset (from background edge to foreground edge) -->
<dimen name="preference_icon_foreground_image_inset">12dp</dimen>
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">72dp</dimen>
<dimen name="switchbar_subsettings_margin_end">16dp</dimen>
<!-- Search bar -->
<dimen name="search_bar_margin">16dp</dimen>
<dimen name="search_bar_height">52dp</dimen>
@@ -239,11 +235,6 @@
<dimen name="accessibility_qs_tooltip_margin">20dp</dimen>
<dimen name="accessibility_qs_tooltip_margin_top">27dp</dimen>
<!-- Restricted icon in switch bar -->
<dimen name="restricted_icon_margin_end">16dp</dimen>
<!-- Restricted icon size in switch bar -->
<dimen name="restricted_icon_size">@*android:dimen/config_restrictedIconSize</dimen>
<!-- Padding for Gestures settings screen -->
<dimen name="gestures_play_button_size">36dp</dimen>

View File

@@ -215,10 +215,6 @@
<style name="TextAppearance.Medium" parent="@android:style/TextAppearance.DeviceDefault.Medium"/>
<style name="TextAppearance.Small" parent="@android:style/TextAppearance.DeviceDefault.Small"/>
<style name="TextAppearance.Switch"
parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title">
<item name="android:textSize">16sp</item>
</style>
<style name="TextAppearance.CategoryTitle"
parent="@*android:style/TextAppearance.DeviceDefault.Body2">
@@ -242,11 +238,6 @@
<item name="android:textColor">?android:attr/colorError</item>
</style>
<style name="TextAppearance.Small.SwitchBar">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textStyle">normal</item>
</style>
<style name="TextAppearance.RemoveDialogContent"
parent="@android:style/TextAppearance.DeviceDefault">
<item name="android:textSize">16sp</item>

View File

@@ -52,8 +52,6 @@
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
<item name="preferenceBackgroundColor">@drawable/preference_background</item>
<!-- For AndroidX AlertDialog -->
@@ -88,7 +86,6 @@
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Widget.ActionBar.SubSettings</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
@@ -109,23 +106,9 @@
<item name="android:textColorHint">?android:attr/textColorSecondary</item>
</style>
<style name="ThemeOverlay.SwitchBar.Settings.Base" parent="@*android:style/ThemeOverlay.DeviceDefault.ActionBar">
<item name="android:elevation">1dp</item>
<item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item>
<item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item>
<item name="switchBarBackgroundColor">@color/switchbar_background_color</item>
<item name="switchBarBackgroundActivatedColor">?android:attr/colorAccent</item>
<item name="switchBarRestrictionIcon">@*android:drawable/ic_info</item>
</style>
<style name="ThemeOverlay.SwitchBar.Settings" parent="ThemeOverlay.SwitchBar.Settings.Base"/>
<style name="Widget.SwitchBar.Switch" parent="@android:style/Widget.Material.CompoundButton.Switch">
<item name="android:trackTint">@color/switchbar_switch_track_tint</item>
<item name="android:thumbTint">@color/switchbar_switch_thumb_tint</item>
<item name="android:minHeight">@dimen/min_tap_target_size</item>
<item name="android:minWidth">@dimen/min_tap_target_size</item>
</style>
<!-- TODO: Clean up this -->
<style name="ThemeOverlay.SwitchBar.Settings"
parent="@*android:style/ThemeOverlay.DeviceDefault.ActionBar" />
<style name="ThemeOverlay.AlertDialog" parent="@android:style/ThemeOverlay.Material.Dialog.Alert">
<item name="android:windowSoftInputMode">adjustResize</item>

View File

@@ -647,7 +647,8 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
}
void updateInterface() {
findViewById(R.id.restricted_icon).setVisibility(View.GONE);
findViewById(com.android.settingslib.widget.restricted.R.id.restricted_icon)
.setVisibility(View.GONE);
mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
try {
@@ -682,7 +683,8 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
final boolean hasBaseRestriction = hasBaseCantRemoveProfileRestriction();
if ((hasBaseRestriction && mDPM.isOrganizationOwnedDeviceWithManagedProfile())
|| (admin != null && !hasBaseRestriction)) {
findViewById(R.id.restricted_icon).setVisibility(View.VISIBLE);
findViewById(com.android.settingslib.widget.restricted.R.id.restricted_icon)
.setVisibility(View.VISIBLE);
}
mActionButton.setEnabled(admin == null && !hasBaseRestriction);
} else if (isProfileOwner || mDeviceAdmin.getComponent().equals(

View File

@@ -62,12 +62,6 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
}
};
public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, int metricsEvent) {
this(context, switchController, metricsFeatureProvider, metricsEvent,
new RestrictionUtils());
}
public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, int metricsEvent,
RestrictionUtils restrictionUtils) {

View File

@@ -43,16 +43,13 @@ public class GraphicsDriverGlobalSwitchBarController
GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener,
LifecycleObserver, OnStart, OnStop {
private final Context mContext;
private final ContentResolver mContentResolver;
@VisibleForTesting
SwitchWidgetController mSwitchWidgetController;
private final SwitchWidgetController mSwitchWidgetController;
@VisibleForTesting
GraphicsDriverContentObserver mGraphicsDriverContentObserver;
GraphicsDriverGlobalSwitchBarController(
Context context, SwitchWidgetController switchWidgetController) {
mContext = context;
mContentResolver = context.getContentResolver();
mGraphicsDriverContentObserver =
new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this);

View File

@@ -1,387 +0,0 @@
/*
* Copyright (C) 2014 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.
*/
package com.android.settings.widget;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.ArrayList;
import java.util.List;
public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener {
public interface OnSwitchChangeListener {
/**
* Called when the checked state of the Switch has changed.
*
* @param switchView The Switch view whose state has changed.
* @param isChecked The new checked state of switchView.
*/
void onSwitchChanged(Switch switchView, boolean isChecked);
}
private static final int[] XML_ATTRIBUTES = {
R.attr.switchBarMarginStart,
R.attr.switchBarMarginEnd,
R.attr.switchBarBackgroundColor,
R.attr.switchBarBackgroundActivatedColor,
R.attr.switchBarRestrictionIcon};
private final List<OnSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final TextAppearanceSpan mSummarySpan;
private ToggleSwitch mSwitch;
private ImageView mRestrictedIcon;
private TextView mTextView;
private String mLabel;
private String mSummary;
private String mOnText;
private String mOffText;
@ColorInt
private int mBackgroundColor;
@ColorInt
private int mBackgroundActivatedColor;
private boolean mLoggingIntialized;
private boolean mDisabledByAdmin;
private EnforcedAdmin mEnforcedAdmin = null;
private String mMetricsTag;
public SwitchBar(Context context) {
this(context, null);
}
public SwitchBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
LayoutInflater.from(context).inflate(R.layout.switch_bar, this);
// Set the whole SwitchBar focusable and clickable.
setFocusable(true);
setClickable(true);
final TypedArray a = context.obtainStyledAttributes(attrs, XML_ATTRIBUTES);
final int switchBarMarginStart = (int) a.getDimension(0, 0);
final int switchBarMarginEnd = (int) a.getDimension(1, 0);
mBackgroundColor = a.getColor(2, 0);
mBackgroundActivatedColor = a.getColor(3, 0);
final Drawable restrictedIconDrawable = a.getDrawable(4);
a.recycle();
mTextView = findViewById(R.id.switch_text);
mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams();
lp.setMarginStart(switchBarMarginStart);
mSwitch = findViewById(R.id.switch_widget);
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
// on our own
mSwitch.setSaveEnabled(false);
// Set the ToggleSwitch non-focusable and non-clickable to avoid multiple focus.
mSwitch.setFocusable(false);
mSwitch.setClickable(false);
lp = (MarginLayoutParams) mSwitch.getLayoutParams();
lp.setMarginEnd(switchBarMarginEnd);
setBackgroundColor(mBackgroundColor);
setSwitchBarText(R.string.switch_on_text, R.string.switch_off_text);
addOnSwitchChangeListener(
(switchView, isChecked) -> setTextViewLabelAndBackground(isChecked));
mRestrictedIcon = findViewById(R.id.restricted_icon);
mRestrictedIcon.setImageDrawable(restrictedIconDrawable);
mRestrictedIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDisabledByAdmin) {
mMetricsFeatureProvider.action(
SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE,
SettingsEnums.PAGE_UNKNOWN,
mMetricsTag + "/switch_bar|restricted",
1);
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(context,
mEnforcedAdmin);
}
}
});
// Default is hide
setVisibility(View.GONE);
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
}
// Override the performClick method to eliminate redundant click.
@Override
public boolean performClick() {
return getDelegatingView().performClick();
}
public void setMetricsTag(String tag) {
mMetricsTag = tag;
}
public void setTextViewLabelAndBackground(boolean isChecked) {
mLabel = isChecked ? mOnText : mOffText;
setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
updateText();
}
public void setSwitchBarText(int onTextId, int offTextId) {
mOnText = getResources().getString(onTextId);
mOffText = getResources().getString(offTextId);
setTextViewLabelAndBackground(isChecked());
}
public void setSwitchBarText(String onText, String offText) {
mOnText = onText;
mOffText = offText;
setTextViewLabelAndBackground(isChecked());
}
public void setSummary(String summary) {
mSummary = summary;
updateText();
}
private void updateText() {
if (TextUtils.isEmpty(mSummary)) {
mTextView.setText(mLabel);
return;
}
final SpannableStringBuilder ssb = new SpannableStringBuilder(mLabel).append('\n');
final int start = ssb.length();
ssb.append(mSummary);
ssb.setSpan(mSummarySpan, start, ssb.length(), 0);
mTextView.setText(ssb);
}
public void setChecked(boolean checked) {
setTextViewLabelAndBackground(checked);
mSwitch.setChecked(checked);
}
public void setCheckedInternal(boolean checked) {
setTextViewLabelAndBackground(checked);
mSwitch.setCheckedInternal(checked);
}
public boolean isChecked() {
return mSwitch.isChecked();
}
public void setEnabled(boolean enabled) {
if (enabled && mDisabledByAdmin) {
setDisabledByAdmin(null);
return;
}
super.setEnabled(enabled);
mTextView.setEnabled(enabled);
mSwitch.setEnabled(enabled);
}
@VisibleForTesting
View getDelegatingView() {
return mDisabledByAdmin ? mRestrictedIcon : mSwitch;
}
/**
* If admin is not null, disables the text and switch but keeps the view clickable.
* Otherwise, calls setEnabled which will enables the entire view including
* the text and switch.
*/
public void setDisabledByAdmin(EnforcedAdmin admin) {
mEnforcedAdmin = admin;
if (admin != null) {
super.setEnabled(true);
mDisabledByAdmin = true;
mTextView.setEnabled(false);
mSwitch.setEnabled(false);
mSwitch.setVisibility(View.GONE);
mRestrictedIcon.setVisibility(View.VISIBLE);
} else {
mDisabledByAdmin = false;
mSwitch.setVisibility(View.VISIBLE);
mRestrictedIcon.setVisibility(View.GONE);
setEnabled(true);
}
}
public final ToggleSwitch getSwitch() {
return mSwitch;
}
public void show() {
if (!isShowing()) {
setVisibility(View.VISIBLE);
mSwitch.setOnCheckedChangeListener(this);
}
}
public void hide() {
if (isShowing()) {
setVisibility(View.GONE);
mSwitch.setOnCheckedChangeListener(null);
}
}
public boolean isShowing() {
return (getVisibility() == View.VISIBLE);
}
public void propagateChecked(boolean isChecked) {
final int count = mSwitchChangeListeners.size();
for (int n = 0; n < count; n++) {
mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked);
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (mLoggingIntialized) {
mMetricsFeatureProvider.action(
SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE,
SettingsEnums.PAGE_UNKNOWN,
mMetricsTag + "/switch_bar",
isChecked ? 1 : 0);
}
mLoggingIntialized = true;
propagateChecked(isChecked);
}
public void addOnSwitchChangeListener(OnSwitchChangeListener listener) {
if (mSwitchChangeListeners.contains(listener)) {
throw new IllegalStateException("Cannot add twice the same OnSwitchChangeListener");
}
mSwitchChangeListeners.add(listener);
}
public void removeOnSwitchChangeListener(OnSwitchChangeListener listener) {
if (!mSwitchChangeListeners.contains(listener)) {
throw new IllegalStateException("Cannot remove OnSwitchChangeListener");
}
mSwitchChangeListeners.remove(listener);
}
static class SavedState extends BaseSavedState {
boolean checked;
boolean visible;
SavedState(Parcelable superState) {
super(superState);
}
/**
* Constructor called from {@link #CREATOR}
*/
private SavedState(Parcel in) {
super(in);
checked = (Boolean) in.readValue(null);
visible = (Boolean) in.readValue(null);
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeValue(checked);
out.writeValue(visible);
}
@Override
public String toString() {
return "SwitchBar.SavedState{"
+ Integer.toHexString(System.identityHashCode(this))
+ " checked=" + checked
+ " visible=" + visible + "}";
}
public static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}
@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss.checked = mSwitch.isChecked();
ss.visible = isShowing();
return ss;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
mSwitch.setCheckedInternal(ss.checked);
setTextViewLabelAndBackground(ss.checked);
setVisibility(ss.visible ? View.VISIBLE : View.GONE);
mSwitch.setOnCheckedChangeListener(ss.visible ? this : null);
requestLayout();
}
}

View File

@@ -1,85 +0,0 @@
/*
* 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.
*/
package com.android.settings.widget;
import android.widget.Switch;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/*
* The switch controller that is used to update the switch widget in the SwitchBar layout.
*/
public class SwitchBarController extends SwitchWidgetController implements
SwitchBar.OnSwitchChangeListener {
private final SwitchBar mSwitchBar;
public SwitchBarController(SwitchBar switchBar) {
mSwitchBar = switchBar;
}
@Override
public void setupView() {
mSwitchBar.show();
}
@Override
public void teardownView() {
mSwitchBar.hide();
}
@Override
public void setTitle(String title) {
}
@Override
public void startListening() {
mSwitchBar.addOnSwitchChangeListener(this);
}
@Override
public void stopListening() {
mSwitchBar.removeOnSwitchChangeListener(this);
}
@Override
public void setChecked(boolean checked) {
mSwitchBar.setChecked(checked);
}
@Override
public boolean isChecked() {
return mSwitchBar.isChecked();
}
@Override
public void setEnabled(boolean enabled) {
mSwitchBar.setEnabled(enabled);
}
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
if (mListener != null) {
mListener.onSwitchToggled(isChecked);
}
}
@Override
public void setDisabledByAdmin(EnforcedAdmin admin) {
mSwitchBar.setDisabledByAdmin(admin);
}
}

View File

@@ -1,63 +0,0 @@
/*
* Copyright (C) 2013 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.
*/
package com.android.settings.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Switch;
public class ToggleSwitch extends Switch {
private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener;
public interface OnBeforeCheckedChangeListener {
boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked);
}
public ToggleSwitch(Context context) {
super(context);
}
public ToggleSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ToggleSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ToggleSwitch(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setOnBeforeCheckedChangeListener(OnBeforeCheckedChangeListener listener) {
mOnBeforeListener = listener;
}
@Override
public void setChecked(boolean checked) {
if (mOnBeforeListener != null
&& mOnBeforeListener.onBeforeCheckedChanged(this, checked)) {
return;
}
super.setChecked(checked);
}
public void setCheckedInternal(boolean checked) {
super.setChecked(checked);
}
}

View File

@@ -20,8 +20,4 @@
<bool name="config_show_camera_laser_sensor">true</bool>
<bool name="config_show_connectivity_monitor">true</bool>
<bool name="config_show_smooth_display">true</bool>
<!-- Fake dimen value for restricted icon size - needed to get around Robolectric
issue loading framework hidden resources -->
<dimen name="restricted_icon_size">24dp</dimen>
</resources>

View File

@@ -19,13 +19,4 @@
<item name="colorPrimaryVariant">@android:color/white</item>
</style>
<style name="ThemeOverlay.SwitchBar.Settings" parent="@android:style/ThemeOverlay.Material.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item>
<item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item>
<item name="switchBarBackgroundColor">?android:attr/textColorSecondary</item>
<item name="switchBarBackgroundActivatedColor">?android:attr/colorAccent</item>
<item name="switchBarRestrictionIcon">@drawable/ic_help</item>
</style>
</resources>

View File

@@ -39,8 +39,6 @@ import android.view.View;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -80,6 +78,7 @@ public class BluetoothEnablerTest {
private SwitchWidgetController.OnSwitchChangeListener mCallback;
private Context mContext;
@Mock
private SwitchWidgetController mSwitchController;
private BluetoothEnabler mBluetoothEnabler;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
@@ -90,7 +89,6 @@ public class BluetoothEnablerTest {
mContext = spy(RuntimeEnvironment.application);
mRestrictedSwitchPreference = new RestrictedSwitchPreference(mContext);
mSwitchController = spy(new SwitchBarController(new SwitchBar(mContext)));
mBluetoothEnabler = new BluetoothEnabler(
mContext,
mSwitchController,
@@ -215,7 +213,7 @@ public class BluetoothEnablerTest {
verify(mSwitchController, never()).setChecked(anyBoolean());
mBluetoothEnabler.resume(mContext);
verify(mSwitchController, never()).setChecked(false);
verify(mSwitchController).setChecked(true);
when(mSwitchController.isChecked()).thenReturn(true);
// Now simulate bluetooth being turned off via an event.
BroadcastReceiver receiver = captor.getValue();

View File

@@ -29,8 +29,7 @@ import androidx.lifecycle.LifecycleOwner;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settings.testutils.shadow.ShadowWirelessDebuggingPreferenceController;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.After;
@@ -49,23 +48,22 @@ import org.robolectric.util.ReflectionHelpers;
public class WirelessDebuggingEnablerTest {
@Mock
private SwitchBar mSwitchBar;
private SwitchWidgetController mSwitchWidgetController;
@Mock
private WirelessDebuggingEnabler.OnEnabledListener mListener;
private WirelessDebuggingEnabler mWirelessDebuggingEnabler;
private Context mContext;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mLifecycleOwner = () -> mLifecycle;
LifecycleOwner mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mWirelessDebuggingEnabler = spy(new WirelessDebuggingEnabler(
mContext, new SwitchBarController(mSwitchBar), mListener, mLifecycle));
mContext, mSwitchWidgetController, mListener, mLifecycle));
}
@After
@@ -75,14 +73,14 @@ public class WirelessDebuggingEnablerTest {
@Test
public void onCreation_shouldShowSwitchBar() {
verify(mSwitchBar).show();
verify(mSwitchWidgetController).setupView();
}
@Test
public void teardownSwitchController_shouldHideSwitchBar() {
mWirelessDebuggingEnabler.teardownSwitchController();
verify(mSwitchBar).hide();
verify(mSwitchWidgetController).teardownView();
}
@Test
@@ -92,7 +90,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(false);
verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
Global.putInt(mContext.getContentResolver(),
@@ -101,7 +99,7 @@ public class WirelessDebuggingEnablerTest {
ReflectionHelpers.getField(mWirelessDebuggingEnabler, "mSettingsObserver");
observer.onChange(true, Global.getUriFor(Global.ADB_WIFI_ENABLED));
verify(mSwitchBar).setChecked(true);
verify(mSwitchWidgetController).setChecked(true);
// Should also get a callback
verify(mListener).onEnabled(true);
}
@@ -112,7 +110,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(true);
verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
Global.putInt(mContext.getContentResolver(),
@@ -121,7 +119,7 @@ public class WirelessDebuggingEnablerTest {
ReflectionHelpers.getField(mWirelessDebuggingEnabler, "mSettingsObserver");
observer.onChange(true, Global.getUriFor(Global.ADB_WIFI_ENABLED));
verify(mSwitchBar).setChecked(false);
verify(mSwitchWidgetController).setChecked(false);
// Should also get a callback
verify(mListener).onEnabled(false);
}
@@ -133,7 +131,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(false);
verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
mWirelessDebuggingEnabler.onSwitchToggled(true);
@@ -149,7 +147,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(false);
verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
mWirelessDebuggingEnabler.onSwitchToggled(true);
@@ -165,7 +163,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(true);
verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
mWirelessDebuggingEnabler.onSwitchToggled(false);
@@ -181,7 +179,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
verify(mSwitchBar).setChecked(true);
verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
mWirelessDebuggingEnabler.onSwitchToggled(false);

View File

@@ -27,8 +27,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before;
@@ -42,8 +40,6 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class GraphicsDriverGlobalSwitchBarControllerTest {
@Mock
private SwitchBar mSwitchBar;
@Mock
private SwitchWidgetController mSwitchWidgetController;
@Mock
@@ -65,9 +61,9 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
verify(mSwitchBar).setChecked(true);
verify(mSwitchWidgetController).setChecked(true);
}
@Test
@@ -75,34 +71,33 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
verify(mSwitchBar).setChecked(false);
verify(mSwitchWidgetController).setChecked(false);
}
@Test
public void constructor_developmentSettingsEnabled_shouldEnableSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
verify(mSwitchBar).setEnabled(true);
verify(mSwitchWidgetController).setEnabled(true);
}
@Test
public void constructor_developmentSettingsDisabled_shouldDisableSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
verify(mSwitchBar).setEnabled(false);
verify(mSwitchWidgetController).setEnabled(false);
}
@Test
public void onStart_shouldStartListeningAndRegister() {
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mController.mSwitchWidgetController = mSwitchWidgetController;
mContext, mSwitchWidgetController);
mController.mGraphicsDriverContentObserver = mGraphicsDriverContentObserver;
mController.onStart();
@@ -113,8 +108,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
@Test
public void onStop_shouldStopListeningAndUnregister() {
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mController.mSwitchWidgetController = mSwitchWidgetController;
mContext, mSwitchWidgetController);
mController.mGraphicsDriverContentObserver = mGraphicsDriverContentObserver;
mController.onStop();
@@ -127,7 +121,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
mController.onSwitchToggled(true);
assertThat(Settings.Global.getInt(
@@ -141,7 +135,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mContext, mSwitchWidgetController);
mController.onSwitchToggled(false);
assertThat(Settings.Global.getInt(

View File

@@ -33,6 +33,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -51,8 +52,6 @@ import android.net.wifi.WifiManager;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.network.TetherEnabler.OnTetherStateUpdateListener;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before;
@@ -82,8 +81,8 @@ public class TetherEnablerTest {
@Mock
private BluetoothAdapter mBluetoothAdapter;
private SwitchBar mSwitchBar;
private TetherEnabler mEnabler;
@Mock
private SwitchWidgetController mSwitchWidgetController;
private static final String[] USB_TETHERED = {"usb"};
@@ -93,8 +92,6 @@ public class TetherEnablerTest {
Context context = spy(ApplicationProvider.getApplicationContext());
AtomicReference<BluetoothPan> panReference = spy(AtomicReference.class);
mSwitchBar = spy(new SwitchBar(context));
mSwitchWidgetController = spy(new SwitchBarController(mSwitchBar));
when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mConnectivityManager);
@@ -115,7 +112,8 @@ public class TetherEnablerTest {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
mEnabler.onStart();
assertThat(mSwitchBar.isChecked()).isTrue();
verify(mSwitchWidgetController).setChecked(true);
}
@Test
@@ -150,26 +148,29 @@ public class TetherEnablerTest {
mEnabler.onStart();
mEnabler.startTethering(TetheringManager.TETHERING_WIFI);
clearInvocations(mSwitchWidgetController);
when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
mEnabler.mOnStartTetheringCallback.onTetheringFailed();
assertThat(mSwitchBar.isChecked()).isFalse();
assertThat(mSwitchBar.isEnabled()).isTrue();
verify(mSwitchWidgetController).setEnabled(true);
verify(mSwitchWidgetController).setChecked(false);
}
@Test
public void onDataSaverChanged_setsEnabledCorrectly() {
mSwitchBar.setEnabled(true);
mSwitchWidgetController.setEnabled(true);
// try to turn data saver on
clearInvocations(mSwitchWidgetController);
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(true);
mEnabler.onDataSaverChanged(true);
assertThat(mSwitchBar.isEnabled()).isFalse();
verify(mSwitchWidgetController).setEnabled(false);
// lets turn data saver off again
clearInvocations(mSwitchWidgetController);
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
mEnabler.onDataSaverChanged(false);
assertThat(mSwitchBar.isEnabled()).isTrue();
verify(mSwitchWidgetController).setEnabled(true);
}
@Test
@@ -250,7 +251,7 @@ public class TetherEnablerTest {
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
mEnabler.updateState(null/*tethered*/);
verify(mSwitchBar).setEnabled(true);
verify(mSwitchWidgetController).setEnabled(true);
}
@Test
@@ -263,7 +264,7 @@ public class TetherEnablerTest {
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
mEnabler.updateState(null/*tethered*/);
verify(mSwitchBar).setEnabled(true);
verify(mSwitchWidgetController).setEnabled(true);
}
@Test

View File

@@ -17,8 +17,8 @@
package com.android.settings.users;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
@@ -26,8 +26,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.After;
import org.junit.Before;
@@ -43,14 +42,14 @@ public class MultiUserSwitchBarControllerTest {
private Context mContext;
private ShadowUserManager mUserManager;
private SwitchBarController mSwitchBarController;
private SwitchWidgetController mSwitchWidgetController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mUserManager = ShadowUserManager.getShadow();
mSwitchBarController = spy(new SwitchBarController(new SwitchBar(mContext)));
mSwitchWidgetController = mock(SwitchWidgetController.class);
mUserManager.setSupportsMultipleUsers(true);
}
@@ -65,9 +64,9 @@ public class MultiUserSwitchBarControllerTest {
UserManager.DISALLOW_USER_SWITCH, true);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
mSwitchBarController, null);
mSwitchWidgetController, null);
verify(mSwitchBarController).setDisabledByAdmin(any());
verify(mSwitchWidgetController).setDisabledByAdmin(any());
}
@Test
@@ -76,8 +75,8 @@ public class MultiUserSwitchBarControllerTest {
UserManager.DISALLOW_USER_SWITCH, false);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
mSwitchBarController, null);
mSwitchWidgetController, null);
verify(mSwitchBarController, never()).setDisabledByAdmin(any());
verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
}
}

View File

@@ -1,123 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.RuntimeEnvironment.application;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class SwitchBarTest {
private static final int COLOR_BACKGROUND = 1;
private static final int COLOR_BACKGROUND_ACTIVATED = 2;
private Context mContext;
private SwitchBar mBar;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mBar = new SwitchBar(application, Robolectric.buildAttributeSet()
.addAttribute(R.attr.switchBarBackgroundColor, String.valueOf(COLOR_BACKGROUND))
.addAttribute(R.attr.switchBarBackgroundActivatedColor,
String.valueOf(COLOR_BACKGROUND_ACTIVATED))
.build());
}
@Test
public void cycleChecked_defaultLabel_shouldUpdateTextAndBackground() {
final int defaultOnText = R.string.switch_on_text;
final int defaultOffText = R.string.switch_off_text;
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(defaultOffText));
mBar.setChecked(true);
assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(defaultOnText));
}
@Test
public void cycleChecked_customLabel_shouldUpdateTextAndBackground() {
final int onText = R.string.main_clear_progress_text;
final int offText = R.string.clear_user_data_text;
mBar.setSwitchBarText(onText, offText);
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(offText));
mBar.setChecked(true);
assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(onText));
}
@Test
public void setCheck_customLabelWithStringType_shouldUpdateTextAndBackground() {
final String onText = mContext.getString(
R.string.accessibility_service_primary_switch_title);
final String offText = mContext.getString(
R.string.accessibility_service_primary_switch_title);
final TextView switchBarTextView = ((TextView) mBar.findViewById(R.id.switch_text));
mBar.setSwitchBarText(onText, offText);
assertThat(switchBarTextView.getText()).isEqualTo(offText);
mBar.setChecked(true);
assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
assertThat(switchBarTextView.getText()).isEqualTo(onText);
}
@Test
public void disabledByAdmin_shouldDelegateToRestrictedIcon() {
mBar.setDisabledByAdmin(new EnforcedAdmin());
assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.restricted_icon);
}
@Test
public void notDisabledByAdmin_shouldDelegateToSwitch() {
mBar.setDisabledByAdmin(null);
assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.switch_widget);
}
@Test
public void performClick_shouldIsCheckedValueChange() {
boolean isChecked = mBar.isChecked();
mBar.performClick();
assertThat(mBar.isChecked()).isEqualTo(!isChecked);
}
}