| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.XmlRes; |
| 22 |
import android.compat.annotation.UnsupportedAppUsage; |
| 23 |
import android.content.Context; |
| 24 |
import android.content.res.Resources; |
| 25 |
import android.content.res.TypedArray; |
| 26 |
import android.content.res.XmlResourceParser; |
| 27 |
import android.graphics.Bitmap; |
| 28 |
import android.graphics.Canvas; |
| 29 |
import android.graphics.Paint; |
| 30 |
import android.graphics.Rect; |
| 31 |
import android.graphics.RectF; |
| 32 |
import android.graphics.drawable.AnimationDrawable; |
| 33 |
import android.graphics.drawable.BitmapDrawable; |
| 34 |
import android.graphics.drawable.Drawable; |
| 35 |
import android.hardware.display.DisplayManager; |
| 36 |
import android.os.Build; |
| 37 |
import android.os.Parcel; |
| 38 |
import android.os.Parcelable; |
| 39 |
import android.util.Log; |
| 40 |
import android.util.SparseArray; |
| 41 |
|
| 42 |
import com.android.internal.util.XmlUtils; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public final class PointerIcon implements Parcelable { |
| 52 |
private static final String TAG = "PointerIcon"; |
| 53 |
|
| 54 |
|
| 55 |
public static final int TYPE_CUSTOM = -1; |
| 56 |
|
| 57 |
|
| 58 |
public static final int TYPE_NULL = 0; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static final int TYPE_NOT_SPECIFIED = 1; |
| 66 |
|
| 67 |
|
| 68 |
public static final int TYPE_ARROW = 1000; |
| 69 |
|
| 70 |
|
| 71 |
public static final int TYPE_SPOT_HOVER = 2000; |
| 72 |
|
| 73 |
|
| 74 |
public static final int TYPE_SPOT_TOUCH = 2001; |
| 75 |
|
| 76 |
|
| 77 |
public static final int TYPE_SPOT_ANCHOR = 2002; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static final int TYPE_CONTEXT_MENU = 1001; |
| 82 |
|
| 83 |
|
| 84 |
public static final int TYPE_HAND = 1002; |
| 85 |
|
| 86 |
|
| 87 |
public static final int TYPE_HELP = 1003; |
| 88 |
|
| 89 |
|
| 90 |
public static final int TYPE_WAIT = 1004; |
| 91 |
|
| 92 |
|
| 93 |
public static final int TYPE_CELL = 1006; |
| 94 |
|
| 95 |
|
| 96 |
public static final int TYPE_CROSSHAIR = 1007; |
| 97 |
|
| 98 |
|
| 99 |
public static final int TYPE_TEXT = 1008; |
| 100 |
|
| 101 |
|
| 102 |
public static final int TYPE_VERTICAL_TEXT = 1009; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public static final int TYPE_ALIAS = 1010; |
| 107 |
|
| 108 |
|
| 109 |
public static final int TYPE_COPY = 1011; |
| 110 |
|
| 111 |
|
| 112 |
public static final int TYPE_NO_DROP = 1012; |
| 113 |
|
| 114 |
|
| 115 |
public static final int TYPE_ALL_SCROLL = 1013; |
| 116 |
|
| 117 |
|
| 118 |
public static final int TYPE_HORIZONTAL_DOUBLE_ARROW = 1014; |
| 119 |
|
| 120 |
|
| 121 |
public static final int TYPE_VERTICAL_DOUBLE_ARROW = 1015; |
| 122 |
|
| 123 |
|
| 124 |
public static final int TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016; |
| 125 |
|
| 126 |
|
| 127 |
public static final int TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017; |
| 128 |
|
| 129 |
|
| 130 |
public static final int TYPE_ZOOM_IN = 1018; |
| 131 |
|
| 132 |
|
| 133 |
public static final int TYPE_ZOOM_OUT = 1019; |
| 134 |
|
| 135 |
|
| 136 |
public static final int TYPE_GRAB = 1020; |
| 137 |
|
| 138 |
|
| 139 |
public static final int TYPE_GRABBING = 1021; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
private static final int TYPE_OEM_FIRST = 10000; |
| 144 |
|
| 145 |
|
| 146 |
public static final int TYPE_DEFAULT = TYPE_ARROW; |
| 147 |
|
| 148 |
private static final PointerIcon gNullIcon = new PointerIcon(TYPE_NULL); |
| 149 |
private static final SparseArray<SparseArray<PointerIcon>> gSystemIconsByDisplay = |
| 150 |
new SparseArray<SparseArray<PointerIcon>>(); |
| 151 |
private static boolean sUseLargeIcons = false; |
| 152 |
|
| 153 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 154 |
private final int mType; |
| 155 |
private int mSystemIconResourceId; |
| 156 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 157 |
private Bitmap mBitmap; |
| 158 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 159 |
private float mHotSpotX; |
| 160 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 161 |
private float mHotSpotY; |
| 162 |
|
| 163 |
|
| 164 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 165 |
private Bitmap mBitmapFrames[]; |
| 166 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 167 |
private int mDurationPerFrame; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
private static DisplayManager.DisplayListener sDisplayListener; |
| 174 |
|
| 175 |
private PointerIcon(int type) { |
| 176 |
mType = type; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
public static @NonNull PointerIcon getNullIcon() { |
| 188 |
return gNullIcon; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public static @NonNull PointerIcon getDefaultIcon(@NonNull Context context) { |
| 201 |
return getSystemIcon(context, TYPE_DEFAULT); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
public static @NonNull PointerIcon getSystemIcon(@NonNull Context context, int type) { |
| 215 |
if (context == null) { |
| 216 |
throw new IllegalArgumentException("context must not be null"); |
| 217 |
} |
| 218 |
|
| 219 |
if (type == TYPE_NULL) { |
| 220 |
return gNullIcon; |
| 221 |
} |
| 222 |
|
| 223 |
if (sDisplayListener == null) { |
| 224 |
registerDisplayListener(context); |
| 225 |
} |
| 226 |
|
| 227 |
final int displayId = context.getDisplayId(); |
| 228 |
SparseArray<PointerIcon> systemIcons = gSystemIconsByDisplay.get(displayId); |
| 229 |
if (systemIcons == null) { |
| 230 |
systemIcons = new SparseArray<>(); |
| 231 |
gSystemIconsByDisplay.put(displayId, systemIcons); |
| 232 |
} |
| 233 |
|
| 234 |
PointerIcon icon = systemIcons.get(type); |
| 235 |
|
| 236 |
if (icon != null) { |
| 237 |
return icon; |
| 238 |
} |
| 239 |
|
| 240 |
int typeIndex = getSystemIconTypeIndex(type); |
| 241 |
if (typeIndex == 0) { |
| 242 |
typeIndex = getSystemIconTypeIndex(TYPE_DEFAULT); |
| 243 |
} |
| 244 |
|
| 245 |
int defStyle = sUseLargeIcons ? |
| 246 |
com.android.internal.R.style.LargePointer : com.android.internal.R.style.Pointer; |
| 247 |
TypedArray a = context.obtainStyledAttributes(null, |
| 248 |
com.android.internal.R.styleable.Pointer, |
| 249 |
0, defStyle); |
| 250 |
int resourceId = a.getResourceId(typeIndex, -1); |
| 251 |
a.recycle(); |
| 252 |
|
| 253 |
if (resourceId == -1) { |
| 254 |
Log.w(TAG, "Missing theme resources for pointer icon type " + type); |
| 255 |
return type == TYPE_DEFAULT ? gNullIcon : getSystemIcon(context, TYPE_DEFAULT); |
| 256 |
} |
| 257 |
|
| 258 |
icon = new PointerIcon(type); |
| 259 |
if ((resourceId & 0xff000000) == 0x01000000) { |
| 260 |
icon.mSystemIconResourceId = resourceId; |
| 261 |
} else { |
| 262 |
icon.loadResource(context, context.getResources(), resourceId); |
| 263 |
} |
| 264 |
systemIcons.append(type, icon); |
| 265 |
return icon; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public static void setUseLargeIcons(boolean use) { |
| 273 |
sUseLargeIcons = use; |
| 274 |
gSystemIconsByDisplay.clear(); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public static @NonNull PointerIcon create(@NonNull Bitmap bitmap, float hotSpotX, |
| 291 |
float hotSpotY) { |
| 292 |
if (bitmap == null) { |
| 293 |
throw new IllegalArgumentException("bitmap must not be null"); |
| 294 |
} |
| 295 |
validateHotSpot(bitmap, hotSpotX, hotSpotY); |
| 296 |
|
| 297 |
PointerIcon icon = new PointerIcon(TYPE_CUSTOM); |
| 298 |
icon.mBitmap = bitmap; |
| 299 |
icon.mHotSpotX = hotSpotX; |
| 300 |
icon.mHotSpotY = hotSpotY; |
| 301 |
return icon; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
public static @NonNull PointerIcon load(@NonNull Resources resources, @XmlRes int resourceId) { |
| 326 |
if (resources == null) { |
| 327 |
throw new IllegalArgumentException("resources must not be null"); |
| 328 |
} |
| 329 |
|
| 330 |
PointerIcon icon = new PointerIcon(TYPE_CUSTOM); |
| 331 |
icon.loadResource(null, resources, resourceId); |
| 332 |
return icon; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 346 |
public @NonNull PointerIcon load(@NonNull Context context) { |
| 347 |
if (context == null) { |
| 348 |
throw new IllegalArgumentException("context must not be null"); |
| 349 |
} |
| 350 |
|
| 351 |
if (mSystemIconResourceId == 0 || mBitmap != null) { |
| 352 |
return this; |
| 353 |
} |
| 354 |
|
| 355 |
PointerIcon result = new PointerIcon(mType); |
| 356 |
result.mSystemIconResourceId = mSystemIconResourceId; |
| 357 |
result.loadResource(context, context.getResources(), mSystemIconResourceId); |
| 358 |
return result; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
public int getType() { |
| 363 |
return mType; |
| 364 |
} |
| 365 |
|
| 366 |
public static final @NonNull Parcelable.Creator<PointerIcon> CREATOR |
| 367 |
= new Parcelable.Creator<PointerIcon>() { |
| 368 |
public PointerIcon createFromParcel(Parcel in) { |
| 369 |
int type = in.readInt(); |
| 370 |
if (type == TYPE_NULL) { |
| 371 |
return getNullIcon(); |
| 372 |
} |
| 373 |
|
| 374 |
int systemIconResourceId = in.readInt(); |
| 375 |
if (systemIconResourceId != 0) { |
| 376 |
PointerIcon icon = new PointerIcon(type); |
| 377 |
icon.mSystemIconResourceId = systemIconResourceId; |
| 378 |
return icon; |
| 379 |
} |
| 380 |
|
| 381 |
Bitmap bitmap = Bitmap.CREATOR.createFromParcel(in); |
| 382 |
float hotSpotX = in.readFloat(); |
| 383 |
float hotSpotY = in.readFloat(); |
| 384 |
return PointerIcon.create(bitmap, hotSpotX, hotSpotY); |
| 385 |
} |
| 386 |
|
| 387 |
public PointerIcon[] newArray(int size) { |
| 388 |
return new PointerIcon[size]; |
| 389 |
} |
| 390 |
}; |
| 391 |
|
| 392 |
public int describeContents() { |
| 393 |
return 0; |
| 394 |
} |
| 395 |
|
| 396 |
public void writeToParcel(Parcel out, int flags) { |
| 397 |
out.writeInt(mType); |
| 398 |
|
| 399 |
if (mType != TYPE_NULL) { |
| 400 |
out.writeInt(mSystemIconResourceId); |
| 401 |
if (mSystemIconResourceId == 0) { |
| 402 |
mBitmap.writeToParcel(out, flags); |
| 403 |
out.writeFloat(mHotSpotX); |
| 404 |
out.writeFloat(mHotSpotY); |
| 405 |
} |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
@Override |
| 410 |
public boolean equals(@Nullable Object other) { |
| 411 |
if (this == other) { |
| 412 |
return true; |
| 413 |
} |
| 414 |
|
| 415 |
if (other == null || !(other instanceof PointerIcon)) { |
| 416 |
return false; |
| 417 |
} |
| 418 |
|
| 419 |
PointerIcon otherIcon = (PointerIcon) other; |
| 420 |
if (mType != otherIcon.mType |
| 421 |
|| mSystemIconResourceId != otherIcon.mSystemIconResourceId) { |
| 422 |
return false; |
| 423 |
} |
| 424 |
|
| 425 |
if (mSystemIconResourceId == 0 && (mBitmap != otherIcon.mBitmap |
| 426 |
|| mHotSpotX != otherIcon.mHotSpotX |
| 427 |
|| mHotSpotY != otherIcon.mHotSpotY)) { |
| 428 |
return false; |
| 429 |
} |
| 430 |
|
| 431 |
return true; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
private Bitmap getBitmapFromDrawable(BitmapDrawable bitmapDrawable) { |
| 443 |
Bitmap bitmap = bitmapDrawable.getBitmap(); |
| 444 |
final int scaledWidth = bitmapDrawable.getIntrinsicWidth(); |
| 445 |
final int scaledHeight = bitmapDrawable.getIntrinsicHeight(); |
| 446 |
if (scaledWidth == bitmap.getWidth() && scaledHeight == bitmap.getHeight()) { |
| 447 |
return bitmap; |
| 448 |
} |
| 449 |
|
| 450 |
Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); |
| 451 |
RectF dst = new RectF(0, 0, scaledWidth, scaledHeight); |
| 452 |
|
| 453 |
Bitmap scaled = Bitmap.createBitmap(scaledWidth, scaledHeight, bitmap.getConfig()); |
| 454 |
Canvas canvas = new Canvas(scaled); |
| 455 |
Paint paint = new Paint(); |
| 456 |
paint.setFilterBitmap(true); |
| 457 |
canvas.drawBitmap(bitmap, src, dst, paint); |
| 458 |
return scaled; |
| 459 |
} |
| 460 |
|
| 461 |
private void loadResource(Context context, Resources resources, @XmlRes int resourceId) { |
| 462 |
final XmlResourceParser parser = resources.getXml(resourceId); |
| 463 |
final int bitmapRes; |
| 464 |
final float hotSpotX; |
| 465 |
final float hotSpotY; |
| 466 |
try { |
| 467 |
XmlUtils.beginDocument(parser, "pointer-icon"); |
| 468 |
|
| 469 |
final TypedArray a = resources.obtainAttributes( |
| 470 |
parser, com.android.internal.R.styleable.PointerIcon); |
| 471 |
bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0); |
| 472 |
hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0); |
| 473 |
hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0); |
| 474 |
a.recycle(); |
| 475 |
} catch (Exception ex) { |
| 476 |
throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex); |
| 477 |
} finally { |
| 478 |
parser.close(); |
| 479 |
} |
| 480 |
|
| 481 |
if (bitmapRes == 0) { |
| 482 |
throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute."); |
| 483 |
} |
| 484 |
|
| 485 |
Drawable drawable; |
| 486 |
if (context == null) { |
| 487 |
drawable = resources.getDrawable(bitmapRes); |
| 488 |
} else { |
| 489 |
drawable = context.getDrawable(bitmapRes); |
| 490 |
} |
| 491 |
if (drawable instanceof AnimationDrawable) { |
| 492 |
|
| 493 |
final AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 494 |
final int frames = animationDrawable.getNumberOfFrames(); |
| 495 |
drawable = animationDrawable.getFrame(0); |
| 496 |
if (frames == 1) { |
| 497 |
Log.w(TAG, "Animation icon with single frame -- simply treating the first " |
| 498 |
+ "frame as a normal bitmap icon."); |
| 499 |
} else { |
| 500 |
|
| 501 |
mDurationPerFrame = animationDrawable.getDuration(0); |
| 502 |
mBitmapFrames = new Bitmap[frames - 1]; |
| 503 |
final int width = drawable.getIntrinsicWidth(); |
| 504 |
final int height = drawable.getIntrinsicHeight(); |
| 505 |
for (int i = 1; i < frames; ++i) { |
| 506 |
Drawable drawableFrame = animationDrawable.getFrame(i); |
| 507 |
if (!(drawableFrame instanceof BitmapDrawable)) { |
| 508 |
throw new IllegalArgumentException("Frame of an animated pointer icon " |
| 509 |
+ "must refer to a bitmap drawable."); |
| 510 |
} |
| 511 |
if (drawableFrame.getIntrinsicWidth() != width || |
| 512 |
drawableFrame.getIntrinsicHeight() != height) { |
| 513 |
throw new IllegalArgumentException("The bitmap size of " + i + "-th frame " |
| 514 |
+ "is different. All frames should have the exact same size and " |
| 515 |
+ "share the same hotspot."); |
| 516 |
} |
| 517 |
BitmapDrawable bitmapDrawableFrame = (BitmapDrawable) drawableFrame; |
| 518 |
mBitmapFrames[i - 1] = getBitmapFromDrawable(bitmapDrawableFrame); |
| 519 |
} |
| 520 |
} |
| 521 |
} |
| 522 |
if (!(drawable instanceof BitmapDrawable)) { |
| 523 |
throw new IllegalArgumentException("<pointer-icon> bitmap attribute must " |
| 524 |
+ "refer to a bitmap drawable."); |
| 525 |
} |
| 526 |
|
| 527 |
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; |
| 528 |
final Bitmap bitmap = getBitmapFromDrawable(bitmapDrawable); |
| 529 |
validateHotSpot(bitmap, hotSpotX, hotSpotY); |
| 530 |
|
| 531 |
mBitmap = bitmap; |
| 532 |
mHotSpotX = hotSpotX; |
| 533 |
mHotSpotY = hotSpotY; |
| 534 |
} |
| 535 |
|
| 536 |
private static void validateHotSpot(Bitmap bitmap, float hotSpotX, float hotSpotY) { |
| 537 |
if (hotSpotX < 0 || hotSpotX >= bitmap.getWidth()) { |
| 538 |
throw new IllegalArgumentException("x hotspot lies outside of the bitmap area"); |
| 539 |
} |
| 540 |
if (hotSpotY < 0 || hotSpotY >= bitmap.getHeight()) { |
| 541 |
throw new IllegalArgumentException("y hotspot lies outside of the bitmap area"); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
private static int getSystemIconTypeIndex(int type) { |
| 546 |
switch (type) { |
| 547 |
case TYPE_ARROW: |
| 548 |
return com.android.internal.R.styleable.Pointer_pointerIconArrow; |
| 549 |
case TYPE_SPOT_HOVER: |
| 550 |
return com.android.internal.R.styleable.Pointer_pointerIconSpotHover; |
| 551 |
case TYPE_SPOT_TOUCH: |
| 552 |
return com.android.internal.R.styleable.Pointer_pointerIconSpotTouch; |
| 553 |
case TYPE_SPOT_ANCHOR: |
| 554 |
return com.android.internal.R.styleable.Pointer_pointerIconSpotAnchor; |
| 555 |
case TYPE_HAND: |
| 556 |
return com.android.internal.R.styleable.Pointer_pointerIconHand; |
| 557 |
case TYPE_CONTEXT_MENU: |
| 558 |
return com.android.internal.R.styleable.Pointer_pointerIconContextMenu; |
| 559 |
case TYPE_HELP: |
| 560 |
return com.android.internal.R.styleable.Pointer_pointerIconHelp; |
| 561 |
case TYPE_WAIT: |
| 562 |
return com.android.internal.R.styleable.Pointer_pointerIconWait; |
| 563 |
case TYPE_CELL: |
| 564 |
return com.android.internal.R.styleable.Pointer_pointerIconCell; |
| 565 |
case TYPE_CROSSHAIR: |
| 566 |
return com.android.internal.R.styleable.Pointer_pointerIconCrosshair; |
| 567 |
case TYPE_TEXT: |
| 568 |
return com.android.internal.R.styleable.Pointer_pointerIconText; |
| 569 |
case TYPE_VERTICAL_TEXT: |
| 570 |
return com.android.internal.R.styleable.Pointer_pointerIconVerticalText; |
| 571 |
case TYPE_ALIAS: |
| 572 |
return com.android.internal.R.styleable.Pointer_pointerIconAlias; |
| 573 |
case TYPE_COPY: |
| 574 |
return com.android.internal.R.styleable.Pointer_pointerIconCopy; |
| 575 |
case TYPE_ALL_SCROLL: |
| 576 |
return com.android.internal.R.styleable.Pointer_pointerIconAllScroll; |
| 577 |
case TYPE_NO_DROP: |
| 578 |
return com.android.internal.R.styleable.Pointer_pointerIconNodrop; |
| 579 |
case TYPE_HORIZONTAL_DOUBLE_ARROW: |
| 580 |
return com.android.internal.R.styleable.Pointer_pointerIconHorizontalDoubleArrow; |
| 581 |
case TYPE_VERTICAL_DOUBLE_ARROW: |
| 582 |
return com.android.internal.R.styleable.Pointer_pointerIconVerticalDoubleArrow; |
| 583 |
case TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW: |
| 584 |
return com.android.internal.R.styleable. |
| 585 |
Pointer_pointerIconTopRightDiagonalDoubleArrow; |
| 586 |
case TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW: |
| 587 |
return com.android.internal.R.styleable. |
| 588 |
Pointer_pointerIconTopLeftDiagonalDoubleArrow; |
| 589 |
case TYPE_ZOOM_IN: |
| 590 |
return com.android.internal.R.styleable.Pointer_pointerIconZoomIn; |
| 591 |
case TYPE_ZOOM_OUT: |
| 592 |
return com.android.internal.R.styleable.Pointer_pointerIconZoomOut; |
| 593 |
case TYPE_GRAB: |
| 594 |
return com.android.internal.R.styleable.Pointer_pointerIconGrab; |
| 595 |
case TYPE_GRABBING: |
| 596 |
return com.android.internal.R.styleable.Pointer_pointerIconGrabbing; |
| 597 |
default: |
| 598 |
return 0; |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
private static void registerDisplayListener(@NonNull Context context) { |
| 607 |
sDisplayListener = new DisplayManager.DisplayListener() { |
| 608 |
@Override |
| 609 |
public void onDisplayAdded(int displayId) { |
| 610 |
} |
| 611 |
|
| 612 |
@Override |
| 613 |
public void onDisplayRemoved(int displayId) { |
| 614 |
gSystemIconsByDisplay.remove(displayId); |
| 615 |
} |
| 616 |
|
| 617 |
@Override |
| 618 |
public void onDisplayChanged(int displayId) { |
| 619 |
gSystemIconsByDisplay.remove(displayId); |
| 620 |
} |
| 621 |
}; |
| 622 |
|
| 623 |
DisplayManager displayManager = context.getSystemService(DisplayManager.class); |
| 624 |
displayManager.registerDisplayListener(sDisplayListener, null ); |
| 625 |
} |
| 626 |
|
| 627 |
} |