Merge "Make SeekBarPreference to be selectable" into qt-dev am: dd59f1193f

am: 574893b860

Change-Id: I7761ee743a356507feff41c5554927c3ad61a815
This commit is contained in:
Raff Tsai
2019-05-21 12:22:42 -07:00
committed by android-build-merger
4 changed files with 100 additions and 4 deletions

View File

@@ -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);
}
@@ -93,7 +100,11 @@ public class SeekBarPreference extends RestrictedPreference
@Override
public boolean isSelectable() {
return isDisabledByAdmin();
if(isDisabledByAdmin()) {
return true;
} else {
return super.isSelectable();
}
}
@Override

View File

@@ -0,0 +1,23 @@
<?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 >

View File

@@ -0,0 +1,24 @@
<?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 >

View File

@@ -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;
@@ -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();
assertThat(mSeekBarPreference.isSelectable()).isFalse();
final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar");
assertThat(seekBarPreference.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);
}
}
}