| 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.Nullable; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.hardware.input.InputManager; |
| 22 |
import android.os.Build; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
import android.text.method.MetaKeyKeyListener; |
| 26 |
import android.util.AndroidRuntimeException; |
| 27 |
import android.util.SparseIntArray; |
| 28 |
|
| 29 |
import com.android.internal.annotations.VisibleForTesting; |
| 30 |
|
| 31 |
import java.text.Normalizer; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class KeyCharacterMap implements Parcelable { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
@Deprecated |
| 52 |
public static final int BUILT_IN_KEYBOARD = 0; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static final int VIRTUAL_KEYBOARD = -1; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static final int NUMERIC = 1; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static final int PREDICTIVE = 2; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public static final int ALPHA = 3; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public static final int FULL = 4; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public static final int SPECIAL_FUNCTION = 5; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public static final char HEX_INPUT = '\uEF00'; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public static final char PICKER_DIALOG_INPUT = '\uEF01'; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public static final int MODIFIER_BEHAVIOR_CHORDED = 0; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public static final int MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED = 1; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public static final int COMBINING_ACCENT = 0x80000000; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public static final int COMBINING_ACCENT_MASK = 0x7FFFFFFF; |
| 154 |
|
| 155 |
|
| 156 |
private static final int ACCENT_ACUTE = '\u00B4'; |
| 157 |
private static final int ACCENT_BREVE = '\u02D8'; |
| 158 |
private static final int ACCENT_CARON = '\u02C7'; |
| 159 |
private static final int ACCENT_CEDILLA = '\u00B8'; |
| 160 |
private static final int ACCENT_CIRCUMFLEX = '\u02C6'; |
| 161 |
private static final int ACCENT_COMMA_ABOVE = '\u1FBD'; |
| 162 |
private static final int ACCENT_COMMA_ABOVE_RIGHT = '\u02BC'; |
| 163 |
private static final int ACCENT_DOT_ABOVE = '\u02D9'; |
| 164 |
private static final int ACCENT_DOT_BELOW = '.'; |
| 165 |
private static final int ACCENT_DOUBLE_ACUTE = '\u02DD'; |
| 166 |
private static final int ACCENT_GRAVE = '\u02CB'; |
| 167 |
private static final int ACCENT_HOOK_ABOVE = '\u02C0'; |
| 168 |
private static final int ACCENT_HORN = '\''; |
| 169 |
private static final int ACCENT_MACRON = '\u00AF'; |
| 170 |
private static final int ACCENT_MACRON_BELOW = '\u02CD'; |
| 171 |
private static final int ACCENT_OGONEK = '\u02DB'; |
| 172 |
private static final int ACCENT_REVERSED_COMMA_ABOVE = '\u02BD'; |
| 173 |
private static final int ACCENT_RING_ABOVE = '\u02DA'; |
| 174 |
private static final int ACCENT_STROKE = '-'; |
| 175 |
private static final int ACCENT_TILDE = '\u02DC'; |
| 176 |
private static final int ACCENT_TURNED_COMMA_ABOVE = '\u02BB'; |
| 177 |
private static final int ACCENT_UMLAUT = '\u00A8'; |
| 178 |
private static final int ACCENT_VERTICAL_LINE_ABOVE = '\u02C8'; |
| 179 |
private static final int ACCENT_VERTICAL_LINE_BELOW = '\u02CC'; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
private static final int ACCENT_GRAVE_LEGACY = '`'; |
| 184 |
private static final int ACCENT_CIRCUMFLEX_LEGACY = '^'; |
| 185 |
private static final int ACCENT_TILDE_LEGACY = '~'; |
| 186 |
|
| 187 |
private static final int CHAR_SPACE = ' '; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
private static final SparseIntArray sCombiningToAccent = new SparseIntArray(); |
| 193 |
private static final SparseIntArray sAccentToCombining = new SparseIntArray(); |
| 194 |
static { |
| 195 |
addCombining('\u0300', ACCENT_GRAVE); |
| 196 |
addCombining('\u0301', ACCENT_ACUTE); |
| 197 |
addCombining('\u0302', ACCENT_CIRCUMFLEX); |
| 198 |
addCombining('\u0303', ACCENT_TILDE); |
| 199 |
addCombining('\u0304', ACCENT_MACRON); |
| 200 |
addCombining('\u0306', ACCENT_BREVE); |
| 201 |
addCombining('\u0307', ACCENT_DOT_ABOVE); |
| 202 |
addCombining('\u0308', ACCENT_UMLAUT); |
| 203 |
addCombining('\u0309', ACCENT_HOOK_ABOVE); |
| 204 |
addCombining('\u030A', ACCENT_RING_ABOVE); |
| 205 |
addCombining('\u030B', ACCENT_DOUBLE_ACUTE); |
| 206 |
addCombining('\u030C', ACCENT_CARON); |
| 207 |
addCombining('\u030D', ACCENT_VERTICAL_LINE_ABOVE); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
addCombining('\u0312', ACCENT_TURNED_COMMA_ABOVE); |
| 213 |
addCombining('\u0313', ACCENT_COMMA_ABOVE); |
| 214 |
addCombining('\u0314', ACCENT_REVERSED_COMMA_ABOVE); |
| 215 |
addCombining('\u0315', ACCENT_COMMA_ABOVE_RIGHT); |
| 216 |
addCombining('\u031B', ACCENT_HORN); |
| 217 |
addCombining('\u0323', ACCENT_DOT_BELOW); |
| 218 |
|
| 219 |
addCombining('\u0327', ACCENT_CEDILLA); |
| 220 |
addCombining('\u0328', ACCENT_OGONEK); |
| 221 |
addCombining('\u0329', ACCENT_VERTICAL_LINE_BELOW); |
| 222 |
addCombining('\u0331', ACCENT_MACRON_BELOW); |
| 223 |
addCombining('\u0335', ACCENT_STROKE); |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
sCombiningToAccent.append('\u0340', ACCENT_GRAVE); |
| 230 |
sCombiningToAccent.append('\u0341', ACCENT_ACUTE); |
| 231 |
sCombiningToAccent.append('\u0343', ACCENT_COMMA_ABOVE); |
| 232 |
|
| 233 |
|
| 234 |
sAccentToCombining.append(ACCENT_GRAVE_LEGACY, '\u0300'); |
| 235 |
sAccentToCombining.append(ACCENT_CIRCUMFLEX_LEGACY, '\u0302'); |
| 236 |
sAccentToCombining.append(ACCENT_TILDE_LEGACY, '\u0303'); |
| 237 |
} |
| 238 |
|
| 239 |
private static void addCombining(int combining, int accent) { |
| 240 |
sCombiningToAccent.append(combining, accent); |
| 241 |
sAccentToCombining.append(accent, combining); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
private static final SparseIntArray sDeadKeyCache = new SparseIntArray(); |
| 250 |
private static final StringBuilder sDeadKeyBuilder = new StringBuilder(); |
| 251 |
static { |
| 252 |
|
| 253 |
|
| 254 |
addDeadKey(ACCENT_STROKE, 'D', '\u0110'); |
| 255 |
addDeadKey(ACCENT_STROKE, 'G', '\u01e4'); |
| 256 |
addDeadKey(ACCENT_STROKE, 'H', '\u0126'); |
| 257 |
addDeadKey(ACCENT_STROKE, 'I', '\u0197'); |
| 258 |
addDeadKey(ACCENT_STROKE, 'L', '\u0141'); |
| 259 |
addDeadKey(ACCENT_STROKE, 'O', '\u00d8'); |
| 260 |
addDeadKey(ACCENT_STROKE, 'T', '\u0166'); |
| 261 |
addDeadKey(ACCENT_STROKE, 'd', '\u0111'); |
| 262 |
addDeadKey(ACCENT_STROKE, 'g', '\u01e5'); |
| 263 |
addDeadKey(ACCENT_STROKE, 'h', '\u0127'); |
| 264 |
addDeadKey(ACCENT_STROKE, 'i', '\u0268'); |
| 265 |
addDeadKey(ACCENT_STROKE, 'l', '\u0142'); |
| 266 |
addDeadKey(ACCENT_STROKE, 'o', '\u00f8'); |
| 267 |
addDeadKey(ACCENT_STROKE, 't', '\u0167'); |
| 268 |
} |
| 269 |
|
| 270 |
private static void addDeadKey(int accent, int c, int result) { |
| 271 |
final int combining = sAccentToCombining.get(accent); |
| 272 |
if (combining == 0) { |
| 273 |
throw new IllegalStateException("Invalid dead key declaration."); |
| 274 |
} |
| 275 |
final int combination = (combining << 16) | c; |
| 276 |
sDeadKeyCache.put(combination, result); |
| 277 |
} |
| 278 |
|
| 279 |
public static final @android.annotation.NonNull Parcelable.Creator<KeyCharacterMap> CREATOR = |
| 280 |
new Parcelable.Creator<KeyCharacterMap>() { |
| 281 |
public KeyCharacterMap createFromParcel(Parcel in) { |
| 282 |
return new KeyCharacterMap(in); |
| 283 |
} |
| 284 |
public KeyCharacterMap[] newArray(int size) { |
| 285 |
return new KeyCharacterMap[size]; |
| 286 |
} |
| 287 |
}; |
| 288 |
|
| 289 |
private long mPtr; |
| 290 |
|
| 291 |
private static native long nativeReadFromParcel(Parcel in); |
| 292 |
private static native void nativeWriteToParcel(long ptr, Parcel out); |
| 293 |
private static native void nativeDispose(long ptr); |
| 294 |
|
| 295 |
private static native char nativeGetCharacter(long ptr, int keyCode, int metaState); |
| 296 |
private static native boolean nativeGetFallbackAction(long ptr, int keyCode, int metaState, |
| 297 |
FallbackAction outFallbackAction); |
| 298 |
private static native char nativeGetNumber(long ptr, int keyCode); |
| 299 |
private static native char nativeGetMatch(long ptr, int keyCode, char[] chars, int metaState); |
| 300 |
private static native char nativeGetDisplayLabel(long ptr, int keyCode); |
| 301 |
private static native int nativeGetKeyboardType(long ptr); |
| 302 |
private static native KeyEvent[] nativeGetEvents(long ptr, char[] chars); |
| 303 |
private static native KeyCharacterMap nativeObtainEmptyKeyCharacterMap(int deviceId); |
| 304 |
private static native boolean nativeEquals(long ptr1, long ptr2); |
| 305 |
|
| 306 |
private KeyCharacterMap(Parcel in) { |
| 307 |
if (in == null) { |
| 308 |
throw new IllegalArgumentException("parcel must not be null"); |
| 309 |
} |
| 310 |
mPtr = nativeReadFromParcel(in); |
| 311 |
if (mPtr == 0) { |
| 312 |
throw new RuntimeException("Could not read KeyCharacterMap from parcel."); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 318 |
private KeyCharacterMap(long ptr) { |
| 319 |
mPtr = ptr; |
| 320 |
} |
| 321 |
|
| 322 |
@Override |
| 323 |
protected void finalize() throws Throwable { |
| 324 |
if (mPtr != 0) { |
| 325 |
nativeDispose(mPtr); |
| 326 |
mPtr = 0; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
@VisibleForTesting |
| 337 |
@Nullable |
| 338 |
public static KeyCharacterMap obtainEmptyMap(int deviceId) { |
| 339 |
return nativeObtainEmptyKeyCharacterMap(deviceId); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
public static KeyCharacterMap load(int deviceId) { |
| 352 |
final InputManager im = InputManager.getInstance(); |
| 353 |
InputDevice inputDevice = im.getInputDevice(deviceId); |
| 354 |
if (inputDevice == null) { |
| 355 |
inputDevice = im.getInputDevice(VIRTUAL_KEYBOARD); |
| 356 |
if (inputDevice == null) { |
| 357 |
throw new UnavailableException( |
| 358 |
"Could not load key character map for device " + deviceId); |
| 359 |
} |
| 360 |
} |
| 361 |
return inputDevice.getKeyCharacterMap(); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
public int get(int keyCode, int metaState) { |
| 386 |
metaState = KeyEvent.normalizeMetaState(metaState); |
| 387 |
char ch = nativeGetCharacter(mPtr, keyCode, metaState); |
| 388 |
|
| 389 |
int map = sCombiningToAccent.get(ch); |
| 390 |
if (map != 0) { |
| 391 |
return map | COMBINING_ACCENT; |
| 392 |
} else { |
| 393 |
return ch; |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public FallbackAction getFallbackAction(int keyCode, int metaState) { |
| 415 |
FallbackAction action = FallbackAction.obtain(); |
| 416 |
metaState = KeyEvent.normalizeMetaState(metaState); |
| 417 |
if (nativeGetFallbackAction(mPtr, keyCode, metaState, action)) { |
| 418 |
action.metaState = KeyEvent.normalizeMetaState(action.metaState); |
| 419 |
return action; |
| 420 |
} |
| 421 |
action.recycle(); |
| 422 |
return null; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public char getNumber(int keyCode) { |
| 447 |
return nativeGetNumber(mPtr, keyCode); |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
public char getMatch(int keyCode, char[] chars) { |
| 464 |
return getMatch(keyCode, chars, 0); |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
public char getMatch(int keyCode, char[] chars, int metaState) { |
| 479 |
if (chars == null) { |
| 480 |
throw new IllegalArgumentException("chars must not be null."); |
| 481 |
} |
| 482 |
|
| 483 |
metaState = KeyEvent.normalizeMetaState(metaState); |
| 484 |
return nativeGetMatch(mPtr, keyCode, chars, metaState); |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
public char getDisplayLabel(int keyCode) { |
| 495 |
return nativeGetDisplayLabel(mPtr, keyCode); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
public static int getDeadChar(int accent, int c) { |
| 509 |
if (c == accent || CHAR_SPACE == c) { |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
return accent; |
| 514 |
} |
| 515 |
|
| 516 |
int combining = sAccentToCombining.get(accent); |
| 517 |
if (combining == 0) { |
| 518 |
return 0; |
| 519 |
} |
| 520 |
|
| 521 |
final int combination = (combining << 16) | c; |
| 522 |
int combined; |
| 523 |
synchronized (sDeadKeyCache) { |
| 524 |
combined = sDeadKeyCache.get(combination, -1); |
| 525 |
if (combined == -1) { |
| 526 |
sDeadKeyBuilder.setLength(0); |
| 527 |
sDeadKeyBuilder.append((char)c); |
| 528 |
sDeadKeyBuilder.append((char)combining); |
| 529 |
String result = Normalizer.normalize(sDeadKeyBuilder, Normalizer.Form.NFC); |
| 530 |
combined = result.codePointCount(0, result.length()) == 1 |
| 531 |
? result.codePointAt(0) : 0; |
| 532 |
sDeadKeyCache.put(combination, combined); |
| 533 |
} |
| 534 |
} |
| 535 |
return combined; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
@Deprecated |
| 545 |
public static class KeyData { |
| 546 |
public static final int META_LENGTH = 4; |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
public char displayLabel; |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public char number; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
public char[] meta = new char[META_LENGTH]; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
@Deprecated |
| 582 |
public boolean getKeyData(int keyCode, KeyData results) { |
| 583 |
if (results.meta.length < KeyData.META_LENGTH) { |
| 584 |
throw new IndexOutOfBoundsException( |
| 585 |
"results.meta.length must be >= " + KeyData.META_LENGTH); |
| 586 |
} |
| 587 |
|
| 588 |
char displayLabel = nativeGetDisplayLabel(mPtr, keyCode); |
| 589 |
if (displayLabel == 0) { |
| 590 |
return false; |
| 591 |
} |
| 592 |
|
| 593 |
results.displayLabel = displayLabel; |
| 594 |
results.number = nativeGetNumber(mPtr, keyCode); |
| 595 |
results.meta[0] = nativeGetCharacter(mPtr, keyCode, 0); |
| 596 |
results.meta[1] = nativeGetCharacter(mPtr, keyCode, KeyEvent.META_SHIFT_ON); |
| 597 |
results.meta[2] = nativeGetCharacter(mPtr, keyCode, KeyEvent.META_ALT_ON); |
| 598 |
results.meta[3] = nativeGetCharacter(mPtr, keyCode, |
| 599 |
KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON); |
| 600 |
return true; |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public KeyEvent[] getEvents(char[] chars) { |
| 626 |
if (chars == null) { |
| 627 |
throw new IllegalArgumentException("chars must not be null."); |
| 628 |
} |
| 629 |
return nativeGetEvents(mPtr, chars); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
public boolean isPrintingKey(int keyCode) { |
| 639 |
int type = Character.getType(nativeGetDisplayLabel(mPtr, keyCode)); |
| 640 |
|
| 641 |
switch (type) |
| 642 |
{ |
| 643 |
case Character.SPACE_SEPARATOR: |
| 644 |
case Character.LINE_SEPARATOR: |
| 645 |
case Character.PARAGRAPH_SEPARATOR: |
| 646 |
case Character.CONTROL: |
| 647 |
case Character.FORMAT: |
| 648 |
return false; |
| 649 |
default: |
| 650 |
return true; |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
public int getKeyboardType() { |
| 666 |
return nativeGetKeyboardType(mPtr); |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
public int getModifierBehavior() { |
| 702 |
switch (getKeyboardType()) { |
| 703 |
case FULL: |
| 704 |
case SPECIAL_FUNCTION: |
| 705 |
return MODIFIER_BEHAVIOR_CHORDED; |
| 706 |
default: |
| 707 |
return MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED; |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
public static boolean deviceHasKey(int keyCode) { |
| 719 |
return InputManager.getInstance().deviceHasKeys(new int[] { keyCode })[0]; |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
public static boolean[] deviceHasKeys(int[] keyCodes) { |
| 732 |
return InputManager.getInstance().deviceHasKeys(keyCodes); |
| 733 |
} |
| 734 |
|
| 735 |
@Override |
| 736 |
public void writeToParcel(Parcel out, int flags) { |
| 737 |
if (out == null) { |
| 738 |
throw new IllegalArgumentException("parcel must not be null"); |
| 739 |
} |
| 740 |
nativeWriteToParcel(mPtr, out); |
| 741 |
} |
| 742 |
|
| 743 |
@Override |
| 744 |
public int describeContents() { |
| 745 |
return 0; |
| 746 |
} |
| 747 |
|
| 748 |
@Override |
| 749 |
public boolean equals(Object obj) { |
| 750 |
if (obj == null || !(obj instanceof KeyCharacterMap)) { |
| 751 |
return false; |
| 752 |
} |
| 753 |
KeyCharacterMap peer = (KeyCharacterMap) obj; |
| 754 |
if (mPtr == 0 || peer.mPtr == 0) { |
| 755 |
return mPtr == peer.mPtr; |
| 756 |
} |
| 757 |
return nativeEquals(mPtr, peer.mPtr); |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
public static class UnavailableException extends AndroidRuntimeException { |
| 764 |
public UnavailableException(String msg) { |
| 765 |
super(msg); |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
public static final class FallbackAction { |
| 775 |
private static final int MAX_RECYCLED = 10; |
| 776 |
private static final Object sRecycleLock = new Object(); |
| 777 |
private static FallbackAction sRecycleBin; |
| 778 |
private static int sRecycledCount; |
| 779 |
|
| 780 |
private FallbackAction next; |
| 781 |
|
| 782 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 783 |
public int keyCode; |
| 784 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 785 |
public int metaState; |
| 786 |
|
| 787 |
private FallbackAction() { |
| 788 |
} |
| 789 |
|
| 790 |
public static FallbackAction obtain() { |
| 791 |
final FallbackAction target; |
| 792 |
synchronized (sRecycleLock) { |
| 793 |
if (sRecycleBin == null) { |
| 794 |
target = new FallbackAction(); |
| 795 |
} else { |
| 796 |
target = sRecycleBin; |
| 797 |
sRecycleBin = target.next; |
| 798 |
sRecycledCount--; |
| 799 |
target.next = null; |
| 800 |
} |
| 801 |
} |
| 802 |
return target; |
| 803 |
} |
| 804 |
|
| 805 |
public void recycle() { |
| 806 |
synchronized (sRecycleLock) { |
| 807 |
if (sRecycledCount < MAX_RECYCLED) { |
| 808 |
next = sRecycleBin; |
| 809 |
sRecycleBin = this; |
| 810 |
sRecycledCount += 1; |
| 811 |
} else { |
| 812 |
next = null; |
| 813 |
} |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
} |