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.platform 18 19 import android.os.Build 20 import androidx.annotation.RequiresApi 21 import androidx.compose.ui.platform.AndroidViewConfigurationApi34.getScaledHandwritingGestureLineMargin 22 import androidx.compose.ui.platform.AndroidViewConfigurationApi34.getScaledHandwritingSlop 23 24 /** 25 * A [ViewConfiguration] with Android's default configurations. Derived from 26 * [android.view.ViewConfiguration] 27 */ 28 class AndroidViewConfiguration(private val viewConfiguration: android.view.ViewConfiguration) : 29 ViewConfiguration { 30 override val longPressTimeoutMillis: Long 31 get() = android.view.ViewConfiguration.getLongPressTimeout().toLong() 32 33 override val doubleTapTimeoutMillis: Long 34 get() = android.view.ViewConfiguration.getDoubleTapTimeout().toLong() 35 36 override val doubleTapMinTimeMillis: Long 37 get() = 40 38 39 override val touchSlop: Float 40 get() = viewConfiguration.scaledTouchSlop.toFloat() 41 42 override val handwritingSlop: Float 43 get() = 44 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { 45 getScaledHandwritingSlop(viewConfiguration) 46 } else { 47 super.handwritingSlop 48 } 49 50 override val maximumFlingVelocity: Float 51 get() = viewConfiguration.scaledMaximumFlingVelocity.toFloat() 52 53 override val handwritingGestureLineMargin: Float 54 get() = 55 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { 56 getScaledHandwritingGestureLineMargin(viewConfiguration) 57 } else { 58 super.handwritingGestureLineMargin 59 } 60 } 61 62 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 63 private object AndroidViewConfigurationApi34 { getScaledHandwritingSlopnull64 fun getScaledHandwritingSlop(viewConfiguration: android.view.ViewConfiguration) = 65 viewConfiguration.scaledHandwritingSlop.toFloat() 66 67 fun getScaledHandwritingGestureLineMargin(viewConfiguration: android.view.ViewConfiguration) = 68 viewConfiguration.scaledHandwritingGestureLineMargin.toFloat() 69 } 70