Java Code Examples for android.view.InputDevice#SOURCE_CLASS_POINTER

The following examples show how to use android.view.InputDevice#SOURCE_CLASS_POINTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 6 votes vote down vote up
@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 2
Source File: ContentViewCore.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @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 3
Source File: ContentViewCore.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @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 4
Source File: StackView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: FilmstripGestureRecognizer.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
public boolean onGenericMotionEvent(MotionEvent event)
{
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_SCROLL:
            {
                final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                final float vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);

                if (hscroll != 0.0f || vscroll != 0.0f)
                {
                    mListener.onMouseScroll(hscroll, vscroll);
                }
            }
        }
    }

    return true;
}
 
Example 6
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
@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 7
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@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 8
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@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 = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 9
Source File: BaseMovementMethod.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
    if ((ApiWrapper.getSourceOfEvent(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_HSCROLL);
                }

                boolean handled = false;
                if (hscroll < 0) {
                    handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
                } else if (hscroll > 0) {
                    handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
                }
                if (vscroll < 0) {
                    handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                } else if (vscroll > 0) {
                    handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                }
                return handled;
            }
        }
    }
    return false;
}
 
Example 10
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @see View#onGenericMotionEvent(MotionEvent)
 */
public boolean onGenericMotionEvent(MotionEvent event) {
    if (GamepadList.onGenericMotionEvent(event)) return true;
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_SCROLL:
                getEventForwarder().onMouseWheelEvent(event.getEventTime(), event.getX(),
                        event.getY(), event.getAxisValue(MotionEvent.AXIS_HSCROLL),
                        event.getAxisValue(MotionEvent.AXIS_VSCROLL),
                        mRenderCoordinates.getWheelScrollFactor());
                return true;
            case MotionEvent.ACTION_BUTTON_PRESS:
            case MotionEvent.ACTION_BUTTON_RELEASE:
                // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
                // crbug.com/592082
                if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
                    return getEventForwarder().onMouseEvent(event);
                }
        }
    } else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
        if (mJoystickScrollEnabled) {
            float velocityX = getFilteredAxisValue(event, MotionEvent.AXIS_X);
            float velocityY = getFilteredAxisValue(event, MotionEvent.AXIS_Y);
            flingViewport(event.getEventTime(), -velocityX, -velocityY, true);
            return true;
        }
    }
    return mContainerViewInternals.super_onGenericMotionEvent(event);
}
 
Example 11
Source File: PagedView.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@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 = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 12
Source File: PagedView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@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 13
Source File: BaseMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
    if ((ApiWrapper.getSourceOfEvent(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_HSCROLL);
                }

                boolean handled = false;
                if (hscroll < 0) {
                    handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
                } else if (hscroll > 0) {
                    handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
                }
                if (vscroll < 0) {
                    handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                } else if (vscroll > 0) {
                    handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                }
                return handled;
            }
        }
    }
    return false;
}
 
Example 14
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onInputEvent(InputEvent event, int displayId) {
    boolean handled = false;
    try {
        if (event instanceof MotionEvent
                && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            MotionEvent dup = MotionEvent.obtainNoHistory((MotionEvent)event);
            dispatchPointer(dup);
            handled = true;
        }
    } finally {
        finishInputEvent(event, handled);
    }
}
 
Example 15
Source File: BaseMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_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);
                }

                boolean handled = false;
                if (hscroll < 0) {
                    handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
                } else if (hscroll > 0) {
                    handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
                }
                if (vscroll < 0) {
                    handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
                } else if (vscroll > 0) {
                    handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
                }
                return handled;
            }
        }
    }
    return false;
}
 
Example 16
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch a pointer event. 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 A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    try {
        WindowManagerGlobal.getWindowManagerService().injectInputAfterTransactionsApplied(event,
                InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
    } catch (RemoteException e) {
    }
}
 
Example 17
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. 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 A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 18
Source File: Instrumentation.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. 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 A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 19
Source File: Instrumentation.java    From droidel with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. 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 A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 20
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. 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 A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}