Merge "Revert "Apply SettingsLib SeekBarPreference to Settings"" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ef0e09f7a3
47
res/layout/battery_saver_schedule_percentage_seekbar.xml
Normal file
47
res/layout/battery_saver_schedule_percentage_seekbar.xml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Layout used by BatterySaverScheduleSeekBarController for the seekbar widget. -->
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="6dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:layout_marginStart="18dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
|
||||||
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
<com.android.settings.widget.DefaultIndicatorSeekBar
|
||||||
|
android:id="@*android:id/seekbar"
|
||||||
|
style="@android:style/Widget.Material.SeekBar.Discrete"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="18dp"
|
||||||
|
android:layout_marginEnd="9dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
79
res/layout/preference_labeled_slider.xml
Normal file
79
res/layout/preference_labeled_slider.xml
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="56dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:fadingEdge="horizontal"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||||
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@*android:id/seekbar"
|
||||||
|
android:layout_below="@android:id/title"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:layout_marginTop="-20dp"
|
||||||
|
android:layout_marginBottom="-28dp"
|
||||||
|
style="@android:style/Widget.Material.SeekBar.Discrete" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@*android:id/seekbar"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start|top"
|
||||||
|
android:gravity="start"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/text2"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|top"
|
||||||
|
android:gravity="end"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
@@ -25,13 +25,28 @@
|
|||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<include layout="@layout/settingslib_icon_frame"/>
|
<LinearLayout
|
||||||
|
android:id="@+id/icon_frame"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="44dp"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingBottom="4dp">
|
||||||
|
<com.android.internal.widget.PreferenceImageView
|
||||||
|
android:id="@android:id/icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="16dp">
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
63
res/layout/preference_widget_seekbar_settings.xml
Normal file
63
res/layout/preference_widget_seekbar_settings.xml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Layout used by SeekBarPreference for the seekbar widget style. -->
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginBottom="6dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:fadingEdge="horizontal"
|
||||||
|
android:paddingStart="56dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
|
||||||
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignStart="@android:id/title"
|
||||||
|
android:layout_below="@android:id/title"
|
||||||
|
android:maxLines="4"
|
||||||
|
android:paddingStart="56dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
|
|
||||||
|
<com.android.settings.widget.DefaultIndicatorSeekBar
|
||||||
|
android:id="@*android:id/seekbar"
|
||||||
|
style="@android:style/Widget.Material.SeekBar.Discrete"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_below="@android:id/summary"
|
||||||
|
android:paddingStart="56dp"
|
||||||
|
android:paddingEnd="12dp" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@@ -157,6 +157,13 @@
|
|||||||
<attr name="textOff" format="reference" />
|
<attr name="textOff" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<!-- For LabeledSeekBarPreference -->
|
||||||
|
<declare-styleable name="LabeledSeekBarPreference">
|
||||||
|
<attr name="textStart" format="reference" />
|
||||||
|
<attr name="textEnd" format="reference" />
|
||||||
|
<attr name="tickMark" format="reference" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="TintDrawable">
|
<declare-styleable name="TintDrawable">
|
||||||
<attr name="android:tint" />
|
<attr name="android:tint" />
|
||||||
<attr name="android:drawable" />
|
<attr name="android:drawable" />
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
<item name="apnPreferenceStyle">@style/ApnPreference</item>
|
<item name="apnPreferenceStyle">@style/ApnPreference</item>
|
||||||
<item name="cardPreferenceStyle">@style/CardPreference</item>
|
<item name="cardPreferenceStyle">@style/CardPreference</item>
|
||||||
<item name="slicePreferenceStyle">@style/SlicePreference</item>
|
<item name="slicePreferenceStyle">@style/SlicePreference</item>
|
||||||
|
<item name="seekBarPreferenceStyle">@style/SettingsSeekBarPreference</item>
|
||||||
<item name="twoStateButtonPreferenceStyle">@style/TwoStateButtonPreference</item>
|
<item name="twoStateButtonPreferenceStyle">@style/TwoStateButtonPreference</item>
|
||||||
<item name="preferenceFragmentCompatStyle">@style/SettingsPreferenceFragmentStyle</item>
|
<item name="preferenceFragmentCompatStyle">@style/SettingsPreferenceFragmentStyle</item>
|
||||||
</style>
|
</style>
|
||||||
@@ -43,6 +44,10 @@
|
|||||||
<item name="android:layout">@layout/slice_preference_layout</item>
|
<item name="android:layout">@layout/slice_preference_layout</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="SettingsSeekBarPreference" parent="@style/Preference.Material">
|
||||||
|
<item name="android:layout">@layout/preference_widget_seekbar_settings</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="SyncSwitchPreference" parent="@style/SettingsSwitchPreference.SettingsLib">
|
<style name="SyncSwitchPreference" parent="@style/SettingsSwitchPreference.SettingsLib">
|
||||||
<item name="android:widgetLayout">@layout/preference_widget_sync_toggle</item>
|
<item name="android:widgetLayout">@layout/preference_widget_sync_toggle</item>
|
||||||
</style>
|
</style>
|
||||||
|
@@ -53,7 +53,7 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
settings:controller="com.android.settings.accessibility.FloatingMenuFadePreferenceController"/>
|
settings:controller="com.android.settings.accessibility.FloatingMenuFadePreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="accessibility_button_opacity"
|
android:key="accessibility_button_opacity"
|
||||||
android:title="@string/accessibility_button_opacity_title"
|
android:title="@string/accessibility_button_opacity_title"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
|
@@ -42,7 +42,7 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/back_sensitivity_dialog_title">
|
android:title="@string/back_sensitivity_dialog_title">
|
||||||
|
|
||||||
<com.android.settingslib.widget.LabeledSeekBarPreference
|
<com.android.settings.widget.LabeledSeekBarPreference
|
||||||
android:key="gesture_left_back_sensitivity"
|
android:key="gesture_left_back_sensitivity"
|
||||||
android:title="@string/left_edge"
|
android:title="@string/left_edge"
|
||||||
android:max="2"
|
android:max="2"
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
settings:textStart="@string/low_label"
|
settings:textStart="@string/low_label"
|
||||||
settings:textEnd="@string/high_label"/>
|
settings:textEnd="@string/high_label"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.LabeledSeekBarPreference
|
<com.android.settings.widget.LabeledSeekBarPreference
|
||||||
android:key="gesture_right_back_sensitivity"
|
android:key="gesture_right_back_sensitivity"
|
||||||
android:title="@string/right_edge"
|
android:title="@string/right_edge"
|
||||||
android:max="2"
|
android:max="2"
|
||||||
|
@@ -52,7 +52,7 @@
|
|||||||
android:title="@string/night_display_end_time_title"
|
android:title="@string/night_display_end_time_title"
|
||||||
settings:controller="com.android.settings.display.NightDisplayCustomEndTimePreferenceController"/>
|
settings:controller="com.android.settings.display.NightDisplayCustomEndTimePreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="night_display_temperature"
|
android:key="night_display_temperature"
|
||||||
android:title="@string/night_display_temperature_title"
|
android:title="@string/night_display_temperature_title"
|
||||||
settings:keywords="@string/keywords_display_night_display"
|
settings:keywords="@string/keywords_display_night_display"
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/reduce_bright_colors_preference_title">
|
android:title="@string/reduce_bright_colors_preference_title">
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="rbc_intensity"
|
android:key="rbc_intensity"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/reduce_bright_colors_intensity_preference_title"/>
|
android:title="@string/reduce_bright_colors_intensity_preference_title"/>
|
||||||
|
@@ -34,14 +34,14 @@
|
|||||||
|
|
||||||
<!-- The max value for seek bars here should be kept in sync
|
<!-- The max value for seek bars here should be kept in sync
|
||||||
with the max value specified in TextToSpeechSettings class. -->
|
with the max value specified in TextToSpeechSettings class. -->
|
||||||
<com.android.settingslib.RestrictedSeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="tts_default_rate"
|
android:key="tts_default_rate"
|
||||||
android:title="@string/tts_default_rate_title"
|
android:title="@string/tts_default_rate_title"
|
||||||
android:summary="@string/tts_default_rate_summary"
|
android:summary="@string/tts_default_rate_summary"
|
||||||
android:defaultValue="50"
|
android:defaultValue="50"
|
||||||
android:max="600"/>
|
android:max="600"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="tts_default_pitch"
|
android:key="tts_default_pitch"
|
||||||
android:title="@string/tts_default_pitch_title"
|
android:title="@string/tts_default_pitch_title"
|
||||||
android:summary="@string/tts_default_pitch_summary"
|
android:summary="@string/tts_default_pitch_summary"
|
||||||
|
@@ -39,17 +39,13 @@ import androidx.appcompat.app.AlertDialog.Builder;
|
|||||||
import androidx.preference.ListPreferenceDialogFragmentCompat;
|
import androidx.preference.ListPreferenceDialogFragmentCompat;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settingslib.Restrictable;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
public class RestrictedListPreference extends CustomListPreference {
|
||||||
* List preference that can be disabled by a device admin using a user restriction.
|
|
||||||
*/
|
|
||||||
public class RestrictedListPreference extends CustomListPreference implements Restrictable {
|
|
||||||
private final RestrictedPreferenceHelper mHelper;
|
private final RestrictedPreferenceHelper mHelper;
|
||||||
private final List<RestrictedItem> mRestrictedItems = new ArrayList<>();
|
private final List<RestrictedItem> mRestrictedItems = new ArrayList<>();
|
||||||
private boolean mRequiresActiveUnlockedProfile = false;
|
private boolean mRequiresActiveUnlockedProfile = false;
|
||||||
@@ -67,10 +63,6 @@ public class RestrictedListPreference extends CustomListPreference implements Re
|
|||||||
mHelper = new RestrictedPreferenceHelper(context, this, attrs);
|
mHelper = new RestrictedPreferenceHelper(context, this, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestrictedListPreference(Context context) {
|
|
||||||
this(context, /* attrs= */ null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
@@ -115,14 +107,14 @@ public class RestrictedListPreference extends CustomListPreference implements Re
|
|||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setDisabledByAdmin(EnforcedAdmin admin) {
|
||||||
public RestrictedPreferenceHelper getHelper() {
|
if (mHelper.setDisabledByAdmin(admin)) {
|
||||||
return mHelper;
|
notifyChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean isDisabledByAdmin() {
|
||||||
public void notifyPreferenceChanged() {
|
return mHelper.isDisabledByAdmin();
|
||||||
notifyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRequiresActiveUnlockedProfile(boolean reqState) {
|
public void setRequiresActiveUnlockedProfile(boolean reqState) {
|
||||||
|
@@ -17,19 +17,23 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.media.AudioSystem;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
import androidx.core.content.res.TypedArrayUtils;
|
import androidx.core.content.res.TypedArrayUtils;
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.RestrictedSeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
/** A slider preference that directly controls audio balance **/
|
/** A slider preference that directly controls audio balance **/
|
||||||
public class BalanceSeekBarPreference extends RestrictedSeekBarPreference {
|
public class BalanceSeekBarPreference extends SeekBarPreference {
|
||||||
private static final int BALANCE_CENTER_VALUE = 100;
|
private static final int BALANCE_CENTER_VALUE = 100;
|
||||||
private static final int BALANCE_MAX_VALUE = 200;
|
private static final int BALANCE_MAX_VALUE = 200;
|
||||||
|
|
||||||
|
@@ -28,10 +28,10 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
/** Preference controller that controls the transparency seekbar in accessibility button page. */
|
/** Preference controller that controls the transparency seekbar in accessibility button page. */
|
||||||
public class FloatingMenuTransparencyPreferenceController extends SliderPreferenceController
|
public class FloatingMenuTransparencyPreferenceController extends SliderPreferenceController
|
||||||
|
@@ -23,7 +23,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
/** PreferenceController for feature intensity. */
|
/** PreferenceController for feature intensity. */
|
||||||
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
|
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
|
||||||
|
@@ -34,9 +34,9 @@ import androidx.preference.SwitchPreference;
|
|||||||
import com.android.internal.accessibility.AccessibilityShortcutController;
|
import com.android.internal.accessibility.AccessibilityShortcutController;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@@ -27,11 +27,9 @@ import android.content.pm.UserInfo;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.AccessiblePreferenceCategory;
|
import com.android.settings.AccessiblePreferenceCategory;
|
||||||
import com.android.settingslib.Restrictable;
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -43,75 +41,35 @@ public class AccountRestrictionHelper {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the account should be shown based on the required authorities for the account type
|
|
||||||
*
|
|
||||||
* @param authorities given authority that is passed as activity extra
|
|
||||||
* @param auths list of authorities for particular account type
|
|
||||||
* @return true if the activity has the required authority to show the account
|
|
||||||
*/
|
|
||||||
public static boolean showAccount(String[] authorities, ArrayList<String> auths) {
|
|
||||||
boolean showAccount = true;
|
|
||||||
if (authorities != null && auths != null) {
|
|
||||||
showAccount = false;
|
|
||||||
for (String requestedAuthority : authorities) {
|
|
||||||
if (auths.contains(requestedAuthority)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return showAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the UI of the preference by checking user restriction.
|
* Configure the UI of the preference by checking user restriction.
|
||||||
*
|
* @param preference The preference we are configuring.
|
||||||
* @param preference The preference we are configuring.
|
|
||||||
* @param userRestriction The user restriction related to the preference.
|
* @param userRestriction The user restriction related to the preference.
|
||||||
* @param userId The user that we retrieve user restriction of.
|
* @param userId The user that we retrieve user restriction of.
|
||||||
*/
|
*/
|
||||||
public void enforceRestrictionOnPreference(Preference preference,
|
public void enforceRestrictionOnPreference(RestrictedPreference preference,
|
||||||
String userRestriction, @UserIdInt int userId) {
|
String userRestriction, @UserIdInt int userId) {
|
||||||
if (preference == null) {
|
if (preference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(preference instanceof Restrictable)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Restrictable restrictedPreference = (Restrictable) preference;
|
|
||||||
|
|
||||||
if (hasBaseUserRestriction(userRestriction, userId)) {
|
if (hasBaseUserRestriction(userRestriction, userId)) {
|
||||||
if (userRestriction.equals(DISALLOW_REMOVE_MANAGED_PROFILE)
|
if (userRestriction.equals(DISALLOW_REMOVE_MANAGED_PROFILE)
|
||||||
&& isOrganizationOwnedDevice()) {
|
&& isOrganizationOwnedDevice()) {
|
||||||
restrictedPreference.setDisabledByAdmin(getEnforcedAdmin(userRestriction, userId));
|
preference.setDisabledByAdmin(getEnforcedAdmin(userRestriction, userId));
|
||||||
} else {
|
} else {
|
||||||
preference.setEnabled(false);
|
preference.setEnabled(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
restrictedPreference.checkRestrictionAndSetDisabled(userRestriction, userId);
|
preference.checkRestrictionAndSetDisabled(userRestriction, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the system has set the user restriction.
|
|
||||||
* @param userRestriction The user restriction.
|
|
||||||
* @param userId The user that we retrieve user restriction of.
|
|
||||||
* @return {@code true} if set restriction.
|
|
||||||
*/
|
|
||||||
public boolean hasBaseUserRestriction(String userRestriction, @UserIdInt int userId) {
|
public boolean hasBaseUserRestriction(String userRestriction, @UserIdInt int userId) {
|
||||||
return RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext, userRestriction,
|
return RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext, userRestriction,
|
||||||
userId);
|
userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean isOrganizationOwnedDevice() {
|
||||||
* Apps can use this method to find out if the device was provisioned as
|
|
||||||
* organization-owend device.
|
|
||||||
*
|
|
||||||
* @return {@code true} if the device was provisioned as organization-owned device,
|
|
||||||
* {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isOrganizationOwnedDevice() {
|
|
||||||
final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
|
final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
|
||||||
Context.DEVICE_POLICY_SERVICE);
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
if (dpm == null) {
|
if (dpm == null) {
|
||||||
@@ -120,13 +78,7 @@ public class AccountRestrictionHelper {
|
|||||||
return dpm.isOrganizationOwnedDeviceWithManagedProfile();
|
return dpm.isOrganizationOwnedDeviceWithManagedProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private EnforcedAdmin getEnforcedAdmin(String userRestriction, int userId) {
|
||||||
* Get the restriction enforced by admin
|
|
||||||
* @param userRestriction The user restriction.
|
|
||||||
* @param userId The user that we retrieve user restriction of.
|
|
||||||
* @return {EnforcedAdmin}
|
|
||||||
*/
|
|
||||||
public EnforcedAdmin getEnforcedAdmin(String userRestriction, int userId) {
|
|
||||||
final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
|
final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
|
||||||
Context.DEVICE_POLICY_SERVICE);
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
if (dpm == null) {
|
if (dpm == null) {
|
||||||
@@ -155,4 +107,23 @@ public class AccountRestrictionHelper {
|
|||||||
public AccessiblePreferenceCategory createAccessiblePreferenceCategory(Context context) {
|
public AccessiblePreferenceCategory createAccessiblePreferenceCategory(Context context) {
|
||||||
return new AccessiblePreferenceCategory(context);
|
return new AccessiblePreferenceCategory(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the account should be shown based on the required authorities for the account type
|
||||||
|
* @param authorities given authority that is passed as activity extra
|
||||||
|
* @param auths list of authorities for particular account type
|
||||||
|
* @return true if the activity has the required authority to show the account
|
||||||
|
*/
|
||||||
|
public static boolean showAccount(String[] authorities, ArrayList<String> auths) {
|
||||||
|
boolean showAccount = true;
|
||||||
|
if (authorities != null && auths != null) {
|
||||||
|
showAccount = false;
|
||||||
|
for (String requestedAuthority : authorities) {
|
||||||
|
if (auths.contains(requestedAuthority)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return showAccount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ import android.content.Context;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.slices.SliceData;
|
import com.android.settings.slices.SliceData;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
public abstract class SliderPreferenceController extends BasePreferenceController implements
|
public abstract class SliderPreferenceController extends BasePreferenceController implements
|
||||||
Preference.OnPreferenceChangeListener {
|
Preference.OnPreferenceChangeListener {
|
||||||
@@ -35,10 +34,12 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (preference instanceof SeekBarPreference) {
|
if (preference instanceof com.android.settings.widget.SeekBarPreference) {
|
||||||
((SeekBarPreference) preference).setProgress(getSliderPosition());
|
((com.android.settings.widget.SeekBarPreference) preference)
|
||||||
|
.setProgress(getSliderPosition());
|
||||||
} else if (preference instanceof androidx.preference.SeekBarPreference) {
|
} else if (preference instanceof androidx.preference.SeekBarPreference) {
|
||||||
((androidx.preference.SeekBarPreference) preference).setValue(getSliderPosition());
|
((androidx.preference.SeekBarPreference) preference)
|
||||||
|
.setValue(getSliderPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,14 +24,14 @@ import androidx.preference.PreferenceViewHolder;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.Restrictable;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||||
import com.android.settingslib.widget.AppSwitchPreference;
|
import com.android.settingslib.widget.AppSwitchPreference;
|
||||||
|
|
||||||
public class UnrestrictedDataAccessPreference extends AppSwitchPreference implements
|
public class UnrestrictedDataAccessPreference extends AppSwitchPreference implements
|
||||||
DataSaverBackend.Listener, Restrictable {
|
DataSaverBackend.Listener {
|
||||||
|
|
||||||
private final ApplicationsState mApplicationsState;
|
private final ApplicationsState mApplicationsState;
|
||||||
private final AppEntry mEntry;
|
private final AppEntry mEntry;
|
||||||
@@ -159,14 +159,12 @@ public class UnrestrictedDataAccessPreference extends AppSwitchPreference implem
|
|||||||
return mEntry;
|
return mEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean isDisabledByAdmin() {
|
||||||
public RestrictedPreferenceHelper getHelper() {
|
return mHelper.isDisabledByAdmin();
|
||||||
return mHelper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setDisabledByAdmin(EnforcedAdmin admin) {
|
||||||
public void notifyPreferenceChanged() {
|
mHelper.setDisabledByAdmin(admin);
|
||||||
notifyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets UI state based on allowlist/denylist status.
|
// Sets UI state based on allowlist/denylist status.
|
||||||
|
@@ -24,7 +24,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
public class NightDisplayIntensityPreferenceController extends SliderPreferenceController {
|
public class NightDisplayIntensityPreferenceController extends SliderPreferenceController {
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds to user actions in the Settings > Battery > Set a Schedule Screen for the seekbar.
|
* Responds to user actions in the Settings > Battery > Set a Schedule Screen for the seekbar.
|
||||||
@@ -55,6 +55,7 @@ public class BatterySaverScheduleSeekBarController implements
|
|||||||
public BatterySaverScheduleSeekBarController(Context context) {
|
public BatterySaverScheduleSeekBarController(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSeekBarPreference = new SeekBarPreference(context);
|
mSeekBarPreference = new SeekBarPreference(context);
|
||||||
|
mSeekBarPreference.setLayoutResource(R.layout.battery_saver_schedule_percentage_seekbar);
|
||||||
mSeekBarPreference.setOnPreferenceChangeListener(this);
|
mSeekBarPreference.setOnPreferenceChangeListener(this);
|
||||||
mSeekBarPreference.setContinuousUpdates(true);
|
mSeekBarPreference.setContinuousUpdates(true);
|
||||||
mSeekBarPreference.setMax(MAX_SEEKBAR_VALUE);
|
mSeekBarPreference.setMax(MAX_SEEKBAR_VALUE);
|
||||||
|
@@ -27,9 +27,9 @@ import android.view.WindowManager;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
import com.android.settingslib.widget.LabeledSeekBarPreference;
|
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment to include all the settings related to Gesture Navigation mode.
|
* A fragment to include all the settings related to Gesture Navigation mode.
|
||||||
|
@@ -27,7 +27,7 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.accounts.AccountRestrictionHelper;
|
import com.android.settings.accounts.AccountRestrictionHelper;
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settingslib.Restrictable;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for preference controller that handles preference that enforce adjust volume
|
* Base class for preference controller that handles preference that enforce adjust volume
|
||||||
@@ -51,10 +51,10 @@ public abstract class AdjustVolumeRestrictedPreferenceController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (!(preference instanceof Restrictable)) {
|
if (!(preference instanceof RestrictedPreference)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mHelper.enforceRestrictionOnPreference(preference,
|
mHelper.enforceRestrictionOnPreference((RestrictedPreference) preference,
|
||||||
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
|
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,12 +32,12 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.RestrictedSeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/** A slider preference that directly controls an audio stream volume (no dialog) **/
|
/** A slider preference that directly controls an audio stream volume (no dialog) **/
|
||||||
public class VolumeSeekBarPreference extends RestrictedSeekBarPreference {
|
public class VolumeSeekBarPreference extends SeekBarPreference {
|
||||||
private static final String TAG = "VolumeSeekBarPreference";
|
private static final String TAG = "VolumeSeekBarPreference";
|
||||||
|
|
||||||
protected SeekBar mSeekBar;
|
protected SeekBar mSeekBar;
|
||||||
|
@@ -22,6 +22,7 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -32,13 +33,13 @@ import androidx.preference.PreferenceViewHolder;
|
|||||||
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.R;
|
import com.android.settingslib.R;
|
||||||
import com.android.settingslib.Restrictable;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tri-state preference allowing a user to specify what gets to bubble.
|
* A tri-state preference allowing a user to specify what gets to bubble.
|
||||||
*/
|
*/
|
||||||
public class BubblePreference extends Preference implements View.OnClickListener, Restrictable {
|
public class BubblePreference extends Preference implements View.OnClickListener {
|
||||||
RestrictedPreferenceHelper mHelper;
|
RestrictedPreferenceHelper mHelper;
|
||||||
|
|
||||||
private int mSelectedPreference;
|
private int mSelectedPreference;
|
||||||
@@ -80,6 +81,12 @@ public class BubblePreference extends Preference implements View.OnClickListener
|
|||||||
return mSelectedPreference;
|
return mSelectedPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDisabledByAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
|
||||||
|
if (mHelper.setDisabledByAdmin(admin)) {
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setSelectedVisibility(boolean visible) {
|
public void setSelectedVisibility(boolean visible) {
|
||||||
mSelectedVisible = visible;
|
mSelectedVisible = visible;
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
@@ -142,16 +149,6 @@ public class BubblePreference extends Preference implements View.OnClickListener
|
|||||||
mBubbleNoneButton.setSelected(mContext, selected == BUBBLE_PREFERENCE_NONE);
|
mBubbleNoneButton.setSelected(mContext, selected == BUBBLE_PREFERENCE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestrictedPreferenceHelper getHelper() {
|
|
||||||
return mHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyPreferenceChanged() {
|
|
||||||
notifyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ButtonViewHolder {
|
private class ButtonViewHolder {
|
||||||
private View mView;
|
private View mView;
|
||||||
private ImageView mImageView;
|
private ImageView mImageView;
|
||||||
|
@@ -49,9 +49,9 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.widget.GearPreference;
|
import com.android.settings.widget.GearPreference;
|
||||||
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
89
src/com/android/settings/widget/DefaultIndicatorSeekBar.java
Normal file
89
src/com/android/settings/widget/DefaultIndicatorSeekBar.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
|
public class DefaultIndicatorSeekBar extends SeekBar {
|
||||||
|
|
||||||
|
private int mDefaultProgress = -1;
|
||||||
|
|
||||||
|
public DefaultIndicatorSeekBar(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
|
int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* N.B. Only draws the default indicator tick mark, NOT equally spaced tick marks.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void drawTickMarks(Canvas canvas) {
|
||||||
|
if (isEnabled() && mDefaultProgress <= getMax() && mDefaultProgress >= getMin()) {
|
||||||
|
final Drawable defaultIndicator = getTickMark();
|
||||||
|
|
||||||
|
// Adjust the drawable's bounds to center it at the point where it's drawn.
|
||||||
|
final int w = defaultIndicator.getIntrinsicWidth();
|
||||||
|
final int h = defaultIndicator.getIntrinsicHeight();
|
||||||
|
final int halfW = w >= 0 ? w / 2 : 1;
|
||||||
|
final int halfH = h >= 0 ? h / 2 : 1;
|
||||||
|
defaultIndicator.setBounds(-halfW, -halfH, halfW, halfH);
|
||||||
|
|
||||||
|
// This mimics the computation of the thumb position, to get the true "default."
|
||||||
|
final int availableWidth = getWidth() - mPaddingLeft - mPaddingRight;
|
||||||
|
final int range = getMax() - getMin();
|
||||||
|
final float scale = range > 0f ? mDefaultProgress / (float) range : 0f;
|
||||||
|
final int offset = (int) ((scale * availableWidth) + 0.5f);
|
||||||
|
final int indicatorPosition = isLayoutRtl() && getMirrorForRtl()
|
||||||
|
? availableWidth - offset + mPaddingRight : offset + mPaddingLeft;
|
||||||
|
|
||||||
|
final int saveCount = canvas.save();
|
||||||
|
canvas.translate(indicatorPosition, getHeight() / 2);
|
||||||
|
defaultIndicator.draw(canvas);
|
||||||
|
canvas.restoreToCount(saveCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* N.B. This sets the default *unadjusted* progress, i.e. in the SeekBar's [0 - max] terms.
|
||||||
|
*/
|
||||||
|
public void setDefaultProgress(int defaultProgress) {
|
||||||
|
if (mDefaultProgress != defaultProgress) {
|
||||||
|
mDefaultProgress = defaultProgress;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultProgress() {
|
||||||
|
return mDefaultProgress;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.core.content.res.TypedArrayUtils;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/** A slider preference with left and right labels **/
|
||||||
|
public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||||
|
|
||||||
|
private final int mTextStartId;
|
||||||
|
private final int mTextEndId;
|
||||||
|
private final int mTickMarkId;
|
||||||
|
private OnPreferenceChangeListener mStopListener;
|
||||||
|
|
||||||
|
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
|
int defStyleRes) {
|
||||||
|
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
setLayoutResource(R.layout.preference_labeled_slider);
|
||||||
|
|
||||||
|
final TypedArray styledAttrs = context.obtainStyledAttributes(attrs,
|
||||||
|
R.styleable.LabeledSeekBarPreference);
|
||||||
|
mTextStartId = styledAttrs.getResourceId(
|
||||||
|
R.styleable.LabeledSeekBarPreference_textStart,
|
||||||
|
R.string.summary_placeholder);
|
||||||
|
mTextEndId = styledAttrs.getResourceId(
|
||||||
|
R.styleable.LabeledSeekBarPreference_textEnd,
|
||||||
|
R.string.summary_placeholder);
|
||||||
|
mTickMarkId = styledAttrs.getResourceId(
|
||||||
|
R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
|
||||||
|
styledAttrs.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LabeledSeekBarPreference(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||||
|
androidx.preference.R.attr.seekBarPreferenceStyle,
|
||||||
|
com.android.internal.R.attr.seekBarPreferenceStyle), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
final TextView startText = (TextView) holder.findViewById(android.R.id.text1);
|
||||||
|
final TextView endText = (TextView) holder.findViewById(android.R.id.text2);
|
||||||
|
startText.setText(mTextStartId);
|
||||||
|
endText.setText(mTextEndId);
|
||||||
|
|
||||||
|
if (mTickMarkId != 0) {
|
||||||
|
final Drawable tickMark = getContext().getDrawable(mTickMarkId);
|
||||||
|
final SeekBar seekBar = (SeekBar) holder.findViewById(
|
||||||
|
com.android.internal.R.id.seekbar);
|
||||||
|
seekBar.setTickMark(tickMark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
|
||||||
|
mStopListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
super.onStopTrackingTouch(seekBar);
|
||||||
|
|
||||||
|
if (mStopListener != null) {
|
||||||
|
mStopListener.onPreferenceChange(this, seekBar.getProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -26,7 +26,7 @@ import androidx.preference.PreferenceManager;
|
|||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.Restrictable;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||||
import com.android.settingslib.widget.AppPreference;
|
import com.android.settingslib.widget.AppPreference;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ import com.android.settingslib.widget.AppPreference;
|
|||||||
* {@link com.android.settingslib.RestrictedPreferenceHelper}.
|
* {@link com.android.settingslib.RestrictedPreferenceHelper}.
|
||||||
* Used to show policy transparency on {@link AppPreference}.
|
* Used to show policy transparency on {@link AppPreference}.
|
||||||
*/
|
*/
|
||||||
public class RestrictedAppPreference extends AppPreference implements Restrictable {
|
public class RestrictedAppPreference extends AppPreference {
|
||||||
private RestrictedPreferenceHelper mHelper;
|
private RestrictedPreferenceHelper mHelper;
|
||||||
private String userRestriction;
|
private String userRestriction;
|
||||||
|
|
||||||
@@ -85,14 +85,14 @@ public class RestrictedAppPreference extends AppPreference implements Restrictab
|
|||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setDisabledByAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
|
||||||
public RestrictedPreferenceHelper getHelper() {
|
if (mHelper.setDisabledByAdmin(admin)) {
|
||||||
return mHelper;
|
notifyChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean isDisabledByAdmin() {
|
||||||
public void notifyPreferenceChanged() {
|
return mHelper.isDisabledByAdmin();
|
||||||
notifyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void useAdminDisabledSummary(boolean useSummary) {
|
public void useAdminDisabledSummary(boolean useSummary) {
|
||||||
@@ -111,4 +111,12 @@ public class RestrictedAppPreference extends AppPreference implements Restrictab
|
|||||||
}
|
}
|
||||||
mHelper.checkRestrictionAndSetDisabled(userRestriction, UserHandle.myUserId());
|
mHelper.checkRestrictionAndSetDisabled(userRestriction, UserHandle.myUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkRestrictionAndSetDisabled(String userRestriction) {
|
||||||
|
mHelper.checkRestrictionAndSetDisabled(userRestriction, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkRestrictionAndSetDisabled(String userRestriction, int userId) {
|
||||||
|
mHelper.checkRestrictionAndSetDisabled(userRestriction, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
436
src/com/android/settings/widget/SeekBarPreference.java
Normal file
436
src/com/android/settings/widget/SeekBarPreference.java
Normal file
@@ -0,0 +1,436 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
|
|
||||||
|
import androidx.core.content.res.TypedArrayUtils;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on android.preference.SeekBarPreference, but uses support preference as base.
|
||||||
|
*/
|
||||||
|
public class SeekBarPreference extends RestrictedPreference
|
||||||
|
implements OnSeekBarChangeListener, View.OnKeyListener {
|
||||||
|
|
||||||
|
public static final int HAPTIC_FEEDBACK_MODE_NONE = 0;
|
||||||
|
public static final int HAPTIC_FEEDBACK_MODE_ON_TICKS = 1;
|
||||||
|
public static final int HAPTIC_FEEDBACK_MODE_ON_ENDS = 2;
|
||||||
|
|
||||||
|
private int mProgress;
|
||||||
|
private int mMax;
|
||||||
|
private int mMin;
|
||||||
|
private boolean mTrackingTouch;
|
||||||
|
|
||||||
|
private boolean mContinuousUpdates;
|
||||||
|
private int mHapticFeedbackMode = HAPTIC_FEEDBACK_MODE_NONE;
|
||||||
|
private int mDefaultProgress = -1;
|
||||||
|
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
private boolean mShouldBlink;
|
||||||
|
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
|
||||||
|
private CharSequence mSeekBarContentDescription;
|
||||||
|
private CharSequence mSeekBarStateDescription;
|
||||||
|
|
||||||
|
public SeekBarPreference(
|
||||||
|
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
|
||||||
|
TypedArray a = context.obtainStyledAttributes(
|
||||||
|
attrs, com.android.internal.R.styleable.ProgressBar, defStyleAttr, defStyleRes);
|
||||||
|
setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax));
|
||||||
|
setMin(a.getInt(com.android.internal.R.styleable.ProgressBar_min, mMin));
|
||||||
|
a.recycle();
|
||||||
|
|
||||||
|
a = context.obtainStyledAttributes(attrs,
|
||||||
|
com.android.internal.R.styleable.SeekBarPreference, defStyleAttr, defStyleRes);
|
||||||
|
final int layoutResId = a.getResourceId(
|
||||||
|
com.android.internal.R.styleable.SeekBarPreference_layout,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
this(context, attrs, defStyleAttr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeekBarPreference(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||||
|
androidx.preference.R.attr.seekBarPreferenceStyle,
|
||||||
|
com.android.internal.R.attr.seekBarPreferenceStyle));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeekBarPreference(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShouldBlink(boolean shouldBlink) {
|
||||||
|
mShouldBlink = shouldBlink;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSelectable() {
|
||||||
|
if(isDisabledByAdmin()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.isSelectable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
|
super.onBindViewHolder(view);
|
||||||
|
view.itemView.setOnKeyListener(this);
|
||||||
|
mSeekBar = (SeekBar) view.findViewById(
|
||||||
|
com.android.internal.R.id.seekbar);
|
||||||
|
mSeekBar.setOnSeekBarChangeListener(this);
|
||||||
|
mSeekBar.setMax(mMax);
|
||||||
|
mSeekBar.setMin(mMin);
|
||||||
|
mSeekBar.setProgress(mProgress);
|
||||||
|
mSeekBar.setEnabled(isEnabled());
|
||||||
|
final CharSequence title = getTitle();
|
||||||
|
if (!TextUtils.isEmpty(mSeekBarContentDescription)) {
|
||||||
|
mSeekBar.setContentDescription(mSeekBarContentDescription);
|
||||||
|
} else if (!TextUtils.isEmpty(title)) {
|
||||||
|
mSeekBar.setContentDescription(title);
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(mSeekBarStateDescription)) {
|
||||||
|
mSeekBar.setStateDescription(mSeekBarStateDescription);
|
||||||
|
}
|
||||||
|
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
||||||
|
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
||||||
|
}
|
||||||
|
if (mShouldBlink) {
|
||||||
|
View v = view.itemView;
|
||||||
|
v.post(() -> {
|
||||||
|
if (v.getBackground() != null) {
|
||||||
|
final int centerX = v.getWidth() / 2;
|
||||||
|
final int centerY = v.getHeight() / 2;
|
||||||
|
v.getBackground().setHotspot(centerX, centerY);
|
||||||
|
}
|
||||||
|
v.setPressed(true);
|
||||||
|
v.setPressed(false);
|
||||||
|
mShouldBlink = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
mSeekBar.setAccessibilityDelegate(new View.AccessibilityDelegate() {
|
||||||
|
@Override
|
||||||
|
public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo info) {
|
||||||
|
super.onInitializeAccessibilityNodeInfo(view, info);
|
||||||
|
// Update the range info with the correct type
|
||||||
|
AccessibilityNodeInfo.RangeInfo rangeInfo = info.getRangeInfo();
|
||||||
|
if (rangeInfo != null) {
|
||||||
|
info.setRangeInfo(AccessibilityNodeInfo.RangeInfo.obtain(
|
||||||
|
mAccessibilityRangeInfoType, rangeInfo.getMin(),
|
||||||
|
rangeInfo.getMax(), rangeInfo.getCurrent()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||||
|
setProgress(restoreValue ? getPersistedInt(mProgress)
|
||||||
|
: (Integer) defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||||
|
return a.getInt(index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
if (event.getAction() != KeyEvent.ACTION_DOWN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeekBar seekBar = (SeekBar) v.findViewById(com.android.internal.R.id.seekbar);
|
||||||
|
if (seekBar == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return seekBar.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(int max) {
|
||||||
|
if (max != mMax) {
|
||||||
|
mMax = max;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMin(int min) {
|
||||||
|
if (min != mMin) {
|
||||||
|
mMin = min;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMax() {
|
||||||
|
return mMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMin() {
|
||||||
|
return mMin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(int progress) {
|
||||||
|
setProgress(progress, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the progress point to draw a single tick mark representing a default value.
|
||||||
|
*/
|
||||||
|
public void setDefaultProgress(int defaultProgress) {
|
||||||
|
if (mDefaultProgress != defaultProgress) {
|
||||||
|
mDefaultProgress = defaultProgress;
|
||||||
|
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
||||||
|
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When {@code continuousUpdates} is true, update the persisted setting immediately as the thumb
|
||||||
|
* is dragged along the SeekBar. Otherwise, only update the value of the setting when the thumb
|
||||||
|
* is dropped.
|
||||||
|
*/
|
||||||
|
public void setContinuousUpdates(boolean continuousUpdates) {
|
||||||
|
mContinuousUpdates = continuousUpdates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the haptic feedback mode. HAPTIC_FEEDBACK_MODE_ON_TICKS means to perform haptic feedback
|
||||||
|
* as the SeekBar's progress is updated; HAPTIC_FEEDBACK_MODE_ON_ENDS means to perform haptic
|
||||||
|
* feedback as the SeekBar's progress value is equal to the min/max value.
|
||||||
|
*
|
||||||
|
* @param hapticFeedbackMode the haptic feedback mode.
|
||||||
|
*/
|
||||||
|
public void setHapticFeedbackMode(int hapticFeedbackMode) {
|
||||||
|
mHapticFeedbackMode = hapticFeedbackMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setProgress(int progress, boolean notifyChanged) {
|
||||||
|
if (progress > mMax) {
|
||||||
|
progress = mMax;
|
||||||
|
}
|
||||||
|
if (progress < mMin) {
|
||||||
|
progress = mMin;
|
||||||
|
}
|
||||||
|
if (progress != mProgress) {
|
||||||
|
mProgress = progress;
|
||||||
|
persistInt(progress);
|
||||||
|
if (notifyChanged) {
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProgress() {
|
||||||
|
return mProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persist the seekBar's progress value if callChangeListener
|
||||||
|
* returns true, otherwise set the seekBar's progress to the stored value
|
||||||
|
*/
|
||||||
|
void syncProgress(SeekBar seekBar) {
|
||||||
|
int progress = seekBar.getProgress();
|
||||||
|
if (progress != mProgress) {
|
||||||
|
if (callChangeListener(progress)) {
|
||||||
|
setProgress(progress, false);
|
||||||
|
switch (mHapticFeedbackMode) {
|
||||||
|
case HAPTIC_FEEDBACK_MODE_ON_TICKS:
|
||||||
|
seekBar.performHapticFeedback(CLOCK_TICK);
|
||||||
|
break;
|
||||||
|
case HAPTIC_FEEDBACK_MODE_ON_ENDS:
|
||||||
|
if (progress == mMax || progress == mMin) {
|
||||||
|
seekBar.performHapticFeedback(CLOCK_TICK);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
seekBar.setProgress(mProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
|
||||||
|
syncProgress(seekBar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
mTrackingTouch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
mTrackingTouch = false;
|
||||||
|
if (seekBar.getProgress() != mProgress) {
|
||||||
|
syncProgress(seekBar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the type of range this seek bar represents.
|
||||||
|
*
|
||||||
|
* @param rangeInfoType The type of range to be shared with accessibility
|
||||||
|
*
|
||||||
|
* @see android.view.accessibility.AccessibilityNodeInfo.RangeInfo
|
||||||
|
*/
|
||||||
|
public void setAccessibilityRangeInfoType(int rangeInfoType) {
|
||||||
|
mAccessibilityRangeInfoType = rangeInfoType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeekBarContentDescription(CharSequence contentDescription) {
|
||||||
|
mSeekBarContentDescription = contentDescription;
|
||||||
|
if (mSeekBar != null) {
|
||||||
|
mSeekBar.setContentDescription(contentDescription);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the state description for this seek bar represents.
|
||||||
|
*
|
||||||
|
* @param stateDescription the state description of seek bar
|
||||||
|
*/
|
||||||
|
public void setSeekBarStateDescription(CharSequence stateDescription) {
|
||||||
|
mSeekBarStateDescription = stateDescription;
|
||||||
|
if (mSeekBar != null) {
|
||||||
|
mSeekBar.setStateDescription(stateDescription);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Parcelable onSaveInstanceState() {
|
||||||
|
/*
|
||||||
|
* Suppose a client uses this preference type without persisting. We
|
||||||
|
* must save the instance state so it is able to, for example, survive
|
||||||
|
* orientation changes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final Parcelable superState = super.onSaveInstanceState();
|
||||||
|
if (isPersistent()) {
|
||||||
|
// No need to save instance state since it's persistent
|
||||||
|
return superState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the instance state
|
||||||
|
final SavedState myState = new SavedState(superState);
|
||||||
|
myState.progress = mProgress;
|
||||||
|
myState.max = mMax;
|
||||||
|
myState.min = mMin;
|
||||||
|
return myState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Parcelable state) {
|
||||||
|
if (!state.getClass().equals(SavedState.class)) {
|
||||||
|
// Didn't save state for us in onSaveInstanceState
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the instance state
|
||||||
|
SavedState myState = (SavedState) state;
|
||||||
|
super.onRestoreInstanceState(myState.getSuperState());
|
||||||
|
mProgress = myState.progress;
|
||||||
|
mMax = myState.max;
|
||||||
|
mMin = myState.min;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SavedState, a subclass of {@link BaseSavedState}, will store the state
|
||||||
|
* of MyPreference, a subclass of Preference.
|
||||||
|
* <p>
|
||||||
|
* It is important to always call through to super methods.
|
||||||
|
*/
|
||||||
|
private static class SavedState extends BaseSavedState {
|
||||||
|
int progress;
|
||||||
|
int max;
|
||||||
|
int min;
|
||||||
|
|
||||||
|
public SavedState(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
|
// Restore the click counter
|
||||||
|
progress = source.readInt();
|
||||||
|
max = source.readInt();
|
||||||
|
min = source.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
|
||||||
|
// Save the click counter
|
||||||
|
dest.writeInt(progress);
|
||||||
|
dest.writeInt(max);
|
||||||
|
dest.writeInt(min);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState(Parcelable superState) {
|
||||||
|
super(superState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||||
|
new Parcelable.Creator<SavedState>() {
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<com.android.settingslib.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="seek_bar"
|
android:key="seek_bar"
|
||||||
android:title="seek_bar_title"/>
|
android:title="seek_bar_title"/>
|
||||||
</PreferenceScreen >
|
</PreferenceScreen >
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<com.android.settingslib.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="seek_bar"
|
android:key="seek_bar"
|
||||||
android:selectable="true"
|
android:selectable="true"
|
||||||
android:title="seek_bar_title"/>
|
android:title="seek_bar_title"/>
|
||||||
|
@@ -36,7 +36,7 @@ import android.provider.Settings;
|
|||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class LabeledSeekBarPreferenceTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
private LabeledSeekBarPreference mSeekBarPreference;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Preference.OnPreferenceChangeListener mListener;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mSeekBarPreference = new LabeledSeekBarPreference(mContext, null);
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
final View view =
|
||||||
|
inflater.inflate(mSeekBarPreference.getLayoutResource(),
|
||||||
|
new LinearLayout(mContext), false);
|
||||||
|
mSeekBar = view.findViewById(com.android.internal.R.id.seekbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void seekBarPreferenceOnStopTrackingTouch_callsListener() {
|
||||||
|
mSeekBar.setProgress(2);
|
||||||
|
|
||||||
|
mSeekBarPreference.setOnPreferenceChangeStopListener(mListener);
|
||||||
|
mSeekBarPreference.onStopTrackingTouch(mSeekBar);
|
||||||
|
|
||||||
|
verify(mListener, times(1)).onPreferenceChange(mSeekBarPreference, 2);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,20 +20,19 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doCallRealMethod;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.accounts.AccountRestrictionHelper;
|
import com.android.settings.accounts.AccountRestrictionHelper;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.RestrictedSeekBarPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -47,10 +46,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
public class AdjustVolumeRestrictedPreferenceControllerTest {
|
public class AdjustVolumeRestrictedPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String KEY = "key";
|
private static final String KEY = "key";
|
||||||
private AccountRestrictionHelper mAccountHelper;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
UserManager mUserManager;
|
private AccountRestrictionHelper mAccountHelper;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AdjustVolumeRestrictedPreferenceControllerTestable mController;
|
private AdjustVolumeRestrictedPreferenceControllerTestable mController;
|
||||||
@@ -59,17 +56,15 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
|
||||||
mAccountHelper = new AccountRestrictionHelper(mContext);
|
|
||||||
mController =
|
mController =
|
||||||
new AdjustVolumeRestrictedPreferenceControllerTestable(mContext, mAccountHelper, KEY);
|
new AdjustVolumeRestrictedPreferenceControllerTestable(mContext, mAccountHelper, KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_hasBaseRestriction_shouldDisable() {
|
public void updateState_hasBaseRestriction_shouldDisable() {
|
||||||
RestrictedSeekBarPreference preference = mock(RestrictedSeekBarPreference.class);
|
RestrictedPreference preference = mock(RestrictedPreference.class);
|
||||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
when(mAccountHelper.hasBaseUserRestriction(
|
||||||
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId())).thenReturn(true);
|
eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
@@ -78,11 +73,13 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_NoBaseRestriction_shouldCheckRestriction() {
|
public void updateState_NoBaseRestriction_shouldCheckRestriction() {
|
||||||
RestrictedSeekBarPreference preference = spy(new RestrictedSeekBarPreference(mContext));
|
RestrictedPreference preference = spy(new RestrictedPreference(mContext));
|
||||||
|
|
||||||
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(null);
|
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(null);
|
||||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
when(mAccountHelper.hasBaseUserRestriction(
|
||||||
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId())).thenReturn(false);
|
eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt())).thenReturn(false);
|
||||||
|
doCallRealMethod().when(mAccountHelper).enforceRestrictionOnPreference(
|
||||||
|
eq(preference), eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt());
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
@@ -43,8 +43,8 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
import com.android.settingslib.media.LocalMediaManager;
|
import com.android.settingslib.media.LocalMediaManager;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@@ -28,6 +28,7 @@ import android.content.pm.ResolveInfo;
|
|||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.service.trust.TrustAgentService;
|
import android.service.trust.TrustAgentService;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
@@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||||
|
import static android.view.HapticFeedbackConstants.CONTEXT_CLICK;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
|
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;
|
||||||
|
private static final int MIN = 5;
|
||||||
|
private static final int PROGRESS = 16;
|
||||||
|
private static final int NEW_PROGRESS = 17;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private SeekBarPreference mSeekBarPreference;
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
|
||||||
|
mSeekBarPreference = spy(new SeekBarPreference(mContext));
|
||||||
|
mSeekBarPreference.setMax(MAX);
|
||||||
|
mSeekBarPreference.setMin(MIN);
|
||||||
|
mSeekBarPreference.setProgress(PROGRESS);
|
||||||
|
mSeekBarPreference.setPersistent(false);
|
||||||
|
mSeekBarPreference.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_NONE);
|
||||||
|
|
||||||
|
mSeekBar = new SeekBar(mContext);
|
||||||
|
mSeekBar.setMax(MAX);
|
||||||
|
mSeekBar.setMin(MIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveAndRestoreInstanceState() {
|
||||||
|
final Parcelable parcelable = mSeekBarPreference.onSaveInstanceState();
|
||||||
|
|
||||||
|
final SeekBarPreference preference = new SeekBarPreference(mContext);
|
||||||
|
preference.onRestoreInstanceState(parcelable);
|
||||||
|
|
||||||
|
assertThat(preference.getMax()).isEqualTo(MAX);
|
||||||
|
assertThat(preference.getMin()).isEqualTo(MIN);
|
||||||
|
assertThat(preference.getProgress()).isEqualTo(PROGRESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSelectable_disabledByAdmin_returnTrue() {
|
||||||
|
when(mSeekBarPreference.isDisabledByAdmin()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mSeekBarPreference.isSelectable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetSeekBarStateDescription() {
|
||||||
|
mSeekBarPreference.setSeekBarStateDescription("test");
|
||||||
|
|
||||||
|
verify(mSeekBarPreference).setSeekBarStateDescription("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onProgressChanged_hapticFeedbackModeNone_clockTickFeedbackNotPerformed() {
|
||||||
|
mSeekBar.setProgress(NEW_PROGRESS);
|
||||||
|
when(mSeekBarPreference.callChangeListener(anyInt())).thenReturn(true);
|
||||||
|
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
|
||||||
|
|
||||||
|
mSeekBarPreference.onProgressChanged(mSeekBar, NEW_PROGRESS, true);
|
||||||
|
|
||||||
|
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isNotEqualTo(CLOCK_TICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onProgressChanged_hapticFeedbackModeOnTicks_clockTickFeedbackPerformed() {
|
||||||
|
mSeekBarPreference.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
|
||||||
|
mSeekBar.setProgress(NEW_PROGRESS);
|
||||||
|
when(mSeekBarPreference.callChangeListener(anyInt())).thenReturn(true);
|
||||||
|
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
|
||||||
|
|
||||||
|
mSeekBarPreference.onProgressChanged(mSeekBar, NEW_PROGRESS, true);
|
||||||
|
|
||||||
|
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isEqualTo(CLOCK_TICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onProgressChanged_hapticFeedbackModeOnEnds_clockTickFeedbackNotPerformed() {
|
||||||
|
mSeekBarPreference.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_ENDS);
|
||||||
|
mSeekBar.setProgress(NEW_PROGRESS);
|
||||||
|
when(mSeekBarPreference.callChangeListener(anyInt())).thenReturn(true);
|
||||||
|
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
|
||||||
|
|
||||||
|
mSeekBarPreference.onProgressChanged(mSeekBar, NEW_PROGRESS, true);
|
||||||
|
|
||||||
|
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isNotEqualTo(CLOCK_TICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onProgressChanged_hapticFeedbackModeOnEndsAndMinValue_clockTickFeedbackPerformed() {
|
||||||
|
mSeekBarPreference.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_ENDS);
|
||||||
|
mSeekBar.setProgress(MIN);
|
||||||
|
when(mSeekBarPreference.callChangeListener(anyInt())).thenReturn(true);
|
||||||
|
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
|
||||||
|
|
||||||
|
mSeekBarPreference.onProgressChanged(mSeekBar, MIN, true);
|
||||||
|
|
||||||
|
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isEqualTo(CLOCK_TICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestFragment extends PreferenceFragmentCompat {
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
addPreferencesFromResource(com.android.settings.R.xml.seekbar_preference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -23,7 +23,7 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.slices.SliceData;
|
import com.android.settings.slices.SliceData;
|
||||||
import com.android.settingslib.widget.SeekBarPreference;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class DefaultIndicatorSeekBarTest {
|
||||||
|
|
||||||
|
private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mDefaultIndicatorSeekBar = new DefaultIndicatorSeekBar(
|
||||||
|
ApplicationProvider.getApplicationContext());
|
||||||
|
mDefaultIndicatorSeekBar.setMax(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
mDefaultIndicatorSeekBar = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultProgress_setSucceeds() {
|
||||||
|
mDefaultIndicatorSeekBar.setDefaultProgress(40);
|
||||||
|
assertEquals(40, mDefaultIndicatorSeekBar.getDefaultProgress());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user