Search in sources :

Example 16 with InputDevice

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

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

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

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

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

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

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

the class WindowManagerService method computeScreenConfigurationLocked.

/** Do not call if mDisplayReady == false */
void computeScreenConfigurationLocked(Configuration config) {
    final DisplayInfo displayInfo = updateDisplayAndOrientationLocked(config.uiMode);
    final int dw = displayInfo.logicalWidth;
    final int dh = displayInfo.logicalHeight;
    config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
    config.screenWidthDp = (int) (mPolicy.getConfigDisplayWidth(dw, dh, mRotation, config.uiMode) / mDisplayMetrics.density);
    config.screenHeightDp = (int) (mPolicy.getConfigDisplayHeight(dw, dh, mRotation, config.uiMode) / mDisplayMetrics.density);
    final boolean rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
    computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, mDisplayMetrics.density, config);
    config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) | ((displayInfo.flags & Display.FLAG_ROUND) != 0 ? Configuration.SCREENLAYOUT_ROUND_YES : Configuration.SCREENLAYOUT_ROUND_NO);
    config.compatScreenWidthDp = (int) (config.screenWidthDp / mCompatibleScreenScale);
    config.compatScreenHeightDp = (int) (config.screenHeightDp / mCompatibleScreenScale);
    config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, mDisplayMetrics, dw, dh);
    config.densityDpi = displayInfo.logicalDensityDpi;
    // 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;
            }
        }
    }
    if (config.navigation == Configuration.NAVIGATION_NONAV && mHasPermanentDpad) {
        config.navigation = Configuration.NAVIGATION_DPAD;
        navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
    }
    // Determine whether a hard keyboard is available and enabled.
    boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
    if (hardKeyboardAvailable != mHardKeyboardAvailable) {
        mHardKeyboardAvailable = hardKeyboardAvailable;
        mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
        mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
    }
    // 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);
}
Also used : InputDevice(android.view.InputDevice) DisplayInfo(android.view.DisplayInfo) Point(android.graphics.Point)

Example 20 with InputDevice

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

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)

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