Merge "Make SeekBarPreference to be selectable" into qt-dev am: dd59f1193f
am: 574893b860
Change-Id: I7761ee743a356507feff41c5554927c3ad61a815
This commit is contained in:
@@ -69,6 +69,13 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
com.android.internal.R.layout.preference_widget_seekbar);
|
com.android.internal.R.layout.preference_widget_seekbar);
|
||||||
a.recycle();
|
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);
|
setLayoutResource(layoutResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +100,11 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSelectable() {
|
public boolean isSelectable() {
|
||||||
return isDisabledByAdmin();
|
if(isDisabledByAdmin()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.isSelectable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
23
tests/robotests/res/xml-mcc998/seekbar_preference.xml
Normal file
23
tests/robotests/res/xml-mcc998/seekbar_preference.xml
Normal 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 >
|
24
tests/robotests/res/xml-mcc999/seekbar_preference.xml
Normal file
24
tests/robotests/res/xml-mcc999/seekbar_preference.xml
Normal 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 >
|
@@ -22,16 +22,24 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.androidx.fragment.FragmentController;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||||
public class SeekBarPreferenceTest {
|
public class SeekBarPreferenceTest {
|
||||||
|
|
||||||
private static final int MAX = 75;
|
private static final int MAX = 75;
|
||||||
@@ -73,9 +81,39 @@ public class SeekBarPreferenceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSelectable_notDisabledByAdmin_returnFalse() {
|
@Config(qualifiers = "mcc998")
|
||||||
when(mSeekBarPreference.isDisabledByAdmin()).thenReturn(false);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user