1 /*
2  * Copyright (C) 2022 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 com.android.systemui.biometrics.udfps
18 
19 import android.graphics.Rect
20 import android.view.MotionEvent
21 
22 /** Touch data in natural orientation and native resolution. */
23 data class NormalizedTouchData(
24 
25     /**
26      * Value obtained from [MotionEvent.getPointerId], or [MotionEvent.INVALID_POINTER_ID] if the ID
27      * is not available.
28      */
29     val pointerId: Int = MotionEvent.INVALID_POINTER_ID,
30 
31     /** [MotionEvent.getRawX] mapped to natural orientation and native resolution. */
32     val x: Float = 0f,
33 
34     /** [MotionEvent.getRawY] mapped to natural orientation and native resolution. */
35     val y: Float = 0f,
36 
37     /** [MotionEvent.getTouchMinor] mapped to natural orientation and native resolution. */
38     val minor: Float = 0f,
39 
40     /** [MotionEvent.getTouchMajor] mapped to natural orientation and native resolution. */
41     val major: Float = 0f,
42 
43     /** [MotionEvent.getOrientation] mapped to natural orientation. */
44     val orientation: Float = 0f,
45 
46     /** [MotionEvent.getEventTime]. */
47     val time: Long = 0,
48 
49     /** [MotionEvent.getDownTime]. */
50     val gestureStart: Long = 0,
51 ) {
52 
53     /**
54      * [nativeBounds] contains the location and dimensions of the area in native resolution and
55      * natural orientation.
56      *
57      * Returns whether the coordinates of the given pointer are within the bounding box.
58      */
isWithinBoundsnull59     fun isWithinBounds(nativeBounds: Rect): Boolean {
60         return nativeBounds.left <= x &&
61             nativeBounds.right >= x &&
62             nativeBounds.top <= y &&
63             nativeBounds.bottom >= y
64     }
65 
66     @JvmOverloads
toPrettyStringnull67     fun toPrettyString(tag: String = ""): String =
68         """
69         |NormalizedTouchData [$tag] {
70         |     pointerId: $pointerId
71         |             x: $x
72         |             y: $y
73         |         minor: $minor
74         |         major: $major
75         |   orientation: $orientation
76         |          time: $time
77         |  gestureStart: $gestureStart
78         |}
79         """
80             .trimMargin()
81 }
82