Loading packages/SettingsLib/src/com/android/settingslib/PrimarySwitchPreference.java +4 −4 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.settingslib; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.Switch; import android.widget.CompoundButton; import androidx.annotation.Keep; import androidx.annotation.Nullable; Loading @@ -35,7 +35,7 @@ import com.android.settingslib.core.instrumentation.SettingsJankMonitor; */ public class PrimarySwitchPreference extends RestrictedPreference { private Switch mSwitch; private CompoundButton mSwitch; private boolean mChecked; private boolean mCheckedSet; private boolean mEnableSwitch = true; Loading Loading @@ -65,7 +65,7 @@ public class PrimarySwitchPreference extends RestrictedPreference { @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mSwitch = (Switch) holder.findViewById(R.id.switchWidget); mSwitch = (CompoundButton) holder.findViewById(R.id.switchWidget); if (mSwitch != null) { mSwitch.setOnClickListener(v -> { if (mSwitch != null && !mSwitch.isEnabled()) { Loading Loading @@ -153,7 +153,7 @@ public class PrimarySwitchPreference extends RestrictedPreference { setSwitchEnabled(admin == null); } public Switch getSwitch() { public CompoundButton getSwitch() { return mSwitch; } Loading packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java +2 −2 Original line number Diff line number Diff line Loading @@ -31,8 +31,8 @@ import android.view.ViewGroup; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.Switch; import android.widget.Toast; import androidx.preference.Preference; Loading Loading @@ -138,7 +138,7 @@ public class InputMethodPreference extends PrimarySwitchPreference @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); final Switch switchWidget = getSwitch(); final CompoundButton switchWidget = getSwitch(); if (switchWidget != null) { // Avoid default behavior in {@link PrimarySwitchPreference#onBindViewHolder}. switchWidget.setOnClickListener(v -> { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/PrimarySwitchPreferenceTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ import static org.mockito.Mockito.verify; import android.content.Context; import android.view.LayoutInflater; import android.widget.CompoundButton; import android.widget.LinearLayout; import android.widget.Switch; import androidx.preference.Preference.OnPreferenceChangeListener; import androidx.preference.PreferenceViewHolder; Loading Loading @@ -62,7 +62,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setChecked_shouldUpdateButtonCheckedState() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); mPreference.setChecked(true); Loading @@ -74,7 +74,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setSwitchEnabled_shouldUpdateButtonEnabledState() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); mPreference.setSwitchEnabled(true); Loading @@ -86,7 +86,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.setSwitchEnabled(false); mPreference.onBindViewHolder(mHolder); Loading @@ -97,7 +97,7 @@ public class PrimarySwitchPreferenceTest { public void clickWidgetView_shouldToggleButton() { assertThat(mWidgetView).isNotNull(); final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); toggle.performClick(); Loading @@ -111,7 +111,7 @@ public class PrimarySwitchPreferenceTest { public void clickWidgetView_shouldNotToggleButtonIfDisabled() { assertThat(mWidgetView).isNotNull(); final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); toggle.setEnabled(false); Loading @@ -122,7 +122,7 @@ public class PrimarySwitchPreferenceTest { @Test public void clickWidgetView_shouldNotifyPreferenceChanged() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class); mPreference.setOnPreferenceChangeListener(listener); Loading @@ -139,7 +139,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); toggle.setEnabled(true); mPreference.onBindViewHolder(mHolder); Loading @@ -149,7 +149,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setDisabledByAdmin_noEnforcedAdmin_shouldEnableButton() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); toggle.setEnabled(false); mPreference.onBindViewHolder(mHolder); Loading @@ -159,7 +159,7 @@ public class PrimarySwitchPreferenceTest { @Test public void onBindViewHolder_toggleButtonShouldHaveContentDescription() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); final String label = "TestButton"; mPreference.setTitle(label); Loading Loading
packages/SettingsLib/src/com/android/settingslib/PrimarySwitchPreference.java +4 −4 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.settingslib; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.Switch; import android.widget.CompoundButton; import androidx.annotation.Keep; import androidx.annotation.Nullable; Loading @@ -35,7 +35,7 @@ import com.android.settingslib.core.instrumentation.SettingsJankMonitor; */ public class PrimarySwitchPreference extends RestrictedPreference { private Switch mSwitch; private CompoundButton mSwitch; private boolean mChecked; private boolean mCheckedSet; private boolean mEnableSwitch = true; Loading Loading @@ -65,7 +65,7 @@ public class PrimarySwitchPreference extends RestrictedPreference { @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mSwitch = (Switch) holder.findViewById(R.id.switchWidget); mSwitch = (CompoundButton) holder.findViewById(R.id.switchWidget); if (mSwitch != null) { mSwitch.setOnClickListener(v -> { if (mSwitch != null && !mSwitch.isEnabled()) { Loading Loading @@ -153,7 +153,7 @@ public class PrimarySwitchPreference extends RestrictedPreference { setSwitchEnabled(admin == null); } public Switch getSwitch() { public CompoundButton getSwitch() { return mSwitch; } Loading
packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java +2 −2 Original line number Diff line number Diff line Loading @@ -31,8 +31,8 @@ import android.view.ViewGroup; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.Switch; import android.widget.Toast; import androidx.preference.Preference; Loading Loading @@ -138,7 +138,7 @@ public class InputMethodPreference extends PrimarySwitchPreference @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); final Switch switchWidget = getSwitch(); final CompoundButton switchWidget = getSwitch(); if (switchWidget != null) { // Avoid default behavior in {@link PrimarySwitchPreference#onBindViewHolder}. switchWidget.setOnClickListener(v -> { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/PrimarySwitchPreferenceTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ import static org.mockito.Mockito.verify; import android.content.Context; import android.view.LayoutInflater; import android.widget.CompoundButton; import android.widget.LinearLayout; import android.widget.Switch; import androidx.preference.Preference.OnPreferenceChangeListener; import androidx.preference.PreferenceViewHolder; Loading Loading @@ -62,7 +62,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setChecked_shouldUpdateButtonCheckedState() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); mPreference.setChecked(true); Loading @@ -74,7 +74,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setSwitchEnabled_shouldUpdateButtonEnabledState() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); mPreference.setSwitchEnabled(true); Loading @@ -86,7 +86,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.setSwitchEnabled(false); mPreference.onBindViewHolder(mHolder); Loading @@ -97,7 +97,7 @@ public class PrimarySwitchPreferenceTest { public void clickWidgetView_shouldToggleButton() { assertThat(mWidgetView).isNotNull(); final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); toggle.performClick(); Loading @@ -111,7 +111,7 @@ public class PrimarySwitchPreferenceTest { public void clickWidgetView_shouldNotToggleButtonIfDisabled() { assertThat(mWidgetView).isNotNull(); final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); mPreference.onBindViewHolder(mHolder); toggle.setEnabled(false); Loading @@ -122,7 +122,7 @@ public class PrimarySwitchPreferenceTest { @Test public void clickWidgetView_shouldNotifyPreferenceChanged() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class); mPreference.setOnPreferenceChangeListener(listener); Loading @@ -139,7 +139,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); toggle.setEnabled(true); mPreference.onBindViewHolder(mHolder); Loading @@ -149,7 +149,7 @@ public class PrimarySwitchPreferenceTest { @Test public void setDisabledByAdmin_noEnforcedAdmin_shouldEnableButton() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); toggle.setEnabled(false); mPreference.onBindViewHolder(mHolder); Loading @@ -159,7 +159,7 @@ public class PrimarySwitchPreferenceTest { @Test public void onBindViewHolder_toggleButtonShouldHaveContentDescription() { final Switch toggle = (Switch) mHolder.findViewById(R.id.switchWidget); final CompoundButton toggle = (CompoundButton) mHolder.findViewById(R.id.switchWidget); final String label = "TestButton"; mPreference.setTitle(label); Loading