Merge "Fix missing declared accessibility PreferenceControllers." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
094a73867c
@@ -6,6 +6,7 @@ aconfig_declarations {
|
|||||||
name: "aconfig_settings_flags",
|
name: "aconfig_settings_flags",
|
||||||
package: "com.android.settings.flags",
|
package: "com.android.settings.flags",
|
||||||
srcs: [
|
srcs: [
|
||||||
|
"settings_accessibility_flag_declarations.aconfig",
|
||||||
"settings_connecteddevice_flag_declarations.aconfig",
|
"settings_connecteddevice_flag_declarations.aconfig",
|
||||||
"settings_globalintl_flag_declarations.aconfig",
|
"settings_globalintl_flag_declarations.aconfig",
|
||||||
"settings_apn_flag_declarations.aconfig",
|
"settings_apn_flag_declarations.aconfig",
|
||||||
|
8
aconfig/settings_accessibility_flag_declarations.aconfig
Normal file
8
aconfig/settings_accessibility_flag_declarations.aconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package: "com.android.settings.flags"
|
||||||
|
|
||||||
|
flag {
|
||||||
|
name: "separate_accessibility_vibration_settings_fragments"
|
||||||
|
namespace: "accessibility"
|
||||||
|
description: "Splits VibrationSettings into two fragments, one per XML resource"
|
||||||
|
bug: "289967175"
|
||||||
|
}
|
@@ -49,13 +49,17 @@
|
|||||||
android:key="toggle_force_bold_text"
|
android:key="toggle_force_bold_text"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/force_bold_text"
|
android:title="@string/force_bold_text"
|
||||||
|
settings:controller=
|
||||||
|
"com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"
|
||||||
settings:keywords="@string/keywords_bold_text" />
|
settings:keywords="@string/keywords_bold_text" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_high_text_contrast_preference"
|
android:key="toggle_high_text_contrast_preference"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:summary="@string/accessibility_toggle_high_text_contrast_preference_summary"
|
android:summary="@string/accessibility_toggle_high_text_contrast_preference_summary"
|
||||||
android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
|
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
|
||||||
|
settings:controller=
|
||||||
|
"com.android.settings.accessibility.HighTextContrastPreferenceController" />
|
||||||
|
|
||||||
<com.android.settings.accessibility.TextReadingResetPreference
|
<com.android.settings.accessibility.TextReadingResetPreference
|
||||||
android:key="reset"
|
android:key="reset"
|
||||||
|
@@ -20,23 +20,23 @@
|
|||||||
android:title="@string/accessibility_vibration_settings_title">
|
android:title="@string/accessibility_vibration_settings_title">
|
||||||
|
|
||||||
<com.android.settingslib.widget.MainSwitchPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
android:key="vibration_main_switch"
|
android:key="vibration_intensity_switch_main"
|
||||||
android:title="@string/accessibility_vibration_primary_switch_title"
|
android:title="@string/accessibility_vibration_primary_switch_title"
|
||||||
app:keywords="@string/keywords_accessibility_vibration_primary_switch"
|
app:keywords="@string/keywords_accessibility_vibration_primary_switch"
|
||||||
app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>
|
app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_call_vibration_category"
|
android:key="vibration_intensity_category_call"
|
||||||
android:title="@string/accessibility_call_vibration_category_title">
|
android:title="@string/accessibility_call_vibration_category_title">
|
||||||
|
|
||||||
<com.android.settings.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="ring_vibration_preference_screen"
|
android:key="vibration_intensity_preference_ring"
|
||||||
android:title="@string/accessibility_ring_vibration_title"
|
android:title="@string/accessibility_ring_vibration_title"
|
||||||
app:keywords="@string/keywords_ring_vibration"
|
app:keywords="@string/keywords_ring_vibration"
|
||||||
app:controller="com.android.settings.accessibility.RingVibrationIntensityPreferenceController" />
|
app:controller="com.android.settings.accessibility.RingVibrationIntensityPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="ramping_ringer"
|
android:key="vibration_intensity_preference_ramping_ringer"
|
||||||
android:title="@string/vibrate_when_ringing_option_ramping_ringer"
|
android:title="@string/vibrate_when_ringing_option_ramping_ringer"
|
||||||
app:keywords="@string/keywords_ramping_ringer_vibration"
|
app:keywords="@string/keywords_ramping_ringer_vibration"
|
||||||
app:controller="com.android.settings.accessibility.VibrationRampingRingerTogglePreferenceController"/>
|
app:controller="com.android.settings.accessibility.VibrationRampingRingerTogglePreferenceController"/>
|
||||||
@@ -44,17 +44,17 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_notification_alarm_vibration_category"
|
android:key="vibration_intensity_category_notification_alarm"
|
||||||
android:title="@string/accessibility_notification_alarm_vibration_category_title">
|
android:title="@string/accessibility_notification_alarm_vibration_category_title">
|
||||||
|
|
||||||
<com.android.settings.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="notification_vibration_preference_screen"
|
android:key="vibration_intensity_preference_notification"
|
||||||
android:title="@string/accessibility_notification_vibration_title"
|
android:title="@string/accessibility_notification_vibration_title"
|
||||||
app:keywords="@string/keywords_notification_vibration"
|
app:keywords="@string/keywords_notification_vibration"
|
||||||
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
|
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
|
||||||
|
|
||||||
<com.android.settings.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="alarm_vibration_preference_screen"
|
android:key="vibration_intensity_preference_alarm"
|
||||||
android:title="@string/accessibility_alarm_vibration_title"
|
android:title="@string/accessibility_alarm_vibration_title"
|
||||||
app:keywords="@string/keywords_alarm_vibration"
|
app:keywords="@string/keywords_alarm_vibration"
|
||||||
app:controller="com.android.settings.accessibility.AlarmVibrationIntensityPreferenceController" />
|
app:controller="com.android.settings.accessibility.AlarmVibrationIntensityPreferenceController" />
|
||||||
@@ -62,17 +62,17 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_interactive_haptics_category"
|
android:key="vibration_intensity_category_haptics"
|
||||||
android:title="@string/accessibility_interactive_haptics_category_title">
|
android:title="@string/accessibility_interactive_haptics_category_title">
|
||||||
|
|
||||||
<com.android.settings.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="touch_vibration_preference_screen"
|
android:key="vibration_intensity_preference_touch"
|
||||||
android:title="@string/accessibility_touch_vibration_title"
|
android:title="@string/accessibility_touch_vibration_title"
|
||||||
app:keywords="@string/keywords_touch_vibration"
|
app:keywords="@string/keywords_touch_vibration"
|
||||||
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
|
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
|
||||||
|
|
||||||
<com.android.settings.widget.SeekBarPreference
|
<com.android.settings.widget.SeekBarPreference
|
||||||
android:key="media_vibration_preference_screen"
|
android:key="vibration_intensity_preference_media"
|
||||||
android:title="@string/accessibility_media_vibration_title"
|
android:title="@string/accessibility_media_vibration_title"
|
||||||
app:keywords="@string/keywords_media_vibration"
|
app:keywords="@string/keywords_media_vibration"
|
||||||
app:controller="com.android.settings.accessibility.MediaVibrationIntensityPreferenceController" />
|
app:controller="com.android.settings.accessibility.MediaVibrationIntensityPreferenceController" />
|
||||||
|
@@ -20,23 +20,23 @@
|
|||||||
android:title="@string/accessibility_vibration_settings_title">
|
android:title="@string/accessibility_vibration_settings_title">
|
||||||
|
|
||||||
<com.android.settingslib.widget.MainSwitchPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
android:key="vibration_main_switch"
|
android:key="vibration_switch_main"
|
||||||
android:title="@string/accessibility_vibration_primary_switch_title"
|
android:title="@string/accessibility_vibration_primary_switch_title"
|
||||||
app:keywords="@string/keywords_accessibility_vibration_primary_switch"
|
app:keywords="@string/keywords_accessibility_vibration_primary_switch"
|
||||||
app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>
|
app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_call_vibration_category"
|
android:key="vibration_category_call"
|
||||||
android:title="@string/accessibility_call_vibration_category_title">
|
android:title="@string/accessibility_call_vibration_category_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="ring_vibration_preference_screen"
|
android:key="vibration_preference_ring"
|
||||||
android:title="@string/accessibility_ring_vibration_title"
|
android:title="@string/accessibility_ring_vibration_title"
|
||||||
app:keywords="@string/keywords_ring_vibration"
|
app:keywords="@string/keywords_ring_vibration"
|
||||||
app:controller="com.android.settings.accessibility.RingVibrationTogglePreferenceController" />
|
app:controller="com.android.settings.accessibility.RingVibrationTogglePreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="ramping_ringer"
|
android:key="vibration_preference_ramping_ringer"
|
||||||
android:title="@string/vibrate_when_ringing_option_ramping_ringer"
|
android:title="@string/vibrate_when_ringing_option_ramping_ringer"
|
||||||
app:keywords="@string/keywords_ramping_ringer_vibration"
|
app:keywords="@string/keywords_ramping_ringer_vibration"
|
||||||
app:controller="com.android.settings.accessibility.VibrationRampingRingerTogglePreferenceController"/>
|
app:controller="com.android.settings.accessibility.VibrationRampingRingerTogglePreferenceController"/>
|
||||||
@@ -44,17 +44,17 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_notification_alarm_vibration_category"
|
android:key="vibration_category_notification_alarm"
|
||||||
android:title="@string/accessibility_notification_alarm_vibration_category_title">
|
android:title="@string/accessibility_notification_alarm_vibration_category_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="notification_vibration_preference_screen"
|
android:key="vibration_preference_notification"
|
||||||
android:title="@string/accessibility_notification_vibration_title"
|
android:title="@string/accessibility_notification_vibration_title"
|
||||||
app:keywords="@string/keywords_notification_vibration"
|
app:keywords="@string/keywords_notification_vibration"
|
||||||
app:controller="com.android.settings.accessibility.NotificationVibrationTogglePreferenceController" />
|
app:controller="com.android.settings.accessibility.NotificationVibrationTogglePreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="alarm_vibration_preference_screen"
|
android:key="vibration_preference_alarm"
|
||||||
android:title="@string/accessibility_alarm_vibration_title"
|
android:title="@string/accessibility_alarm_vibration_title"
|
||||||
app:keywords="@string/keywords_alarm_vibration"
|
app:keywords="@string/keywords_alarm_vibration"
|
||||||
app:controller="com.android.settings.accessibility.AlarmVibrationTogglePreferenceController" />
|
app:controller="com.android.settings.accessibility.AlarmVibrationTogglePreferenceController" />
|
||||||
@@ -62,17 +62,17 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="accessibility_interactive_haptics_category"
|
android:key="vibration_category_haptics"
|
||||||
android:title="@string/accessibility_interactive_haptics_category_title">
|
android:title="@string/accessibility_interactive_haptics_category_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="touch_vibration_preference_screen"
|
android:key="vibration_preference_touch"
|
||||||
android:title="@string/accessibility_touch_vibration_title"
|
android:title="@string/accessibility_touch_vibration_title"
|
||||||
app:keywords="@string/keywords_touch_vibration"
|
app:keywords="@string/keywords_touch_vibration"
|
||||||
app:controller="com.android.settings.accessibility.HapticFeedbackTogglePreferenceController" />
|
app:controller="com.android.settings.accessibility.HapticFeedbackTogglePreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="media_vibration_preference_screen"
|
android:key="vibration_preference_media"
|
||||||
android:title="@string/accessibility_media_vibration_title"
|
android:title="@string/accessibility_media_vibration_title"
|
||||||
app:keywords="@string/keywords_media_vibration"
|
app:keywords="@string/keywords_media_vibration"
|
||||||
app:controller="com.android.settings.accessibility.MediaVibrationTogglePreferenceController" />
|
app:controller="com.android.settings.accessibility.MediaVibrationTogglePreferenceController" />
|
||||||
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.accessibility;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Vibrator;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
/** Accessibility settings for the vibration. */
|
||||||
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
|
public class VibrationIntensitySettingsFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "VibrationIntensitySettings";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.ACCESSIBILITY_VIBRATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_uri_accessibility_vibration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.accessibility_vibration_intensity_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isPageSearchEnabled(Context context) {
|
||||||
|
final int supportedIntensityLevels = context.getResources().getInteger(
|
||||||
|
R.integer.config_vibration_supported_intensity_levels);
|
||||||
|
final boolean hasVibrator = context.getSystemService(Vibrator.class).hasVibrator();
|
||||||
|
if (Flags.separateAccessibilityVibrationSettingsFragments()) {
|
||||||
|
return hasVibrator && supportedIntensityLevels > 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
final Resources res = view.getResources();
|
||||||
|
final RecyclerView rv = getListView();
|
||||||
|
if (rv != null) {
|
||||||
|
final int bottom_padding = res.getDimensionPixelSize(
|
||||||
|
com.android.settingslib.widget.theme.R.dimen
|
||||||
|
.settingslib_listPreferredItemPaddingEnd);
|
||||||
|
rv.setPaddingRelative(rv.getPaddingStart(), rv.getPaddingTop(), rv.getPaddingEnd(),
|
||||||
|
rv.getPaddingBottom() + bottom_padding);
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.accessibility_vibration_intensity_settings) {
|
||||||
|
@Override
|
||||||
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
|
return VibrationIntensitySettingsFragment.isPageSearchEnabled(context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@@ -21,9 +21,15 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
/** Controller for "Vibration & haptics" settings page. */
|
/** Controller for "Vibration & haptics" settings page. */
|
||||||
public class VibrationPreferenceController extends BasePreferenceController {
|
public class VibrationPreferenceController extends BasePreferenceController {
|
||||||
@@ -49,4 +55,29 @@ public class VibrationPreferenceController extends BasePreferenceController {
|
|||||||
? R.string.accessibility_vibration_settings_state_on
|
? R.string.accessibility_vibration_settings_state_on
|
||||||
: R.string.accessibility_vibration_settings_state_off);
|
: R.string.accessibility_vibration_settings_state_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void launchVibrationSettingsFragment(Class klass) {
|
||||||
|
new SubSettingLauncher(mContext)
|
||||||
|
.setSourceMetricsCategory(getMetricsCategory())
|
||||||
|
.setDestination(klass.getName())
|
||||||
|
.launch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
if (Flags.separateAccessibilityVibrationSettingsFragments()
|
||||||
|
&& TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
|
if (mContext.getResources().getInteger(
|
||||||
|
R.integer.config_vibration_supported_intensity_levels) > 1) {
|
||||||
|
launchVibrationSettingsFragment(VibrationIntensitySettingsFragment.class);
|
||||||
|
} else {
|
||||||
|
launchVibrationSettingsFragment(VibrationSettings.class);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.handlePreferenceTreeClick(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,10 +26,12 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
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.flags.Flags;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
@@ -43,6 +45,9 @@ public class VibrationSettings extends DashboardFragment {
|
|||||||
private static final String TAG = "VibrationSettings";
|
private static final String TAG = "VibrationSettings";
|
||||||
|
|
||||||
private static int getVibrationXmlResourceId(Context context) {
|
private static int getVibrationXmlResourceId(Context context) {
|
||||||
|
if (Flags.separateAccessibilityVibrationSettingsFragments()) {
|
||||||
|
return R.xml.accessibility_vibration_settings;
|
||||||
|
}
|
||||||
final int supportedIntensities = context.getResources().getInteger(
|
final int supportedIntensities = context.getResources().getInteger(
|
||||||
R.integer.config_vibration_supported_intensity_levels);
|
R.integer.config_vibration_supported_intensity_levels);
|
||||||
return supportedIntensities > 1
|
return supportedIntensities > 1
|
||||||
@@ -74,6 +79,9 @@ public class VibrationSettings extends DashboardFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
if (Flags.separateAccessibilityVibrationSettingsFragments()) {
|
||||||
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
}
|
||||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
final RecyclerView rv = getListView();
|
final RecyclerView rv = getListView();
|
||||||
final Resources res = view.getResources();
|
final Resources res = view.getResources();
|
||||||
@@ -88,12 +96,23 @@ public class VibrationSettings extends DashboardFragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isPageSearchEnabled(Context context) {
|
||||||
|
final int supportedIntensityLevels = context.getResources().getInteger(
|
||||||
|
R.integer.config_vibration_supported_intensity_levels);
|
||||||
|
final boolean hasVibrator = context.getSystemService(Vibrator.class).hasVibrator();
|
||||||
|
if (Flags.separateAccessibilityVibrationSettingsFragments()) {
|
||||||
|
return hasVibrator && supportedIntensityLevels == 1;
|
||||||
|
} else {
|
||||||
|
return hasVibrator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return context.getSystemService(Vibrator.class).hasVibrator();
|
return VibrationSettings.isPageSearchEnabled(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
com.android.settings.accessibility.AccessibilitySlicePreferenceController
|
com.android.settings.accessibility.AccessibilitySlicePreferenceController
|
||||||
|
com.android.settings.accessibility.MagnificationAlwaysOnPreferenceController
|
||||||
|
com.android.settings.accessibility.MagnificationFollowTypingPreferenceController
|
||||||
|
com.android.settings.accessibility.MagnificationJoystickPreferenceController
|
||||||
com.android.settings.accessibility.ReduceBrightColorsIntensityPreferenceController
|
com.android.settings.accessibility.ReduceBrightColorsIntensityPreferenceController
|
||||||
com.android.settings.accessibility.ReduceBrightColorsPersistencePreferenceController
|
com.android.settings.accessibility.ReduceBrightColorsPersistencePreferenceController
|
||||||
com.android.settings.biometrics.face.FaceSettingsAttentionPreferenceController
|
com.android.settings.biometrics.face.FaceSettingsAttentionPreferenceController
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.accessibility;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link VibrationIntensitySettingsFragment}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||||
|
public class VibrationIntensitySettingsFragmentTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
private VibrationIntensitySettingsFragment mFragment;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
mFragment = new VibrationIntensitySettingsFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMetricsCategory_returnsCorrectCategory() {
|
||||||
|
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||||
|
SettingsEnums.ACCESSIBILITY_VIBRATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getHelpResource_returnsCorrectString() {
|
||||||
|
assertThat(mFragment.getHelpResource()).isEqualTo(
|
||||||
|
R.string.help_uri_accessibility_vibration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPreferenceScreenResId_returnsCorrectXml() {
|
||||||
|
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
|
||||||
|
R.xml.accessibility_vibration_intensity_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLogTag_returnsCorrectTag() {
|
||||||
|
assertThat(mFragment.getLogTag()).isEqualTo("VibrationIntensitySettings");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPageSearchEnabled_oneIntensityLevel_returnsFalse() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(1);
|
||||||
|
assertThat(VibrationIntensitySettingsFragment.isPageSearchEnabled(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPageSearchEnabled_multipleIntensityLevels_returnsTrue() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(2);
|
||||||
|
assertThat(VibrationIntensitySettingsFragment.isPageSearchEnabled(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
}
|
@@ -18,14 +18,20 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
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.content.res.Resources;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -33,8 +39,10 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -44,6 +52,9 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VibrationPreferenceControllerTest {
|
public class VibrationPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
private static final String PREFERENCE_KEY = "preference_key";
|
private static final String PREFERENCE_KEY = "preference_key";
|
||||||
private static final int OFF = 0;
|
private static final int OFF = 0;
|
||||||
private static final int ON = 1;
|
private static final int ON = 1;
|
||||||
@@ -52,13 +63,17 @@ public class VibrationPreferenceControllerTest {
|
|||||||
@Mock private PreferenceScreen mScreen;
|
@Mock private PreferenceScreen mScreen;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private Resources mResources;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||||
|
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -85,7 +100,6 @@ public class VibrationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_vibrateSettingNotSet_returnsOnText() {
|
public void getSummary_vibrateSettingNotSet_returnsOnText() {
|
||||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.VIBRATE_ON,
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.VIBRATE_ON,
|
||||||
/* value= */ null);
|
/* value= */ null);
|
||||||
VibrationPreferenceController controller = createPreferenceController();
|
VibrationPreferenceController controller = createPreferenceController();
|
||||||
@@ -97,7 +111,6 @@ public class VibrationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_vibrateSettingOn_returnsOnText() {
|
public void getSummary_vibrateSettingOn_returnsOnText() {
|
||||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
|
||||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, ON);
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, ON);
|
||||||
VibrationPreferenceController controller = createPreferenceController();
|
VibrationPreferenceController controller = createPreferenceController();
|
||||||
controller.updateState(mPreference);
|
controller.updateState(mPreference);
|
||||||
@@ -108,7 +121,6 @@ public class VibrationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_vibrateSettingOff_returnsOffText() {
|
public void getSummary_vibrateSettingOff_returnsOffText() {
|
||||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
|
||||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, OFF);
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, OFF);
|
||||||
VibrationPreferenceController controller = createPreferenceController();
|
VibrationPreferenceController controller = createPreferenceController();
|
||||||
controller.updateState(mPreference);
|
controller.updateState(mPreference);
|
||||||
@@ -117,11 +129,39 @@ public class VibrationPreferenceControllerTest {
|
|||||||
mContext.getString(R.string.accessibility_vibration_settings_state_off));
|
mContext.getString(R.string.accessibility_vibration_settings_state_off));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||||
|
public void handlePreferenceTreeClick_oneIntensityLevel_opensVibrationSettings() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(1);
|
||||||
|
VibrationPreferenceController controller = spy(createPreferenceController());
|
||||||
|
|
||||||
|
doNothing().when(controller).launchVibrationSettingsFragment(any());
|
||||||
|
controller.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
|
verify(controller).launchVibrationSettingsFragment(eq(VibrationSettings.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||||
|
public void handlePreferenceTreeClick_multipleIntensityLevels_opensVibrationIntensity() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(2);
|
||||||
|
VibrationPreferenceController controller = spy(createPreferenceController());
|
||||||
|
|
||||||
|
doNothing().when(controller).launchVibrationSettingsFragment(any());
|
||||||
|
controller.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
|
verify(controller).launchVibrationSettingsFragment(
|
||||||
|
eq(VibrationIntensitySettingsFragment.class));
|
||||||
|
}
|
||||||
|
|
||||||
private VibrationPreferenceController createPreferenceController() {
|
private VibrationPreferenceController createPreferenceController() {
|
||||||
VibrationPreferenceController controller =
|
VibrationPreferenceController controller =
|
||||||
new VibrationPreferenceController(mContext, PREFERENCE_KEY);
|
new VibrationPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
mPreference.setSummary("Test summary");
|
mPreference.setSummary("Test summary");
|
||||||
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference);
|
when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference);
|
||||||
controller.displayPreference(mScreen);
|
controller.displayPreference(mScreen);
|
||||||
return controller;
|
return controller;
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.accessibility;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link VibrationSettings} fragment. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||||
|
public class VibrationSettingsTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
private VibrationSettings mFragment;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
mFragment = new VibrationSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMetricsCategory_returnsCorrectCategory() {
|
||||||
|
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||||
|
SettingsEnums.ACCESSIBILITY_VIBRATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getHelpResource_returnsCorrectString() {
|
||||||
|
assertThat(mFragment.getHelpResource()).isEqualTo(
|
||||||
|
R.string.help_uri_accessibility_vibration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPreferenceScreenResId_returnsCorrectXml() {
|
||||||
|
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
|
||||||
|
R.xml.accessibility_vibration_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLogTag_returnsCorrectTag() {
|
||||||
|
assertThat(mFragment.getLogTag()).isEqualTo("VibrationSettings");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPageSearchEnabled_oneIntensityLevel_returnsTrue() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(1);
|
||||||
|
assertThat(VibrationSettings.isPageSearchEnabled(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPageSearchEnabled_multipleIntensityLevels_returnsFalse() {
|
||||||
|
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||||
|
.thenReturn(2);
|
||||||
|
assertThat(VibrationSettings.isPageSearchEnabled(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user