Search in sources :

Example 76 with InputDevice

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

the class KeyboardShortcuts method retrieveKeyCharacterMap.

/**
     * Retrieves a {@link KeyCharacterMap} and assigns it to mKeyCharacterMap. If the given id is an
     * existing device, that device's map is used. Otherwise, it checks first all available devices
     * and if there is a full keyboard it uses that map, otherwise falls back to the Virtual
     * Keyboard with its default map.
     */
private void retrieveKeyCharacterMap(int deviceId) {
    final InputManager inputManager = InputManager.getInstance();
    if (deviceId != -1) {
        final InputDevice inputDevice = inputManager.getInputDevice(deviceId);
        if (inputDevice != null) {
            mKeyCharacterMap = inputDevice.getKeyCharacterMap();
            return;
        }
    }
    final int[] deviceIds = inputManager.getInputDeviceIds();
    for (int i = 0; i < deviceIds.length; ++i) {
        final InputDevice inputDevice = inputManager.getInputDevice(deviceIds[i]);
        // resort.
        if (inputDevice.getId() != -1 && inputDevice.isFullKeyboard()) {
            mKeyCharacterMap = inputDevice.getKeyCharacterMap();
            return;
        }
    }
    final InputDevice inputDevice = inputManager.getInputDevice(-1);
    mKeyCharacterMap = inputDevice.getKeyCharacterMap();
}
Also used : InputDevice(android.view.InputDevice) InputManager(android.hardware.input.InputManager)

Example 77 with InputDevice

use of android.view.InputDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method updateHardKeyboards.

private void updateHardKeyboards() {
    if (mHardKeyboardCategory == null) {
        return;
    }
    mHardKeyboardPreferenceList.clear();
    final int[] devices = InputDevice.getDeviceIds();
    for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
            final InputDeviceIdentifier identifier = device.getIdentifier();
            final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
            final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
            final PreferenceScreen pref = new PreferenceScreen(getPrefContext(), null);
            pref.setTitle(device.getName());
            if (keyboardLayout != null) {
                pref.setSummary(keyboardLayout.toString());
            } else {
                pref.setSummary(R.string.keyboard_layout_default_label);
            }
            pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    showKeyboardLayoutDialog(identifier);
                    return true;
                }
            });
            mHardKeyboardPreferenceList.add(pref);
        }
    }
    if (!mHardKeyboardPreferenceList.isEmpty()) {
        for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
            final Preference pref = mHardKeyboardCategory.getPreference(i);
            if (pref.getOrder() < 1000) {
                mHardKeyboardCategory.removePreference(pref);
            }
        }
        Collections.sort(mHardKeyboardPreferenceList);
        final int count = mHardKeyboardPreferenceList.size();
        for (int i = 0; i < count; i++) {
            final Preference pref = mHardKeyboardPreferenceList.get(i);
            pref.setOrder(i);
            mHardKeyboardCategory.addPreference(pref);
        }
        getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
        getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
}
Also used : InputDeviceIdentifier(android.hardware.input.InputDeviceIdentifier) InputDevice(android.view.InputDevice) PreferenceScreen(android.support.v7.preference.PreferenceScreen) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) KeyboardLayout(android.hardware.input.KeyboardLayout)

Example 78 with InputDevice

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

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 79 with InputDevice

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

the class Input method getInputDeviceId.

private int getInputDeviceId(int inputSource) {
    final int DEFAULT_DEVICE_ID = 0;
    int[] devIds = InputDevice.getDeviceIds();
    for (int devId : devIds) {
        InputDevice inputDev = InputDevice.getDevice(devId);
        if (inputDev.supportsSource(inputSource)) {
            return devId;
        }
    }
    return DEFAULT_DEVICE_ID;
}
Also used : InputDevice(android.view.InputDevice)

Example 80 with InputDevice

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

the class InputManager method onInputDevicesChanged.

private void onInputDevicesChanged(int[] deviceIdAndGeneration) {
    if (DEBUG) {
        Log.d(TAG, "Received input devices changed.");
    }
    synchronized (mInputDevicesLock) {
        for (int i = mInputDevices.size(); --i > 0; ) {
            final int deviceId = mInputDevices.keyAt(i);
            if (!containsDeviceId(deviceIdAndGeneration, deviceId)) {
                if (DEBUG) {
                    Log.d(TAG, "Device removed: " + deviceId);
                }
                mInputDevices.removeAt(i);
                sendMessageToInputDeviceListenersLocked(MSG_DEVICE_REMOVED, deviceId);
            }
        }
        for (int i = 0; i < deviceIdAndGeneration.length; i += 2) {
            final int deviceId = deviceIdAndGeneration[i];
            int index = mInputDevices.indexOfKey(deviceId);
            if (index >= 0) {
                final InputDevice device = mInputDevices.valueAt(index);
                if (device != null) {
                    final int generation = deviceIdAndGeneration[i + 1];
                    if (device.getGeneration() != generation) {
                        if (DEBUG) {
                            Log.d(TAG, "Device changed: " + deviceId);
                        }
                        mInputDevices.setValueAt(index, null);
                        sendMessageToInputDeviceListenersLocked(MSG_DEVICE_CHANGED, deviceId);
                    }
                }
            } else {
                if (DEBUG) {
                    Log.d(TAG, "Device added: " + deviceId);
                }
                mInputDevices.put(deviceId, null);
                sendMessageToInputDeviceListenersLocked(MSG_DEVICE_ADDED, deviceId);
            }
        }
    }
}
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