Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 android.view; |
| 18 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 20 | import android.annotation.XmlRes; |
Artur Satayev | ad9254c | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 21 | import android.compat.annotation.UnsupportedAppUsage; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.Resources; |
| 24 | import android.content.res.TypedArray; |
| 25 | import android.content.res.XmlResourceParser; |
| 26 | import android.graphics.Bitmap; |
Leon Scroggins III | 2f1b06b | 2018-02-15 10:40:33 -0500 | [diff] [blame] | 27 | import android.graphics.Canvas; |
| 28 | import android.graphics.Paint; |
| 29 | import android.graphics.Rect; |
| 30 | import android.graphics.RectF; |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 31 | import android.graphics.drawable.AnimationDrawable; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 32 | import android.graphics.drawable.BitmapDrawable; |
| 33 | import android.graphics.drawable.Drawable; |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 34 | import android.hardware.display.DisplayManager; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 35 | import android.os.Build; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.Parcelable; |
| 38 | import android.util.Log; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 39 | import android.util.SparseArray; |
| 40 | |
| 41 | import com.android.internal.util.XmlUtils; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Represents an icon that can be used as a mouse pointer. |
| 45 | * <p> |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 46 | * Pointer icons can be provided either by the system using system types, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 47 | * or by applications using bitmaps or application resources. |
| 48 | * </p> |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 49 | */ |
| 50 | public final class PointerIcon implements Parcelable { |
| 51 | private static final String TAG = "PointerIcon"; |
| 52 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 53 | /** {@hide} Type constant: Custom icon with a user-supplied bitmap. */ |
| 54 | public static final int TYPE_CUSTOM = -1; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 55 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 56 | /** Type constant: Null icon. It has no bitmap. */ |
| 57 | public static final int TYPE_NULL = 0; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 58 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 59 | /** Type constant: no icons are specified. If all views uses this, then falls back |
| 60 | * to the default type, but this is helpful to distinguish a view explicitly want |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 61 | * to have the default icon. |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 62 | * @hide |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 63 | */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 64 | public static final int TYPE_NOT_SPECIFIED = 1; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 65 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 66 | /** Type constant: Arrow icon. (Default mouse pointer) */ |
| 67 | public static final int TYPE_ARROW = 1000; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 68 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 69 | /** {@hide} Type constant: Spot hover icon for touchpads. */ |
| 70 | public static final int TYPE_SPOT_HOVER = 2000; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 71 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 72 | /** {@hide} Type constant: Spot touch icon for touchpads. */ |
| 73 | public static final int TYPE_SPOT_TOUCH = 2001; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 74 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 75 | /** {@hide} Type constant: Spot anchor icon for touchpads. */ |
| 76 | public static final int TYPE_SPOT_ANCHOR = 2002; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 77 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 78 | // Type constants for additional predefined icons for mice. |
| 79 | /** Type constant: context-menu. */ |
| 80 | public static final int TYPE_CONTEXT_MENU = 1001; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 81 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 82 | /** Type constant: hand. */ |
| 83 | public static final int TYPE_HAND = 1002; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 84 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 85 | /** Type constant: help. */ |
| 86 | public static final int TYPE_HELP = 1003; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 87 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 88 | /** Type constant: wait. */ |
| 89 | public static final int TYPE_WAIT = 1004; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 90 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 91 | /** Type constant: cell. */ |
| 92 | public static final int TYPE_CELL = 1006; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 93 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 94 | /** Type constant: crosshair. */ |
| 95 | public static final int TYPE_CROSSHAIR = 1007; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 96 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 97 | /** Type constant: text. */ |
| 98 | public static final int TYPE_TEXT = 1008; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 99 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 100 | /** Type constant: vertical-text. */ |
| 101 | public static final int TYPE_VERTICAL_TEXT = 1009; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 102 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 103 | /** Type constant: alias (indicating an alias of/shortcut to something is |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 104 | * to be created. */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 105 | public static final int TYPE_ALIAS = 1010; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 106 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 107 | /** Type constant: copy. */ |
| 108 | public static final int TYPE_COPY = 1011; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 109 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 110 | /** Type constant: no-drop. */ |
| 111 | public static final int TYPE_NO_DROP = 1012; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 112 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 113 | /** Type constant: all-scroll. */ |
| 114 | public static final int TYPE_ALL_SCROLL = 1013; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 115 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 116 | /** Type constant: horizontal double arrow mainly for resizing. */ |
| 117 | public static final int TYPE_HORIZONTAL_DOUBLE_ARROW = 1014; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 118 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 119 | /** Type constant: vertical double arrow mainly for resizing. */ |
| 120 | public static final int TYPE_VERTICAL_DOUBLE_ARROW = 1015; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 121 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 122 | /** Type constant: diagonal double arrow -- top-right to bottom-left. */ |
| 123 | public static final int TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 124 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 125 | /** Type constant: diagonal double arrow -- top-left to bottom-right. */ |
| 126 | public static final int TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 127 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 128 | /** Type constant: zoom-in. */ |
| 129 | public static final int TYPE_ZOOM_IN = 1018; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 130 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 131 | /** Type constant: zoom-out. */ |
| 132 | public static final int TYPE_ZOOM_OUT = 1019; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 133 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 134 | /** Type constant: grab. */ |
| 135 | public static final int TYPE_GRAB = 1020; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 136 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 137 | /** Type constant: grabbing. */ |
| 138 | public static final int TYPE_GRABBING = 1021; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 139 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 140 | // OEM private types should be defined starting at this range to avoid |
| 141 | // conflicts with any system types that may be defined in the future. |
| 142 | private static final int TYPE_OEM_FIRST = 10000; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 143 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 144 | /** The default pointer icon. */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 145 | public static final int TYPE_DEFAULT = TYPE_ARROW; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 146 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 147 | private static final PointerIcon gNullIcon = new PointerIcon(TYPE_NULL); |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 148 | private static final SparseArray<SparseArray<PointerIcon>> gSystemIconsByDisplay = |
| 149 | new SparseArray<SparseArray<PointerIcon>>(); |
Jun Mukai | 1f3dbff | 2015-12-16 14:41:25 -0800 | [diff] [blame] | 150 | private static boolean sUseLargeIcons = false; |
Jun Mukai | e4e75da | 2015-12-15 16:19:20 -0800 | [diff] [blame] | 151 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 152 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 153 | private final int mType; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 154 | private int mSystemIconResourceId; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 155 | @UnsupportedAppUsage |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 156 | private Bitmap mBitmap; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 157 | @UnsupportedAppUsage |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 158 | private float mHotSpotX; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 159 | @UnsupportedAppUsage |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 160 | private float mHotSpotY; |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 161 | // The bitmaps for the additional frame of animated pointer icon. Note that the first frame |
| 162 | // will be stored in mBitmap. |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 163 | @UnsupportedAppUsage |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 164 | private Bitmap mBitmapFrames[]; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 165 | @UnsupportedAppUsage |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 166 | private int mDurationPerFrame; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 167 | |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 168 | /** |
| 169 | * Listener for displays lifecycle. |
| 170 | * @hide |
| 171 | */ |
| 172 | private static DisplayManager.DisplayListener sDisplayListener; |
| 173 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 174 | private PointerIcon(int type) { |
| 175 | mType = type; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Gets a special pointer icon that has no bitmap. |
| 180 | * |
| 181 | * @return The null pointer icon. |
| 182 | * |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 183 | * @see #TYPE_NULL |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 184 | * @hide |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 185 | */ |
| 186 | public static PointerIcon getNullIcon() { |
| 187 | return gNullIcon; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Gets the default pointer icon. |
| 192 | * |
| 193 | * @param context The context. |
| 194 | * @return The default pointer icon. |
| 195 | * |
| 196 | * @throws IllegalArgumentException if context is null. |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 197 | * @hide |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 198 | */ |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 199 | public static PointerIcon getDefaultIcon(@NonNull Context context) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 200 | return getSystemIcon(context, TYPE_DEFAULT); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 204 | * Gets a system pointer icon for the given type. |
| 205 | * If typeis not recognized, returns the default pointer icon. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 206 | * |
| 207 | * @param context The context. |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 208 | * @param type The pointer icon type. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 209 | * @return The pointer icon. |
| 210 | * |
| 211 | * @throws IllegalArgumentException if context is null. |
| 212 | */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 213 | public static PointerIcon getSystemIcon(@NonNull Context context, int type) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 214 | if (context == null) { |
| 215 | throw new IllegalArgumentException("context must not be null"); |
| 216 | } |
| 217 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 218 | if (type == TYPE_NULL) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 219 | return gNullIcon; |
| 220 | } |
| 221 | |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 222 | if (sDisplayListener == null) { |
| 223 | registerDisplayListener(context); |
| 224 | } |
| 225 | |
| 226 | final int displayId = context.getDisplayId(); |
| 227 | SparseArray<PointerIcon> systemIcons = gSystemIconsByDisplay.get(displayId); |
| 228 | if (systemIcons == null) { |
| 229 | systemIcons = new SparseArray<>(); |
| 230 | gSystemIconsByDisplay.put(displayId, systemIcons); |
| 231 | } |
| 232 | |
| 233 | PointerIcon icon = systemIcons.get(type); |
| 234 | // Reload if not in the same display. |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 235 | if (icon != null) { |
| 236 | return icon; |
| 237 | } |
| 238 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 239 | int typeIndex = getSystemIconTypeIndex(type); |
| 240 | if (typeIndex == 0) { |
| 241 | typeIndex = getSystemIconTypeIndex(TYPE_DEFAULT); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Jun Mukai | e4e75da | 2015-12-15 16:19:20 -0800 | [diff] [blame] | 244 | int defStyle = sUseLargeIcons ? |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 245 | com.android.internal.R.style.LargePointer : com.android.internal.R.style.Pointer; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 246 | TypedArray a = context.obtainStyledAttributes(null, |
| 247 | com.android.internal.R.styleable.Pointer, |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 248 | 0, defStyle); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 249 | int resourceId = a.getResourceId(typeIndex, -1); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 250 | a.recycle(); |
| 251 | |
| 252 | if (resourceId == -1) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 253 | Log.w(TAG, "Missing theme resources for pointer icon type " + type); |
| 254 | return type == TYPE_DEFAULT ? gNullIcon : getSystemIcon(context, TYPE_DEFAULT); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 257 | icon = new PointerIcon(type); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 258 | if ((resourceId & 0xff000000) == 0x01000000) { |
| 259 | icon.mSystemIconResourceId = resourceId; |
| 260 | } else { |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 261 | icon.loadResource(context, context.getResources(), resourceId); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 262 | } |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 263 | systemIcons.append(type, icon); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 264 | return icon; |
| 265 | } |
| 266 | |
| 267 | /** |
Jun Mukai | 1f3dbff | 2015-12-16 14:41:25 -0800 | [diff] [blame] | 268 | * Updates wheter accessibility large icons are used or not. |
| 269 | * @hide |
| 270 | */ |
| 271 | public static void setUseLargeIcons(boolean use) { |
| 272 | sUseLargeIcons = use; |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 273 | gSystemIconsByDisplay.clear(); |
Jun Mukai | 1f3dbff | 2015-12-16 14:41:25 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /** |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 277 | * Creates a custom pointer icon from the given bitmap and hotspot information. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 278 | * |
| 279 | * @param bitmap The bitmap for the icon. |
Alan Viverette | 376d10e | 2014-09-02 10:45:30 -0700 | [diff] [blame] | 280 | * @param hotSpotX The X offset of the pointer icon hotspot in the bitmap. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 281 | * Must be within the [0, bitmap.getWidth()) range. |
Alan Viverette | 376d10e | 2014-09-02 10:45:30 -0700 | [diff] [blame] | 282 | * @param hotSpotY The Y offset of the pointer icon hotspot in the bitmap. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 283 | * Must be within the [0, bitmap.getHeight()) range. |
| 284 | * @return A pointer icon for this bitmap. |
| 285 | * |
| 286 | * @throws IllegalArgumentException if bitmap is null, or if the x/y hotspot |
| 287 | * parameters are invalid. |
| 288 | */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 289 | public static PointerIcon create(@NonNull Bitmap bitmap, float hotSpotX, float hotSpotY) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 290 | if (bitmap == null) { |
| 291 | throw new IllegalArgumentException("bitmap must not be null"); |
| 292 | } |
| 293 | validateHotSpot(bitmap, hotSpotX, hotSpotY); |
| 294 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 295 | PointerIcon icon = new PointerIcon(TYPE_CUSTOM); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 296 | icon.mBitmap = bitmap; |
| 297 | icon.mHotSpotX = hotSpotX; |
| 298 | icon.mHotSpotY = hotSpotY; |
| 299 | return icon; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Loads a custom pointer icon from an XML resource. |
| 304 | * <p> |
| 305 | * The XML resource should have the following form: |
| 306 | * <code> |
| 307 | * <?xml version="1.0" encoding="utf-8"?> |
| 308 | * <pointer-icon xmlns:android="http://schemas.android.com/apk/res/android" |
| 309 | * android:bitmap="@drawable/my_pointer_bitmap" |
| 310 | * android:hotSpotX="24" |
| 311 | * android:hotSpotY="24" /> |
| 312 | * </code> |
| 313 | * </p> |
| 314 | * |
| 315 | * @param resources The resources object. |
| 316 | * @param resourceId The resource id. |
| 317 | * @return The pointer icon. |
| 318 | * |
| 319 | * @throws IllegalArgumentException if resources is null. |
| 320 | * @throws Resources.NotFoundException if the resource was not found or the drawable |
| 321 | * linked in the resource was not found. |
| 322 | */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 323 | public static PointerIcon load(@NonNull Resources resources, @XmlRes int resourceId) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 324 | if (resources == null) { |
| 325 | throw new IllegalArgumentException("resources must not be null"); |
| 326 | } |
| 327 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 328 | PointerIcon icon = new PointerIcon(TYPE_CUSTOM); |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 329 | icon.loadResource(null, resources, resourceId); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 330 | return icon; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Loads the bitmap and hotspot information for a pointer icon, if it is not already loaded. |
| 335 | * Returns a pointer icon (not necessarily the same instance) with the information filled in. |
| 336 | * |
| 337 | * @param context The context. |
| 338 | * @return The loaded pointer icon. |
| 339 | * |
| 340 | * @throws IllegalArgumentException if context is null. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 341 | * @hide |
| 342 | */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 343 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 344 | public PointerIcon load(@NonNull Context context) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 345 | if (context == null) { |
| 346 | throw new IllegalArgumentException("context must not be null"); |
| 347 | } |
| 348 | |
| 349 | if (mSystemIconResourceId == 0 || mBitmap != null) { |
| 350 | return this; |
| 351 | } |
| 352 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 353 | PointerIcon result = new PointerIcon(mType); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 354 | result.mSystemIconResourceId = mSystemIconResourceId; |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 355 | result.loadResource(context, context.getResources(), mSystemIconResourceId); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 356 | return result; |
| 357 | } |
| 358 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 359 | /** @hide */ |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 360 | public int getType() { |
| 361 | return mType; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 364 | public static final @android.annotation.NonNull Parcelable.Creator<PointerIcon> CREATOR |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 365 | = new Parcelable.Creator<PointerIcon>() { |
| 366 | public PointerIcon createFromParcel(Parcel in) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 367 | int type = in.readInt(); |
| 368 | if (type == TYPE_NULL) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 369 | return getNullIcon(); |
| 370 | } |
| 371 | |
| 372 | int systemIconResourceId = in.readInt(); |
| 373 | if (systemIconResourceId != 0) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 374 | PointerIcon icon = new PointerIcon(type); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 375 | icon.mSystemIconResourceId = systemIconResourceId; |
| 376 | return icon; |
| 377 | } |
| 378 | |
| 379 | Bitmap bitmap = Bitmap.CREATOR.createFromParcel(in); |
| 380 | float hotSpotX = in.readFloat(); |
| 381 | float hotSpotY = in.readFloat(); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 382 | return PointerIcon.create(bitmap, hotSpotX, hotSpotY); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | public PointerIcon[] newArray(int size) { |
| 386 | return new PointerIcon[size]; |
| 387 | } |
| 388 | }; |
| 389 | |
| 390 | public int describeContents() { |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | public void writeToParcel(Parcel out, int flags) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 395 | out.writeInt(mType); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 396 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 397 | if (mType != TYPE_NULL) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 398 | out.writeInt(mSystemIconResourceId); |
| 399 | if (mSystemIconResourceId == 0) { |
| 400 | mBitmap.writeToParcel(out, flags); |
| 401 | out.writeFloat(mHotSpotX); |
| 402 | out.writeFloat(mHotSpotY); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public boolean equals(Object other) { |
| 409 | if (this == other) { |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | if (other == null || !(other instanceof PointerIcon)) { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | PointerIcon otherIcon = (PointerIcon) other; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 418 | if (mType != otherIcon.mType |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 419 | || mSystemIconResourceId != otherIcon.mSystemIconResourceId) { |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | if (mSystemIconResourceId == 0 && (mBitmap != otherIcon.mBitmap |
| 424 | || mHotSpotX != otherIcon.mHotSpotX |
| 425 | || mHotSpotY != otherIcon.mHotSpotY)) { |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | return true; |
| 430 | } |
| 431 | |
Leon Scroggins III | 2f1b06b | 2018-02-15 10:40:33 -0500 | [diff] [blame] | 432 | /** |
| 433 | * Get the Bitmap from the Drawable. |
| 434 | * |
| 435 | * If the Bitmap needed to be scaled up to account for density, BitmapDrawable |
| 436 | * handles this at draw time. But this class doesn't actually draw the Bitmap; |
| 437 | * it is just a holder for native code to access its SkBitmap. So this needs to |
| 438 | * get a version that is scaled to account for density. |
| 439 | */ |
| 440 | private Bitmap getBitmapFromDrawable(BitmapDrawable bitmapDrawable) { |
| 441 | Bitmap bitmap = bitmapDrawable.getBitmap(); |
| 442 | final int scaledWidth = bitmapDrawable.getIntrinsicWidth(); |
| 443 | final int scaledHeight = bitmapDrawable.getIntrinsicHeight(); |
| 444 | if (scaledWidth == bitmap.getWidth() && scaledHeight == bitmap.getHeight()) { |
| 445 | return bitmap; |
| 446 | } |
| 447 | |
| 448 | Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); |
| 449 | RectF dst = new RectF(0, 0, scaledWidth, scaledHeight); |
| 450 | |
| 451 | Bitmap scaled = Bitmap.createBitmap(scaledWidth, scaledHeight, bitmap.getConfig()); |
| 452 | Canvas canvas = new Canvas(scaled); |
| 453 | Paint paint = new Paint(); |
| 454 | paint.setFilterBitmap(true); |
| 455 | canvas.drawBitmap(bitmap, src, dst, paint); |
| 456 | return scaled; |
| 457 | } |
| 458 | |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 459 | private void loadResource(Context context, Resources resources, @XmlRes int resourceId) { |
Alan Viverette | 376d10e | 2014-09-02 10:45:30 -0700 | [diff] [blame] | 460 | final XmlResourceParser parser = resources.getXml(resourceId); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 461 | final int bitmapRes; |
| 462 | final float hotSpotX; |
| 463 | final float hotSpotY; |
| 464 | try { |
| 465 | XmlUtils.beginDocument(parser, "pointer-icon"); |
| 466 | |
Alan Viverette | 376d10e | 2014-09-02 10:45:30 -0700 | [diff] [blame] | 467 | final TypedArray a = resources.obtainAttributes( |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 468 | parser, com.android.internal.R.styleable.PointerIcon); |
| 469 | bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0); |
Alan Viverette | 376d10e | 2014-09-02 10:45:30 -0700 | [diff] [blame] | 470 | hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0); |
| 471 | hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 472 | a.recycle(); |
| 473 | } catch (Exception ex) { |
| 474 | throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex); |
| 475 | } finally { |
| 476 | parser.close(); |
| 477 | } |
| 478 | |
| 479 | if (bitmapRes == 0) { |
| 480 | throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute."); |
| 481 | } |
| 482 | |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 483 | Drawable drawable; |
| 484 | if (context == null) { |
| 485 | drawable = resources.getDrawable(bitmapRes); |
| 486 | } else { |
| 487 | drawable = context.getDrawable(bitmapRes); |
| 488 | } |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 489 | if (drawable instanceof AnimationDrawable) { |
| 490 | // Extract animation frame bitmaps. |
| 491 | final AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 492 | final int frames = animationDrawable.getNumberOfFrames(); |
| 493 | drawable = animationDrawable.getFrame(0); |
| 494 | if (frames == 1) { |
| 495 | Log.w(TAG, "Animation icon with single frame -- simply treating the first " |
| 496 | + "frame as a normal bitmap icon."); |
| 497 | } else { |
| 498 | // Assumes they have the exact duration. |
| 499 | mDurationPerFrame = animationDrawable.getDuration(0); |
| 500 | mBitmapFrames = new Bitmap[frames - 1]; |
| 501 | final int width = drawable.getIntrinsicWidth(); |
| 502 | final int height = drawable.getIntrinsicHeight(); |
| 503 | for (int i = 1; i < frames; ++i) { |
| 504 | Drawable drawableFrame = animationDrawable.getFrame(i); |
| 505 | if (!(drawableFrame instanceof BitmapDrawable)) { |
| 506 | throw new IllegalArgumentException("Frame of an animated pointer icon " |
| 507 | + "must refer to a bitmap drawable."); |
| 508 | } |
| 509 | if (drawableFrame.getIntrinsicWidth() != width || |
| 510 | drawableFrame.getIntrinsicHeight() != height) { |
| 511 | throw new IllegalArgumentException("The bitmap size of " + i + "-th frame " |
| 512 | + "is different. All frames should have the exact same size and " |
| 513 | + "share the same hotspot."); |
| 514 | } |
Leon Scroggins III | 2f1b06b | 2018-02-15 10:40:33 -0500 | [diff] [blame] | 515 | BitmapDrawable bitmapDrawableFrame = (BitmapDrawable) drawableFrame; |
| 516 | mBitmapFrames[i - 1] = getBitmapFromDrawable(bitmapDrawableFrame); |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 520 | if (!(drawable instanceof BitmapDrawable)) { |
| 521 | throw new IllegalArgumentException("<pointer-icon> bitmap attribute must " |
| 522 | + "refer to a bitmap drawable."); |
| 523 | } |
| 524 | |
Leon Scroggins III | 2f1b06b | 2018-02-15 10:40:33 -0500 | [diff] [blame] | 525 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; |
| 526 | final Bitmap bitmap = getBitmapFromDrawable(bitmapDrawable); |
Vladislav Kaznacheev | 44e7de3 | 2017-12-20 12:18:03 -0800 | [diff] [blame] | 527 | validateHotSpot(bitmap, hotSpotX, hotSpotY); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 528 | // Set the properties now that we have successfully loaded the icon. |
Vladislav Kaznacheev | 44e7de3 | 2017-12-20 12:18:03 -0800 | [diff] [blame] | 529 | mBitmap = bitmap; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 530 | mHotSpotX = hotSpotX; |
| 531 | mHotSpotY = hotSpotY; |
| 532 | } |
| 533 | |
| 534 | private static void validateHotSpot(Bitmap bitmap, float hotSpotX, float hotSpotY) { |
| 535 | if (hotSpotX < 0 || hotSpotX >= bitmap.getWidth()) { |
| 536 | throw new IllegalArgumentException("x hotspot lies outside of the bitmap area"); |
| 537 | } |
| 538 | if (hotSpotY < 0 || hotSpotY >= bitmap.getHeight()) { |
| 539 | throw new IllegalArgumentException("y hotspot lies outside of the bitmap area"); |
| 540 | } |
| 541 | } |
| 542 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 543 | private static int getSystemIconTypeIndex(int type) { |
| 544 | switch (type) { |
| 545 | case TYPE_ARROW: |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 546 | return com.android.internal.R.styleable.Pointer_pointerIconArrow; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 547 | case TYPE_SPOT_HOVER: |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 548 | return com.android.internal.R.styleable.Pointer_pointerIconSpotHover; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 549 | case TYPE_SPOT_TOUCH: |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 550 | return com.android.internal.R.styleable.Pointer_pointerIconSpotTouch; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 551 | case TYPE_SPOT_ANCHOR: |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 552 | return com.android.internal.R.styleable.Pointer_pointerIconSpotAnchor; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 553 | case TYPE_HAND: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 554 | return com.android.internal.R.styleable.Pointer_pointerIconHand; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 555 | case TYPE_CONTEXT_MENU: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 556 | return com.android.internal.R.styleable.Pointer_pointerIconContextMenu; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 557 | case TYPE_HELP: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 558 | return com.android.internal.R.styleable.Pointer_pointerIconHelp; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 559 | case TYPE_WAIT: |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 560 | return com.android.internal.R.styleable.Pointer_pointerIconWait; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 561 | case TYPE_CELL: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 562 | return com.android.internal.R.styleable.Pointer_pointerIconCell; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 563 | case TYPE_CROSSHAIR: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 564 | return com.android.internal.R.styleable.Pointer_pointerIconCrosshair; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 565 | case TYPE_TEXT: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 566 | return com.android.internal.R.styleable.Pointer_pointerIconText; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 567 | case TYPE_VERTICAL_TEXT: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 568 | return com.android.internal.R.styleable.Pointer_pointerIconVerticalText; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 569 | case TYPE_ALIAS: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 570 | return com.android.internal.R.styleable.Pointer_pointerIconAlias; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 571 | case TYPE_COPY: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 572 | return com.android.internal.R.styleable.Pointer_pointerIconCopy; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 573 | case TYPE_ALL_SCROLL: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 574 | return com.android.internal.R.styleable.Pointer_pointerIconAllScroll; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 575 | case TYPE_NO_DROP: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 576 | return com.android.internal.R.styleable.Pointer_pointerIconNodrop; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 577 | case TYPE_HORIZONTAL_DOUBLE_ARROW: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 578 | return com.android.internal.R.styleable.Pointer_pointerIconHorizontalDoubleArrow; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 579 | case TYPE_VERTICAL_DOUBLE_ARROW: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 580 | return com.android.internal.R.styleable.Pointer_pointerIconVerticalDoubleArrow; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 581 | case TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 582 | return com.android.internal.R.styleable. |
| 583 | Pointer_pointerIconTopRightDiagonalDoubleArrow; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 584 | case TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 585 | return com.android.internal.R.styleable. |
| 586 | Pointer_pointerIconTopLeftDiagonalDoubleArrow; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 587 | case TYPE_ZOOM_IN: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 588 | return com.android.internal.R.styleable.Pointer_pointerIconZoomIn; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 589 | case TYPE_ZOOM_OUT: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 590 | return com.android.internal.R.styleable.Pointer_pointerIconZoomOut; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 591 | case TYPE_GRAB: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 592 | return com.android.internal.R.styleable.Pointer_pointerIconGrab; |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 593 | case TYPE_GRABBING: |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 594 | return com.android.internal.R.styleable.Pointer_pointerIconGrabbing; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 595 | default: |
| 596 | return 0; |
| 597 | } |
| 598 | } |
Andrii Kulian | fd8666d | 2018-10-05 16:58:39 -0700 | [diff] [blame] | 599 | |
| 600 | /** |
| 601 | * Manage system icon cache handled by display lifecycle. |
| 602 | * @param context The context. |
| 603 | */ |
| 604 | private static void registerDisplayListener(@NonNull Context context) { |
| 605 | sDisplayListener = new DisplayManager.DisplayListener() { |
| 606 | @Override |
| 607 | public void onDisplayAdded(int displayId) { |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public void onDisplayRemoved(int displayId) { |
| 612 | gSystemIconsByDisplay.remove(displayId); |
| 613 | } |
| 614 | |
| 615 | @Override |
| 616 | public void onDisplayChanged(int displayId) { |
| 617 | gSystemIconsByDisplay.remove(displayId); |
| 618 | } |
| 619 | }; |
| 620 | |
| 621 | DisplayManager displayManager = context.getSystemService(DisplayManager.class); |
| 622 | displayManager.registerDisplayListener(sDisplayListener, null /* handler */); |
| 623 | } |
| 624 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 625 | } |