Merge "Move vibrate for calls setting to "Vibration & haptics" screen"

This commit is contained in:
TreeHugger Robot
2021-12-20 11:26:34 +00:00
committed by Android (Google) Code Review
9 changed files with 62 additions and 234 deletions

View File

@@ -5553,11 +5553,17 @@
<!-- Description for the seekbar that adjust auto click time. [CHAR_LIMIT=NONE] -->
<string name="accessibility_autoclick_seekbar_desc">Auto click time</string>
<!-- Title for accessibility preference screen for configuring vibrations. -->
<string name="accessibility_vibration_settings_title">Vibration &amp; haptic strength</string>
<!-- Title for accessibility preference for configuring notification vibrations. -->
<string name="accessibility_notification_vibration_title">Notification vibration</string>
<string name="accessibility_vibration_settings_title">Vibration &amp; haptics</string>
<!-- Title for the category of preferences to configure device vibrations related to calls. [CHAR LIMIT=NONE] -->
<string name="accessibility_call_vibration_category_title">Calls</string>
<!-- Title for the category of preferences to configure device vibrations related to notifications and alarms. [CHAR LIMIT=NONE] -->
<string name="accessibility_notification_alarm_vibration_category_title">Notifications and alarms</string>
<!-- Title for the category of preferences to configure device vibrations triggered by user interaction with the device. [CHAR LIMIT=NONE] -->
<string name="accessibility_interactive_haptics_category_title">Interactive haptics</string>
<!-- Title for accessibility preference for configuring ring vibrations. [CHAR LIMIT=NONE] -->
<string name="accessibility_ring_vibration_title">Ring vibration</string>
<!-- Title for accessibility preference for configuring notification vibrations. -->
<string name="accessibility_notification_vibration_title">Notification vibration</string>
<!-- Title for accessibility preference for configuring touch feedback vibrations. -->
<string name="accessibility_touch_vibration_title">Touch feedback</string>
<!-- Used in the accessibility service settings to control turning on/off the service entirely [CHAR LIMIT=60] -->
@@ -8269,8 +8275,6 @@
<string name="keywords_wifi_notify_open_networks">Wi\u2011Fi notification, wifi notification</string>
<!-- Search keyword for "Wi-fi data usage" settings. [CHAR_LIMIT=NONE]-->
<string name="keywords_wifi_data_usage">data usage</string>
<!-- Search keyword for "Vibrate on touch" settings. [CHAR_LIMIT=NONE]-->
<string name="keywords_vibrate_on_touch">Stop vibration, tap, keyboard</string>
<!-- Search keyword for "Time format" settings. [CHAR_LIMIT=NONE]-->
<string name="keywords_time_format">Use 24-hour format</string>
<!-- Search keyword for "Files" settings under Settings > Storage. [CHAR_LIMIT=NONE]-->
@@ -8406,11 +8410,12 @@
<!-- List of synonyms for touch vibration setting (where you get a haptic response for touching things on the screen), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_touch_vibration">haptics, vibrate, screen, sensitivity</string>
<!-- List of synonyms for ring vibration setting (changes whether your phone vibrates when it rings), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_ring_vibration">haptics, vibrate, phone, call, sensitivity, ring</string>
<!-- List of synonyms for notification vibration setting (changes whether your phone vibrates when it shows a notification), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_notification_vibration">haptics, vibrate, sensitivity</string>
<!-- List of synonyms for vibration and haptics setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_vibration">haptics, vibrate, vibration</string>
<!-- Battery Saver: Search terms for sticky battery saver preference [CHAR_LIMIT=NONE] -->
<string name="keywords_battery_saver_sticky">battery saver, sticky, persist, power saver, battery</string>
<!-- Battery Saver: Search terms for battery saver schedule preference. Feel free to add additional terms when translating if appropriate [CHAR_LIMIT=NONE] -->
@@ -8522,12 +8527,6 @@
<!-- Sound: Other sounds: Title for the option enabling touch sounds. [CHAR LIMIT=30] -->
<string name="touch_sounds_title">Touch sounds</string>
<!-- Sound: Other sounds: Title for the option enabling haptic feedback on touch. [CHAR LIMIT=30] -->
<string name="vibrate_on_touch_title">Touch vibration</string>
<!-- Sound: Other sounds: Preference summary to the option enabling haptic feedback on touch. -->
<string name="vibrate_on_touch_summary">Haptic feedback for tap, keyboard, and more</string>
<!-- Sound: Other sounds: Title for the option enabling dock audio media. [CHAR LIMIT=50] -->
<string name="dock_audio_media_title">Dock speaker plays</string>

