Java Examples for android.view.InputDevice

The following java examples will help you to understand the usage of android.view.InputDevice. These source code samples are taken from different open source projects.

Example 1
Project: AutoClick-master  File: Clicker.java View source code
/**
	 * Clicks on a given coordinate on the screen.
	 *
	 * @param x the x coordinate
	 * @param y the y coordinate
	 */
private void click(float x, float y) {
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
    MotionEvent event2 = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
    event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    event2.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    inst.sendPointerSync(event);
    inst.sendPointerSync(event2);
    event.recycle();
    event2.recycle();
}
Example 2
Project: robotium-master  File: Rotator.java View source code
public void generateRotateGesture(int size, PointF center1, PointF center2) {
    double incrementFactor = 0;
    float startX1 = center1.x;
    float startY1 = center1.y;
    float startX2 = center2.x;
    float startY2 = center2.y;
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    // pointer 1
    float x1 = startX1;
    float y1 = startY1;
    // pointer 2
    float x2 = startX2;
    float y2 = startY2;
    PointerCoords[] pointerCoords = new PointerCoords[2];
    PointerCoords pc1 = new PointerCoords();
    PointerCoords pc2 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pc2.x = x2;
    pc2.y = y2;
    pc2.pressure = 1;
    pc2.size = 1;
    pointerCoords[0] = pc1;
    pointerCoords[1] = pc2;
    PointerProperties[] pointerProperties = new PointerProperties[2];
    PointerProperties pp1 = new PointerProperties();
    PointerProperties pp2 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pp2.id = 1;
    pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    pointerProperties[1] = pp2;
    MotionEvent event;
    // send the initial touches
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords, // metaState, buttonState
    0, // metaState, buttonState
    0, // x precision
    1, // y precision
    1, // deviceId, edgeFlags
    0, // deviceId, edgeFlags
    0, InputDevice.SOURCE_TOUCHSCREEN, // source, flags
    0);
    _instrument.sendPointerSync(event);
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_DOWN + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
    switch(size) {
        case 0:
            {
                incrementFactor = 0.01;
            }
            break;
        case 1:
            {
                incrementFactor = 0.1;
            }
            break;
    }
    for (double i = 0; i < Math.PI; i += incrementFactor) {
        eventTime += EVENT_TIME_INTERVAL_MS;
        pointerCoords[0].x += Math.cos(i);
        pointerCoords[0].y += Math.sin(i);
        pointerCoords[1].x += Math.cos(i + Math.PI);
        pointerCoords[1].y += Math.sin(i + Math.PI);
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);
    }
    // and remove them fingers from the screen
    eventTime += EVENT_TIME_INTERVAL_MS;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_UP + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
    eventTime += EVENT_TIME_INTERVAL_MS;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 1, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
}
Example 3
Project: RxBinding-master  File: MotionEventUtil.java View source code
public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) {
    MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent);
    MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
    pointerProperties[0] = new MotionEvent.PointerProperties();
    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
    pointerCoords[0] = new MotionEvent.PointerCoords();
    pointerCoords[0].x = ev.getX();
    pointerCoords[0].y = ev.getY();
    return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties, pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(), ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags());
}
Example 4
Project: ajaxAquery-master  File: Rotator.java View source code
public void generateRotateGesture(int size, PointF center1, PointF center2) {
    double incrementFactor = 0;
    float startX1 = center1.x;
    float startY1 = center1.y;
    float startX2 = center2.x;
    float startY2 = center2.y;
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    // pointer 1
    float x1 = startX1;
    float y1 = startY1;
    // pointer 2
    float x2 = startX2;
    float y2 = startY2;
    PointerCoords[] pointerCoords = new PointerCoords[2];
    PointerCoords pc1 = new PointerCoords();
    PointerCoords pc2 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pc2.x = x2;
    pc2.y = y2;
    pc2.pressure = 1;
    pc2.size = 1;
    pointerCoords[0] = pc1;
    pointerCoords[1] = pc2;
    PointerProperties[] pointerProperties = new PointerProperties[2];
    PointerProperties pp1 = new PointerProperties();
    PointerProperties pp2 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pp2.id = 1;
    pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    pointerProperties[1] = pp2;
    MotionEvent event;
    // send the initial touches
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords, // metaState, buttonState
    0, // metaState, buttonState
    0, // x precision
    1, // y precision
    1, // deviceId, edgeFlags
    0, // deviceId, edgeFlags
    0, InputDevice.SOURCE_TOUCHSCREEN, // source, flags
    0);
    _instrument.sendPointerSync(event);
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_DOWN + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
    switch(size) {
        case 0:
            {
                incrementFactor = 0.01;
            }
            break;
        case 1:
            {
                incrementFactor = 0.1;
            }
            break;
    }
    for (double i = 0; i < Math.PI; i += incrementFactor) {
        eventTime += EVENT_TIME_INTERVAL_MS;
        pointerCoords[0].x += Math.cos(i);
        pointerCoords[0].y += Math.sin(i);
        pointerCoords[1].x += Math.cos(i + Math.PI);
        pointerCoords[1].y += Math.sin(i + Math.PI);
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);
    }
    // and remove them fingers from the screen
    eventTime += EVENT_TIME_INTERVAL_MS;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_UP + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
    eventTime += EVENT_TIME_INTERVAL_MS;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 1, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
}
Example 5
Project: android-sdk-sources-for-api-level-23-master  File: InputManagerService.java View source code
/**
     * Gets information about the input device with the specified id.
     * @param deviceId The device id.
     * @return The input device or null if not found.
     */
