Example usage for android.view MotionEvent ACTION_HOVER_MOVE

List of usage examples for android.view MotionEvent ACTION_HOVER_MOVE

Introduction

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

Prototype

int ACTION_HOVER_MOVE

To view the source code for android.view MotionEvent ACTION_HOVER_MOVE.

Click Source Link

Document

Constant for #getActionMasked : A change happened but the pointer is not down (unlike #ACTION_MOVE ).

Usage

From source file:hide.com.googlecode.eyesfree.utils.TouchExplorationHelper.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean onHover(View view, MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }/*from w w  w.  j  a va 2  s  .  com*/

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_ENTER:
    case MotionEvent.ACTION_HOVER_MOVE:
        final T item = getItemAt(event.getX(), event.getY());
        setCurrentItem(item);
        return true;
    case MotionEvent.ACTION_HOVER_EXIT:
        setCurrentItem(null);
        return true;
    }

    return false;
}

From source file:com.deange.datetimepicker.TouchExplorationHelper.java

@Override
public boolean onHover(View view, MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }/*from   w  ww  .  j  a v  a  2s  . co  m*/

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_ENTER:
    case MotionEvent.ACTION_HOVER_MOVE:
        final T item = getItemAt(event.getX(), event.getY());
        setCurrentItem(item);
        return true;
    case MotionEvent.ACTION_HOVER_EXIT:
        setCurrentItem(null);
        return true;
    }

    return false;
}

From source file:org.holoeverywhere.widget.datetimepicker.TouchExplorationHelper.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public View.OnHoverListener getOnHoverListener() {
    if (mOnHoverListener == null) {
        mOnHoverListener = new View.OnHoverListener() {
            @Override//w  w w .  j a va 2s  .c  om
            public boolean onHover(View view, MotionEvent event) {
                if (!mManager.isTouchExplorationEnabled()) {
                    return false;
                }

                switch (event.getAction()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                case MotionEvent.ACTION_HOVER_MOVE:
                    final T item = getItemAt(event.getX(), event.getY());
                    setCurrentItem(item);
                    return true;
                case MotionEvent.ACTION_HOVER_EXIT:
                    setCurrentItem(null);
                    return true;
                }

                return false;
            }
        };
    }
    return (View.OnHoverListener) mOnHoverListener;
}

From source file:com.commonsware.android.kbmouse.hotkeys.MainActivity.java

private void onHover(MotionEvent event, @StringRes final int message, final View anchor) {
    Runnable hover = hoverTimers.get(anchor.getId());

    if (hover == null && (event.getAction() == MotionEvent.ACTION_HOVER_ENTER
            || event.getAction() == MotionEvent.ACTION_HOVER_MOVE)) {

        hover = new Runnable() {
            @Override/*from  w w w.  j  av  a2 s .  c o  m*/
            public void run() {
                showTooltip(message);
            }
        };

        hoverTimers.put(anchor.getId(), hover);
        thumbnailLarge.postDelayed(hover, TOOLTIP_DELAY);
    } else if (hover != null && event.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
        thumbnailLarge.removeCallbacks(hover);
        hoverTimers.remove(anchor.getId());
    }
}

From source file:com.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when touch exploration is turned on in SDK versions ICS and higher.
 *
 * @param event The hover event./*from  w ww.  java  2 s . co  m*/
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(final MotionEvent event, final PointerTracker tracker) {
    if (mView == null) {
        return false;
    }

    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key previousKey = mLastHoverKey;
    final Key key;

    if (pointInView(x, y)) {
        key = tracker.getKeyOn(x, y);
    } else {
        key = null;
    }
    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (key != null) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        }
        return onHoverKey(key, event);
    }
    return false;
}

From source file:com.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT on the previous key,
 * a HOVER_ENTER on the current key, and a HOVER_MOVE on the current key.
 *
 * @param currentKey The currently hovered key.
 * @param previousKey The previously hovered key.
 * @param event The event that triggered the transition.
 * @return {@code true} if the event was handled.
 *//*  w  w w. j  a va  2  s.  c  o m*/
private boolean onTransitionKey(final Key currentKey, final Key previousKey, final MotionEvent event) {
    final int savedAction = event.getAction();
    event.setAction(MotionEvent.ACTION_HOVER_EXIT);
    onHoverKey(previousKey, event);
    event.setAction(MotionEvent.ACTION_HOVER_ENTER);
    onHoverKey(currentKey, event);
    event.setAction(MotionEvent.ACTION_HOVER_MOVE);
    final boolean handled = onHoverKey(currentKey, event);
    event.setAction(savedAction);
    return handled;
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

@Override
public boolean onHoverEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mAccessibilityManager.isTouchExplorationEnabled()) {
            final int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER:
                event.setAction(MotionEvent.ACTION_DOWN);
                break;
            case MotionEvent.ACTION_HOVER_MOVE:
                event.setAction(MotionEvent.ACTION_MOVE);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
                event.setAction(MotionEvent.ACTION_UP);
                break;
            }//from   ww w.  j av  a2  s  . co  m
            onTouchEvent(event);
            event.setAction(action);
        }
    }
    return super.onHoverEvent(event);
}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

/**
 * A "generic motion event" includes joystick and mouse motion
 * when the mouse button isn't down. In our simple sample, we're
 * not handling the joystick, but this is where any such code
 * would live.//  w ww  .j av  a2  s.co m
 *
 * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the
 * function using \@TargetApi to allow it to call the super.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    if (event.getSource() == InputDevice.SOURCE_MOUSE) {
        event.getPointerCoords(0, mCoordHolder);
        switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_MOVE:
            AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0);
            break;

        default:
            return super.dispatchGenericMotionEvent(event);
        }
        return true;
    } else if (event.getSource() == InputDevice.SOURCE_JOYSTICK) {
        Log.v(TAG, "Joystick event:" + event.toString());

        if (!mInitializedJoystick) {
            mInitializedJoystick = true;

            InputDevice joystick = InputDevice.getDevice(event.getDeviceId());
            InputDevice.MotionRange lThumbX = joystick.getMotionRange(MotionEvent.AXIS_X,
                    InputDevice.SOURCE_JOYSTICK);
            InputDevice.MotionRange lThumbY = joystick.getMotionRange(MotionEvent.AXIS_Y,
                    InputDevice.SOURCE_JOYSTICK);
            InputDevice.MotionRange rThumbX = joystick.getMotionRange(MotionEvent.AXIS_Z);
            InputDevice.MotionRange rThumbY = joystick.getMotionRange(MotionEvent.AXIS_RZ);
            InputDevice.MotionRange rTrigger = joystick.getMotionRange(MotionEvent.AXIS_GAS);
            if (rTrigger == null) {
                rTrigger = joystick.getMotionRange(MotionEvent.AXIS_RTRIGGER);
                mRTrigger = MotionEvent.AXIS_RTRIGGER;
            }

            InputDevice.MotionRange lTrigger = joystick.getMotionRange(MotionEvent.AXIS_BRAKE);
            if (lTrigger == null) {
                lTrigger = joystick.getMotionRange(MotionEvent.AXIS_LTRIGGER);
                mLTrigger = MotionEvent.AXIS_LTRIGGER;
            }

            List<InputDevice.MotionRange> ranges = joystick.getMotionRanges();

            InputDevice.MotionRange dPad = null;
            String name = joystick.getName();

            /*
            The Amazon Fire Game Controller follows the NVidia standard of sending
            AXIS_HAT_X/AXIS_HAT_Y results when the user hits the D-Pad. Only if we
            return false from dispatchGenericMotionEvent() will it then send
            DPAD keycodes.
                    
            But the most popular Android joystick on the market at this time, the
            Nyko Playpad Pro, returns AXIS_HAT_X/AXIS_HAT_Y results when the left
            analog stick hits its extremes, meaning that the analog stick will
            generate DPAD keys if we return false. The Nyko generates DPAD keys
            directly for the DPAD controller.
                    
            So we have two incompatible standards fighting with each other. Probably
            the safest thing to do would be to ask the user to press on their DPAD
            and see what messages we get, but that is beyond the scope of this
            example code.
            */
            if (name.equals("Amazon Fire Game Controler")) {
                for (int i = 0; i < ranges.size(); ++i) {
                    InputDevice.MotionRange range = ranges.get(i);
                    int axis = range.getAxis();

                    if (axis == MotionEvent.AXIS_HAT_X || axis == MotionEvent.AXIS_HAT_Y) {
                        dPad = ranges.get(i);
                        break;
                    }
                }
            }

            JoystickHelper.joystickDeadZones(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, dPad);
        }

        float lThumbX = event.getAxisValue(MotionEvent.AXIS_X);
        float lThumbY = -event.getAxisValue(MotionEvent.AXIS_Y);
        float rThumbX = event.getAxisValue(MotionEvent.AXIS_Z);
        float rThumbY = -event.getAxisValue(MotionEvent.AXIS_RZ);
        float lTrigger = event.getAxisValue(mLTrigger);
        float rTrigger = event.getAxisValue(mRTrigger);
        float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
        float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);

        JoystickHelper.setJoystickState(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, hatX, hatY);
        return true;
    }

    return super.dispatchGenericMotionEvent(event);
}

