Java Code Examples for android.view.MotionEvent#ACTION_HOVER_ENTER

The following examples show how to use android.view.MotionEvent#ACTION_HOVER_ENTER . 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: LockPatternViewEx.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).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;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 2
Source File: LockPatternView.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
   public boolean onHoverEvent(MotionEvent event) {
       if (isEnabled()) {
           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;
           }
           onTouchEvent(event);
           event.setAction(action);
       }
       return super.onHoverEvent(event);
   }
 
Example 3
Source File: HoverView.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    super.onHoverEvent(event);

    final int action = event.getActionMasked();
    switch (action){
        case MotionEvent.ACTION_HOVER_ENTER:
        case MotionEvent.ACTION_HOVER_MOVE:
            x = event.getX();
            y = event.getY();
            radius = (event.getEventTime() - event.getDownTime()) / 100 + 1;
            break;

        case MotionEvent.ACTION_HOVER_EXIT:
            radius = 0;
            break;
    }
    return true;
}
 
Example 4
Source File: LockPatternView.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(@NonNull MotionEvent event) {
    AccessibilityManager accessibilityManager =
            (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.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;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 5
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setContentViewMotionEventOffsets(MotionEvent e, boolean canClear) {
    // TODO(dtrainor): Factor this out to LayoutDriver.
    if (e == null || mTabVisible == null) return;

    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return;

    int actionMasked = SPenSupport.convertSPenEventAction(e.getActionMasked());

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
        contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    } else if (canClear && (actionMasked == MotionEvent.ACTION_UP
                                   || actionMasked == MotionEvent.ACTION_CANCEL
                                   || actionMasked == MotionEvent.ACTION_HOVER_EXIT)) {
        contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
    }
}
 
Example 6
Source File: GlowPadView.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).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;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    super.onHoverEvent(event);
    return true;
}
 
Example 7
Source File: LockPatternView.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).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;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 8
Source File: RadialMenuView.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_HOVER_ENTER:
      onEnter(event.getX(), event.getY());
      // Fall-through to movement events.
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_HOVER_MOVE:
      onMove(event.getX(), event.getY());
      break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_HOVER_EXIT:
      onUp(event.getX(), event.getY());
      break;
    default:
      // Don't handle other types of events.
      return false;
  }

  handler.onTouch(this, event);

  return true;
}
 
Example 9
Source File: LayoutManager.java    From delion with Apache License 2.0 6 votes vote down vote up
private Point getMotionOffsets(MotionEvent e) {
    int actionMasked = e.getActionMasked();
    if (SPenSupport.isSPenSupported(mHost.getContext())) {
        actionMasked = SPenSupport.convertSPenEventAction(actionMasked);
    }

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        getViewportPixel(mCachedRect);

        mCachedPoint.set(-mCachedRect.left, -mCachedRect.top);
        return mCachedPoint;
    } else if (actionMasked == MotionEvent.ACTION_UP
            || actionMasked == MotionEvent.ACTION_CANCEL
            || actionMasked == MotionEvent.ACTION_HOVER_EXIT) {
        mCachedPoint.set(0, 0);
        return mCachedPoint;
    }

    return null;
}
 
Example 10
Source File: WindowWidget.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void handleHoverEvent(MotionEvent aEvent) {
    if (aEvent.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
        mHovered = true;
        updateBorder();
    } else if (aEvent.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
        mHovered = false;
        updateBorder();
    }

    if (!mActive) {
        // Do not send touch events to not focused windows.
        return;
    }

    if (mView != null) {
        super.handleHoverEvent(aEvent);

    } else {
        GeckoSession session = mSession.getGeckoSession();
        if (session != null && !isContextMenuVisible()) {
            session.getPanZoomController().onMotionEvent(aEvent);
        }
    }
}
 
Example 11
Source File: MaterialLockView.java    From MaterialPatternllockView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).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;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 12
Source File: UsMotionEvent.java    From walt with Apache License 2.0 6 votes vote down vote up
public static String actionToString(int action) {
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            return "ACTION_DOWN";
        case MotionEvent.ACTION_UP:
            return "ACTION_UP";
        case MotionEvent.ACTION_CANCEL:
            return "ACTION_CANCEL";
        case MotionEvent.ACTION_OUTSIDE:
            return "ACTION_OUTSIDE";
        case MotionEvent.ACTION_MOVE:
            return "ACTION_MOVE";
        case MotionEvent.ACTION_HOVER_MOVE:
            return "ACTION_HOVER_MOVE";
        case MotionEvent.ACTION_SCROLL:
            return "ACTION_SCROLL";
        case MotionEvent.ACTION_HOVER_ENTER:
            return "ACTION_HOVER_ENTER";
        case MotionEvent.ACTION_HOVER_EXIT:
            return "ACTION_HOVER_EXIT";
    }
    return "UNKNOWN_ACTION";
}
 
