Search in sources :

Example 16 with InputManager

use of android.hardware.input.InputManager in project android_frameworks_base by DirtyUnicorns.

the class KeyCharacterMap method load.

/**
     * Loads the key character maps for the keyboard with the specified device id.
     *
     * @param deviceId The device id of the keyboard.
     * @return The associated key character map.
     * @throws {@link UnavailableException} if the key character map
     * could not be loaded because it was malformed or the default key character map
     * is missing from the system.
     */
public static KeyCharacterMap load(int deviceId) {
    final InputManager im = InputManager.getInstance();
    InputDevice inputDevice = im.getInputDevice(deviceId);
    if (inputDevice == null) {
        inputDevice = im.getInputDevice(VIRTUAL_KEYBOARD);
        if (inputDevice == null) {
            throw new UnavailableException("Could not load key character map for device " + deviceId);
        }
    }
    return inputDevice.getKeyCharacterMap();
}
Also used : InputManager(android.hardware.input.InputManager)

Example 17 with InputManager

use of android.hardware.input.InputManager in project android_frameworks_base by ResurrectionRemix.

the class Action method triggerVirtualKeypress.

public static void triggerVirtualKeypress(final int keyCode, boolean longpress) {
    InputManager im = InputManager.getInstance();
    long now = SystemClock.uptimeMillis();
    int downflags = 0;
    int upflags = 0;
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        downflags = upflags = KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE;
    } else {
        downflags = upflags = KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY;
    }
    if (longpress) {
        downflags |= KeyEvent.FLAG_LONG_PRESS;
    }
    final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, downflags, InputDevice.SOURCE_KEYBOARD);
    im.injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    final KeyEvent upEvent = new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, upflags, InputDevice.SOURCE_KEYBOARD);
    im.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}
Also used : KeyEvent(android.view.KeyEvent) InputManager(android.hardware.input.InputManager)

Example 18 with InputManager

use of android.hardware.input.InputManager in project android_frameworks_base by ResurrectionRemix.

the class KeyCharacterMap method load.

/**
     * Loads the key character maps for the keyboard with the specified device id.
     *
     * @param deviceId The device id of the keyboard.
     * @return The associated key character map.
     * @throws {@link UnavailableException} if the key character map
     * could not be loaded because it was malformed or the default key character map
     * is missing from the system.
     */
public static KeyCharacterMap load(int deviceId) {
    final InputManager im = InputManager.getInstance();
    InputDevice inputDevice = im.getInputDevice(deviceId);
    if (inputDevice == null) {
        inputDevice = im.getInputDevice(VIRTUAL_KEYBOARD);
        if (inputDevice == null) {
            throw new UnavailableException("Could not load key character map for device " + deviceId);
        }
    }
    return inputDevice.getKeyCharacterMap();
}
Also used : InputManager(android.hardware.input.InputManager)

Example 19 with InputManager

use of android.hardware.input.InputManager in project android_frameworks_base by ResurrectionRemix.

the class KeyboardUI method init.

// Shoud only be called on the handler thread
private void init() {
    Context context = mContext;
    mKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
    if (TextUtils.isEmpty(mKeyboardName)) {
        if (DEBUG) {
            Slog.d(TAG, "No packaged keyboard name given.");
        }
        return;
    }
    LocalBluetoothManager bluetoothManager = LocalBluetoothManager.getInstance(context, null);
    if (bluetoothManager == null) {
        if (DEBUG) {
            Slog.e(TAG, "Failed to retrieve LocalBluetoothManager instance");
        }
        return;
    }
    mEnabled = true;
    mCachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    mLocalBluetoothAdapter = bluetoothManager.getBluetoothAdapter();
    mProfileManager = bluetoothManager.getProfileManager();
    bluetoothManager.getEventManager().registerCallback(new BluetoothCallbackHandler());
    Utils.setErrorListener(new BluetoothErrorListener());
    InputManager im = context.getSystemService(InputManager.class);
    im.registerOnTabletModeChangedListener(this, mHandler);
    mInTabletMode = im.isInTabletMode();
    processKeyboardState();
    mUIHandler = new KeyboardUIHandler();
}
Also used : Context(android.content.Context) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) InputManager(android.hardware.input.InputManager)

Example 20 with InputManager

use of android.hardware.input.InputManager in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method triggerVirtualKeypress.

private void triggerVirtualKeypress(final int keyCode) {
    InputManager im = InputManager.getInstance();
    long now = SystemClock.uptimeMillis();
    final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD);
    final KeyEvent upEvent = KeyEvent.changeAction(downEvent, KeyEvent.ACTION_UP);
    im.injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    im.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}
Also used : KeyEvent(android.view.KeyEvent) InputManager(android.hardware.input.InputManager)

Aggregations

InputManager (android.hardware.input.InputManager)24 KeyEvent (android.view.KeyEvent)6 Context (android.content.Context)5 InputDevice (android.view.InputDevice)5 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)5 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1 PrintServiceInfo (android.printservice.PrintServiceInfo)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1 InputMethodInfo (android.view.inputmethod.InputMethodInfo)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1