Search in sources :

Example 6 with InputDevice

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

the class WindowManagerService method computeScreenConfigurationLocked.

boolean computeScreenConfigurationLocked(Configuration config) {
    if (!mDisplayReady) {
        return false;
    }
    // TODO(multidisplay): For now, apply Configuration to main screen only.
    final DisplayContent displayContent = getDefaultDisplayContentLocked();
    // Use the effective "visual" dimensions based on current rotation
    final boolean rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
    final int realdw = rotated ? displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth;
    final int realdh = rotated ? displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight;
    int dw = realdw;
    int dh = realdh;
    if (mAltOrientation) {
        if (realdw > realdh) {
            // Turn landscape into portrait.
            int maxw = (int) (realdh / 1.3f);
            if (maxw < realdw) {
                dw = maxw;
            }
        } else {
            // Turn portrait into landscape.
            int maxh = (int) (realdw / 1.3f);
            if (maxh < realdh) {
                dh = maxh;
            }
        }
    }
    if (config != null) {
        config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
    }
    // Update application display metrics.
    final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
    final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
    final DisplayInfo displayInfo = displayContent.getDisplayInfo();
    synchronized (displayContent.mDisplaySizeLock) {
        displayInfo.rotation = mRotation;
        displayInfo.logicalWidth = dw;
        displayInfo.logicalHeight = dh;
        displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity;
        displayInfo.appWidth = appWidth;
        displayInfo.appHeight = appHeight;
        displayInfo.getLogicalMetrics(mRealDisplayMetrics, null);
        displayInfo.getAppMetrics(mDisplayMetrics, null);
        mDisplayManagerService.setDisplayInfoOverrideFromWindowManager(displayContent.getDisplayId(), displayInfo);
    }
    if (false) {
        Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight);
    }
    final DisplayMetrics dm = mDisplayMetrics;
    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(displayInfo, 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);
        config.densityDpi = displayContent.mBaseDisplayDensity;
        // 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;
}
Also used : InputDevice(android.view.InputDevice) DisplayInfo(android.view.DisplayInfo) DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point)

Example 7 with InputDevice

use of android.view.InputDevice in project jmonkeyengine by jMonkeyEngine.

the class AndroidJoystickJoyInput14 method loadJoysticks.

public List<Joystick> loadJoysticks(int joyId, InputManager inputManager) {
    logger.log(Level.INFO, "loading Joystick devices");
    ArrayList<Joystick> joysticks = new ArrayList<Joystick>();
    joysticks.clear();
    joystickIndex.clear();
    ArrayList gameControllerDeviceIds = new ArrayList();
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();
        logger.log(Level.FINE, "deviceId[{0}] sources: {1}", new Object[] { deviceId, sources });
        // Verify that the device has gamepad buttons, control sticks, or both.
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // This device is a game controller. Store its device ID.
            if (!gameControllerDeviceIds.contains(deviceId)) {
                gameControllerDeviceIds.add(deviceId);
                logger.log(Level.FINE, "Attempting to create joystick for device: {0}", dev);
                // Create an AndroidJoystick and store the InputDevice so we
                // can later correspond the input from the InputDevice to the
                // appropriate jME Joystick event
                AndroidJoystick joystick = new AndroidJoystick(inputManager, joyInput, dev, joyId + joysticks.size(), dev.getName());
                joystickIndex.put(deviceId, joystick);
                joysticks.add(joystick);
                // Each analog input is reported as a MotionRange
                // The axis number corresponds to the type of axis
                // The AndroidJoystick.addAxis(MotionRange) converts the axis
                // type reported by Android into the jME Joystick axis
                List<MotionRange> motionRanges = dev.getMotionRanges();
                for (MotionRange motionRange : motionRanges) {
                    logger.log(Level.INFO, "motion range: {0}", motionRange.toString());
                    logger.log(Level.INFO, "axis: {0}", motionRange.getAxis());
                    JoystickAxis axis = joystick.addAxis(motionRange);
                    logger.log(Level.INFO, "added axis: {0}", axis);
                }
                // device, but I haven't found a better way yet.
                for (int keyCode : AndroidGamepadButtons) {
                    logger.log(Level.INFO, "button[{0}]: {1}", new Object[] { keyCode, KeyCharacterMap.deviceHasKey(keyCode) });
                    if (KeyCharacterMap.deviceHasKey(keyCode)) {
                        // add button even though we aren't sure if the button
                        // actually exists on this InputDevice
                        logger.log(Level.INFO, "button[{0}] exists somewhere", keyCode);
                        JoystickButton button = joystick.addButton(keyCode);
                        logger.log(Level.INFO, "added button: {0}", button);
                    }
                }
            }
        }
    }
    loaded = true;
    return joysticks;
}
Also used : DefaultJoystickButton(com.jme3.input.DefaultJoystickButton) JoystickButton(com.jme3.input.JoystickButton) InputDevice(android.view.InputDevice) AbstractJoystick(com.jme3.input.AbstractJoystick) Joystick(com.jme3.input.Joystick) ArrayList(java.util.ArrayList) JoystickAxis(com.jme3.input.JoystickAxis) DefaultJoystickAxis(com.jme3.input.DefaultJoystickAxis) MotionRange(android.view.InputDevice.MotionRange)

Example 8 with InputDevice

use of android.view.InputDevice in project platform_frameworks_base by android.

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

use of android.view.InputDevice in project platform_frameworks_base by android.

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

use of android.view.InputDevice in project platform_frameworks_base by android.

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();
            }
        }
    }
}
Also used : InputDevice(android.view.InputDevice)

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