// Binder call
@Override
public InputDevice getInputDevice(int deviceId) {
    synchronized (mInputDevicesLock) {
        final int count = mInputDevices.length;
        for (int i = 0; i < count; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            if (inputDevice.getId() == deviceId) {
                return inputDevice;
            }
        }
    }
    return null;
}
Example 6
Project: android_frameworks_base-master  File: TouchExplorer.java View source code
@Override
public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
    if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
        if (mNext != null) {
            mNext.onMotionEvent(event, rawEvent, policyFlags);
        }
        return;
    }
    if (DEBUG) {
        Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags));
        Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState));
    }
    mReceivedPointerTracker.onMotionEvent(rawEvent);
    // transformations.
    if (mGestureDetector.onMotionEvent(rawEvent, policyFlags)) {
        // Event was handled by the gesture detector.
        return;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
        clear(event, policyFlags);
        return;
    }
    switch(mCurrentState) {
        case STATE_TOUCH_EXPLORING:
            {
                handleMotionEventStateTouchExploring(event, rawEvent, policyFlags);
            }
            break;
        case STATE_DRAGGING:
            {
                handleMotionEventStateDragging(event, policyFlags);
            }
            break;
        case STATE_DELEGATING:
            {
                handleMotionEventStateDelegating(event, policyFlags);
            }
            break;
        case STATE_GESTURE_DETECTING:
            {
            // Already handled.
            }
            break;
        default:
            throw new IllegalStateException("Illegal state: " + mCurrentState);
    }
}
Example 7
Project: appium-android-bootstrap-master  File: MultiPointerGesture.java View source code
private boolean injectPointers(long downTime, int action, final List<PointerProperties> properties, final List<PointerCoords> coords) {
    // Injects pointers using some default values. Number of pointers is assumed
    // to be the length of the coords list.
    final MotionEvent event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, coords.size(), properties.toArray(new PointerProperties[0]), coords.toArray(new PointerCoords[0]), 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    return injectEventSync(event);
}
Example 8
Project: platform_frameworks_base-master  File: TouchExplorer.java View source code
@Override
public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
    if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
        if (mNext != null) {
            mNext.onMotionEvent(event, rawEvent, policyFlags);
        }
        return;
    }
    if (DEBUG) {
        Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags));
        Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState));
    }
    mReceivedPointerTracker.onMotionEvent(rawEvent);
    // transformations.
    if (mGestureDetector.onMotionEvent(rawEvent, policyFlags)) {
        // Event was handled by the gesture detector.
        return;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
        clear(event, policyFlags);
        return;
    }
    switch(mCurrentState) {
        case STATE_TOUCH_EXPLORING:
            {
                handleMotionEventStateTouchExploring(event, rawEvent, policyFlags);
            }
            break;
        case STATE_DRAGGING:
            {
                handleMotionEventStateDragging(event, policyFlags);
            }
            break;
        case STATE_DELEGATING:
            {
                handleMotionEventStateDelegating(event, policyFlags);
            }
            break;
        case STATE_GESTURE_DETECTING:
            {
            // Already handled.
            }
            break;
        default:
            throw new IllegalStateException("Illegal state: " + mCurrentState);
    }
}
Example 9
Project: selendroid-master  File: WebViewMotionSender.java View source code
public void run() {
    float zoom = webview.getScale();
    for (MotionEvent event : events) {
        event.setLocation(zoom * event.getX(), zoom * event.getY());
        try {
            event.setSource(InputDevice.SOURCE_CLASS_POINTER);
        } catch (NoSuchMethodError e) {
            throw new SelendroidException("You are using an Android WebDriver APK " + "for ICS SDKs or more recent SDK versions. For more info see " + "http://code.google.com/p/selenium/wiki/AndroidDriver#Supported_Platforms.", e);
        }
        webview.dispatchTouchEvent(event);
        synchronized (syncObject) {
            done = true;
            syncObject.notify();
        }
    }
}
Example 10
Project: android-15-master  File: WindowManagerService.java View source code
@Override
public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
    boolean handled = false;
    try {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 && mDragState != null) {
            boolean endDrag = false;
            final float newX = event.getRawX();
            final float newY = event.getRawY();
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    {
                        if (DEBUG_DRAG) {
                            Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
                        }
                    }
                    break;
                case MotionEvent.ACTION_MOVE:
                    {
                        synchronized (mWindowMap) {
                            // move the surface and tell the involved window(s) where we are
                            mDragState.notifyMoveLw(newX, newY);
                        }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    {
                        if (DEBUG_DRAG)
                            Slog.d(TAG, "Got UP on move channel; dropping at " + newX + "," + newY);
                        synchronized (mWindowMap) {
                            endDrag = mDragState.notifyDropLw(newX, newY);
                        }
                    }
                    break;
                case MotionEvent.ACTION_CANCEL:
                    {
                        if (DEBUG_DRAG)
                            Slog.d(TAG, "Drag cancelled!");
                        endDrag = true;
                    }
                    break;
            }
            if (endDrag) {
                if (DEBUG_DRAG)
                    Slog.d(TAG, "Drag ended; tearing down state");
                // tell all the windows that the drag has ended
                synchronized (mWindowMap) {
                    mDragState.endDragLw();
                }
            }
            handled = true;
        }
    } catch (Exception e) {
        Slog.e(TAG, "Exception caught by drag handleMotion", e);
    } finally {
        finishedCallback.finished(handled);
    }
}
Example 11
Project: android_device_softwinner_cubieboard1-master  File: InputMethodAndLanguageSettings.java View source code
private void updateHardKeyboards() {
    mHardKeyboardPreferenceList.clear();
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
        final int[] devices = InputDevice.getDeviceIds();
        for (int i = 0; i < devices.length; i++) {
            InputDevice device = InputDevice.getDevice(devices[i]);
            if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
                final String inputDeviceDescriptor = device.getDescriptor();
                final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
                final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
                final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
                pref.setTitle(device.getName());
                if (keyboardLayout != null) {
                    pref.setSummary(keyboardLayout.toString());
                } else {
                    pref.setSummary(R.string.keyboard_layout_default_label);
                }
                pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        showKeyboardLayoutDialog(inputDeviceDescriptor);
                        return true;
                    }
                });
                mHardKeyboardPreferenceList.add(pref);
            }
        }
    }
    if (!mHardKeyboardPreferenceList.isEmpty()) {
        for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
            final Preference pref = mHardKeyboardCategory.getPreference(i);
            if (pref.getOrder() < 1000) {
                mHardKeyboardCategory.removePreference(pref);
            }
        }
        Collections.sort(mHardKeyboardPreferenceList);
        final int count = mHardKeyboardPreferenceList.size();
        for (int i = 0; i < count; i++) {
            final Preference pref = mHardKeyboardPreferenceList.get(i);
            pref.setOrder(i);
            mHardKeyboardCategory.addPreference(pref);
        }
        getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
        getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
}
Example 12
Project: attentive-ui-master  File: MonkeyKeyEvent.java View source code
@Override
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
    if (verbose > 1) {
        String note;
        if (mAction == KeyEvent.ACTION_UP) {
            note = "ACTION_UP";
        } else {
            note = "ACTION_DOWN";
        }
        try {
            System.out.println(":Sending Key (" + note + "): " + mKeyCode + "    // " + MonkeySourceRandom.getKeyName(mKeyCode));
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(":Sending Key (" + note + "): " + mKeyCode + "    // Unknown key event");
        }
    }
    KeyEvent keyEvent = mKeyEvent;
    if (keyEvent == null) {
        long eventTime = mEventTime;
        if (eventTime <= 0) {
            eventTime = SystemClock.uptimeMillis();
        }
        long downTime = mDownTime;
        if (downTime <= 0) {
            downTime = eventTime;
        }
        keyEvent = new KeyEvent(downTime, eventTime, mAction, mKeyCode, mRepeatCount, mMetaState, mDeviceId, mScanCode, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD);
    }
    if (!InputManager.getInstance().injectInputEvent(keyEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT)) {
        return MonkeyEvent.INJECT_FAIL;
    }
    return MonkeyEvent.INJECT_SUCCESS;
}
Example 13
Project: frameworks_base_disabled-master  File: AccessibilityManagerService.java View source code
private void sendDownAndUpKeyEvents(int keyCode) {
    final long token = Binder.clearCallingIdentity();
    // Inject down.
    final long downTime = SystemClock.uptimeMillis();
    KeyEvent down = KeyEvent.obtain(downTime, downTime, KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD, null);
    InputManager.getInstance().injectInputEvent(down, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    down.recycle();
    // Inject up.
    final long upTime = SystemClock.uptimeMillis();
    KeyEvent up = KeyEvent.obtain(downTime, upTime, KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD, null);
    InputManager.getInstance().injectInputEvent(up, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    up.recycle();
    Binder.restoreCallingIdentity(token);
}
Example 14
Project: libgdx-master  File: AndroidControllers.java View source code
@Override
public boolean onGenericMotion(View view, MotionEvent motionEvent) {
    if ((motionEvent.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
        return false;
    AndroidController controller = controllerMap.get(motionEvent.getDeviceId());
    if (controller != null) {
        synchronized (eventQueue) {
            final int historySize = motionEvent.getHistorySize();
            if (controller.hasPovAxis()) {
                int direction = 0;
                float povX = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_X);
                float povY = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_Y);
                if (Float.compare(povY, -1.0f) == 0) {
                    direction |= 0x00000001;
                } else if (Float.compare(povY, 1.0f) == 0) {
                    direction |= 0x00000010;
                }
                if (Float.compare(povX, 1.0f) == 0) {
                    direction |= 0x00000100;
                } else if (Float.compare(povX, -1.0f) == 0) {
                    direction |= 0x00001000;
                }
                if (direction != controller.pov) {
                    controller.pov = direction;
                    AndroidControllerEvent event = eventPool.obtain();
                    event.type = AndroidControllerEvent.POV;
                    event.controller = controller;
                    event.povDirection = controller.getPov(0);
                    eventQueue.add(event);
                }
            }
            int axisIndex = 0;
            for (int axisId : controller.axesIds) {
                float axisValue = motionEvent.getAxisValue(axisId);
                if (controller.getAxis(axisIndex) == axisValue) {
                    axisIndex++;
                    continue;
                }
                AndroidControllerEvent event = eventPool.obtain();
                event.type = AndroidControllerEvent.AXIS;
                event.controller = controller;
                event.code = axisIndex;
                event.axisValue = axisValue;
                eventQueue.add(event);
                axisIndex++;
            }
        }
        return true;
    }
    return false;
}
Example 15
Project: packages_apps_settings-master  File: InputMethodAndLanguageSettings.java View source code
private void updateHardKeyboards() {
    if (mHardKeyboardCategory == null) {
        return;
    }
    mHardKeyboardPreferenceList.clear();
    final int[] devices = InputDevice.getDeviceIds();
    for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
            final InputDeviceIdentifier identifier = device.getIdentifier();
            final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
            final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
            final PreferenceScreen pref = new PreferenceScreen(getPrefContext(), null);
            pref.setTitle(device.getName());
            if (keyboardLayout != null) {
                pref.setSummary(keyboardLayout.toString());
            } else {
                pref.setSummary(R.string.keyboard_layout_default_label);
            }
            pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    showKeyboardLayoutDialog(identifier);
                    return true;
                }
            });
            mHardKeyboardPreferenceList.add(pref);
        }
    }
    if (!mHardKeyboardPreferenceList.isEmpty()) {
        for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
            final Preference pref = mHardKeyboardCategory.getPreference(i);
            if (pref.getOrder() < 1000) {
                mHardKeyboardCategory.removePreference(pref);
            }
        }
        Collections.sort(mHardKeyboardPreferenceList);
        final int count = mHardKeyboardPreferenceList.size();
        for (int i = 0; i < count; i++) {
            final Preference pref = mHardKeyboardPreferenceList.get(i);
            pref.setOrder(i);
            mHardKeyboardCategory.addPreference(pref);
        }
        getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
        getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
}
Example 16
Project: platform_packages_apps_settings-master  File: InputMethodAndLanguageSettings.java View source code
private void updateHardKeyboards() {
    if (mHardKeyboardCategory == null) {
        return;
    }
    mHardKeyboardPreferenceList.clear();
    final int[] devices = InputDevice.getDeviceIds();
    for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
            final InputDeviceIdentifier identifier = device.getIdentifier();
            final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
            final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
            final PreferenceScreen pref = new PreferenceScreen(getPrefContext(), null);
            pref.setTitle(device.getName());
            if (keyboardLayout != null) {
                pref.setSummary(keyboardLayout.toString());
            } else {
                pref.setSummary(R.string.keyboard_layout_default_label);
            }
            pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    showKeyboardLayoutDialog(identifier);
                    return true;
                }
            });
            mHardKeyboardPreferenceList.add(pref);
        }
    }
    if (!mHardKeyboardPreferenceList.isEmpty()) {
        for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
            final Preference pref = mHardKeyboardCategory.getPreference(i);
            if (pref.getOrder() < 1000) {
                mHardKeyboardCategory.removePreference(pref);
            }
        }
        Collections.sort(mHardKeyboardPreferenceList);
        final int count = mHardKeyboardPreferenceList.size();
        for (int i = 0; i < count; i++) {
            final Preference pref = mHardKeyboardPreferenceList.get(i);
            pref.setOrder(i);
            mHardKeyboardCategory.addPreference(pref);
        }
        getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
        getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
}
Example 17
Project: Project-M-1-master  File: InputMethodAndLanguageSettings.java View source code
private void updateHardKeyboards() {
    mHardKeyboardPreferenceList.clear();
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
        final int[] devices = InputDevice.getDeviceIds();
        for (int i = 0; i < devices.length; i++) {
            InputDevice device = InputDevice.getDevice(devices[i]);
            if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
                final String inputDeviceDescriptor = device.getDescriptor();
                final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
                final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
                final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
                pref.setTitle(device.getName());
                if (keyboardLayout != null) {
                    pref.setSummary(keyboardLayout.toString());
                } else {
                    pref.setSummary(R.string.keyboard_layout_default_label);
                }
                pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        showKeyboardLayoutDialog(inputDeviceDescriptor);
                        return true;
                    }
                });
                mHardKeyboardPreferenceList.add(pref);
            }
        }
    }
    if (!mHardKeyboardPreferenceList.isEmpty()) {
        for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
            final Preference pref = mHardKeyboardCategory.getPreference(i);
            if (pref.getOrder() < 1000) {
                mHardKeyboardCategory.removePreference(pref);
            }
        }
        Collections.sort(mHardKeyboardPreferenceList);
        final int count = mHardKeyboardPreferenceList.size();
        for (int i = 0; i < count; i++) {
            final Preference pref = mHardKeyboardPreferenceList.get(i);
            pref.setOrder(i);
            mHardKeyboardCategory.addPreference(pref);
        }
        getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
        getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
}
Example 18
Project: remote-desktop-clients-master  File: RemoteCanvasActivity.java View source code
// Send e.g. mouse events like hover and scroll to be handled.
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    // Ignore TOOL_TYPE_FINGER events that come from the touchscreen with HOVER type action
    // which cause pointer jumping trouble in simulated touchpad for some devices.
    int a = event.getAction();
    if (!((a == MotionEvent.ACTION_HOVER_ENTER || a == MotionEvent.ACTION_HOVER_EXIT || a == MotionEvent.ACTION_HOVER_MOVE) && event.getSource() == InputDevice.SOURCE_TOUCHSCREEN && event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER)) {
        try {
            return inputHandler.onTouchEvent(event);
        } catch (NullPointerException e) {
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 19
Project: android-inputinjector-master  File: InjectionManager.java View source code
public void injectTouchEventDown(int x, int y) {
    MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 10, MotionEvent.ACTION_DOWN, x, y, 0);
    if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN)
        ;
    else
        me.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    injectEvent(me, INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT);
    me.recycle();
}
Example 20
Project: android-test-kit-master  File: InputManagerEventInjectionStrategy.java View source code
@Override
public boolean injectMotionEvent(MotionEvent motionEvent) throws InjectEventSecurityException {
    try {
        // TODO(user): proper handling of events from a trackball (SOURCE_TRACKBALL) and joystick.
        if ((motionEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0 && !isFromTouchpadInGlassDevice(motionEvent)) {
            // Need to do runtime invocation of setSource because it was not added until 2.3_r1.
            setSourceMotionMethod.invoke(motionEvent, InputDevice.SOURCE_TOUCHSCREEN);
        }
        return (Boolean) injectInputEventMethod.invoke(instanceInputManagerObject, motionEvent, motionEventMode);
    } catch (IllegalAccessException e) {
        propagate(e);
    } catch (IllegalArgumentException e) {
        propagate(e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof SecurityException) {
            throw new InjectEventSecurityException(cause);
        }
        propagate(e);
    } catch (SecurityException e) {
        throw new InjectEventSecurityException(e);
    }
    return false;
}
Example 21
Project: bluetooth-master  File: GameView.java View source code
// Iterate through the input devices, looking for controllers. Create a ship
// for every device that reports itself as a gamepad or joystick.
void findControllersAndAttachShips() {
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = mInputManager.getInputDevice(deviceId);
        int sources = dev.getSources();
        // if the device is a gamepad/joystick, create a ship to represent it
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // if the device has a gamepad or joystick
            getShipForId(deviceId);
        }
    }
}
Example 22
Project: cnAndroidDocs-master  File: InputManagerService.java View source code
/**
     * Gets information about the input device with the specified id.
     * @param deviceId The device id.
     * @return The input device or null if not found.
     */
