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();
}
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);
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations