use of android.view.InputDevice in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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);
}
}
}
}
use of android.view.InputDevice in project cornerstone by Onskreen.
the class WindowManagerService method computeScreenConfigurationLocked.
boolean computeScreenConfigurationLocked(Configuration config) {
if (mDisplay == null) {
return false;
}
// Use the effective "visual" dimensions based on current rotation
final boolean rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
synchronized (mDisplaySizeLock) {
if (mAltOrientation) {
mCurDisplayWidth = realdw;
mCurDisplayHeight = realdh;
if (realdw > realdh) {
// Turn landscape into portrait.
int maxw = (int) (realdh / 1.3f);
if (maxw < realdw) {
mCurDisplayWidth = maxw;
}
} else {
// Turn portrait into landscape.
int maxh = (int) (realdw / 1.3f);
if (maxh < realdh) {
mCurDisplayHeight = maxh;
}
}
} else {
mCurDisplayWidth = realdw;
mCurDisplayHeight = realdh;
}
}
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
if (config != null) {
int orientation = Configuration.ORIENTATION_SQUARE;
if (dw < dh) {
orientation = Configuration.ORIENTATION_PORTRAIT;
} else if (dw > dh) {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
config.orientation = orientation;
}
// Update real display metrics.
mDisplay.getMetricsWithSize(mRealDisplayMetrics, mCurDisplayWidth, mCurDisplayHeight);
// Update application display metrics.
final DisplayMetrics dm = mDisplayMetrics;
final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
synchronized (mDisplaySizeLock) {
mAppDisplayWidth = appWidth;
mAppDisplayHeight = appHeight;
mAnimator.setDisplayDimensions(mCurDisplayWidth, mCurDisplayHeight, mAppDisplayWidth, mAppDisplayHeight);
}
if (false) {
Slog.i(TAG, "Set app display size: " + mAppDisplayWidth + " x " + mAppDisplayHeight);
}
mDisplay.getMetricsWithSize(dm, mAppDisplayWidth, mAppDisplayHeight);
mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm, mCompatDisplayMetrics);
if (config != null) {
config.screenWidthDp = (int) (mPolicy.getConfigDisplayWidth(dw, dh, mRotation) / dm.density);
config.screenHeightDp = (int) (mPolicy.getConfigDisplayHeight(dw, dh, mRotation) / dm.density);
computeSizeRangesAndScreenLayout(rotated, dw, dh, dm.density, config);
config.compatScreenWidthDp = (int) (config.screenWidthDp / mCompatibleScreenScale);
config.compatScreenHeightDp = (int) (config.screenHeightDp / mCompatibleScreenScale);
config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
// Update the configuration based on available input devices, lid switch,
// and platform configuration.
config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
config.keyboard = Configuration.KEYBOARD_NOKEYS;
config.navigation = Configuration.NAVIGATION_NONAV;
int keyboardPresence = 0;
int navigationPresence = 0;
final InputDevice[] devices = mInputManager.getInputDevices();
final int len = devices.length;
for (int i = 0; i < len; i++) {
InputDevice device = devices[i];
if (!device.isVirtual()) {
final int sources = device.getSources();
final int presenceFlag = device.isExternal() ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL;
if (mIsTouchDevice) {
if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
}
} else {
config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
}
if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
config.navigation = Configuration.NAVIGATION_TRACKBALL;
navigationPresence |= presenceFlag;
} else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD && config.navigation == Configuration.NAVIGATION_NONAV) {
config.navigation = Configuration.NAVIGATION_DPAD;
navigationPresence |= presenceFlag;
}
if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
config.keyboard = Configuration.KEYBOARD_QWERTY;
keyboardPresence |= presenceFlag;
}
}
}
// Determine whether a hard keyboard is available and enabled.
boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
if (hardKeyboardAvailable != mHardKeyboardAvailable) {
mHardKeyboardAvailable = hardKeyboardAvailable;
mHardKeyboardEnabled = hardKeyboardAvailable;
mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
}
if (!mHardKeyboardEnabled) {
config.keyboard = Configuration.KEYBOARD_NOKEYS;
}
// Let the policy update hidden states.
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
}
return true;
}
use of android.view.InputDevice in project platform_frameworks_base by android.
the class VibratorService method updateInputDeviceVibrators.
private void updateInputDeviceVibrators() {
synchronized (mVibrations) {
doCancelVibrateLocked();
synchronized (mInputDeviceVibrators) {
mVibrateInputDevicesSetting = false;
try {
mVibrateInputDevicesSetting = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0;
} catch (SettingNotFoundException snfe) {
}
mLowPowerMode = mPowerManagerInternal.getLowPowerModeEnabled();
if (mVibrateInputDevicesSetting) {
if (!mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = true;
mIm.registerInputDeviceListener(this, mH);
}
} else {
if (mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = false;
mIm.unregisterInputDeviceListener(this);
}
}
mInputDeviceVibrators.clear();
if (mVibrateInputDevicesSetting) {
int[] ids = mIm.getInputDeviceIds();
for (int i = 0; i < ids.length; i++) {
InputDevice device = mIm.getInputDevice(ids[i]);
Vibrator vibrator = device.getVibrator();
if (vibrator.hasVibrator()) {
mInputDeviceVibrators.add(vibrator);
}
}
}
}
startNextVibrationLocked();
}
}
use of android.view.InputDevice in project android_frameworks_base by DirtyUnicorns.
the class InputManagerService method systemRunning.
// TODO(BT) Pass in paramter for bluetooth system
public void systemRunning() {
if (DEBUG) {
Slog.d(TAG, "System ready.");
}
mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mSystemReady = true;
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addDataScheme("package");
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateKeyboardLayouts();
}
}, filter, null, mHandler);
filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
reloadDeviceAliases();
}
}, filter, null, mHandler);
mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES);
mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS);
synchronized (mInputDevicesLock) {
if (mInputDevices.length > 0 && !mInputDevicesChangedPending && !mKeyboardLayoutNotificationShown) {
mInputDevicesChangedPending = true;
mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED, new InputDevice[0]).sendToTarget();
}
}
if (mWiredAccessoryCallbacks != null) {
mWiredAccessoryCallbacks.systemReady();
}
}
Aggregations