Loading src/com/android/settings/widget/SeekBarPreference.java +12 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,13 @@ public class SeekBarPreference extends RestrictedPreference com.android.internal.R.layout.preference_widget_seekbar); a.recycle(); a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes); final boolean isSelectable = a.getBoolean( com.android.settings.R.styleable.Preference_android_selectable, false); setSelectable(isSelectable); a.recycle(); setLayoutResource(layoutResId); } Loading @@ -93,7 +100,11 @@ public class SeekBarPreference extends RestrictedPreference @Override public boolean isSelectable() { return isDisabledByAdmin(); if(isDisabledByAdmin()) { return true; } else { return super.isSelectable(); } } @Override Loading tests/robotests/res/xml-mcc998/seekbar_preference.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.SeekBarPreference android:key="seek_bar" android:title="seek_bar_title"/> </PreferenceScreen > tests/robotests/res/xml-mcc999/seekbar_preference.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.SeekBarPreference android:key="seek_bar" android:selectable="true" android:title="seek_bar_title"/> </PreferenceScreen > tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java +41 −3 Original line number Diff line number Diff line Loading @@ -22,16 +22,24 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import androidx.preference.PreferenceFragmentCompat; import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.androidx.fragment.FragmentController; @RunWith(RobolectricTestRunner.class) @Config(shadows = ShadowRestrictedLockUtilsInternal.class) public class SeekBarPreferenceTest { private static final int MAX = 75; Loading Loading @@ -73,9 +81,39 @@ public class SeekBarPreferenceTest { } @Test public void isSelectable_notDisabledByAdmin_returnFalse() { when(mSeekBarPreference.isDisabledByAdmin()).thenReturn(false); @Config(qualifiers = "mcc998") public void isSelectable_default_returnFalse() { final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(), new Bundle()) .create() .start() .resume() .get(); final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar"); assertThat(seekBarPreference.isSelectable()).isFalse(); } assertThat(mSeekBarPreference.isSelectable()).isFalse(); @Test @Config(qualifiers = "mcc999") public void isSelectable_selectableInXml_returnTrue() { final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(), new Bundle()) .create() .start() .resume() .get(); final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar"); assertThat(seekBarPreference.isSelectable()).isTrue(); } public static class TestFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(com.android.settings.R.xml.seekbar_preference); } } } Loading
src/com/android/settings/widget/SeekBarPreference.java +12 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,13 @@ public class SeekBarPreference extends RestrictedPreference com.android.internal.R.layout.preference_widget_seekbar); a.recycle(); a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes); final boolean isSelectable = a.getBoolean( com.android.settings.R.styleable.Preference_android_selectable, false); setSelectable(isSelectable); a.recycle(); setLayoutResource(layoutResId); } Loading @@ -93,7 +100,11 @@ public class SeekBarPreference extends RestrictedPreference @Override public boolean isSelectable() { return isDisabledByAdmin(); if(isDisabledByAdmin()) { return true; } else { return super.isSelectable(); } } @Override Loading
tests/robotests/res/xml-mcc998/seekbar_preference.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.SeekBarPreference android:key="seek_bar" android:title="seek_bar_title"/> </PreferenceScreen >
tests/robotests/res/xml-mcc999/seekbar_preference.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.SeekBarPreference android:key="seek_bar" android:selectable="true" android:title="seek_bar_title"/> </PreferenceScreen >
tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java +41 −3 Original line number Diff line number Diff line Loading @@ -22,16 +22,24 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import androidx.preference.PreferenceFragmentCompat; import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.androidx.fragment.FragmentController; @RunWith(RobolectricTestRunner.class) @Config(shadows = ShadowRestrictedLockUtilsInternal.class) public class SeekBarPreferenceTest { private static final int MAX = 75; Loading Loading @@ -73,9 +81,39 @@ public class SeekBarPreferenceTest { } @Test public void isSelectable_notDisabledByAdmin_returnFalse() { when(mSeekBarPreference.isDisabledByAdmin()).thenReturn(false); @Config(qualifiers = "mcc998") public void isSelectable_default_returnFalse() { final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(), new Bundle()) .create() .start() .resume() .get(); final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar"); assertThat(seekBarPreference.isSelectable()).isFalse(); } assertThat(mSeekBarPreference.isSelectable()).isFalse(); @Test @Config(qualifiers = "mcc999") public void isSelectable_selectableInXml_returnTrue() { final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(), new Bundle()) .create() .start() .resume() .get(); final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar"); assertThat(seekBarPreference.isSelectable()).isTrue(); } public static class TestFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(com.android.settings.R.xml.seekbar_preference); } } }