Example usage for android.view MotionEvent getMetaState

List of usage examples for android.view MotionEvent getMetaState

Introduction

In this page you can find the example usage for android.view MotionEvent getMetaState.

Prototype

public final int getMetaState() 

Source Link

Document

Returns the state of any meta / modifier keys that were in effect when the event was generated.

Usage

From source file:com.android.launcher2.PagedView.java

@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;// ww  w .  ja va 2s.c o m
                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);
}

From source file:com.hippo.widget.BothScrollView.java

@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;
                        }/*w  w  w  .j  a v a 2s .  c  o m*/
                        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);
}

From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java

private void sendCancelEvent() {
    System.out.println("sendCancelEvent");
    MotionEvent last = mLastMoveEvent;
    MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_CANCEL,
            last.getX(), last.getY(), last.getMetaState());
    dispatchTouchEventSupper(e);/*from  w  ww . ja va2s . c o  m*/
}

From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java

private void sendDownEvent() {
    System.out.println("sendDownEvent");
    final MotionEvent last = mLastMoveEvent;
    if (last == null)
        return;// w  w w  .  j  a  va2s  .c  o  m
    MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_DOWN,
            last.getX(), last.getY(), last.getMetaState());
    dispatchTouchEventSupper(e);
}

From source file:cc.flydev.launcher.Page.java

@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;/*from w w  w.ja  va  2 s.  c  om*/
                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);
}

From source file:com.n2hsu.launcher.Page.java

@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;//from   w w w .ja  v a  2s. c  o m
                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);
}

From source file:com.processing.core.PApplet.java

/**
 * Figure out how to process a mouse event. When loop() has been
 * called, the events will be queued up until drawing is complete.
 * If noLoop() has been called, then events will happen immediately.
 *//*from w  w  w .ja  va 2  s  .c  o m*/
protected void nativeMotionEvent(android.view.MotionEvent motionEvent) {
    //    enqueueMotionEvent(event);
    //
    //    // this will be the last event in the list
    //    AndroidTouchEvent pme = motionEventQueue[motionEventCount + historyCount];
    //    pme.setAction(event.getAction());
    //    pme.setNumPointers(event.getPointerCount());
    //    pme.setPointers(event);
    //
    //    // historical events happen before the 'current' values
    //    if (pme.action == MotionEvent.ACTION_MOVE && historyCount > 0) {
    //      for (int i = 0; i < historyCount; i++) {
    //        AndroidTouchEvent hist = motionEventQueue[motionEventCount++];
    //        hist.setAction(event.getAction());
    //        hist.setNumPointers(event.getPointerCount());
    //        hist.setPointers(event, i);
    //      }
    //    }

    // ACTION_HOVER_ENTER and ACTION_HOVER_EXIT are passed into
    // onGenericMotionEvent(android.view.MotionEvent)
    // if we want to implement mouseEntered/Exited

    // http://developer.android.com/reference/android/view/MotionEvent.html
    // http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
    // http://www.techrepublic.com/blog/app-builder/use-androids-gesture-detector-to-translate-a-swipe-into-an-event/1577

    int metaState = motionEvent.getMetaState();
    int modifiers = 0;
    if ((metaState & android.view.KeyEvent.META_SHIFT_ON) != 0) {
        modifiers |= Event.SHIFT;
    }
    if ((metaState & META_CTRL_ON) != 0) {
        modifiers |= Event.CTRL;
    }
    if ((metaState & META_META_ON) != 0) {
        modifiers |= Event.META;
    }
    if ((metaState & android.view.KeyEvent.META_ALT_ON) != 0) {
        modifiers |= Event.ALT;
    }

    int clickCount = 1; // not really set... (i.e. not catching double taps)
    int index;

    // MotionEvent.html -> getButtonState() does BUTTON_PRIMARY, SECONDARY, TERTIARY
    //   use this for left/right/etc
    switch (motionEvent.getAction()) {
    case MotionEvent.ACTION_DOWN:
        motionPointerId = motionEvent.getPointerId(0);
        postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.PRESS, modifiers,
                (int) motionEvent.getX(), (int) motionEvent.getY(), LEFT, clickCount));
        break;
    case MotionEvent.ACTION_MOVE:
        //      int historySize = motionEvent.getHistorySize();
        index = motionEvent.findPointerIndex(motionPointerId);
        if (index != -1) {
            postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.DRAG, modifiers,
                    (int) motionEvent.getX(index), (int) motionEvent.getY(index), LEFT, clickCount));
        }
        break;
    case MotionEvent.ACTION_UP:
        index = motionEvent.findPointerIndex(motionPointerId);
        if (index != -1) {
            postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.RELEASE, modifiers,
                    (int) motionEvent.getX(index), (int) motionEvent.getY(index), LEFT, clickCount));
        }
        break;
    }
    //postEvent(pme);
}