Example 13
Source File: TouchDebugUtils.java    From FreeFlow with Apache License 2.0 5 votes vote down vote up
public static String getMotionEventString(int action){
	switch(action){
		case(MotionEvent.ACTION_DOWN): return "action_down";
		case(MotionEvent.ACTION_UP): return "action_down";
		case(MotionEvent.ACTION_CANCEL): return "action_down";
		case(MotionEvent.ACTION_MOVE): return "action_move";
		case(MotionEvent.ACTION_OUTSIDE): return "action_outside";
		case(MotionEvent.ACTION_HOVER_ENTER): return "action_hover_enter";
		case(MotionEvent.ACTION_HOVER_EXIT): return "action_hover_exit";
		case(MotionEvent.ACTION_HOVER_MOVE): return "action_hover_move";
		case(MotionEvent.ACTION_MASK): return "action_mask";
	}
	return "unknown action event";
}
 
Example 14
Source File: ViewUtil.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static String motionActionToString(int action,boolean forChineseStr) {
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            return forChineseStr ? "按下" : "ACTION_DOWN";
        case MotionEvent.ACTION_UP:
            return forChineseStr ? "抬起" : "ACTION_UP";
        case MotionEvent.ACTION_CANCEL:
            return forChineseStr ? "取消" : "ACTION_CANCEL";
        case MotionEvent.ACTION_OUTSIDE:
            return forChineseStr ? "外部" : "ACTION_OUTSIDE";
        case MotionEvent.ACTION_MOVE:
            return forChineseStr ? "移动" : "ACTION_MOVE";
        case MotionEvent.ACTION_HOVER_MOVE:
            return forChineseStr ? "悬浮移动(一般是鼠标)" : "ACTION_HOVER_MOVE";
        case MotionEvent.ACTION_SCROLL:
            return forChineseStr ? "滚动" : "ACTION_SCROLL";
        case MotionEvent.ACTION_HOVER_ENTER:
            return "ACTION_HOVER_ENTER";
        case MotionEvent.ACTION_HOVER_EXIT:
            return "ACTION_HOVER_EXIT";
        case MotionEvent.ACTION_BUTTON_PRESS:
            return "ACTION_BUTTON_PRESS";
        case MotionEvent.ACTION_BUTTON_RELEASE:
            return "ACTION_BUTTON_RELEASE";
    }
    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN:
            return "ACTION_POINTER_DOWN(" + index + ")";
        case MotionEvent.ACTION_POINTER_UP:
            return "ACTION_POINTER_UP(" + index + ")";
        default:
            return Integer.toString(action);
    }
}
 
Example 15
Source File: HoneycombButton.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_ENTER:
            if (mIcon != null && mText != null) {
                if (mButtonIconHover) {
                    mIcon.setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.asphalt, getContext().getTheme()), PorterDuff.Mode.MULTIPLY));
                }
                mText.setTextColor(getContext().getColor(R.color.asphalt));
                mSecondaryText.setTextColor(getContext().getColor(R.color.asphalt));
            }
            break;
        case MotionEvent.ACTION_HOVER_EXIT:
            if (mIcon != null && mText != null) {
                if (mButtonIconHover) {
                    mIcon.setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.fog, getContext().getTheme()), PorterDuff.Mode.MULTIPLY));
                }
                mText.setTextColor(getContext().getColor(R.color.fog));
                mSecondaryText.setTextColor(getContext().getColor(R.color.fog));
            }
            break;
    }

    if (mEventDelegate.isInside(event)) {
        return super.onHoverEvent(event);

    } else {
        setHovered(false);
        if (mIcon != null && mText != null) {
            if (mButtonIconHover) {
                mIcon.setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.fog, getContext().getTheme()), PorterDuff.Mode.MULTIPLY));
            }
            mText.setTextColor(getContext().getColor(R.color.fog));
            mSecondaryText.setTextColor(getContext().getColor(R.color.fog));
        }
        return false;
    }
}
 
