1 /*
2  * Copyright 2021 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.input.pointer
18 
19 import android.view.PointerIcon.TYPE_ARROW
20 import android.view.PointerIcon.TYPE_CROSSHAIR
21 import android.view.PointerIcon.TYPE_HAND
22 import android.view.PointerIcon.TYPE_TEXT
23 
24 internal class AndroidPointerIconType(val type: Int) : PointerIcon {
equalsnull25     override fun equals(other: Any?): Boolean {
26         if (this === other) return true
27         if (javaClass != other?.javaClass) return false
28 
29         other as AndroidPointerIconType
30 
31         if (type != other.type) return false
32 
33         return true
34     }
35 
hashCodenull36     override fun hashCode(): Int {
37         return type
38     }
39 
toStringnull40     override fun toString(): String {
41         return "AndroidPointerIcon(type=$type)"
42     }
43 }
44 
45 internal class AndroidPointerIcon(val pointerIcon: android.view.PointerIcon) : PointerIcon {
equalsnull46     override fun equals(other: Any?): Boolean {
47         if (this === other) return true
48         if (javaClass != other?.javaClass) return false
49 
50         other as AndroidPointerIcon
51 
52         return pointerIcon == other.pointerIcon
53     }
54 
hashCodenull55     override fun hashCode(): Int {
56         return pointerIcon.hashCode()
57     }
58 
toStringnull59     override fun toString(): String {
60         return "AndroidPointerIcon(pointerIcon=$pointerIcon)"
61     }
62 }
63 
64 /** Creates [PointerIcon] from [android.view.PointerIcon] */
PointerIconnull65 fun PointerIcon(pointerIcon: android.view.PointerIcon): PointerIcon =
66     AndroidPointerIcon(pointerIcon)
67 
68 /** Creates [PointerIcon] from pointer icon type (see [android.view.PointerIcon.getSystemIcon] */
69 fun PointerIcon(pointerIconType: Int): PointerIcon = AndroidPointerIconType(pointerIconType)
70 
71 internal actual val pointerIconDefault: PointerIcon = AndroidPointerIconType(TYPE_ARROW)
72 internal actual val pointerIconCrosshair: PointerIcon = AndroidPointerIconType(TYPE_CROSSHAIR)
73 internal actual val pointerIconText: PointerIcon = AndroidPointerIconType(TYPE_TEXT)
74 internal actual val pointerIconHand: PointerIcon = AndroidPointerIconType(TYPE_HAND)
75