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

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

Merge "Add primary switch for vibration settings screen"

parents 423ea182 fd54fc34
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -5461,6 +5461,8 @@
    <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 primary switch preference for enabling device vibrations. [CHAR LIMIT=NONE] -->
    <string name="accessibility_vibration_primary_switch_title">Use vibration &amp; haptics</string>
    <!-- Title for preference for configuring alarm vibrations. [CHAR LIMIT=NONE] -->
    <string name="accessibility_alarm_vibration_title">Alarm vibration</string>
    <!-- Title for preference for configuring media vibrations (e.g. vibrations played together with animations, music, videos, etc). [CHAR LIMIT=NONE] -->
@@ -8251,6 +8253,8 @@
    <!-- List of synonyms for hotspot and tethering setting (where you share your wifi with other devices), used to match in settings search [CHAR LIMIT=NONE] -->
    <string name="keywords_hotspot_tethering">usb tether, bluetooth tether, wifi hotspot</string>
    <!-- List of synonyms for device vibration primary setting, used to match in settings search [CHAR LIMIT=NONE] -->
    <string name="keywords_accessibility_vibration_primary_switch">haptics, vibrate, vibration</string>
    <!-- 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] -->
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,12 @@
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:title="@string/accessibility_vibration_settings_title">

    <com.android.settingslib.widget.MainSwitchPreference
        android:key="vibration_main_switch"
        android:title="@string/accessibility_vibration_primary_switch_title"
        app:keywords="@string/keywords_accessibility_vibration_primary_switch"
        app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>

    <PreferenceCategory
        android:key="accessibility_call_vibration_category"
        android:title="@string/accessibility_call_vibration_category_title">
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,12 @@
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:title="@string/accessibility_vibration_settings_title">

    <com.android.settingslib.widget.MainSwitchPreference
        android:key="vibration_main_switch"
        android:title="@string/accessibility_vibration_primary_switch_title"
        app:keywords="@string/keywords_accessibility_vibration_primary_switch"
        app:controller="com.android.settings.accessibility.VibrationMainSwitchPreferenceController"/>

    <PreferenceCategory
        android:key="accessibility_call_vibration_category"
        android:title="@string/accessibility_call_vibration_category_title">
+0 −45
Original line number Diff line number Diff line
@@ -16,57 +16,12 @@

package com.android.settings.accessibility;

import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;

import android.content.Context;
import android.media.AudioManager;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;

/** Preference controller for ringtone vibration intensity */
public class RingVibrationIntensityPreferenceController
        extends VibrationIntensityPreferenceController {

    /** General configuration for ringtone vibration intensity settings. */
    public static final class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
        private final AudioManager mAudioManager;

        public RingVibrationPreferenceConfig(Context context) {
            super(context, Settings.System.RING_VIBRATION_INTENSITY,
                    VibrationAttributes.USAGE_RINGTONE);
            mAudioManager = context.getSystemService(AudioManager.class);
        }

        @Override
        public int readIntensity() {
            final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
                    Settings.System.VIBRATE_WHEN_RINGING, ON);

            if ((vibrateWhenRinging == OFF)
                    && !mAudioManager.isRampingRingerEnabled()) {
                // VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
                // turned it off and has not enabled the ramping ringer (old three-state setting).
                return Vibrator.VIBRATION_INTENSITY_OFF;
            }

            return super.readIntensity();
        }

        @Override
        public boolean updateIntensity(int intensity) {
            final boolean success = super.updateIntensity(intensity);

            // VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
            // Ramping ringer is independent of the ring intensity and should not be affected.
            Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
                    (intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);

            return success;
        }
    }

    public RingVibrationIntensityPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey, new RingVibrationPreferenceConfig(context));
    }
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;

import android.content.Context;
import android.media.AudioManager;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;

/** General configuration for ringtone vibration intensity settings. */
public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
    private final AudioManager mAudioManager;

    public RingVibrationPreferenceConfig(Context context) {
        super(context, Settings.System.RING_VIBRATION_INTENSITY,
                VibrationAttributes.USAGE_RINGTONE);
        mAudioManager = context.getSystemService(AudioManager.class);
    }

    @Override
    public int readIntensity() {
        final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
                Settings.System.VIBRATE_WHEN_RINGING, ON);

        if ((vibrateWhenRinging == OFF)
                && !mAudioManager.isRampingRingerEnabled()) {
            // VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
            // turned it off and has not enabled the ramping ringer (old three-state setting).
            return Vibrator.VIBRATION_INTENSITY_OFF;
        }

        return super.readIntensity();
    }

    @Override
    public boolean updateIntensity(int intensity) {
        final boolean success = super.updateIntensity(intensity);

        // VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
        // Ramping ringer is independent of the ring intensity and should not be affected.
        Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
                (intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);

        return success;
    }
}
Loading