本文整理汇总了Java中android.view.MotionEvent.getAction方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getAction方法的具体用法?Java MotionEvent.getAction怎么用?Java MotionEvent.getAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mAutoPlayAble && !mIsOneImg) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
stopAutoPlay();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
startAutoPlay();
break;
}
}
return super.dispatchTouchEvent(ev);
}
示例2: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_UP && mDragging) {
mDragging = false;
mVelocityHelper.calculateVelocity(ev);
getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(ScrollEvent.obtain(
getId(),
ScrollEventType.END_DRAG,
0, /* offsetX = 0, horizontal scrolling only */
computeVerticalScrollOffset(),
mVelocityHelper.getXVelocity(),
mVelocityHelper.getYVelocity(),
getWidth(),
computeVerticalScrollRange(),
getWidth(),
getHeight()));
}
return super.onTouchEvent(ev);
}
示例3: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
xLast = ev.getX();
yLast = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - xLast);
yDistance += Math.abs(curY - yLast);
xLast = curX;
yLast = curY;
Log.e("SiberiaDante", "xDistance :" + xDistance + "---yDistance:" + yDistance);
return !(xDistance > yDistance || yDistance < scaledTouchSlop) && isNeedScroll;
}
return super.onInterceptTouchEvent(ev);
}
示例4: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction()== MotionEvent.ACTION_UP){
//TODO 画水波纹
currentRadius = 0; //重置初始状态
centerX = event.getX();//event.getRawX代表相对于屏幕的原点X轴上的距离
centerY = event.getY();
invalidate();
//TODO 缩放动画
startScaleAnimation();
//TODO 上述完成后,触发控件的点击事件。
postDelayed(new Runnable() {
@Override
public void run() {
//因为ontouchevent返回true。所以,此控件不能触发对应的点击事件。 用performClick可触发点击事件。
//点击事件的底层,也是调用此方法来触发点击事件。l
performClick();
}
},300);
}
return true;
}
示例5: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
mScaleDetector.onTouchEvent(event);
if (!mScaleDetector.isInProgress()) {
mGestureDetector.onTouchEvent(event);
}
int action = event.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
if (getScale() < getMinScale()) {
zoomTo(getMinScale(), 500);
}
break;
}
return true;
}
示例6: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
// Detect when the user lifts their finger off the screen after a touch
if (event.getAction() == MotionEvent.ACTION_UP) {
// If not flinging then we are idle now. The user just finished a finger scroll.
if (mFlingTracker == null || mFlingTracker.isFinished()) {
setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE);
}
// Allow the user to interact with parent views
requestParentListViewToNotInterceptTouchEvents(false);
releaseEdgeGlow();
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
unpressTouchedChild();
releaseEdgeGlow();
// Allow the user to interact with parent views
requestParentListViewToNotInterceptTouchEvents(false);
}
return super.onTouchEvent(event);
}
示例7: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean intercepted = false;
int x = (int) ev.getX();
int y = (int) ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
intercepted = false;
if (!mScroller.isFinished()) {
mScroller.abortAnimation(); //优化滑动体验
intercepted = true;
}
break;
case MotionEvent.ACTION_MOVE:
int deltaX = x - mLastXIntercept;
int deltaY = y - mLastYIntercept;
if (Math.abs(deltaX) > Math.abs(deltaY)) {
intercepted = true;
} else {
intercepted = false;
}
break;
case MotionEvent.ACTION_UP:
intercepted = false;
break;
default:
break;
}
Log.d(TAG, "onInterceptTouchEvent: " + intercepted);
mLastX = x;
mLastY = y;
mLastXIntercept = x;
mLastYIntercept = y;
return intercepted;
}
示例8: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouch(View v, MotionEvent event) {
if(v instanceof Button ==false)
return false;
mRawX = event.getRawX();
mRawY = event.getRawY() ;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 以当前父视图左上角为原点
Point p=new Point();
p.x = (int)(mRawX - map.get(v).x);
p.y = (int)(mRawY - map.get(v).y);
mapPoint.put(v,p);
break;
case MotionEvent.ACTION_MOVE:
// 获取相对屏幕的坐标,以屏幕左上角为原点
// x = event.getRawX();
// y = event.getRawY();
map.get(v).x = (int)(mRawX - mapPoint.get(v).x);
map.get(v).y = (int)(mRawY - mapPoint.get(v).y);
windowManager.updateViewLayout(v,map.get(v) );
break;
case MotionEvent.ACTION_UP:
// map.get(v).x = (int)(mRawX - mapPoint.get(v).x);
// map.get(v).y = (int)(mRawY - mapPoint.get(v).y);
//
// windowManager.updateViewLayout(v,map.get(v) );
break;
}
return false;
}
示例9: dispatchTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (isShouldHideKeyboard(v, ev)) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return super.dispatchTouchEvent(ev);
}
示例10: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* 因为我们不能直接给EditText设置点击事件,所以我们用记住我们按下的位置来模拟点击事件
* 当我们按下的位置在 EditText的宽度 - 图标到控件右侧的间距 - 图标的宽度 和
* EditText的宽度 - 图标到控件右侧的间距 之间我们就算点击了图标,竖直方向没有考虑
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP){
if(getCompoundDrawables()[2] != null){
boolean isTouched = event.getX() > (getWidth() - getTotalPaddingRight())
&& (event.getX() < (getWidth() - getPaddingLeft()));
if(isTouched){
if(mRightClickListener == null){
if(funcType == TYPE_CAN_CLEAR){
this.setText("");
}else if(funcType == TYPE_CAN_WATCH_PWD){
if(eyeOpen){
//变为密文,TYPE_CLASS_TEXT 和 TYPE_TEXT_VARIATION_PASSWORD 必须一起使用
this.setTransformationMethod(PasswordTransformationMethod.getInstance());
eyeOpen = false;
}else{
//变为明文
this.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
eyeOpen = true;
}
switchWatchPwdIcon();
}
}else {
//如果没有则回调
mRightClickListener.onClick(this);
}
}
}
}
return super.onTouchEvent(event);
}
示例11: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
cancelFling();
return true;
}
return false;
}
示例12: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int x = (int) ev.getX();
int y = (int) ev.getY();
if(mStatus==Status.Open && viewDragHelper.isViewUnder(mainView, x, y)){
return true;
}
// Log.e(TAG, "onInterceptTouchEvent : "+);
if(viewDragHelper.isViewUnder(mainView, x, y)){
switch (ev.getAction()) {
case MotionEvent.ACTION_MOVE:
int deltaX = x - lastX;
int deltaY = y - lastY;
if(Math.abs(deltaX)>Math.abs(deltaY)*2) {
// Log.e(TAG, "移动斜角太大,拦截事件");
viewDragHelper.cancel();
return true;
}
break;
case MotionEvent.ACTION_UP:
lastX = 0;
lastY = 0;
break;
}
lastX = x;
lastY = y;
}
return viewDragHelper.shouldInterceptTouchEvent(ev);
}
示例13: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* This is detect when mButtonRegion is clicked. Which means
* play/pause action happened.
*
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
isDragging = isInDiscArea(x, y);
startAngle = touchAngle(x, y);
getParent().requestDisallowInterceptTouchEvent(true);
return true;
case MotionEvent.ACTION_MOVE:
if (isDragging) {
touchAngle = touchAngle(x, y);
return true;
}
break;
case MotionEvent.ACTION_UP:
isDragging = false;
if (onInteractionListener != null)
onInteractionListener.onSeek(secondsFromDegree(calculatePastProgressDegree() + touchAngle - startAngle));
startAngle = touchAngle = -1;
getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.onTouchEvent(event);
}
示例14: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
getBackground().setHotspot(event.getX(), event.getY());
}
}
return super.onTouchEvent(event);
}
示例15: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Remember where the user clicked
mTouchX = (int)event.getX();
mTouchY = (int)event.getY();
}
return false;
}