// Binder call
@Override
public InputDevice getInputDevice(int deviceId) {
    synchronized (mInputDevicesLock) {
        final int count = mInputDevices.length;
        for (int i = 0; i < count; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            if (inputDevice.getId() == deviceId) {
                return inputDevice;
            }
        }
    }
    return null;
}
Example 23
Project: double-espresso-master  File: InputManagerEventInjectionStrategy.java View source code
@Override
public boolean injectMotionEvent(MotionEvent motionEvent) throws InjectEventSecurityException {
    try {
        // TODO(user): proper handling of events from a trackball (SOURCE_TRACKBALL) and joystick.
        if ((motionEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0 && !isFromTouchpadInGlassDevice(motionEvent)) {
            // Need to do runtime invocation of setSource because it was not added until 2.3_r1.
            setSourceMotionMethod.invoke(motionEvent, InputDevice.SOURCE_TOUCHSCREEN);
        }
        return (Boolean) injectInputEventMethod.invoke(instanceInputManagerObject, motionEvent, motionEventMode);
    } catch (IllegalAccessException e) {
        propagate(e);
    } catch (IllegalArgumentException e) {
        propagate(e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof SecurityException) {
            throw new InjectEventSecurityException(cause);
        }
        propagate(e);
    } catch (SecurityException e) {
        throw new InjectEventSecurityException(e);
    }
    return false;
}
Example 24
Project: droiddriver-master  File: Events.java View source code
/**
   * @return a touch down event at the specified coordinates
   */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static MotionEvent newTouchDownEvent(int x, int y) {
    long downTime = SystemClock.uptimeMillis();
    MotionEvent event = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 1);
    // TODO: Fix this if 'source' is required on devices older than HONEYCOMB_MR1.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    return event;
}
Example 25
Project: jmonkeyengine-master  File: AndroidInputHandler.java View source code
/*
     *  Android input events include the source from which the input came from.
     *  We must look at the source of the input event to determine which type
     *  of jME input it belongs to.
     *  If the input is from a gamepad or joystick source, the event is sent
     *  to the JoyInput class to convert the event into jME joystick events.
     *  </br>
     *  If the input is from a touchscreen source, the event is sent to the
     *  TouchProcessor to convert the event into touch events.
     *  The TouchProcessor also converts the events into Mouse and Key events
     *  if AppSettings is set to simulate Mouse or Keyboard events.
     *
     *  Android reports the source as a bitmask as shown below.</br>
     *
     *  InputDevice Sources
     *     0000 0000 0000 0000 0000 0000 0000 0000 - 32 bit bitmask
     *
     *     0000 0000 0000 0000 0000 0000 1111 1111 - SOURCE_CLASS_MASK       (0x000000ff)
     *     0000 0000 0000 0000 0000 0000 0000 0000 - SOURCE_CLASS_NONE       (0x00000000)
     *     0000 0000 0000 0000 0000 0000 0000 0001 - SOURCE_CLASS_BUTTON     (0x00000001)
     *     0000 0000 0000 0000 0000 0000 0000 0010 - SOURCE_CLASS_POINTER    (0x00000002)
     *     0000 0000 0000 0000 0000 0000 0000 0100 - SOURCE_CLASS_TRACKBALL  (0x00000004)
     *     0000 0000 0000 0000 0000 0000 0000 1000 - SOURCE_CLASS_POSITION   (0x00000008)
     *     0000 0000 0000 0000 0000 0000 0001 0000 - SOURCE_CLASS_JOYSTICK   (0x00000010)
     *
     *     1111 1111 1111 1111 1111 1111 0000 0000 - Source_Any              (0xffffff00)
     *     0000 0000 0000 0000 0000 0000 0000 0000 - SOURCE_UNKNOWN          (0x00000000)
     *     0000 0000 0000 0000 0000 0001 0000 0001 - SOURCE_KEYBOARD         (0x00000101)
     *     0000 0000 0000 0000 0000 0010 0000 0001 - SOURCE_DPAD             (0x00000201)
     *     0000 0000 0000 0000 0000 0100 0000 0001 - SOURCE_GAMEPAD          (0x00000401)
     *     0000 0000 0000 0000 0001 0000 0000 0010 - SOURCE_TOUCHSCREEN      (0x00001002)
     *     0000 0000 0000 0000 0010 0000 0000 0010 - SOURCE_MOUSE            (0x00002002)
     *     0000 0000 0000 0000 0100 0000 0000 0010 - SOURCE_STYLUS           (0x00004002)
     *     0000 0000 0000 0001 0000 0000 0000 0100 - SOURCE_TRACKBALL        (0x00010004)
     *     0000 0000 0001 0000 0000 0000 0000 1000 - SOURCE_TOUCHPAD         (0x00100008)
     *     0000 0000 0010 0000 0000 0000 0000 0000 - SOURCE_TOUCH_NAVIGATION (0x00200000)
     *     0000 0001 0000 0000 0000 0000 0001 0000 - SOURCE_JOYSTICK         (0x01000010)
     *     0000 0010 0000 0000 0000 0000 0000 0001 - SOURCE_HDMI             (0x02000001)
     *
     * Example values reported by Android for Source
     * 4,098 = 0x00001002 =
     *     0000 0000 0000 0000 0001 0000 0000 0010 - SOURCE_CLASS_POINTER
     *                                               SOURCE_TOUCHSCREEN
     * 1,281 = 0x00000501 =
     *     0000 0000 0000 0000 0000 0101 0000 0001 - SOURCE_CLASS_BUTTON
     *                                               SOURCE_KEYBOARD
     *                                               SOURCE_GAMEPAD
     * 16,777,232 = 0x01000010 =
     *     0000 0001 0000 0000 0000 0000 0001 0000 - SOURCE_CLASS_JOYSTICK
     *                                               SOURCE_JOYSTICK
     *
     * 16,778,513 = 0x01000511 =
     *     0000 0001 0000 0000 0000 0101 0001 0001 - SOURCE_CLASS_BUTTON
     *                                               SOURCE_CLASS_JOYSTICK
     *                                               SOURCE_GAMEPAD
     *                                               SOURCE_KEYBOARD
     *                                               SOURCE_JOYSTICK
     *
     * 257 = 0x00000101 =
     *     0000 0000 0000 0000 0000 0001 0000 0001 - SOURCE_CLASS_BUTTON
     *                                               SOURCE_KEYBOARD
     *
     *
     *
     */
