|
16 | 16 |
|
17 | 17 | package android.hardware.input; |
18 | 18 |
|
| 19 | +import com.android.internal.util.ArrayUtils; |
| 20 | + |
19 | 21 | import android.annotation.SdkConstant; |
20 | 22 | import android.annotation.SdkConstant.SdkConstantType; |
21 | 23 | import android.content.Context; |
@@ -216,6 +218,41 @@ public InputDevice getInputDevice(int id) { |
216 | 218 | } |
217 | 219 | } |
218 | 220 |
|
| 221 | + /** |
| 222 | + * Gets information about the input device with the specified descriptor. |
| 223 | + * @param descriptor The input device descriptor. |
| 224 | + * @return The input device or null if not found. |
| 225 | + * @hide |
| 226 | + */ |
| 227 | + public InputDevice getInputDeviceByDescriptor(String descriptor) { |
| 228 | + if (descriptor == null) { |
| 229 | + throw new IllegalArgumentException("descriptor must not be null."); |
| 230 | + } |
| 231 | + |
| 232 | + synchronized (mInputDevicesLock) { |
| 233 | + populateInputDevicesLocked(); |
| 234 | + |
| 235 | + int numDevices = mInputDevices.size(); |
| 236 | + for (int i = 0; i < numDevices; i++) { |
| 237 | + InputDevice inputDevice = mInputDevices.valueAt(i); |
| 238 | + if (inputDevice == null) { |
| 239 | + int id = mInputDevices.keyAt(i); |
| 240 | + try { |
| 241 | + inputDevice = mIm.getInputDevice(id); |
| 242 | + } catch (RemoteException ex) { |
| 243 | + // Ignore the problem for the purposes of this method. |
| 244 | + continue; |
| 245 | + } |
| 246 | + mInputDevices.setValueAt(i, inputDevice); |
| 247 | + } |
| 248 | + if (descriptor.equals(inputDevice.getDescriptor())) { |
| 249 | + return inputDevice; |
| 250 | + } |
| 251 | + } |
| 252 | + return null; |
| 253 | + } |
| 254 | + } |
| 255 | + |
219 | 256 | /** |
220 | 257 | * Gets the ids of all input devices in the system. |
221 | 258 | * @return The input device ids. |
@@ -332,50 +369,129 @@ public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) { |
332 | 369 | } |
333 | 370 |
|
334 | 371 | /** |
335 | | - * Gets the keyboard layout descriptor for the specified input device. |
| 372 | + * Gets the current keyboard layout descriptor for the specified input device. |
336 | 373 | * |
337 | 374 | * @param inputDeviceDescriptor The input device descriptor. |
338 | | - * @return The keyboard layout descriptor, or null if unknown or if the default |
339 | | - * keyboard layout will be used. |
| 375 | + * @return The keyboard layout descriptor, or null if no keyboard layout has been set. |
340 | 376 | * |
341 | 377 | * @hide |
342 | 378 | */ |
343 | | - public String getKeyboardLayoutForInputDevice(String inputDeviceDescriptor) { |
| 379 | + public String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor) { |
344 | 380 | if (inputDeviceDescriptor == null) { |
345 | 381 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
346 | 382 | } |
347 | 383 |
|
348 | 384 | try { |
349 | | - return mIm.getKeyboardLayoutForInputDevice(inputDeviceDescriptor); |
| 385 | + return mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor); |
350 | 386 | } catch (RemoteException ex) { |
351 | | - Log.w(TAG, "Could not get keyboard layout for input device.", ex); |
| 387 | + Log.w(TAG, "Could not get current keyboard layout for input device.", ex); |
352 | 388 | return null; |
353 | 389 | } |
354 | 390 | } |
355 | 391 |
|
356 | 392 | /** |
357 | | - * Sets the keyboard layout descriptor for the specified input device. |
| 393 | + * Sets the current keyboard layout descriptor for the specified input device. |
| 394 | + * <p> |
| 395 | + * This method may have the side-effect of causing the input device in question |
| 396 | + * to be reconfigured. |
| 397 | + * </p> |
| 398 | + * |
| 399 | + * @param inputDeviceDescriptor The input device descriptor. |
| 400 | + * @param keyboardLayoutDescriptor The keyboard layout descriptor to use, must not be null. |
| 401 | + * |
| 402 | + * @hide |
| 403 | + */ |
| 404 | + public void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
| 405 | + String keyboardLayoutDescriptor) { |
| 406 | + if (inputDeviceDescriptor == null) { |
| 407 | + throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 408 | + } |
| 409 | + if (keyboardLayoutDescriptor == null) { |
| 410 | + throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 411 | + } |
| 412 | + |
| 413 | + try { |
| 414 | + mIm.setCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor, |
| 415 | + keyboardLayoutDescriptor); |
| 416 | + } catch (RemoteException ex) { |
| 417 | + Log.w(TAG, "Could not set current keyboard layout for input device.", ex); |
| 418 | + } |
| 419 | + } |
| 420 | + |
| 421 | + /** |
| 422 | + * Gets all keyboard layout descriptors that are enabled for the specified input device. |
| 423 | + * |
| 424 | + * @param inputDeviceDescriptor The input device descriptor. |
| 425 | + * @return The keyboard layout descriptors. |
| 426 | + * |
| 427 | + * @hide |
| 428 | + */ |
| 429 | + public String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor) { |
| 430 | + if (inputDeviceDescriptor == null) { |
| 431 | + throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 432 | + } |
| 433 | + |
| 434 | + try { |
| 435 | + return mIm.getKeyboardLayoutsForInputDevice(inputDeviceDescriptor); |
| 436 | + } catch (RemoteException ex) { |
| 437 | + Log.w(TAG, "Could not get keyboard layouts for input device.", ex); |
| 438 | + return ArrayUtils.emptyArray(String.class); |
| 439 | + } |
| 440 | + } |
| 441 | + |
| 442 | + /** |
| 443 | + * Adds the keyboard layout descriptor for the specified input device. |
358 | 444 | * <p> |
359 | 445 | * This method may have the side-effect of causing the input device in question |
360 | 446 | * to be reconfigured. |
361 | 447 | * </p> |
362 | 448 | * |
363 | 449 | * @param inputDeviceDescriptor The input device descriptor. |
364 | | - * @param keyboardLayoutDescriptor The keyboard layout descriptor, or null to remove |
365 | | - * the mapping so that the default keyboard layout will be used for the input device. |
| 450 | + * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to add. |
366 | 451 | * |
367 | 452 | * @hide |
368 | 453 | */ |
369 | | - public void setKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
| 454 | + public void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
370 | 455 | String keyboardLayoutDescriptor) { |
371 | 456 | if (inputDeviceDescriptor == null) { |
372 | 457 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
373 | 458 | } |
| 459 | + if (keyboardLayoutDescriptor == null) { |
| 460 | + throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 461 | + } |
| 462 | + |
| 463 | + try { |
| 464 | + mIm.addKeyboardLayoutForInputDevice(inputDeviceDescriptor, keyboardLayoutDescriptor); |
| 465 | + } catch (RemoteException ex) { |
| 466 | + Log.w(TAG, "Could not add keyboard layout for input device.", ex); |
| 467 | + } |
| 468 | + } |
| 469 | + |
| 470 | + /** |
| 471 | + * Removes the keyboard layout descriptor for the specified input device. |
| 472 | + * <p> |
| 473 | + * This method may have the side-effect of causing the input device in question |
| 474 | + * to be reconfigured. |
| 475 | + * </p> |
| 476 | + * |
| 477 | + * @param inputDeviceDescriptor The input device descriptor. |
| 478 | + * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to remove. |
| 479 | + * |
| 480 | + * @hide |
| 481 | + */ |
| 482 | + public void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
| 483 | + String keyboardLayoutDescriptor) { |
| 484 | + if (inputDeviceDescriptor == null) { |
| 485 | + throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 486 | + } |
| 487 | + if (keyboardLayoutDescriptor == null) { |
| 488 | + throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 489 | + } |
374 | 490 |
|
375 | 491 | try { |
376 | | - mIm.setKeyboardLayoutForInputDevice(inputDeviceDescriptor, keyboardLayoutDescriptor); |
| 492 | + mIm.removeKeyboardLayoutForInputDevice(inputDeviceDescriptor, keyboardLayoutDescriptor); |
377 | 493 | } catch (RemoteException ex) { |
378 | | - Log.w(TAG, "Could not set keyboard layout for input device.", ex); |
| 494 | + Log.w(TAG, "Could not remove keyboard layout for input device.", ex); |
379 | 495 | } |
380 | 496 | } |
381 | 497 |
|
|
0 commit comments