下面列出了android.view.MotionEvent#ACTION_HOVER_ENTER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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);
}
@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);
}
@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;
}
@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);
}
@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;
}
@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);
}
}
}
@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);
}
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";
}
@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);
}
@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;
}
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);
}
}
@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;
}
@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;
}
}
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";
}
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);
}
}
@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;
}
@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;
}
@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;
}
@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;
}