Search in sources :

Example 46 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

the class MLand method getGameControllers.

public ArrayList getGameControllers() {
    mGameControllers.clear();
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        if (isGamePad(dev)) {
            if (!mGameControllers.contains(deviceId)) {
                mGameControllers.add(deviceId);
            }
        }
    }
    return mGameControllers;
}
Also used : InputDevice(android.view.InputDevice) Paint(android.graphics.Paint)

Example 47 with InputDevice

use of android.view.InputDevice in project platform_frameworks_base by android.

the class InputManagerService method deliverInputDevicesChanged.

// Must be called on handler.
private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
    // Scan for changes.
    int numFullKeyboardsAdded = 0;
    mTempInputDevicesChangedListenersToNotify.clear();
    mTempFullKeyboards.clear();
    final int numListeners;
    final int[] deviceIdAndGeneration;
    synchronized (mInputDevicesLock) {
        if (!mInputDevicesChangedPending) {
            return;
        }
        mInputDevicesChangedPending = false;
        numListeners = mInputDevicesChangedListeners.size();
        for (int i = 0; i < numListeners; i++) {
            mTempInputDevicesChangedListenersToNotify.add(mInputDevicesChangedListeners.valueAt(i));
        }
        final int numDevices = mInputDevices.length;
        deviceIdAndGeneration = new int[numDevices * 2];
        for (int i = 0; i < numDevices; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            deviceIdAndGeneration[i * 2] = inputDevice.getId();
            deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
            if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
                if (!containsInputDeviceWithDescriptor(oldInputDevices, inputDevice.getDescriptor())) {
                    mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
                } else {
                    mTempFullKeyboards.add(inputDevice);
                }
            }
        }
    }
    // Notify listeners.
    for (int i = 0; i < numListeners; i++) {
        mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(deviceIdAndGeneration);
    }
    mTempInputDevicesChangedListenersToNotify.clear();
    // Check for missing keyboard layouts.
    List<InputDevice> keyboardsMissingLayout = new ArrayList<>();
    final int numFullKeyboards = mTempFullKeyboards.size();
    synchronized (mDataStore) {
        for (int i = 0; i < numFullKeyboards; i++) {
            final InputDevice inputDevice = mTempFullKeyboards.get(i);
            String layout = getCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier());
            if (layout == null) {
                layout = getDefaultKeyboardLayout(inputDevice);
                if (layout != null) {
                    setCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier(), layout);
                }
            }
            if (layout == null) {
                keyboardsMissingLayout.add(inputDevice);
            }
        }
    }
    if (mNotificationManager != null) {
        if (!keyboardsMissingLayout.isEmpty()) {
            if (keyboardsMissingLayout.size() > 1) {
                // We have more than one keyboard missing a layout, so drop the
                // user at the generic input methods page so they can pick which
                // one to set.
                showMissingKeyboardLayoutNotification(null);
            } else {
                showMissingKeyboardLayoutNotification(keyboardsMissingLayout.get(0));
            }
        } else if (mKeyboardLayoutNotificationShown) {
            hideMissingKeyboardLayoutNotification();
        }
    }
    mTempFullKeyboards.clear();
}
Also used : InputDevice(android.view.InputDevice) ArrayList(java.util.ArrayList)

Example 48 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by crdroidandroid.

the class InputManagerService method deliverInputDevicesChanged.

