Example usage for android.view MotionEvent ACTION_HOVER_EXIT

List of usage examples for android.view MotionEvent ACTION_HOVER_EXIT

Introduction

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

Prototype

int ACTION_HOVER_EXIT

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

Click Source Link

Document

Constant for #getActionMasked : The pointer is not down but has exited the boundaries of a window or view.

Usage

From source file:com.android.hareime.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.//from www. ja v  a2s.  co m
 *
 * @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.
 */
private boolean onTransitionKey(Key currentKey, Key previousKey, 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.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Receives hover events when touch exploration is turned on in SDK versions ICS and higher.
 *
 * @param event The hover event.//  w  ww .  j  av a 2 s. c om
 * @return {@code true} if the event is handled.
 */
public boolean onHoverEvent(final MotionEvent event) {
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_HOVER_ENTER:
        onHoverEnter(event);
        break;
    case MotionEvent.ACTION_HOVER_MOVE:
        onHoverMove(event);
        break;
    case MotionEvent.ACTION_HOVER_EXIT:
        onHoverExit(event);
        break;
    default:
        Log.w(getClass().getSimpleName(), "Unknown hover event: " + event);
        break;
    }
    return true;
}

From source file:com.limewoodmedia.nsdroid.fragments.NavigationDrawerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup layout = (ViewGroup) (inflater.inflate(R.layout.fragment_navigation_drawer, container, false));
    MenuItemHolder[] holders = new MenuItemHolder[] {
            new MenuItemHolder(R.id.menu_start, R.drawable.icon_start, R.string.menu_start),
            new MenuItemHolder(R.id.menu_nation, R.drawable.icon_nation, R.string.menu_nation),
            new MenuItemHolder(R.id.submenu_issues, R.drawable.icon_issues, R.string.menu_issues),
            new MenuItemHolder(R.id.submenu_dossier, R.drawable.icon_dossier, R.string.menu_dossier),
            new MenuItemHolder(R.id.menu_region, R.drawable.icon_region, R.string.menu_region),
            new MenuItemHolder(R.id.submenu_rmb, R.drawable.icon_rmb, R.string.menu_rmb),
            new MenuItemHolder(R.id.submenu_officers, R.drawable.icon_officers, R.string.menu_officers),
            new MenuItemHolder(R.id.submenu_embassies, R.drawable.icon_embassies, R.string.menu_embassies),
            new MenuItemHolder(R.id.menu_world, R.drawable.icon_world, R.string.menu_world),
            new MenuItemHolder(R.id.menu_wa, R.drawable.icon_wa, R.string.menu_wa),
            new MenuItemHolder(R.id.menu_news, R.drawable.icon_news, R.string.menu_news),
            new MenuItemHolder(R.id.menu_settings, R.drawable.icon_settings, R.string.menu_settings),
            new MenuItemHolder(R.id.menu_logout, R.drawable.icon_logout, R.string.menu_logout) };
    View view;/*w  w w. ja  v  a 2s  . c  o m*/
    for (final MenuItemHolder holder : holders) {
        view = layout.findViewById(holder.viewId);
        if (view == null)
            continue;
        ((ImageView) view.findViewById(R.id.menu_item_image)).setImageResource(holder.imageId);
        ((TextView) view.findViewById(R.id.menu_item_text)).setText(holder.textId);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectMenuItem(holder.viewId);
            }
        });
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    view.setBackgroundColor(getActivity().getResources().getColor(R.color.menu_item_selected));
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_OUTSIDE:
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_HOVER_EXIT:
                case MotionEvent.ACTION_POINTER_UP:
                    view.setBackgroundColor(0x00000000);
                    break;
                }
                return false;
            }
        });
    }
    //      layout.setOnTouchListener(new View.OnTouchListener() {
    //         @Override
    //         public boolean onTouch(View view, MotionEvent motionEvent) {
    //            return true;
    //         }
    //      });
    return layout;
}

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  ww  .  ja va  2s  . c  om*/

    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.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Handles a hover event on a key. If {@link Key} extended View, this would
 * be analogous to calling View.onHoverEvent(MotionEvent).
 *
 * @param key The currently hovered key.
 * @param event The hover event.//  ww  w .  jav a 2 s  .  c o m
 * @return {@code true} if the event was handled.
 */
private boolean onHoverKey(Key key, MotionEvent event) {
    // Null keys can't receive events.
    if (key == null) {
        return false;
    }

    final AccessibilityEntityProvider provider = getAccessibilityNodeProvider();

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_ENTER:
        provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
        provider.performActionForKey(key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, null);
        break;
    case MotionEvent.ACTION_HOVER_EXIT:
        provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
        break;
    }

    return true;
}

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

@Override
public boolean onHover(View view, MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }//from  w w  w . j  ava  2s.  c  o 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 ava2s.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.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 w w . j a  v  a2 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.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 ww  w.ja va 2s.co  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

/**
 * 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.com
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;
}