View File

@@ -100,7 +100,8 @@
android:icon="@drawable/ic_vibration"
android:persistent="false"
android:title="@string/accessibility_vibration_settings_title"
settings:controller="com.android.settings.accessibility.VibrationPreferenceController"/>
settings:controller="com.android.settings.accessibility.VibrationPreferenceController"
settings:keywords="@string/keywords_vibration"/>
</PreferenceCategory>

View File

@@ -20,24 +20,49 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/accessibility_vibration_settings_title">
<Preference
android:fragment="com.android.settings.accessibility.RingVibrationPreferenceFragment"
android:key="ring_vibration_preference_screen"
android:title="@string/accessibility_ring_vibration_title"
settings:keywords="@string/keywords_ring_vibration"
app:controller="com.android.settings.accessibility.RingVibrationIntensityPreferenceController" />
<PreferenceCategory
android:key="accessibility_call_vibration_category"
android:title="@string/accessibility_call_vibration_category_title">
<Preference
android:fragment="com.android.settings.accessibility.NotificationVibrationPreferenceFragment"
android:key="notification_vibration_preference_screen"
android:title="@string/accessibility_notification_vibration_title"
settings:keywords="@string/keywords_notification_vibration"
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
<Preference
android:fragment="com.android.settings.accessibility.RingVibrationPreferenceFragment"
android:key="ring_vibration_preference_screen"
android:title="@string/accessibility_ring_vibration_title"
settings:keywords="@string/keywords_ring_vibration"
app:controller="com.android.settings.accessibility.RingVibrationIntensityPreferenceController" />
<Preference
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
android:key="vibrate_for_calls"
android:title="@string/vibrate_when_ringing_title"
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"/>
</PreferenceCategory>
<PreferenceCategory
android:key="accessibility_notification_alarm_vibration_category"
android:title="@string/accessibility_notification_alarm_vibration_category_title">
<Preference
android:fragment="com.android.settings.accessibility.NotificationVibrationPreferenceFragment"
android:key="notification_vibration_preference_screen"
android:title="@string/accessibility_notification_vibration_title"
settings:keywords="@string/keywords_notification_vibration"
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
</PreferenceCategory>
<PreferenceCategory
android:key="accessibility_interactive_haptics_category"
android:title="@string/accessibility_interactive_haptics_category_title">
<Preference
android:fragment="com.android.settings.accessibility.TouchVibrationPreferenceFragment"
android:key="touch_vibration_preference_screen"
android:title="@string/accessibility_touch_vibration_title"
settings:keywords="@string/keywords_touch_vibration"
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
</PreferenceCategory>
<Preference
android:fragment="com.android.settings.accessibility.TouchVibrationPreferenceFragment"
android:key="touch_vibration_preference_screen"
android:title="@string/accessibility_touch_vibration_title"
settings:keywords="@string/keywords_touch_vibration"
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
</PreferenceScreen>

View File

@@ -44,12 +44,6 @@
android:key="touch_sounds"
android:title="@string/touch_sounds_title" />
<!-- Vibrate on touch -->
<SwitchPreference
android:key="vibrate_on_touch"
android:title="@string/vibrate_on_touch_title"
android:summary="@string/vibrate_on_touch_summary" />
<!-- Dock speaker plays -->
<DropDownPreference
android:key="dock_audio_media"

View File

@@ -119,14 +119,14 @@
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
settings:keywords="@string/keywords_media_controls"/>
<!-- Also vibrate for calls -->
<!-- Also vibration -->
<Preference
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
android:key="vibrate_for_calls"
android:title="@string/vibrate_when_ringing_title"
android:fragment="com.android.settings.accessibility.VibrationSettings"
android:key="vibration_and_haptics"
android:title="@string/accessibility_vibration_settings_title"
android:order="-90"
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
settings:keywords="@string/keywords_vibrate_for_calls"/>
settings:controller="com.android.settings.accessibility.VibrationPreferenceController"
settings:keywords="@string/keywords_vibration"/>
<com.android.settingslib.PrimarySwitchPreference
android:key="gesture_prevent_ringing_sound"
@@ -191,14 +191,6 @@
android:title="@string/touch_sounds_title"
android:order="-30"/>
<!-- Vibrate on touch -->
<SwitchPreference
android:key="vibrate_on_touch"
android:title="@string/vibrate_on_touch_title"
android:summary="@string/vibrate_on_touch_summary"
settings:keywords="@string/keywords_vibrate_on_touch"
android:order="-25"/>
<!-- Dock speaker plays -->
<DropDownPreference
android:key="dock_audio_media"