Example 16
Source File: DragLayer.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptHoverEvent(MotionEvent ev) {
    if (mLauncher == null || mLauncher.getWorkspace() == null) {
        return false;
    }
    Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
    if (currentFolder == null) {
        return false;
    } else {
            AccessibilityManager accessibilityManager = (AccessibilityManager)
                    getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (accessibilityManager.isTouchExplorationEnabled()) {
            final int action = ev.getAction();
            boolean isOverFolder;
            switch (action) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    isOverFolder = isEventOverFolder(currentFolder, ev);
                    if (!isOverFolder) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    }
                    mHoverPointClosesFolder = false;
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    isOverFolder = isEventOverFolder(currentFolder, ev);
                    if (!isOverFolder && !mHoverPointClosesFolder) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    } else if (!isOverFolder) {
                        return true;
                    }
                    mHoverPointClosesFolder = false;
            }
        }
    }
    return false;
}
 
Example 17
Source File: DragLayer.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onInterceptHoverEvent(MotionEvent ev) {
    if (mLauncher == null || mLauncher.getWorkspace() == null) {
        return false;
    }
    Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
    if (currentFolder == null) {
        return false;
    } else {
            AccessibilityManager accessibilityManager = (AccessibilityManager)
                    getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (accessibilityManager.isTouchExplorationEnabled()) {
            final int action = ev.getAction();
            boolean isOverFolderOrSearchBar;
            switch (action) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    isOverFolderOrSearchBar = isEventOverFolder(currentFolder, ev) ||
                        (isInAccessibleDrag() && isEventOverDropTargetBar(ev));
                    if (!isOverFolderOrSearchBar) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    }
                    mHoverPointClosesFolder = false;
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    isOverFolderOrSearchBar = isEventOverFolder(currentFolder, ev) ||
                        (isInAccessibleDrag() && isEventOverDropTargetBar(ev));
                    if (!isOverFolderOrSearchBar && !mHoverPointClosesFolder) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    } else if (!isOverFolderOrSearchBar) {
                        return true;
                    }
                    mHoverPointClosesFolder = false;
            }
        }
    }
    return false;
}
 
Example 18
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean dispatchHoverEvent(MotionEvent event) {
    if (!mHasSelectorWheel) {
        return super.dispatchHoverEvent(event);
    }
    AccessibilityManager acm = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (acm.isEnabled()) {
        final int eventY = (int) event.getY();
        final int hoveredVirtualViewId;
        if (eventY < mTopSelectionDividerTop) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_DECREMENT;
        } else if (eventY > mBottomSelectionDividerBottom) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INCREMENT;
        } else {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT;
        }
        final int action = event.getActionMasked();
        AccessibilityNodeProviderImpl provider =
            (AccessibilityNodeProviderImpl) getAccessibilityNodeProvider();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                provider.performAction(hoveredVirtualViewId,
                        AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
            } break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                if (mLastHoveredChildVirtualViewId != hoveredVirtualViewId
                        && mLastHoveredChildVirtualViewId != View.NO_ID) {
                    provider.sendAccessibilityEventForVirtualView(
                            mLastHoveredChildVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                    provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                    mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                    provider.performAction(hoveredVirtualViewId,
                            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                }
            } break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                mLastHoveredChildVirtualViewId = View.NO_ID;
            } break;
        }
    }
    return false;
}
 
Example 19
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean dispatchHoverEvent(MotionEvent event) {
    if (!mHasSelectorWheel) {
        return super.dispatchHoverEvent(event);
    }
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        final int eventY = (int) event.getY();
        final int hoveredVirtualViewId;
        if (eventY < mTopSelectionDividerTop) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_DECREMENT;
        } else if (eventY > mBottomSelectionDividerBottom) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INCREMENT;
        } else {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT;
        }
        final int action = event.getActionMasked();
        AccessibilityNodeProviderImpl provider =
            (AccessibilityNodeProviderImpl) getAccessibilityNodeProvider();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                provider.performAction(hoveredVirtualViewId,
                        AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
            } break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                if (mLastHoveredChildVirtualViewId != hoveredVirtualViewId
                        && mLastHoveredChildVirtualViewId != View.NO_ID) {
                    provider.sendAccessibilityEventForVirtualView(
                            mLastHoveredChildVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                    provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                    mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                    provider.performAction(hoveredVirtualViewId,
                            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                }
            } break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                mLastHoveredChildVirtualViewId = View.NO_ID;
            } break;
        }
    }
    return false;
}
 
Example 20
Source File: SuggestionStripView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(final MotionEvent me) {
    if (!mMoreSuggestionsView.isShowingInParent()) {
        // Ignore any touch event while more suggestions panel hasn't been shown.
        // Detecting sliding up is done at {@link #onInterceptTouchEvent}.
        return true;
    }
    // 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);
    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;
}