1 /* 2 * Copyright 2020 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 17 package androidx.compose.ui.hapticfeedback 18 19 import android.view.HapticFeedbackConstants 20 import android.view.View 21 22 /** Android implementation for [HapticFeedback] */ 23 internal class PlatformHapticFeedback(private val view: View) : HapticFeedback { 24 performHapticFeedbacknull25 override fun performHapticFeedback(hapticFeedbackType: HapticFeedbackType) { 26 when (hapticFeedbackType) { 27 HapticFeedbackType.Confirm -> 28 view.performHapticFeedback(HapticFeedbackConstants.CONFIRM) 29 HapticFeedbackType.ContextClick -> 30 view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK) 31 HapticFeedbackType.GestureEnd -> 32 view.performHapticFeedback(HapticFeedbackConstants.GESTURE_END) 33 HapticFeedbackType.GestureThresholdActivate -> 34 view.performHapticFeedback(HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE) 35 HapticFeedbackType.KeyboardTap -> 36 view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) 37 HapticFeedbackType.LongPress -> 38 view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) 39 HapticFeedbackType.Reject -> view.performHapticFeedback(HapticFeedbackConstants.REJECT) 40 HapticFeedbackType.SegmentFrequentTick -> 41 view.performHapticFeedback(HapticFeedbackConstants.SEGMENT_FREQUENT_TICK) 42 HapticFeedbackType.SegmentTick -> 43 view.performHapticFeedback(HapticFeedbackConstants.SEGMENT_TICK) 44 HapticFeedbackType.TextHandleMove -> 45 view.performHapticFeedback(HapticFeedbackConstants.TEXT_HANDLE_MOVE) 46 HapticFeedbackType.ToggleOff -> 47 view.performHapticFeedback(HapticFeedbackConstants.TOGGLE_OFF) 48 HapticFeedbackType.ToggleOn -> 49 view.performHapticFeedback(HapticFeedbackConstants.TOGGLE_ON) 50 HapticFeedbackType.VirtualKey -> 51 view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) 52 } 53 } 54 } 55 56 internal actual object PlatformHapticFeedbackType { 57 actual val Confirm: HapticFeedbackType = HapticFeedbackType(HapticFeedbackConstants.CONFIRM) 58 actual val ContextClick: HapticFeedbackType = 59 HapticFeedbackType(HapticFeedbackConstants.CONTEXT_CLICK) 60 actual val GestureEnd: HapticFeedbackType = 61 HapticFeedbackType(HapticFeedbackConstants.GESTURE_END) 62 actual val GestureThresholdActivate: HapticFeedbackType = 63 HapticFeedbackType(HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE) 64 actual val KeyboardTap: HapticFeedbackType = 65 HapticFeedbackType(HapticFeedbackConstants.KEYBOARD_TAP) 66 actual val LongPress: HapticFeedbackType = 67 HapticFeedbackType(HapticFeedbackConstants.LONG_PRESS) 68 actual val Reject: HapticFeedbackType = HapticFeedbackType(HapticFeedbackConstants.REJECT) 69 actual val SegmentFrequentTick: HapticFeedbackType = 70 HapticFeedbackType(HapticFeedbackConstants.SEGMENT_FREQUENT_TICK) 71 actual val SegmentTick: HapticFeedbackType = 72 HapticFeedbackType(HapticFeedbackConstants.SEGMENT_TICK) 73 actual val TextHandleMove: HapticFeedbackType = 74 HapticFeedbackType(HapticFeedbackConstants.TEXT_HANDLE_MOVE) 75 actual val ToggleOff: HapticFeedbackType = 76 HapticFeedbackType(HapticFeedbackConstants.TOGGLE_OFF) 77 actual val ToggleOn: HapticFeedbackType = HapticFeedbackType(HapticFeedbackConstants.TOGGLE_ON) 78 actual val VirtualKey: HapticFeedbackType = 79 HapticFeedbackType(HapticFeedbackConstants.VIRTUAL_KEY) 80 } 81