@Override
public boolean onTouch(View view, MotionEvent event) {
    if (view != getView()) {
        return false;
    }
    boolean consumed = false;
    int source = event.getSource();
    //        logger.log(Level.INFO, "onTouch source: {0}", source);
    boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN);
    if (isTouch && touchInput != null) {
        // send the event to the touch processor
        consumed = touchInput.onTouch(event);
    }
    return consumed;
}
Example 26
Project: kuliah_mobile-master  File: GameView.java View source code
// Iterate through the input devices, looking for controllers. Create a ship
// for every device that reports itself as a gamepad or joystick.
void findControllersAndAttachShips() {
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = mInputManager.getInputDevice(deviceId);
        int sources = dev.getSources();
        // if the device is a gamepad/joystick, create a ship to represent it
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // if the device has a gamepad or joystick
            getShipForId(deviceId);
        }
    }
}
Example 27
Project: MD360Player4Android-master  File: MDAbsView.java View source code
@Override
public void onEyeHitIn(MDHitEvent hitEvent) {
    super.onEyeHitIn(hitEvent);
    MDHitPoint point = hitEvent.getHitPoint();
    if (point == null || mAttachedView == null) {
        return;
    }
    int action = mTouchStatus == TouchStatus.NOP ? MotionEvent.ACTION_HOVER_ENTER : MotionEvent.ACTION_HOVER_MOVE;
    float x = mAttachedView.getLeft() + mAttachedView.getWidth() * point.getU();
    float y = mAttachedView.getTop() + mAttachedView.getHeight() * point.getV();
    MotionEvent motionEvent = MotionEvent.obtain(hitEvent.getTimestamp(), System.currentTimeMillis(), action, x, y, 0);
    motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);
    mAttachedView.dispatchGenericMotionEvent(motionEvent);
    motionEvent.recycle();
    mTouchStatus = TouchStatus.DOWN;
    invalidate();
}
Example 28
Project: osmdroid-master  File: StarterMapFragment.java View source code
/**
                  * mouse wheel zooming ftw
                  * http://stackoverflow.com/questions/11024809/how-can-my-view-respond-to-a-mousewheel
                  * @param v
                  * @param event
                  * @return
                  */
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
    if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f)
                    mMapView.getController().zoomOut();
                else {
                    //this part just centers the map on the current mouse location before the zoom action occurs
                    IGeoPoint iGeoPoint = mMapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
                    mMapView.getController().animateTo(iGeoPoint);
                    mMapView.getController().zoomIn();
                }
                return true;
        }
    }
    return false;
}
Example 29
Project: property-db-master  File: InputManagerService.java View source code
/**
     * Gets information about the input device with the specified id.
     * @param deviceId The device id.
     * @return The input device or null if not found.
     */
// Binder call
@Override
public InputDevice getInputDevice(int deviceId) {
    synchronized (mInputDevicesLock) {
        final int count = mInputDevices.length;
        for (int i = 0; i < count; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            if (inputDevice.getId() == deviceId) {
                return inputDevice;
            }
        }
    }
    return null;
}
Example 30
Project: XposedMenuBeGone-master  File: Main.java View source code
protected void injectKey(int keycode) {
    InputManager inputManager = (InputManager) XposedHelpers.callStaticMethod(InputManager.class, "getInstance");
    long now = SystemClock.uptimeMillis();
    final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keycode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD);
    final KeyEvent upEvent = KeyEvent.changeAction(downEvent, KeyEvent.ACTION_UP);
    Integer INJECT_INPUT_EVENT_MODE_ASYNC = XposedHelpers.getStaticIntField(InputManager.class, "INJECT_INPUT_EVENT_MODE_ASYNC");
    XposedHelpers.callMethod(inputManager, "injectInputEvent", downEvent, INJECT_INPUT_EVENT_MODE_ASYNC);
    XposedHelpers.callMethod(inputManager, "injectInputEvent", upEvent, INJECT_INPUT_EVENT_MODE_ASYNC);
}
Example 31
Project: andevcon-2014-jl-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 32
Project: android-apidemos-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 33
Project: android-maven-plugin-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 34
Project: Android-SDK-Samples-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 35
Project: apidemo-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 36
Project: ApiDemos-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 37
Project: ApkLauncher-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 38
Project: ApkLauncher_legacy-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 39
Project: felix-on-android-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 40
Project: GradleCodeLab-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 41
Project: mobile-spec-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 42
Project: platform_development-master  File: GameView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }
        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }
        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }
        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 43
