1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settings.accessibility; 17 18 import android.graphics.drawable.Drawable; 19 import android.media.AudioAttributes; 20 import android.os.Vibrator; 21 import android.os.VibrationEffect; 22 import android.provider.Settings; 23 24 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 25 import com.android.settings.R; 26 27 /** 28 * Fragment for picking accessibility shortcut service 29 */ 30 public class TouchVibrationPreferenceFragment extends VibrationPreferenceFragment { 31 @Override getMetricsCategory()32 public int getMetricsCategory() { 33 return MetricsEvent.ACCESSIBILITY_VIBRATION_TOUCH; 34 } 35 36 @Override getPreferenceScreenResId()37 protected int getPreferenceScreenResId() { 38 return R.xml.accessibility_touch_vibration_settings; 39 } 40 41 /** 42 * Get the setting string of the vibration intensity setting this preference is dealing with. 43 */ 44 @Override getVibrationIntensitySetting()45 protected String getVibrationIntensitySetting() { 46 return Settings.System.HAPTIC_FEEDBACK_INTENSITY; 47 } 48 49 @Override getDefaultVibrationIntensity()50 protected int getDefaultVibrationIntensity() { 51 Vibrator vibrator = getContext().getSystemService(Vibrator.class); 52 return vibrator.getDefaultHapticFeedbackIntensity(); 53 } 54 55 @Override getPreviewVibrationAudioAttributesUsage()56 protected int getPreviewVibrationAudioAttributesUsage() { 57 return AudioAttributes.USAGE_ASSISTANCE_SONIFICATION; 58 } 59 60 @Override onVibrationIntensitySelected(int intensity)61 public void onVibrationIntensitySelected(int intensity) { 62 // We want to keep HAPTIC_FEEDBACK_ENABLED consistent with this setting since some 63 // applications check it directly before triggering their own haptic feedback. 64 final boolean hapticFeedbackEnabled = !(intensity == Vibrator.VIBRATION_INTENSITY_OFF); 65 Settings.System.putInt(getContext().getContentResolver(), 66 Settings.System.HAPTIC_FEEDBACK_ENABLED, hapticFeedbackEnabled ? 1 : 0); 67 } 68 } 69