// Must be called on handler.
private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
    // Scan for changes.
    int numFullKeyboardsAdded = 0;
    mTempInputDevicesChangedListenersToNotify.clear();
    mTempFullKeyboards.clear();
    final int numListeners;
    final int[] deviceIdAndGeneration;
    synchronized (mInputDevicesLock) {
        if (!mInputDevicesChangedPending) {
            return;
        }
        mInputDevicesChangedPending = false;
        numListeners = mInputDevicesChangedListeners.size();
        for (int i = 0; i < numListeners; i++) {
            mTempInputDevicesChangedListenersToNotify.add(mInputDevicesChangedListeners.valueAt(i));
        }
        final int numDevices = mInputDevices.length;
        deviceIdAndGeneration = new int[numDevices * 2];
        for (int i = 0; i < numDevices; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            deviceIdAndGeneration[i * 2] = inputDevice.getId();
            deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
            if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
                if (!containsInputDeviceWithDescriptor(oldInputDevices, inputDevice.getDescriptor())) {
                    mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
                } else {
                    mTempFullKeyboards.add(inputDevice);
                }
            }
        }
    }
    // Notify listeners.
    for (int i = 0; i < numListeners; i++) {
        mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(deviceIdAndGeneration);
    }
    mTempInputDevicesChangedListenersToNotify.clear();
    // Check for missing keyboard layouts.
    List<InputDevice> keyboardsMissingLayout = new ArrayList<>();
    final int numFullKeyboards = mTempFullKeyboards.size();
    synchronized (mDataStore) {
        for (int i = 0; i < numFullKeyboards; i++) {
            final InputDevice inputDevice = mTempFullKeyboards.get(i);
            String layout = getCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier());
            if (layout == null) {
                layout = getDefaultKeyboardLayout(inputDevice);
                if (layout != null) {
                    setCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier(), layout);
                }
            }
            if (layout == null) {
                keyboardsMissingLayout.add(inputDevice);
            }
        }
    }
    if (mNotificationManager != null) {
        if (!keyboardsMissingLayout.isEmpty()) {
            if (keyboardsMissingLayout.size() > 1) {
                // We have more than one keyboard missing a layout, so drop the
                // user at the generic input methods page so they can pick which
                // one to set.
                showMissingKeyboardLayoutNotification(null);
            } else {
                showMissingKeyboardLayoutNotification(keyboardsMissingLayout.get(0));
            }
        } else if (mKeyboardLayoutNotificationShown) {
            hideMissingKeyboardLayoutNotification();
        }
    }
    mTempFullKeyboards.clear();
}
Also used : InputDevice(android.view.InputDevice) ArrayList(java.util.ArrayList)

Example 49 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by crdroidandroid.

the class InputManagerService method handleSwitchKeyboardLayout.

// Must be called on handler.
private void handleSwitchKeyboardLayout(@Nullable InputDeviceIdentifier identifier, InputMethodSubtypeHandle handle) {
    synchronized (mInputDevicesLock) {
        for (InputDevice device : mInputDevices) {
            if (identifier != null && !device.getIdentifier().equals(identifier) || !device.isFullKeyboard()) {
                continue;
            }
            String key = getLayoutDescriptor(device.getIdentifier());
            boolean changed = false;
            synchronized (mDataStore) {
                try {
                    if (mDataStore.switchKeyboardLayout(key, handle)) {
                        changed = true;
                    }
                } finally {
                    mDataStore.saveIfNeeded();
                }
            }
            if (changed) {
                reloadKeyboardLayouts();
            }
        }
    }
}
Also used : InputDevice(android.view.InputDevice)

Example 50 with InputDevice

use of android.view.InputDevice in project libgdx by libgdx.

the class AndroidControllers method addController.

protected void addController(int deviceId, boolean sendEvent) {
    InputDevice device = InputDevice.getDevice(deviceId);
    if (!isController(device))
        return;
    String name = device.getName();
    AndroidController controller = new AndroidController(deviceId, name);
    controllerMap.put(deviceId, controller);
    if (sendEvent) {
        synchronized (eventQueue) {
            AndroidControllerEvent event = eventPool.obtain();
            event.type = AndroidControllerEvent.CONNECTED;
            event.controller = controller;
            eventQueue.add(event);
        }
    } else {
        controllers.add(controller);
    }
    Gdx.app.log(TAG, "added controller '" + name + "'");
}
Also used : InputDevice(android.view.InputDevice)

Aggregations

InputDevice (android.view.InputDevice)83 Paint (android.graphics.Paint)15 RemoteException (android.os.RemoteException)12 ArrayList (java.util.ArrayList)7 Vibrator (android.os.Vibrator)6 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 Point (android.graphics.Point)5 InputManager (android.hardware.input.InputManager)5 PointerCoords (android.view.MotionEvent.PointerCoords)5 DisplayInfo (android.view.DisplayInfo)4 KeyboardLayout (android.hardware.input.KeyboardLayout)2 DisplayMetrics (android.util.DisplayMetrics)2 Test (org.junit.Test)2 NonNull (android.annotation.NonNull)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 InputDeviceIdentifier (android.hardware.input.InputDeviceIdentifier)1