Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd59f119 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make SeekBarPreference to be selectable" into qt-dev

parents 91c7f77f 81b9f508
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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
+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 >
+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 >
+41 −3
Original line number Diff line number Diff line
@@ -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();

        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);
        }
    }
}