Java Code Examples for android.view.MotionEvent#ACTION_HOVER_MOVE
The following examples show how to use
android.view.MotionEvent#ACTION_HOVER_MOVE .
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: LockPatternView.java From android-lockpattern with Apache License 2.0 | 6 votes |
@Override public boolean onHoverEvent(MotionEvent event) { if (AccessibilityManager.getInstance(mContext).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 android-lockpattern with Apache License 2.0 | 6 votes |
@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 3
Source File: RadialMenuView.java From talkback with Apache License 2.0 | 6 votes |
@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 4
Source File: GlowPadView.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@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 5
Source File: LockPatternView.java From EhViewer with Apache License 2.0 | 6 votes |
@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 6
Source File: MDAbsView.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 6 votes |
@Override public void onEyeHitIn(MDHitEvent hitEvent) { super.onEyeHitIn(hitEvent); MDHitPoint point = hitEvent.getHitPoint(); if (point == null || mAttachedView == null) { return; } int action = mTouchStatus == TouchStatus.NOP ? MotionEvent.ACTION_HOVER_ENTER : MotionEvent.ACTION_HOVER_MOVE; float x = mAttachedView.getLeft() + mAttachedView.getWidth() * point.getU(); float y = mAttachedView.getTop() + mAttachedView.getHeight() * point.getV(); MotionEvent motionEvent = MotionEvent.obtain(hitEvent.getTimestamp(), System.currentTimeMillis(), action, x, y, 0); motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER); mAttachedView.dispatchGenericMotionEvent(motionEvent); motionEvent.recycle(); mTouchStatus = TouchStatus.DOWN; invalidate(); }
Example 7
Source File: KeyboardView.java From libcommon with Apache License 2.0 | 6 votes |
@Override public boolean onHoverEvent(MotionEvent event) { if (mAccessibilityManager.isTouchExplorationEnabled() && event.getPointerCount() == 1) { 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; } return onTouchEvent(event); } return true; }
Example 8
Source File: LockPatternView.java From MHViewer with Apache License 2.0 | 6 votes |
@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 9
Source File: LockPatternView.java From GestureLock with Apache License 2.0 | 6 votes |
@Override public boolean onHoverEvent(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 10
Source File: UsMotionEvent.java From walt with Apache License 2.0 | 6 votes |
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 11
Source File: BaldButtonInterface.java From BaldPhone with Apache License 2.0 | 5 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(final View v, final MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, MEDIUM_PRESS_TIMEOUT); } else if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if (!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { final float currentX = event.getX(); final float currentY = event.getY(); final float firstX = lastActionMoveEventBeforeUpX; final float firstY = lastActionMoveEventBeforeUpY; final double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if (distance > MEDIUM_PRESS_DISTANCE) { longPressHandler.removeCallbacks(longPressedRunnable); } } } else if (event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if (isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return consumeOthers(v, event); } else { BaldToast.longer(v.getContext()); return consumeOthers(v, event); } } return consumeOthers(v, event); }
Example 12
Source File: CustomScrollView.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
private boolean onHoverEventInternal(@NonNull MotionEvent event) { final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: { setHoveredThumb(true); return true; } case MotionEvent.ACTION_HOVER_EXIT: { setHoveredThumb(false); return true; } } return false; }
Example 13
Source File: DropDownListView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onHoverEvent(@NonNull MotionEvent ev) { final int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_HOVER_EXIT && mResolveHoverRunnable == null) { // This may be transitioning to TOUCH_DOWN. Postpone drawable state // updates until either the next frame or the next touch event. mResolveHoverRunnable = new ResolveHoverRunnable(); mResolveHoverRunnable.post(); } // Allow the super class to handle hover state management first. final boolean handled = super.onHoverEvent(ev); if (action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_MOVE) { final int position = pointToPosition((int) ev.getX(), (int) ev.getY()); if (position != INVALID_POSITION && position != mSelectedPosition) { final View hoveredItem = getChildAt(position - getFirstVisiblePosition()); if (hoveredItem.isEnabled()) { // Force a focus so that the proper selector state gets // used when we update. requestFocus(); positionSelector(position, hoveredItem); setSelectedPositionInt(position); setNextSelectedPositionInt(position); } updateSelectorState(); } } else { // Do not cancel the selected position if the selection is visible // by other means. if (!super.shouldShowSelector()) { setSelectedPositionInt(INVALID_POSITION); setNextSelectedPositionInt(INVALID_POSITION); } } return handled; }
Example 14
Source File: TouchDebugUtils.java From FreeFlow with Apache License 2.0 | 5 votes |
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 15
Source File: NumberPicker.java From ticdesign with Apache License 2.0 | 4 votes |
@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 16
Source File: NumberPicker.java From DateTimePicker with Apache License 2.0 | 4 votes |
@Override protected boolean dispatchHoverEvent(MotionEvent event) { if (!mHasSelectorWheel) { return super.dispatchHoverEvent(event); } AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); //if (AccessibilityManager.getInstance(mContext).isEnabled()) { if (accessibilityManager != null && accessibilityManager.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 17
Source File: SystemGesturesPointerEventListener.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public void onPointerEvent(MotionEvent event) { if (mGestureDetector != null && event.isTouchEvent()) { mGestureDetector.onTouchEvent(event); } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: mSwipeFireable = true; mDebugFireable = true; mDownPointers = 0; captureDown(event, 0); if (mMouseHoveringAtEdge) { mMouseHoveringAtEdge = false; mCallbacks.onMouseLeaveFromEdge(); } mCallbacks.onDown(); break; case MotionEvent.ACTION_POINTER_DOWN: captureDown(event, event.getActionIndex()); if (mDebugFireable) { mDebugFireable = event.getPointerCount() < 5; if (!mDebugFireable) { if (DEBUG) Slog.d(TAG, "Firing debug"); mCallbacks.onDebug(); } } break; case MotionEvent.ACTION_MOVE: if (mSwipeFireable) { final int swipe = detectSwipe(event); mSwipeFireable = swipe == SWIPE_NONE; if (swipe == SWIPE_FROM_TOP) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromTop"); mCallbacks.onSwipeFromTop(); } else if (swipe == SWIPE_FROM_BOTTOM) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromBottom"); mCallbacks.onSwipeFromBottom(); } else if (swipe == SWIPE_FROM_RIGHT) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromRight"); mCallbacks.onSwipeFromRight(); } else if (swipe == SWIPE_FROM_LEFT) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromLeft"); mCallbacks.onSwipeFromLeft(); } } break; case MotionEvent.ACTION_HOVER_MOVE: if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { if (!mMouseHoveringAtEdge && event.getY() == 0) { mCallbacks.onMouseHoverAtTop(); mMouseHoveringAtEdge = true; } else if (!mMouseHoveringAtEdge && event.getY() >= screenHeight - 1) { mCallbacks.onMouseHoverAtBottom(); mMouseHoveringAtEdge = true; } else if (mMouseHoveringAtEdge && (event.getY() > 0 && event.getY() < screenHeight - 1)) { mCallbacks.onMouseLeaveFromEdge(); mMouseHoveringAtEdge = false; } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mSwipeFireable = false; mDebugFireable = false; mCallbacks.onUpOrCancel(); break; default: if (DEBUG) Slog.d(TAG, "Ignoring " + event); } }
Example 18
Source File: DragLayer.java From Trebuchet with GNU General Public License v3.0 | 4 votes |
@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 19
Source File: DocumentView.java From spline with Apache License 2.0 | 4 votes |
/** * Adds support for different mouse pointer icons depending on document state and mouse position */ @Override public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) { int icon = PointerIcon.TYPE_DEFAULT; Layer l = mCurrentLayer; float x = event.getX() - getViewportX(); float y = event.getY() - getViewportY(); if (mMode == MODE_LAYER_DRAG || mMode == MODE_LAYER_PRE_DRAG) { icon = PointerIcon.TYPE_GRABBING; } else { if (l != null) { if (inPointTouchRadius(x, y, l.getTopLeft()) || inPointTouchRadius(x, y, l.getBottomRight())) { icon = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW; } else if (inPointTouchRadius(x, y, l.getTopRight()) || inPointTouchRadius(x, y, l.getBottomLeft())) { icon = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW; } else if (inPointTouchRadius(x, y, l.getMidTop()) || inPointTouchRadius(x, y, l.getMidBottom())) { icon = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; } else if (inPointTouchRadius(x, y, l.getMidLeft()) || inPointTouchRadius(x, y, l.getMidRight())) { icon = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; } else if (l.inBounds(x, y)) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: // Only change to hand if this is a primary button click if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) { icon = PointerIcon.TYPE_GRABBING; } else { icon = PointerIcon.TYPE_DEFAULT; } break; case MotionEvent.ACTION_HOVER_MOVE: icon = PointerIcon.TYPE_GRAB; break; case MotionEvent.ACTION_UP: default: if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) { icon = PointerIcon.TYPE_GRAB; } else { icon = PointerIcon.TYPE_DEFAULT; } } } } } return PointerIcon.getSystemIcon(getContext(), icon); }
Example 20
Source File: TextPicker.java From GifAssistant with Apache License 2.0 | 4 votes |
@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.getAction() & MotionEvent.ACTION_MASK; SupportAccessibilityNodeProvider provider = getSupportAccessibilityNodeProvider(); 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; }