diff --git a/res/layout/restricted_preference_widget_primary_switch.xml b/res/layout/restricted_preference_widget_primary_switch.xml deleted file mode 100644 index 81d729169cc..00000000000 --- a/res/layout/restricted_preference_widget_primary_switch.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index 14879a8852f..61f527d98dc 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -44,7 +44,7 @@ android:title="@string/accessibility_text_and_display_title" settings:searchable="true"/> - - - - - - - + - - - - + settings:controller="com.android.settings.privacy.EnableContentCaptureWithServiceSettingsPreferenceController"/> - - - { - return event.getActionMasked() == MotionEvent.ACTION_MOVE; - }); - } - - mSwitch = (Switch) holder.findViewById(R.id.switchWidget); - if (mSwitch != null) { - mSwitch.setContentDescription(getTitle()); - mSwitch.setChecked(mChecked); - mSwitch.setEnabled(mEnableSwitch); - } - } - - public boolean isChecked() { - return mSwitch != null && mChecked; - } - - /** - * Used to validate the state of mChecked and mCheckedSet when testing, without requiring - * that a ViewHolder be bound to the object. - */ - @Keep - @Nullable - public Boolean getCheckedState() { - return mCheckedSet ? mChecked : null; - } - - /** - * Set the checked status to be {@code checked}. - * - * @param checked The new checked status - */ - public void setChecked(boolean checked) { - // Always set checked the first time; don't assume the field's default of false. - final boolean changed = mChecked != checked; - if (changed || !mCheckedSet) { - mChecked = checked; - mCheckedSet = true; - if (mSwitch != null) { - mSwitch.setChecked(checked); - } - } - } - - /** - * Set the Switch to be the status of {@code enabled}. - * - * @param enabled The new enabled status - */ - public void setSwitchEnabled(boolean enabled) { - mEnableSwitch = enabled; - if (mSwitch != null) { - mSwitch.setEnabled(enabled); - } - } - - /** - * If admin is not null, disables the switch. - * Otherwise, keep it enabled. - */ - public void setDisabledByAdmin(EnforcedAdmin admin) { - super.setDisabledByAdmin(admin); - setSwitchEnabled(admin == null); - } - - public Switch getSwitch() { - return mSwitch; - } - - @Override - protected boolean shouldHideSecondTarget() { - return getSecondTargetResId() == 0; - } -} diff --git a/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceController.java b/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceController.java index fdc12aa9dd0..ae44b932c0f 100644 --- a/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceController.java +++ b/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceController.java @@ -22,8 +22,8 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.widget.GenericSwitchController; -import com.android.settings.widget.PrimarySwitchPreference; import com.android.settings.widget.SummaryUpdater; +import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.lifecycle.LifecycleObserver; diff --git a/tests/legacy_unit/src/com/android/settings/notification/app/ChannelListPreferenceControllerTest.java b/tests/legacy_unit/src/com/android/settings/notification/app/ChannelListPreferenceControllerTest.java index b54782c684c..015addc671c 100644 --- a/tests/legacy_unit/src/com/android/settings/notification/app/ChannelListPreferenceControllerTest.java +++ b/tests/legacy_unit/src/com/android/settings/notification/app/ChannelListPreferenceControllerTest.java @@ -43,7 +43,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.settings.notification.NotificationBackend; import com.android.settings.notification.NotificationBackend.NotificationsSentState; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import org.junit.Before; import org.junit.Test; diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java index 7116b0142b4..fd1c8ff528b 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java @@ -48,7 +48,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.slices.BlockingSlicePrefController; import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin; diff --git a/tests/robotests/src/com/android/settings/development/WirelessDebuggingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/WirelessDebuggingPreferenceControllerTest.java index 54bd54b65bf..e8b03170df2 100644 --- a/tests/robotests/src/com/android/settings/development/WirelessDebuggingPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/WirelessDebuggingPreferenceControllerTest.java @@ -33,7 +33,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowWirelessDebuggingPreferenceController; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import org.junit.After; diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java index 384ddc3e6ac..a0f188dc873 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java @@ -45,7 +45,7 @@ import com.android.settings.core.BasePreferenceController; import com.android.settings.deletionhelper.ActivationWarningFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import org.junit.Before; import org.junit.Test; diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java index 48a047f2da8..04467a4ed60 100644 --- a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java @@ -38,7 +38,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import org.junit.Before; import org.junit.Test; diff --git a/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java index 7dcd6d483aa..c216671eca1 100644 --- a/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java @@ -40,7 +40,7 @@ import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import org.junit.Before; import org.junit.Test; diff --git a/tests/robotests/src/com/android/settings/widget/PrimarySwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/PrimarySwitchPreferenceTest.java deleted file mode 100644 index c58f5958d25..00000000000 --- a/tests/robotests/src/com/android/settings/widget/PrimarySwitchPreferenceTest.java +++ /dev/null @@ -1,173 +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 static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import android.content.Context; -import android.view.LayoutInflater; -import android.widget.LinearLayout; -import android.widget.Switch; - -import androidx.preference.Preference.OnPreferenceChangeListener; -import androidx.preference.PreferenceViewHolder; - -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.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -@RunWith(RobolectricTestRunner.class) -public class PrimarySwitchPreferenceTest { - - private Context mContext; - private PrimarySwitchPreference mPreference; - private PreferenceViewHolder mHolder; - private LinearLayout mWidgetView; - - @Before - public void setUp() { - mContext = RuntimeEnvironment.application; - mPreference = new PrimarySwitchPreference(mContext); - LayoutInflater inflater = LayoutInflater.from(mContext); - mHolder = PreferenceViewHolder.createInstanceForTests(inflater.inflate( - com.android.settingslib.R.layout.preference_two_target, null)); - mWidgetView = mHolder.itemView.findViewById(android.R.id.widget_frame); - inflater.inflate(R.layout.restricted_preference_widget_primary_switch, mWidgetView, true); - } - - @Test - public void createNewPreference_shouldSetLayout() { - assertThat(mPreference.getWidgetLayoutResource()) - .isEqualTo(R.layout.restricted_preference_widget_primary_switch); - } - - @Test - public void setChecked_shouldUpdateButtonCheckedState() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - mPreference.onBindViewHolder(mHolder); - - mPreference.setChecked(true); - assertThat(toggle.isChecked()).isTrue(); - - mPreference.setChecked(false); - assertThat(toggle.isChecked()).isFalse(); - } - - @Test - public void setSwitchEnabled_shouldUpdateButtonEnabledState() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - mPreference.onBindViewHolder(mHolder); - - mPreference.setSwitchEnabled(true); - assertThat(toggle.isEnabled()).isTrue(); - - mPreference.setSwitchEnabled(false); - assertThat(toggle.isEnabled()).isFalse(); - } - - @Test - public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - - mPreference.setSwitchEnabled(false); - mPreference.onBindViewHolder(mHolder); - assertThat(toggle.isEnabled()).isFalse(); - } - - @Test - public void clickWidgetView_shouldToggleButton() { - assertThat(mWidgetView).isNotNull(); - - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - mPreference.onBindViewHolder(mHolder); - - toggle.performClick(); - assertThat(toggle.isChecked()).isTrue(); - - toggle.performClick(); - assertThat(toggle.isChecked()).isFalse(); - } - - @Test - public void clickWidgetView_shouldNotToggleButtonIfDisabled() { - assertThat(mWidgetView).isNotNull(); - - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - mPreference.onBindViewHolder(mHolder); - toggle.setEnabled(false); - - mWidgetView.performClick(); - assertThat(toggle.isChecked()).isFalse(); - } - - @Test - public void clickWidgetView_shouldNotifyPreferenceChanged() { - - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - - final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class); - mPreference.setOnPreferenceChangeListener(listener); - mPreference.onBindViewHolder(mHolder); - - mPreference.setChecked(false); - toggle.performClick(); - verify(listener).onPreferenceChange(mPreference, true); - - mPreference.setChecked(true); - toggle.performClick(); - verify(listener).onPreferenceChange(mPreference, false); - } - - @Test - public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - toggle.setEnabled(true); - mPreference.onBindViewHolder(mHolder); - - mPreference.setDisabledByAdmin(mock(EnforcedAdmin.class)); - assertThat(toggle.isEnabled()).isFalse(); - } - - @Test - public void setDisabledByAdmin_noEnforcedAdmin_shouldEnableButton() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - toggle.setEnabled(false); - mPreference.onBindViewHolder(mHolder); - - mPreference.setDisabledByAdmin(null); - assertThat(toggle.isEnabled()).isTrue(); - } - - @Test - public void onBindViewHolder_toggleButtonShouldHaveContentDescription() { - final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); - final String label = "TestButton"; - mPreference.setTitle(label); - - mPreference.onBindViewHolder(mHolder); - - assertThat(toggle.getContentDescription()).isEqualTo(label); - } -} diff --git a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java index b94df29401e..7f76950c089 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java @@ -38,7 +38,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import org.junit.Before; diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java index 23bb0db3896..c3014cae328 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java @@ -31,7 +31,7 @@ import androidx.lifecycle.LifecycleOwner; import androidx.preference.PreferenceScreen; import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.widget.PrimarySwitchPreference; +import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import org.junit.Before;