Project: Galaxy-Nexus-SystemUI-master  File: KeyButtonView.java View source code
void sendEvent(int action, int flags, long when) {
    final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
    final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, InputDevice.SOURCE_KEYBOARD);
    try {
        //Slog.d(TAG, "injecting event " + ev);
        mWindowManager.injectInputEventNoWait(ev);
    } catch (RemoteException ex) {
    }
}
Example 44
Project: Galaxy-Nexus-SystemUI-with-toggle-widgets-master  File: KeyButtonView.java View source code
void sendEvent(int action, int flags, long when) {
    final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
    final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, InputDevice.SOURCE_KEYBOARD);
    try {
        //Slog.d(TAG, "injecting event " + ev);
        mWindowManager.injectInputEventNoWait(ev);
    } catch (RemoteException ex) {
    }
}
Example 45
Project: moonlight-android-master  File: ControllerHandler.java View source code
private static InputDevice.MotionRange getMotionRangeForJoystickAxis(InputDevice dev, int axis) {
    InputDevice.MotionRange range;
    // First get the axis for SOURCE_JOYSTICK
    range = dev.getMotionRange(axis, InputDevice.SOURCE_JOYSTICK);
    if (range == null) {
        // Now try the axis for SOURCE_GAMEPAD
        range = dev.getMotionRange(axis, InputDevice.SOURCE_GAMEPAD);
    }
    return range;
}
Example 46
Project: moonlight-master  File: ControllerHandler.java View source code
private static InputDevice.MotionRange getMotionRangeForJoystickAxis(InputDevice dev, int axis) {
    InputDevice.MotionRange range;
    // First get the axis for SOURCE_JOYSTICK
    range = dev.getMotionRange(axis, InputDevice.SOURCE_JOYSTICK);
    if (range == null) {
        // Now try the axis for SOURCE_GAMEPAD
        range = dev.getMotionRange(axis, InputDevice.SOURCE_GAMEPAD);
    }
    return range;
}
Example 47
Project: PTVGlass-master  File: TouchpadView.java View source code
/** Looks up the hardware resolution of the Glass touchpad. */
private void lookupTouchpadHardwareResolution() {
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice device = InputDevice.getDevice(deviceId);
        if ((device.getSources() & InputDevice.SOURCE_TOUCHPAD) != 0) {
            mTouchpadHardwareWidth = device.getMotionRange(MotionEvent.AXIS_X).getRange();
            mTouchpadHardwareHeight = device.getMotionRange(MotionEvent.AXIS_Y).getRange();
            // first one will always be the hardware touchpad.
            break;
        }
    }
}
Example 48
Project: secrets-for-android-master  File: OS.java View source code
/** Does the device support a scroll wheel or trackball? */
public static boolean supportsScrollWheel() {
    int[] ids = InputDevice.getDeviceIds();
    for (int id : ids) {
        InputDevice device = InputDevice.getDevice(id);
        int sources = device.getSources();
        final int sourceTbOrDpad = InputDevice.SOURCE_TRACKBALL | InputDevice.SOURCE_DPAD;
        if (0 != (sources & sourceTbOrDpad))
            return true;
    }
    return false;
}
Example 49
Project: termux-app-master  File: TerminalView.java View source code
@Override
public boolean onSingleTapUp(MotionEvent e) {
    if (mEmulator == null)
        return true;
    if (mIsSelectingText) {
        toggleSelectingText(null);
        return true;
    }
    requestFocus();
    if (!mEmulator.isMouseTrackingActive()) {
        if (!e.isFromSource(InputDevice.SOURCE_MOUSE)) {
            mClient.onSingleTapUp(e);
            return true;
        }
    }
    return false;
}
Example 50
Project: VCL-Android-master  File: AudioPlayerActivity.java View source code
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    //Check for a joystick event
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK || event.getAction() != MotionEvent.ACTION_MOVE)
        return false;
    InputDevice inputDevice = event.getDevice();
    float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
    float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
    if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f)
        return false;
    float x = AndroidDevices.getCenteredAxis(event, inputDevice, MotionEvent.AXIS_X);
    if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY) {
        if (Math.abs(x) > 0.3) {
            seek(x > 0.0f ? 10000 : -10000);
            mLastMove = System.currentTimeMillis();
            return true;
        }
    }
    return true;
}
Example 51
Project: vlc-android-master  File: AudioPlayerActivity.java View source code
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    //Check for a joystick event
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK || event.getAction() != MotionEvent.ACTION_MOVE)
        return false;
    InputDevice inputDevice = event.getDevice();
    float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
    float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
    if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f)
        return false;
    float x = AndroidDevices.getCenteredAxis(event, inputDevice, MotionEvent.AXIS_X);
    if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY) {
        if (Math.abs(x) > 0.3) {
            seek(x > 0.0f ? 10000 : -10000);
            mLastMove = System.currentTimeMillis();
            return true;
        }
    }
    return true;
}
Example 52
Project: XieDaDeng-master  File: TaskStackViewTouchHandler.java View source code
/** Handles generic motion events */
public boolean onGenericMotionEvent(MotionEvent ev) {
    if ((ev.getSource() & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) {
        int action = ev.getAction();
        switch(action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_SCROLL:
                // Find the front most task and scroll the next task to the front
                float vScroll = ev.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vScroll > 0) {
                    if (mSv.ensureFocusedTask()) {
                        mSv.focusNextTask(true, false);
                    }
                } else {
                    if (mSv.ensureFocusedTask()) {
                        mSv.focusNextTask(false, false);
                    }
                }
                return true;
        }
    }
    return false;
}
Example 53
Project: connectbot-master  File: TerminalTextViewOverlay.java View source code
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // Selection may be beginning. Sync the TextView with the buffer.
        refreshTextFromBuffer();
    }
    // Mouse input is treated differently:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) {
        if (onMouseEvent(event, terminalView.bridge)) {
            return true;
        }
        terminalView.viewPager.setPagingEnabled(true);
    } else {
        if (terminalView.onTouchEvent(event)) {
            return true;
        }
    }
    return super.onTouchEvent(event);
}
Example 54
Project: FasterGallery-master  File: Gallery.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final boolean isTouchPad = (event.getSource() & InputDevice.SOURCE_CLASS_POSITION) != 0;
    if (isTouchPad) {
        float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
        float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
        View decor = getWindow().getDecorView();
        float scaleX = decor.getWidth() / maxX;
        float scaleY = decor.getHeight() / maxY;
        float x = event.getX() * scaleX;
        // x = decor.getWidth() - x; // invert x
        float y = event.getY() * scaleY;
        // y = decor.getHeight() - y; // invert y
        MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), x, y, event.getMetaState());
        return dispatchTouchEvent(touchEvent);
    }
    return super.onGenericMotionEvent(event);
}
Example 55
Project: Gallery2-master  File: GalleryActivity.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final boolean isTouchPad = (event.getSource() & InputDevice.SOURCE_CLASS_POSITION) != 0;
    if (isTouchPad) {
        float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
        float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
        View decor = getWindow().getDecorView();
        float scaleX = decor.getWidth() / maxX;
        float scaleY = decor.getHeight() / maxY;
        float x = event.getX() * scaleX;
        //x = decor.getWidth() - x; // invert x
        float y = event.getY() * scaleY;
        //y = decor.getHeight() - y; // invert y
        MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), x, y, event.getMetaState());
        return dispatchTouchEvent(touchEvent);
    }
    return super.onGenericMotionEvent(event);
}
Example 56
Project: Gallery3D_EVO_3D-master  File: Gallery.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final boolean isTouchPad = (event.getSource() & InputDevice.SOURCE_CLASS_POSITION) != 0;
    if (isTouchPad) {
        float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
        float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
        View decor = getWindow().getDecorView();
        float scaleX = decor.getWidth() / maxX;
        float scaleY = decor.getHeight() / maxY;
        float x = event.getX() * scaleX;
        //x = decor.getWidth() - x; // invert x
        float y = event.getY() * scaleY;
        //y = decor.getHeight() - y; // invert y
        MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), x, y, event.getMetaState());
        return dispatchTouchEvent(touchEvent);
    }
    return super.onGenericMotionEvent(event);
}
Example 57
Project: gdk-apidemo-sample-master  File: TouchpadView.java View source code
/** Looks up the hardware resolution of the Glass touchpad. */
private void lookupTouchpadHardwareResolution() {
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice device = InputDevice.getDevice(deviceId);
        if ((device.getSources() & InputDevice.SOURCE_TOUCHPAD) != 0) {
            logVerbose("Touchpad motion range: x-axis [%d, %d] y-axis [%d, %d]", device.getMotionRange(MotionEvent.AXIS_X).getMin(), device.getMotionRange(MotionEvent.AXIS_X).getMax(), device.getMotionRange(MotionEvent.AXIS_Y).getMin(), device.getMotionRange(MotionEvent.AXIS_Y).getMax());
            mTouchpadHardwareWidth = device.getMotionRange(MotionEvent.AXIS_X).getRange();
            mTouchpadHardwareHeight = device.getMotionRange(MotionEvent.AXIS_Y).getRange();
            // first one will always be the hardware touchpad.
            break;
        }
    }
}
Example 58
Project: platform_frameworks_support-master  File: DragStartHelperTest.java View source code
private static MotionEvent obtainMouseEvent(int action, int buttonState, View anchor, int offsetX, int offsetY) {
    final long eventTime = SystemClock.uptimeMillis();
    final int[] xy = getViewCenter(anchor);
    MotionEvent.PointerProperties[] props = new MotionEvent.PointerProperties[] { new MotionEvent.PointerProperties() };
    props[0].id = 0;
    props[0].toolType = MotionEvent.TOOL_TYPE_MOUSE;
    MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[] { new MotionEvent.PointerCoords() };
    coords[0].x = xy[0] + offsetX;
    coords[0].y = xy[1] + offsetY;
    return MotionEvent.obtain(eventTime, eventTime, action, 1, props, coords, 0, buttonState, 0, 0, -1, 0, InputDevice.SOURCE_MOUSE, 0);
}
Example 59
Project: XobotOS-master  File: StackView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll < 0) {
                        pacedScroll(false);
                        return true;
                    } else if (vscroll > 0) {
                        pacedScroll(true);
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 60
Project: androidtv-GameController-master  File: GameState.java View source code
/**
     * Finds a player's Spaceship object that corresponds to a given input event.
     *
     * Events that do not come from game controllers are ignored.  If the event is from a new
     * controller, the corresponding player's ship is activated.
     *
     * @param event The InputEvent to check.
     * @return a player's ship or null if the event was not from a controller.
     */
private Spaceship mapInputEventToShip(InputEvent event) {
    // getControllerNumber() will return "0" for devices that are not game controllers or
    // joysticks.
    int controllerNumber = InputDevice.getDevice(event.getDeviceId()).getControllerNumber() - 1;
    if (CONTROLLER_DEBUG_PRINT) {
        Utils.logDebug("----------------------------------------------");
        Utils.logDebug("Input event: ");
        Utils.logDebug("Source: " + event.getSource());
        Utils.logDebug("isFromSource(gamepad): " + event.isFromSource(InputDevice.SOURCE_GAMEPAD));
        Utils.logDebug("isFromSource(joystick): " + event.isFromSource(InputDevice.SOURCE_JOYSTICK));
        Utils.logDebug("isFromSource(touch nav): " + event.isFromSource(InputDevice.SOURCE_TOUCH_NAVIGATION));
        Utils.logDebug("Controller: " + controllerNumber);
        Utils.logDebug("----------------------------------------------");
    }
    if (controllerNumber >= 0 && controllerNumber < mPlayerList.length) {
        // Bind the device to the player's controller.
        mPlayerList[controllerNumber].getController().setDeviceId(event.getDeviceId());
        return mPlayerList[controllerNumber];
    }
    return null;
}
Example 61
Project: santa-tracker-android-master  File: FPLActivity.java View source code
// Capture motionevents and keyevents to check for gamepad movement.  Any events we catch
// (That look like they were from a gamepad or joystick) get sent to C++ via JNI, where
// they are stored, so C++ can deal with them next time it updates the game state.
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    if ((event.getAction() == MotionEvent.ACTION_MOVE) && (event.getSource() & (InputDevice.SOURCE_JOYSTICK | InputDevice.SOURCE_GAMEPAD)) != 0) {
        float axisX = event.getAxisValue(MotionEvent.AXIS_X);
        float axisY = event.getAxisValue(MotionEvent.AXIS_Y);
        float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
        float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
        float finalX, finalY;
        // Decide which values to send, based on magnitude.  Hat values, or analog/axis values?
        if (Math.abs(axisX) + Math.abs(axisY) > Math.abs(hatX) + Math.abs(hatY)) {
            finalX = axisX;
            finalY = axisY;
        } else {
            finalX = hatX;
            finalY = hatY;
        }
        nativeOnGamepadInput(event.getDeviceId(), event.getAction(), // Control Code is not needed for motionEvents.
        0, finalX, finalY);
    }
    return super.dispatchGenericMotionEvent(event);
}
Example 62
Project: XPrivacyTester-master  File: MainActivity.java View source code
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Cursor cursor;
    final ContentResolver cr = getContentResolver();
    final AccountManager accountManager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    ConnectivityManager conMan = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    TelephonyManager telManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    LocationManager locMan = (LocationManager) getSystemService(LOCATION_SERVICE);
    SensorManager sensitiveMan = (SensorManager) getSystemService(SENSOR_SERVICE);
    // Account manager methods
    try {
        ((TextView) findViewById(R.id.getAccounts)).setText(Integer.toString(accountManager.getAccounts().length));
        ((TextView) findViewById(R.id.getAccountsByType)).setText(Integer.toString(accountManager.getAccountsByType("com.google").length));
        OnAccountsUpdateListener listener = new OnAccountsUpdateListener() {

            @Override
            public void onAccountsUpdated(Account[] accounts) {
                ((TextView) MainActivity.this.findViewById(R.id.addOnAccountsUpdatedListener)).setText(Integer.toString(accounts.length));
                accountManager.removeOnAccountsUpdatedListener(this);
            }
        };
        accountManager.addOnAccountsUpdatedListener(listener, null, true);
        ((TextView) findViewById(R.id.getCurrentSyncs)).setText(Integer.toString(ContentResolver.getCurrentSyncs().size()));
    } catch (Throwable ex) {
        ex.printStackTrace();
        Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
    }
    // Package manager methods
    try {
        PackageManager packageManager = getPackageManager();
        ((TextView) findViewById(R.id.getInstalledApplications)).setText(Integer.toString(packageManager.getInstalledApplications(0).size()));
        ((TextView) findViewById(R.id.getInstalledPackages)).setText(Integer.toString(packageManager.getInstalledPackages(0).size()));
        Intent view = new Intent(Intent.ACTION_VIEW);
        view.setData(Uri.parse("http://www.faircode.eu/"));
        ((TextView) findViewById(R.id.queryIntentActivities)).setText(Integer.toString(packageManager.queryIntentActivities(view, 0).size()));
    } catch (Throwable ex) {
        ex.printStackTrace();
        Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
    }
    // Browser provider
    try {
        String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
        String sel = Browser.BookmarkColumns.BOOKMARK + " = 0";
        // 0 = history, 1 = bookmark
        cursor = getContentResolver().query(Browser.BOOKMARKS_URI, proj, sel, null, null);
        ((TextView) findViewById(R.id.BrowserProvider2)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
    }
    // Calendar provider
    try {
        cursor = cr.query(Calendars.CONTENT_URI, new String[] { Calendars._ID }, null, null, null);
        ((TextView) findViewById(R.id.CalendarProvider2)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.CalendarProvider2)).setText(ex.getClass().getName());
    }
    // Callog provider
    try {
        cursor = this.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, new String[] { CallLog.Calls._ID }, null, null, null);
        ((TextView) findViewById(R.id.CallLogProvider)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.CallLogProvider)).setText(ex.getClass().getName());
    }
    // Contacts provider
    try {
        cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, new String[] { ContactsContract.Contacts._ID }, null, null, null);
        ((TextView) findViewById(R.id.ContactsProvider2)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.ContactsProvider2)).setText(ex.getClass().getName());
    }
    // SMS provider
    try {
        cursor = cr.query(Uri.parse("content://sms/"), null, null, null, null);
        ((TextView) findViewById(R.id.SmsProvider)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.SmsProvider)).setText(ex.getClass().getName());
    }
    // Read SMSes
    try {
        SmsManager smsManager = SmsManager.getDefault();
        Method getMessages = smsManager.getClass().getMethod("getAllMessagesFromIcc");
        @SuppressWarnings("unchecked") List<SmsMessage> msgs = (List<SmsMessage>) getMessages.invoke(smsManager);
        ((TextView) findViewById(R.id.getAllMessagesFromIcc)).setText(Integer.toString(msgs.size()));
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.getAllMessagesFromIcc)).setText(ex.getClass().getName());
    }
    // Line 1 number
    try {
        String phoneNumber = telManager.getLine1Number();
        ((TextView) findViewById(R.id.getLine1Number)).setText(phoneNumber == null ? "null" : phoneNumber);
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.getLine1Number)).setText(ex.getClass().getName());
    }
    // Android ID
    try {
        String value = android.provider.Settings.Secure.getString(cr, android.provider.Settings.Secure.ANDROID_ID);
        ((TextView) findViewById(R.id.Settings_Secure_ANDROID_ID)).setText(value == null ? "null" : value);
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.Settings_Secure_ANDROID_ID)).setText(ex.getClass().getName());
    }
    // default_dns_server
    try {
        String value = android.provider.Settings.Global.getString(cr, "default_dns_server");
        ((TextView) findViewById(R.id.default_dns_server)).setText(value == null ? "null" : value);
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.default_dns_server)).setText(ex.getClass().getName());
    }
    // wifi_country_code
    try {
        String value = android.provider.Settings.Global.getString(cr, "wifi_country_code");
        ((TextView) findViewById(R.id.wifi_country_code)).setText(value == null ? "null" : value);
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.wifi_country_code)).setText(ex.getClass().getName());
    }
    // Input device
    try {
        int[] deviceId = InputDevice.getDeviceIds();
        if (deviceId == null || deviceId.length == 0)
            ((TextView) findViewById(R.id.InputDevice)).setText("-");
        else {
            InputDevice inputDevice = InputDevice.getDevice(deviceId[0]);
            ((TextView) findViewById(R.id.InputDevice)).setText(inputDevice.getName() + "/" + inputDevice.getDescriptor());
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.InputDevice)).setText(ex.getClass().getName());
    }
    // Downloads provider
    try {
        cursor = cr.query(Uri.parse("content://downloads/my_downloads"), null, null, null, null);
        ((TextView) findViewById(R.id.Downloads)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.Downloads)).setText(ex.getClass().getName());
    }
    // User dictionary
    try {
        cursor = cr.query(UserDictionary.Words.CONTENT_URI, null, null, null, null);
        ((TextView) findViewById(R.id.UserDictionary)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.UserDictionary)).setText(ex.getClass().getName());
    }
    // GMailProvider
    try {
        accountManager.getAccountsByTypeAndFeatures("com.google", new String[] { "service_mail" }, new AccountManagerCallback<Account[]>() {

            @Override
            public void run(AccountManagerFuture<Account[]> future) {
                Account[] accounts = null;
                try {
                    accounts = future.getResult();
                    if (accounts != null && accounts.length > 0) {
                        // e-mail address
                        String selectedAccount = accounts[0].name;
                        Uri labels = GmailContract.Labels.getLabelsUri(selectedAccount);
                        Cursor cursor = cr.query(labels, null, null, null, null);
                        ((TextView) findViewById(R.id.GMailProvider)).setText(cursor == null ? "null" : Integer.toString(cursor.getCount()));
                        if (cursor != null)
                            cursor.close();
                    } else
                        ((TextView) findViewById(R.id.GMailProvider)).setText("No e-mail account");
                } catch (Throwable ex) {
                    ex.printStackTrace();
                    ((TextView) findViewById(R.id.GMailProvider)).setText(ex.getClass().getName());
                }
            }
        }, null);
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.GMailProvider)).setText(ex.getClass().getName());
    }
    // GservicesProvider
    try {
        Uri gsf = Uri.parse("content://com.google.android.gsf.gservices");
        cursor = cr.query(gsf, null, null, new String[] { "android_id" }, null);
        String gsf_id = null;
        if (cursor.moveToFirst())
            gsf_id = Long.toHexString(Long.parseLong(cursor.getString(1)));
        ((TextView) findViewById(R.id.GservicesProvider)).setText(gsf_id == null ? "null" : gsf_id);
        if (cursor != null)
            cursor.close();
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.GservicesProvider)).setText(ex.getClass().getName());
    }
    // SERIAL
    ((TextView) findViewById(R.id.SERIAL)).setText(Build.SERIAL);
    // AdvertisingId
    new Thread() {

        @Override
        public void run() {
            try {
                final String adId = AdvertisingIdClient.getAdvertisingIdInfo(MainActivity.this).getId();
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        ((TextView) findViewById(R.id.AdvertisingId)).setText(adId == null ? "null" : adId);
                    }
                });
            } catch (final Throwable ex) {
                ex.printStackTrace();
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        ((TextView) findViewById(R.id.AdvertisingId)).setText(ex.getClass().getName());
                    }
                });
            }
        }
    }.start();
    // IoBridge
    try {
        Class<?> cSystemProperties = Class.forName("android.os.SystemProperties");
        Method mGet = cSystemProperties.getMethod("get", String.class);
        String hostName = (String) mGet.invoke(null, "net.hostname");
        String serialNo = (String) mGet.invoke(null, "ro.serialno");
        ((TextView) findViewById(R.id.net_hostname)).setText(hostName == null ? "null" : hostName);
        ((TextView) findViewById(R.id.ro_serialno)).setText(serialNo == null ? "null" : serialNo);
    } catch (Throwable ex) {
        ex.printStackTrace();
        Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
    }
    try {
        new FileReader("/proc/stat").close();
        ((TextView) findViewById(R.id.proc)).setText("readable");
    } catch (Throwable ex) {
        ((TextView) findViewById(R.id.proc)).setText(ex.getClass().getName());
    }
    // USB device
    try {
        HashMap<String, UsbDevice> mapUsbDevice = usbManager.getDeviceList();
        if (mapUsbDevice.size() == 0)
            ((TextView) findViewById(R.id.UsbDevice)).setText("no devices");
        else {
            UsbDevice usbDevice = mapUsbDevice.values().toArray(new UsbDevice[0])[0];
            ((TextView) findViewById(R.id.UsbDevice)).setText(usbDevice.getDeviceId() + "/" + usbDevice.getDeviceName());
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.UsbDevice)).setText(ex.getClass().getName());
    }
    // InetAddress
    new Thread() {

        @Override
        public void run() {
            try {
                final InetAddress addr1 = InetAddress.getByName("faircode.eu");
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        ((TextView) findViewById(R.id.InetAddress)).setText(addr1.toString());
                    }
                });
            } catch (final Throwable ex) {
                ex.printStackTrace();
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        ((TextView) findViewById(R.id.InetAddress)).setText(ex.getClass().getName());
                    }
                });
            }
        }
    }.start();
    // NetworkInterface
    try {
        Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
        if (netInterfaces == null)
            ((TextView) findViewById(R.id.NetworkInterface)).setText("null");
        else {
            int count = 0;
            while (netInterfaces.hasMoreElements()) {
                count++;
                netInterfaces.nextElement();
            }
            ((TextView) findViewById(R.id.NetworkInterface)).setText(Integer.toString(count));
        }
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.NetworkInterface)).setText(ex.getClass().getName());
    }
    // NetworkInfo
    try {
        NetworkInfo ni = conMan.getActiveNetworkInfo();
        DetailedState ds = ni.getDetailedState();
        ((TextView) findViewById(R.id.NetworkInfo)).setText(ds == null ? "null" : ds.toString());
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.NetworkInfo)).setText(ex.getClass().getName());
    }
    // NetworkInfo
    try {
        NetworkInfo[] ani = conMan.getAllNetworkInfo();
        ((TextView) findViewById(R.id.Connectivity)).setText(ani == null ? "null" : Integer.toString(ani.length));
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.Connectivity)).setText(ex.getClass().getName());
    }
    // WifiManager
    try {
        List<ScanResult> scans = wifiManager.getScanResults();
        ((TextView) findViewById(R.id.WifiManager_getScanResults)).setText(scans == null ? "null" : Integer.toString(scans.size()));
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.WifiManager_getScanResults)).setText(ex.getClass().getName());
    }
    try {
        WifiInfo winfo = wifiManager.getConnectionInfo();
        ((TextView) findViewById(R.id.WifiManager_getConnectionInfo)).setText(winfo == null ? "null" : winfo.toString());
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.WifiManager_getConnectionInfo)).setText(ex.getClass().getName());
    }
    try {
        DhcpInfo dhcp = wifiManager.getDhcpInfo();
        ((TextView) findViewById(R.id.WifiManager_getDhcpInfo)).setText(dhcp == null ? "null" : dhcp.toString());
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.WifiManager_getDhcpInfo)).setText(ex.getClass().getName());
    }
    // BluetoothAdapter
    try {
        String btAddr = BluetoothAdapter.getDefaultAdapter().getAddress();
        ((TextView) findViewById(R.id.BluetoothAdapter)).setText(btAddr == null ? "null" : btAddr);
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.BluetoothAdapter)).setText(ex.getClass().getName());
    }
    // Configuration
    try {
        int mcc = Resources.getSystem().getConfiguration().mcc;
        ((TextView) findViewById(R.id.Configuration)).setText(Integer.toString(mcc));
    } catch (final Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.Configuration)).setText(ex.getClass().getName());
    }
    // Cell info
    try {
        List<CellInfo> listCellInfo = telManager.getAllCellInfo();
        ((TextView) findViewById(R.id.getAllCellInfo)).setText(Integer.toString(listCellInfo.size()));
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.getAllCellInfo)).setText(ex.getClass().getName());
    }
    // Cell info
    try {
        Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        ((TextView) findViewById(R.id.getLastKnownLocation)).setText(lastLoc == null ? "null" : lastLoc.toString());
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.getLastKnownLocation)).setText(ex.getClass().getName());
    }
    // Sensor manager
    try {
        List<Sensor> listSensor = sensitiveMan.getSensorList(Sensor.TYPE_ALL);
        ((TextView) findViewById(R.id.SensorManager)).setText(Integer.toString(listSensor.size()));
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.SensorManager)).setText(ex.getClass().getName());
    }
    try {
        Process sh = Runtime.getRuntime().exec("getprop ro.serialno");
        BufferedReader br = new BufferedReader(new InputStreamReader(sh.getInputStream()));
        ((TextView) findViewById(R.id.shell_ro_serialno)).setText(br.readLine());
    } catch (Throwable ex) {
        ex.printStackTrace();
        ((TextView) findViewById(R.id.shell_ro_serialno)).setText(ex.getClass().getName());
    }
    gClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addApi(ActivityRecognition.API).addApi(AppIndex.APP_INDEX_API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    gClient.connect();
// TODO: EMailProvider
// TODO: NFC
// TODO: notifications
// TODO: overlay
}
Example 63
Project: chromium_webview-master  File: ContentViewGestureHandler.java View source code
private MotionEvent obtainActionCancelMotionEvent() {
    MotionEvent me = MotionEvent.obtain(mCurrentDownEvent != null ? mCurrentDownEvent.getDownTime() : SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
    me.setSource(mCurrentDownEvent != null ? mCurrentDownEvent.getSource() : InputDevice.SOURCE_CLASS_POINTER);
    return me;
}
Example 64
Project: Osmand-master  File: OsmandMapTileView.java View source code
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 && event.getAction() == MotionEvent.ACTION_SCROLL && event.getAxisValue(MotionEvent.AXIS_VSCROLL) != 0) {
        final RotatedTileBox tb = getCurrentRotatedTileBox();
        final double lat = tb.getLatFromPixel(event.getX(), event.getY());
        final double lon = tb.getLonFromPixel(event.getX(), event.getY());
        int zoomDir = event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0 ? -1 : 1;
        getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + zoomDir, true);
        return true;
    }
    return false;
}
Example 65
Project: SealBrowser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                // getHorizontalScrollFactor()
                                final int delta = (int) (hscroll * mScrollFactor);
                                final int range = getScrollRange();
                                int oldScrollX = getScrollX();
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, getScrollY());
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                // getVerticalScrollFactor()
                                final int delta = (int) (vscroll * mScrollFactor);
                                final int range = getScrollRange();
                                int oldScrollY = getScrollY();
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(getScrollX(), newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 66
Project: glview-master  File: ScrollView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        if (vscroll != 0) {
                            final int delta = (int) (vscroll * getVerticalScrollFactor());
                            final int range = getScrollRange();
                            int oldScrollY = mScrollY;
                            int newScrollY = oldScrollY - delta;
                            if (newScrollY < 0) {
                                newScrollY = 0;
                            } else if (newScrollY > range) {
                                newScrollY = range;
                            }
                            if (newScrollY != oldScrollY) {
                                super.scrollTo(mScrollX, newScrollY);
                                return true;
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 67
Project: MapEver-master  File: LargeImageView.java View source code
// For zooming via mouse scrollwheel
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 && event.getAction() == MotionEvent.ACTION_SCROLL && event.getAxisValue(MotionEvent.AXIS_VSCROLL) != 0) {
        float factor = event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0 ? 0.90f : 1.10f;
        // Calculate pan offsetting.
        float focusX = (event.getX() - getWidth() / 2) / zoomScale;
        float focusY = (event.getY() - getHeight() / 2) / zoomScale;
        float dx = focusX * (1 - factor);
        float dy = focusY * (1 - factor);
        float new_x = Float.isNaN(panCenterX) ? -dx : panCenterX - dx;
        float new_y = Float.isNaN(panCenterY) ? -dy : panCenterY - dy;
        setPanZoom(new_x, new_y, zoomScale * factor);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
Example 68
Project: Android-Launcher2-Standalone-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 69
Project: Android-Trebuchet-Launcher-Standalone-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 70
Project: AndroidLuancher-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending
                    // on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 71
Project: AndroidStudyDemo-master  File: ZrcAbsListView.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= 12) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_SCROLL:
                    {
                        if (mTouchMode == TOUCH_MODE_REST) {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                if (!trackMotionScroll(delta, delta)) {
                                    return true;
                                }
                            }
                        }
                    }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 72
Project: android_Browser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollX = mScrollX;
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, mScrollY);
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollY = mScrollY;
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(mScrollX, newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 73
Project: android_packages_apps-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 74
Project: android_packages_apps_Launcher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 75
Project: android_packages_apps_Trebuchet-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0);
                        if (isForwardScroll) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 76
