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