Search in sources :

Example 41 with InputDevice

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

the class InputManager method getInputDevice.

/**
     * Gets information about the input device with the specified id.
     * @param id The device id.
     * @return The input device or null if not found.
     */
public InputDevice getInputDevice(int id) {
    synchronized (mInputDevicesLock) {
        populateInputDevicesLocked();
        int index = mInputDevices.indexOfKey(id);
        if (index < 0) {
            return null;
        }
        InputDevice inputDevice = mInputDevices.valueAt(index);
        if (inputDevice == null) {
            try {
                inputDevice = mIm.getInputDevice(id);
            } catch (RemoteException ex) {
                throw ex.rethrowFromSystemServer();
            }
            if (inputDevice != null) {
                mInputDevices.setValueAt(index, inputDevice);
            }
        }
        return inputDevice;
    }
}
Also used : InputDevice(android.view.InputDevice) RemoteException(android.os.RemoteException)

Example 42 with InputDevice

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

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

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

the class TaskTapPointerEventListener method onPointerEvent.

@Override
public void onPointerEvent(MotionEvent motionEvent) {
    doGestureDetection(motionEvent);
    final int action = motionEvent.getAction();
    switch(action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            {
                final int x = (int) motionEvent.getX();
                final int y = (int) motionEvent.getY();
                synchronized (this) {
                    if (!mTouchExcludeRegion.contains(x, y)) {
                        mService.mH.obtainMessage(H.TAP_OUTSIDE_TASK, x, y, mDisplayContent).sendToTarget();
                    }
                }
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                if (motionEvent.getPointerCount() != 2) {
                    stopTwoFingerScroll();
                }
                break;
            }
        case MotionEvent.ACTION_HOVER_MOVE:
            {
                final int x = (int) motionEvent.getX();
                final int y = (int) motionEvent.getY();
                final Task task;
                synchronized (mService.mWindowMap) {
                    task = mDisplayContent.findTaskForControlPoint(x, y);
                }
                InputDevice inputDevice = motionEvent.getDevice();
                if (task == null || inputDevice == null) {
                    mPointerIconType = TYPE_NOT_SPECIFIED;
                    break;
                }
                task.getDimBounds(mTmpRect);
                if (!mTmpRect.isEmpty() && !mTmpRect.contains(x, y)) {
                    int iconType = TYPE_DEFAULT;
                    if (x < mTmpRect.left) {
                        iconType = (y < mTmpRect.top) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW : (y > mTmpRect.bottom) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW : TYPE_HORIZONTAL_DOUBLE_ARROW;
                    } else if (x > mTmpRect.right) {
                        iconType = (y < mTmpRect.top) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW : (y > mTmpRect.bottom) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW : TYPE_HORIZONTAL_DOUBLE_ARROW;
                    } else if (y < mTmpRect.top || y > mTmpRect.bottom) {
                        iconType = TYPE_VERTICAL_DOUBLE_ARROW;
                    }
                    if (mPointerIconType != iconType) {
                        mPointerIconType = iconType;
                        inputDevice.setPointerType(iconType);
                    }
                } else {
                    mPointerIconType = TYPE_NOT_SPECIFIED;
                }
            }
            break;
        case MotionEvent.ACTION_HOVER_EXIT:
            mPointerIconType = TYPE_NOT_SPECIFIED;
            InputDevice inputDevice = motionEvent.getDevice();
            if (inputDevice != null) {
                inputDevice.setPointerType(TYPE_DEFAULT);
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            {
                stopTwoFingerScroll();
                break;
            }
    }
}
Also used : InputDevice(android.view.InputDevice)

Example 44 with InputDevice

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

the class MLand method thump.

private void thump(int playerIndex, long ms) {
    if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
        // No interruptions. Not even game haptics.
        return;
    }
    if (playerIndex < mGameControllers.size()) {
        int controllerId = mGameControllers.get(playerIndex);
        InputDevice dev = InputDevice.getDevice(controllerId);
        if (dev != null && dev.getVibrator().hasVibrator()) {
            dev.getVibrator().vibrate((long) (ms * CONTROLLER_VIBRATION_MULTIPLIER), mAudioAttrs);
            return;
        }
    }
    mVibrator.vibrate(ms, mAudioAttrs);
}
Also used : InputDevice(android.view.InputDevice) Paint(android.graphics.Paint)

Example 45 with InputDevice

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

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();
    }
}
Also used : InputDevice(android.view.InputDevice) Vibrator(android.os.Vibrator) SettingNotFoundException(android.provider.Settings.SettingNotFoundException)

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