本文整理匯總了Java中android.view.MotionEvent.setAction方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.setAction方法的具體用法?Java MotionEvent.setAction怎麽用?Java MotionEvent.setAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.setAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(redirectTouchesToStickyView){
ev.offsetLocation(0, ((getScrollY() + stickyViewTopOffset) - getTopForViewRelativeOnlyChild(currentlyStickingView)));
}
if(ev.getAction()==MotionEvent.ACTION_DOWN){
hasNotDoneActionDown = false;
}
if(hasNotDoneActionDown){
MotionEvent down = MotionEvent.obtain(ev);
down.setAction(MotionEvent.ACTION_DOWN);
super.onTouchEvent(down);
hasNotDoneActionDown = false;
}
if(ev.getAction()==MotionEvent.ACTION_UP || ev.getAction()==MotionEvent.ACTION_CANCEL){
hasNotDoneActionDown = true;
}
return super.onTouchEvent(ev);
}
示例2: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mDrawableSide == null) {
return super.onTouchEvent(event);
}
final Rect bounds = mDrawableSide.getBounds();
final int x = (int) event.getRawX(); // 點擊的位置
int iconX = (int) getTopRightCorner().x;
// Icon的位置
int leftIcon = iconX - bounds.width();
Log.e(TAG, "x: " + x + ", leftIcon: " + leftIcon);
// 大於Icon的位置, 才能觸發點擊
if (x >= leftIcon) {
togglePasswordIconVisibility(); // 變換狀態
event.setAction(MotionEvent.ACTION_CANCEL);
return false;
}
return super.onTouchEvent(event);
}
示例3: onHoverEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@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;
}
示例4: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
public void onTouchEvent(MotionEvent event) {
if (!this.running)
return;
boolean result = this.detector.onTouchEvent(event);
if (this.mode == MODE_SOLID)
event.setAction(MotionEvent.ACTION_CANCEL);
else if (this.mode == MODE_DYNAMIC) {
if (event.getAction() == ACTION_FAKE)
event.setAction(MotionEvent.ACTION_UP);
else if (result)
event.setAction(MotionEvent.ACTION_CANCEL);
else if (this.tapIndicator) {
event.setAction(MotionEvent.ACTION_DOWN);
this.tapIndicator = false;
}
}
// else just do nothing, it's Transparent
}
示例5: onHoverEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@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);
}
示例6: dispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
event.setAction(MotionEvent.ACTION_CANCEL);
}
return super.dispatchTouchEvent(event);
}
示例7: handleMessage
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean handleMessage(Message msg) {
if (msg.what == ACTION_DOWN) {
if (mAbleToggle && mPopup.getVisibility() == INVISIBLE && !isshowing) {
/**
* 如果沒有設置回調代表不關心勾選狀態
* 在這裏清除勾選狀態 防止View被複用時狀態錯亂
* */
if (mOnMenuEventListener == null)
resetButton();
MotionEvent newEv = (MotionEvent) msg.obj;
isshowing = true;
mAlphAnimator.start();
mPopup.setVisibility(VISIBLE);
mDecorView.addView(mPopup, mLayoutParams);
if (mOpenDirection != UNDEFIEN)
mPopup.resetCenter(getViewCenterPoint(), mOpenDirection);
else
mPopup.resetCenter(new Point((int) newEv.getRawX(), (int) newEv.getRawY()), mOpenDirection);
newEv.setAction(MotionEvent.ACTION_DOWN);
mPopup.dispatchTouchEvent(newEv);
getParent().requestDisallowInterceptTouchEvent(true);
}
} else if (msg.what == ACTION_UP) {
mPopup.setVisibility(INVISIBLE);
mDecorView.removeView(mPopup);
isshowing = false;
mAbleToggle = false;
getParent().requestDisallowInterceptTouchEvent(false);
if (juageCallback()) {
mOnMenuEventListener.onMenuToggle(mButtons.get(mPopup.getSelectedIndex()));
}
}
return false;
}
示例8: dispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final float x = ev.getX();
final float y = ev.getY();
final int action = ev.getAction();
if (action == MotionEvent.ACTION_DOWN
&& mTouchTarget == null
&& mPinnedSection != null
&& isPinnedViewTouched(mPinnedSection.view, x, y)) { // create touch target
// user touched pinned view
mTouchTarget = mPinnedSection.view;
mTouchPoint.x = x;
mTouchPoint.y = y;
// copy down event for eventually be used later
mDownEvent = MotionEvent.obtain(ev);
}
if (mTouchTarget != null) {
if (isPinnedViewTouched(mTouchTarget, x, y)) { // forward event to pinned view
mTouchTarget.dispatchTouchEvent(ev);
}
if (action == MotionEvent.ACTION_UP) { // perform onClick on pinned view
super.dispatchTouchEvent(ev);
performPinnedItemClick();
clearTouchTarget();
} else if (action == MotionEvent.ACTION_CANCEL) { // cancel
clearTouchTarget();
} else if (action == MotionEvent.ACTION_MOVE) {
if (Math.abs(y - mTouchPoint.y) > mTouchSlop) {
// cancel sequence on touch target
MotionEvent event = MotionEvent.obtain(ev);
event.setAction(MotionEvent.ACTION_CANCEL);
mTouchTarget.dispatchTouchEvent(event);
event.recycle();
// provide correct sequence to super class for further handling
super.dispatchTouchEvent(mDownEvent);
super.dispatchTouchEvent(ev);
clearTouchTarget();
}
}
return true;
}
// call super if this was not our pinned view
return super.dispatchTouchEvent(ev);
}
示例9: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = false;
MotionEvent trackedEvent = MotionEvent.obtain(event);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedYOffset = 0;
}
int y = (int) event.getY();
event.offsetLocation(0, mNestedYOffset);
switch (action) {
case MotionEvent.ACTION_DOWN:
mLastMotionY = y;
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
result = super.onTouchEvent(event);
mChange = false;
break;
case MotionEvent.ACTION_MOVE:
int deltaY = mLastMotionY - y;
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
int oldY = getScrollY();
mLastMotionY = y - mScrollOffset[1];
int newScrollY = Math.max(0, oldY + deltaY);
deltaY -= newScrollY - oldY;
if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
mLastMotionY -= mScrollOffset[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
if (mScrollConsumed[1] == 0 && mScrollOffset[1] == 0) {
if (mChange) {
mChange = false;
trackedEvent.setAction(MotionEvent.ACTION_DOWN);
super.onTouchEvent(trackedEvent);
} else {
result = super.onTouchEvent(trackedEvent);
}
trackedEvent.recycle();
} else {
if (!mChange) {
mChange = true;
super.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0,
0, 0));
}
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
stopNestedScroll();
result = super.onTouchEvent(event);
break;
}
return result;
}
示例10: onTouch
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
final PieController.Tracker tracker = (PieController.Tracker)v.getTag();
if (tracker == null) {
if (DEBUG_INPUT) {
log("Pie trigger onTouch: action: " + action + ", ("
+ event.getAxisValue(MotionEvent.AXIS_X) + ","
+ event.getAxisValue(MotionEvent.AXIS_Y) + ") position: NULL returning: false");
}
return false;
}
if (!mPieController.isShowing()) {
if (event.getPointerCount() > 1) {
if (DEBUG_INPUT) {
log("Pie trigger onTouch: action: " + action
+ ", (to many pointers) position: " + tracker.position.name()
+ " returning: false");
}
return false;
}
switch (action) {
case MotionEvent.ACTION_DOWN:
tracker.start(event);
break;
case MotionEvent.ACTION_MOVE:
if (tracker.move(event)) {
if (DEBUG) {
log("Pie control activated on: ("
+ event.getAxisValue(MotionEvent.AXIS_X) + ","
+ event.getAxisValue(MotionEvent.AXIS_Y) + ") with position: "
+ tracker.position.name());
}
// send the activation to the controller
mPieController.activateFromTrigger(v, event, tracker.position);
// forward a spoofed ACTION_DOWN event
MotionEvent echo = (MotionEvent) XposedHelpers.callMethod(event, "copy");
echo.setAction(MotionEvent.ACTION_DOWN);
return mPieContainer.onTouch(v, echo);
}
break;
default:
// whatever it was, we are giving up on this one
tracker.active = false;
break;
}
} else {
if (DEBUG_INPUT) {
log("Pie trigger onTouch: action: " + action + ", ("
+ event.getAxisValue(MotionEvent.AXIS_X) + ","
+ event.getAxisValue(MotionEvent.AXIS_Y)
+ ") position: " + tracker.position.name() + " delegating");
}
return mPieContainer.onTouch(v, event);
}
if (DEBUG_INPUT) {
log("Pie trigger onTouch: action: " + action + ", ("
+ event.getAxisValue(MotionEvent.AXIS_X) + ","
+ event.getAxisValue(MotionEvent.AXIS_Y) + ") position: "
+ tracker.position.name() + " returning: " + tracker.active);
}
return tracker.active;
}
示例11: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
int a = event.getActionMasked();
FLog.v(getLogTag(), "onTouchEvent: %d, view %x, received", a, this.hashCode());
if (mTapGestureDetector.onTouchEvent(event)) {
FLog.v(
getLogTag(),
"onTouchEvent: %d, view %x, handled by tap gesture detector",
a,
this.hashCode());
return true;
}
if (mUseSimpleTouchHandling) {
if (mZoomableController.onTouchEvent(event)) {
return true;
}
} else if (mZoomableController.onTouchEvent(event)) {
// Do not allow the parent to intercept touch events if:
// - we do not allow swiping while zoomed and the image is zoomed
// - we allow swiping while zoomed and the transform was corrected
if ((!mAllowTouchInterceptionWhileZoomed && !mZoomableController.isIdentity()) ||
(mAllowTouchInterceptionWhileZoomed && !mZoomableController.wasTransformCorrected())) {
getParent().requestDisallowInterceptTouchEvent(true);
}
FLog.v(
getLogTag(),
"onTouchEvent: %d, view %x, handled by zoomable controller",
a,
this.hashCode());
return true;
}
if (super.onTouchEvent(event)) {
FLog.v(getLogTag(), "onTouchEvent: %d, view %x, handled by the super", a, this.hashCode());
return true;
}
// None of our components reported that they handled the touch event. Upon returning false
// from this method, our parent won't send us any more events for this gesture. Unfortunately,
// some componentes may have started a delayed action, such as a long-press timer, and since we
// won't receive an ACTION_UP that would cancel that timer, a false event may be triggered.
// To prevent that we explicitly send one last cancel event when returning false.
MotionEvent cancelEvent = MotionEvent.obtain(event);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
mTapGestureDetector.onTouchEvent(cancelEvent);
mZoomableController.onTouchEvent(cancelEvent);
cancelEvent.recycle();
return false;
}
示例12: cancelSuperTouch
import android.view.MotionEvent; //導入方法依賴的package包/類
private void cancelSuperTouch(MotionEvent ev) {
MotionEvent cancel = MotionEvent.obtain(ev);
cancel.setAction(3);
super.onTouchEvent(cancel);
cancel.recycle();
}
示例13: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
int a = event.getActionMasked();
FLog.v(getLogTag(), "onTouchEvent: %d, view %x, received", a, this.hashCode());
if (mTapGestureDetector.onTouchEvent(event)) {
FLog.v(
getLogTag(),
"onTouchEvent: %d, view %x, handled by tap gesture detector",
a,
this.hashCode());
return true;
}
if (mUseSimpleTouchHandling) {
if (mZoomableController.onTouchEvent(event)) {
return true;
}
} else if (mZoomableController.onTouchEvent(event)) {
// Do not allow the parent to intercept touch events if:
// - we do not allow swiping while zoomed and the image is zoomed
// - we allow swiping while zoomed and the transform was corrected
if ((!mAllowTouchInterceptionWhileZoomed && !mZoomableController.isIdentity()) ||
(!mAllowTouchInterceptionWhileZoomed && !mZoomableController.wasTransformCorrected())) {
getParent().requestDisallowInterceptTouchEvent(true);
}
FLog.v(
getLogTag(),
"onTouchEvent: %d, view %x, handled by zoomable controller",
a,
this.hashCode());
return true;
}
if (super.onTouchEvent(event)) {
FLog.v(getLogTag(), "onTouchEvent: %d, view %x, handled by the super", a, this.hashCode());
return true;
}
// None of our components reported that they handled the touch event. Upon returning false
// from this method, our parent won't send us any more events for this gesture. Unfortunately,
// some componentes may have started a delayed action, such as a long-press timer, and since we
// won't receive an ACTION_UP that would cancel that timer, a false event may be triggered.
// To prevent that we explicitly send one last cancel event when returning false.
MotionEvent cancelEvent = MotionEvent.obtain(event);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
mTapGestureDetector.onTouchEvent(cancelEvent);
mZoomableController.onTouchEvent(cancelEvent);
cancelEvent.recycle();
return false;
}
示例14: dispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:// 獲取手指第一次接觸屏幕
dx = 0;
dy = 0;
isclick = false;//當按下的時候設置isclick為false,具體原因看後邊的講解
startTime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_MOVE:// 手指在屏幕上移動對應的事件
int x = (int) event.getRawX();
int y = (int) event.getRawY();
// 獲取手指移動的距離
dx = x - lastx;
dy = y - lasty;
setAlpha(0.5f);
int l = getLeft();
int r = getRight();
int t = getTop();
int b = getBottom();
// 更改在窗體的位置//確保位置顯示在屏幕內
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
if ((l + dx) >= 0 && (t + dy) > 0 && (r + dx) <= dm.widthPixels && (b + dy) <= dm.heightPixels)
layout(l + dx, t + dy, r + dx, b + dy);
// 獲取移動後的位置
lastx = (int) event.getRawX();
lasty = (int) event.getRawY();
if (Math.abs(dx) > 20 || Math.abs(dy) > 20) {
event.setAction(MotionEvent.ACTION_CANCEL);
return true;
}
case MotionEvent.ACTION_UP:// 手指離開屏幕對應事件
// 記錄最後圖片在窗體的位置
endTime = System.currentTimeMillis();
//當從點擊到彈起小於半秒的時候,則判斷為點擊,如果超過則不響應點擊事件
isclick = (endTime - startTime) > 0.1 * 1000L;
lastx = (int) event.getRawX();
lasty = (int) event.getRawY();
setAlpha(1.0f);
}
return isclick || super.dispatchTouchEvent(event);
}
示例15: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@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;
}