View File

@@ -256,8 +256,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
new DockingSoundPreferenceController(context, fragment, lifecycle);
final TouchSoundPreferenceController touchSoundPreferenceController =
new TouchSoundPreferenceController(context, fragment, lifecycle);
final VibrateOnTouchPreferenceController vibrateOnTouchPreferenceController =
new VibrateOnTouchPreferenceController(context, fragment, lifecycle);
final DockAudioMediaPreferenceController dockAudioMediaPreferenceController =
new DockAudioMediaPreferenceController(context, fragment, lifecycle);
final BootSoundPreferenceController bootSoundPreferenceController =
@@ -270,7 +268,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
controllers.add(chargingSoundPreferenceController);
controllers.add(dockingSoundPreferenceController);
controllers.add(touchSoundPreferenceController);
controllers.add(vibrateOnTouchPreferenceController);
controllers.add(dockAudioMediaPreferenceController);
controllers.add(bootSoundPreferenceController);
controllers.add(emergencyTonePreferenceController);
@@ -281,7 +278,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
chargingSoundPreferenceController,
dockingSoundPreferenceController,
touchSoundPreferenceController,
vibrateOnTouchPreferenceController,
dockAudioMediaPreferenceController,
bootSoundPreferenceController,
emergencyTonePreferenceController)));

View File

@@ -1,50 +0,0 @@
/*
* 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.notification;
import static com.android.settings.notification.SettingPref.TYPE_SYSTEM;
import android.content.Context;
import android.os.Vibrator;
import android.provider.Settings.System;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class VibrateOnTouchPreferenceController extends SettingPrefController {
private static final String KEY_VIBRATE_ON_TOUCH = "vibrate_on_touch";
public VibrateOnTouchPreferenceController(Context context, SettingsPreferenceFragment parent,
Lifecycle lifecycle) {
super(context, parent, lifecycle);
mPreference = new SettingPref(
TYPE_SYSTEM, KEY_VIBRATE_ON_TOUCH, System.HAPTIC_FEEDBACK_ENABLED, 0) {
@Override
public boolean isApplicable(Context context) {
return hasHaptic(context);
}
};
}
private static boolean hasHaptic(Context context) {
final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
return vibrator != null && vibrator.hasVibrator();
}
}

View File

@@ -1,121 +0,0 @@
/*
* 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.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Vibrator;
import android.provider.Settings.System;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
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 VibrateOnTouchPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
@Mock
private FragmentActivity mActivity;
@Mock
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
@Mock
private Context mContext;
@Mock
private Vibrator mVibrator;
private VibrateOnTouchPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mActivity.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
when(mVibrator.hasVibrator()).thenReturn(true);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(RuntimeEnvironment.application);
mController = new VibrateOnTouchPreferenceController(mContext, mSetting, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
doReturn(mScreen).when(mSetting).getPreferenceScreen();
}
@Test
public void isAvailable_hasHaptic_shouldReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_noHaptic_shouldReturnFalse() {
when(mVibrator.hasVibrator()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_hapticEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1);
mController.displayPreference(mScreen);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void displayPreference_hapticDisabled_shouldUncheckedPreference() {
System.putInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 0);
mController.displayPreference(mScreen);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void onPreferenceChanged_preferenceChecked_shouldEnabledHaptic() {
mController.displayPreference(mScreen);
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
assertThat(System.getInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1)).isEqualTo(1);
}
@Test
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledHaptic() {
mController.displayPreference(mScreen);
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
assertThat(System.getInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1)).isEqualTo(0);
}
}

View File

@@ -153,14 +153,6 @@ public class SoundSettingsTest extends InstrumentationTestCase {
"Touch sounds", Settings.System.SOUND_EFFECTS_ENABLED));
}
@MediumTest
public void testOtherSoundsVibrateOnTap() throws Exception {
loadOtherSoundsPage();
assertTrue("Vibrate on tap not toggled",
mHelper.verifyToggleSetting(SettingsType.SYSTEM, PAGE,
"Vibrate on tap", Settings.System.HAPTIC_FEEDBACK_ENABLED));
}
private void loadOtherSoundsPage() throws Exception {
launchSoundSettings();
mHelper.scrollVert(false);