From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java

/**
 * A "generic motion event" includes joystick and mouse motion
 * when the mouse button isn't down. In our simple sample, we're
 * not handling the joystick, but this is where any such code
 * would live.//from  w ww  .  jav a 2 s .  c om
 *
 * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the
 * function using \@TargetApi to allow it to call the super.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    if (event.getSource() == InputDevice.SOURCE_MOUSE) {
        event.getPointerCoords(0, mCoordHolder);
        switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_MOVE:
            AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0);
            break;

        default:
            return super.dispatchGenericMotionEvent(event);
        }
        return true;
    }
    return super.dispatchGenericMotionEvent(event);
}

From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java

@Override
public boolean onTouchEvent(final MotionEvent me) {
    // In the sliding input mode. {@link MotionEvent} should be forwarded to
    // {@link MoreSuggestionsView}.
    final int index = me.getActionIndex();
    final int x = mMoreSuggestionsView.translateX((int) me.getX(index));
    final int y = mMoreSuggestionsView.translateY((int) me.getY(index));
    me.setLocation(x, y);//  w w w  .ja v a2 s.c  o m
    if (!mNeedsToTransformTouchEventToHoverEvent) {
        mMoreSuggestionsView.onTouchEvent(me);
        return true;
    }
    // In sliding suggestion mode with accessibility mode on, a touch event should be
    // transformed to a hover event.
    final int width = mMoreSuggestionsView.getWidth();
    final int height = mMoreSuggestionsView.getHeight();
    final boolean onMoreSuggestions = (x >= 0 && x < width && y >= 0 && y < height);
    if (!onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Just drop this touch event because dispatching hover event isn't started yet and
        // the touch event isn't on {@link MoreSuggestionsView}.
        return true;
    }
    final int hoverAction;
    if (onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Transform this touch event to a hover enter event and start dispatching a hover
        // event to {@link MoreSuggestionsView}.
        mIsDispatchingHoverEventToMoreSuggestions = true;
        hoverAction = MotionEvent.ACTION_HOVER_ENTER;
    } else if (me.getActionMasked() == MotionEvent.ACTION_UP) {
        // Transform this touch event to a hover exit event and stop dispatching a hover event
        // after this.
        mIsDispatchingHoverEventToMoreSuggestions = false;
        mNeedsToTransformTouchEventToHoverEvent = false;
        hoverAction = MotionEvent.ACTION_HOVER_EXIT;
    } else {
        // Transform this touch event to a hover move event.
        hoverAction = MotionEvent.ACTION_HOVER_MOVE;
    }
    me.setAction(hoverAction);
    mMoreSuggestionsView.onHoverEvent(me);
    return true;
}