Project: AntennaPod-master  File: PlaybackService.java View source code
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, "OnStartCommand called");
    final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
    final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false);
    final Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
    if (keycode == -1 && playable == null && !castDisconnect) {
        Log.e(TAG, "PlaybackService was started with no arguments");
        stopSelf();
        return Service.START_REDELIVER_INTENT;
    }
    if ((flags & Service.START_FLAG_REDELIVERY) != 0) {
        Log.d(TAG, "onStartCommand is a redelivered intent, calling stopForeground now.");
        stopForeground(true);
    } else {
        if (keycode != -1) {
            Log.d(TAG, "Received media button event");
            handleKeycode(keycode, intent.getIntExtra(MediaButtonReceiver.EXTRA_SOURCE, InputDevice.SOURCE_CLASS_NONE));
        } else if (castDisconnect) {
            castManager.disconnect();
        } else {
            started = true;
            boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, true);
            boolean startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false);
            boolean prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false);
            sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
            //If the user asks to play External Media, the casting session, if on, should end.
            if (playable instanceof ExternalMedia) {
                castManager.disconnect();
            }
            mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately);
        }
    }
    return Service.START_REDELIVER_INTENT;
}
Example 77
Project: browser.apk-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollX = mScrollX;
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, mScrollY);
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollY = mScrollY;
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(mScrollX, newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 78
Project: Compiled_Android_Launcher4.2.2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 79
Project: CompilingLauncher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 80
Project: droidel-master  File: Instrumentation.java View source code
/**
     * Send a key event to the currently focused window/view and wait for it to
     * be processed.  Finished at some point after the recipient has returned
     * from its event processing, though it may <em>not</em> have completely
     * finished reacting from the event -- for example, if it needs to update
     * its display as a result, it may still be in the process of doing that.
     * 
     * @param event The event to send to the current focus.
     */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();
    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int action = event.getAction();
    int code = event.getKeyCode();
    int repeatCount = event.getRepeatCount();
    int metaState = event.getMetaState();
    int deviceId = event.getDeviceId();
    int scancode = event.getScanCode();
    int source = event.getSource();
    int flags = event.getFlags();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
    InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
Example 81
Project: Fairphone---DEPRECATED-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 82
Project: Fairphone-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 83
Project: GeekBand-Android-1501-Homework-master  File: ZrcAbsListView.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (APIUtil.isSupport(12)) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_SCROLL:
                    {
                        if (mTouchMode == TOUCH_MODE_REST) {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                if (!trackMotionScroll(delta, delta)) {
                                    return true;
                                }
                            }
                        }
                    }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 84
Project: gyz-master  File: ZrcAbsListView.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (APIUtil.isSupport(12)) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_SCROLL:
                    {
                        if (mTouchMode == TOUCH_MODE_REST) {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                if (!trackMotionScroll(delta, delta)) {
                                    return true;
                                }
                            }
                        }
                    }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 85
Project: homescreen-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0);
                        if (isForwardScroll) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 86
Project: Joker-master  File: ZrcAbsListView.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (APIUtil.isSupport(12)) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_SCROLL:
                    {
                        if (mTouchMode == TOUCH_MODE_REST) {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                if (!trackMotionScroll(delta, delta)) {
                                    return true;
                                }
                            }
                        }
                    }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 87
Project: Launcher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 88
Project: Launcher3-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0);
                        if (isForwardScroll) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 89
Project: my-starter-with-all-effects-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 90
Project: Nimingban-master  File: BothScrollView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (hscroll != 0) {
                                final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                final int range = getHorizontalScrollRange();
                                int oldScrollX = getScrollX();
                                int newScrollX = oldScrollX + delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, getScrollY());
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                final int range = getVerticalScrollRange();
                                int oldScrollY = getScrollY();
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(getScrollX(), newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 91
Project: packages-apps-Launcher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 92
Project: packages_apps_Launcher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 93
Project: platform_packages_apps_browser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollX = mScrollX;
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, mScrollY);
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollY = mScrollY;
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(mScrollX, newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 94
Project: platform_packages_apps_Launcher2-master  File: PagedView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    // Handle mouse (or ext. device) by shifting the page depending on the scroll
                    final float vscroll;
                    final float hscroll;
                    if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                        vscroll = 0;
                        hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    } else {
                        vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                    }
                    if (hscroll != 0 || vscroll != 0) {
                        if (hscroll > 0 || vscroll > 0) {
                            scrollRight();
                        } else {
                            scrollLeft();
                        }
                        return true;
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 95
Project: RocBrowser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                //final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                Method m;
                                int f = 1;
                                try {
                                    m = ScrollerView.this.getClass().getMethod("getHorizontalScrollFactor", new Class[] {});
                                    f = (Integer) m.invoke(null, null);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                final int delta = (int) (hscroll * f);
                                final int range = getScrollRange();
                                int oldScrollX = getScrollX();
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, getScrollY());
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                //final int delta = (int) (vscroll * getVerticalScrollFactor());
                                Method m;
                                int f = 1;
                                try {
                                    m = ScrollerView.this.getClass().getMethod("getVerticalScrollFactor", new Class[] {});
                                    f = (Integer) m.invoke(null, null);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                final int delta = (int) (vscroll * f);
                                final int range = getScrollRange();
                                int oldScrollY = getScrollY();
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(getScrollX(), newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 96
Project: SMouse-and-Faketooth-master  File: InputManagerService.java View source code
/**
     * Gets information about the input device with the specified id.
     * @param deviceId The device id.
     * @return The input device or null if not found.
     */
// Binder call
@Override
public InputDevice getInputDevice(int deviceId) {
    synchronized (mInputDevicesLock) {
        final int count = mInputDevices.length;
        for (int i = 0; i < count; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            if (inputDevice.getId() == deviceId) {
                return inputDevice;
            }
        }
    }
    return null;
}
Example 97
Project: TintBrowser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                //getHorizontalScrollFactor()
                                final int delta = (int) (hscroll * mScrollFactor);
                                final int range = getScrollRange();
                                int oldScrollX = getScrollX();
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, getScrollY());
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                //getVerticalScrollFactor()
                                final int delta = (int) (vscroll * mScrollFactor);
                                final int range = getScrollRange();
                                int oldScrollY = getScrollY();
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(getScrollX(), newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 98
Project: XBrowser-master  File: ScrollerView.java View source code
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                {
                    if (!mIsBeingDragged) {
                        if (mHorizontal) {
                            final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                            if (hscroll != 0) {
                                final int delta = (int) (hscroll * getHorizontalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollX = mScrollX;
                                int newScrollX = oldScrollX - delta;
                                if (newScrollX < 0) {
                                    newScrollX = 0;
                                } else if (newScrollX > range) {
                                    newScrollX = range;
                                }
                                if (newScrollX != oldScrollX) {
                                    super.scrollTo(newScrollX, mScrollY);
                                    return true;
                                }
                            }
                        } else {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                final int range = getScrollRange();
                                int oldScrollY = mScrollY;
                                int newScrollY = oldScrollY - delta;
                                if (newScrollY < 0) {
                                    newScrollY = 0;
                                } else if (newScrollY > range) {
                                    newScrollY = range;
                                }
                                if (newScrollY != oldScrollY) {
                                    super.scrollTo(mScrollX, newScrollY);
                                    return true;
                                }
                            }
                        }
                    }
                }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 99
Project: ZrcListView-master  File: ZrcAbsListView.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (APIUtil.isSupport(12)) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_SCROLL:
                    {
                        if (mTouchMode == TOUCH_MODE_REST) {
                            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                            if (vscroll != 0) {
                                final int delta = (int) (vscroll * getVerticalScrollFactor());
                                if (!trackMotionScroll(delta, delta)) {
                                    return true;
                                }
                            }
                        }
                    }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
Example 100
Project: android-chromium-master  File: ContentViewCore.java View source code
/**
     * @see View#onGenericMotionEvent(MotionEvent)
     */
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                nativeSendMouseWheelEvent(mNativeContentViewCore, event.getEventTime(), event.getX(), event.getY(), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
                mContainerView.removeCallbacks(mFakeMouseMoveRunnable);
                // Send a delayed onMouseMove event so that we end
                // up hovering over the right position after the scroll.
                final MotionEvent eventFakeMouseMove = MotionEvent.obtain(event);
                mFakeMouseMoveRunnable = new Runnable() {

                    @Override
                    public void run() {
                        onHoverEvent(eventFakeMouseMove);
                    }
                };
                mContainerView.postDelayed(mFakeMouseMoveRunnable, 250);
                return true;
        }
    }
    return mContainerViewInternals.super_onGenericMotionEvent(event);
}
Example 101
Project: android-chromium-view-master  File: ContentViewCore.java View source code
/**
     * @see View#onGenericMotionEvent(MotionEvent)
     */
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                nativeSendMouseWheelEvent(mNativeContentViewCore, event.getEventTime(), event.getX(), event.getY(), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
                mContainerView.removeCallbacks(mFakeMouseMoveRunnable);
                // Send a delayed onMouseMove event so that we end
                // up hovering over the right position after the scroll.
                final MotionEvent eventFakeMouseMove = MotionEvent.obtain(event);
                mFakeMouseMoveRunnable = new Runnable() {

                    @Override
                    public void run() {
                        onHoverEvent(eventFakeMouseMove);
                    }
                };
                mContainerView.postDelayed(mFakeMouseMoveRunnable, 250);
                return true;
        }
    }
    return mContainerViewInternals.super_onGenericMotionEvent(event);
}