本文整理了Java中android.view.MotionEvent.getAction()
方法的一些代码示例,展示了MotionEvent.getAction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getAction()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getAction
暂无
代码示例来源:origin: stackoverflow.com
@Override
public boolean onTouchEvent(MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
}
return false;
}
代码示例来源:origin: stackoverflow.com
viewB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {}
});
viewB.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getRawX();
int y = (int)event.getRawY();
if(event.getAction() == MotionEvent.ACTION_UP){
if(isViewInBounds(viewA, x, y))
viewA.dispatchTouchEvent(event);
else if(isViewInBounds(viewB, x, y)){
Log.d(TAG, "onTouch ViewB");
//Here goes code to execute on onTouch ViewB
}
}
// Further touch is not handled
return false;
}
});
代码示例来源:origin: jiajunhui/PlayerBase
public boolean onTouchEvent(MotionEvent event) {
if(!mDragEnable)
return false;
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
firstTouch = true;
break;
case MotionEvent.ACTION_MOVE:
if (firstTouch) {
floatX = (int) event.getX();
floatY = (int) (event.getY() + PUtils.getStatusBarHeight(mWindowView.getContext()));
firstTouch = false;
}
wX = X - floatX;
wY = Y - floatY;
updateWindowViewLayout(wX, wY);
break;
}
return false;
}
代码示例来源:origin: stackoverflow.com
dv = new DrawingView(this);
setContentView(dv);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.GREEN);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
circlePaint = new Paint();
circlePath = new Path();
circlePaint.setAntiAlias(true);
circlePaint.setColor(Color.BLUE);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeJoin(Paint.Join.MITER);
circlePaint.setStrokeWidth(4f);
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
代码示例来源:origin: timusus/RecyclerView-FastScroll
int action = ev.getAction();
int y = (int) ev.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
mThumb.setColor(mThumbActiveColor);
mThumb.setColor(mThumbInactiveColor);
代码示例来源:origin: aa112901/remusic
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = tempX = (int) event.getRawX();
downY = (int) event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int moveX = (int) event.getRawX();
int deltaX = tempX - moveX;
tempX = moveX;
if (Math.abs(moveX - downX) > mTouchSlop
&& Math.abs((int) event.getRawY() - downY) < mTouchSlop) {
isSilding = true;
代码示例来源:origin: stackoverflow.com
pTouch.setColor(Color.TRANSPARENT);
pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;
代码示例来源:origin: stackoverflow.com
public boolean onTouch(View view, MotionEvent event) {
if(event.getAction() != MotionEvent.ACTION_UP){
Point point = new Point();
point.x = event.getX();
point.y = event.getY();
points.add(point);
invalidate();
Log.d(TAG, "point: " + point);
return true;
}
return super.onTouchEvent(event);
}
代码示例来源:origin: stackoverflow.com
viewA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {}
});
viewA.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getRawX();
int y = (int)event.getRawY();
if(event.getAction() == MotionEvent.ACTION_UP){
if(isViewInBounds(viewB, x, y))
viewB.dispatchTouchEvent(event);
else if(isViewInBounds(viewA, x, y)){
Log.d(TAG, "onTouch ViewA");
//Here goes code to execute on onTouch ViewA
}
}
// Further touch is not handled
return false;
}
});
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteToParcel() {
Parcel parcel = Parcel.obtain();
motionEvent2.writeToParcel(parcel, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
parcel.setDataPosition(0);
MotionEvent motionEvent = MotionEvent.CREATOR.createFromParcel(parcel);
assertThat(motionEvent).rawY().isWithin(TOLERANCE).of(motionEvent2.getRawY());
assertThat(motionEvent).rawX().isWithin(TOLERANCE).of(motionEvent2.getRawX());
assertThat(motionEvent).y().isWithin(TOLERANCE).of(motionEvent2.getY());
assertThat(motionEvent).x().isWithin(TOLERANCE).of(motionEvent2.getX());
assertThat(motionEvent).hasAction(motionEvent2.getAction());
assertThat(motionEvent).hasDownTime(motionEvent2.getDownTime());
assertThat(motionEvent).hasEventTime(motionEvent2.getEventTime());
assertThat(motionEvent).hasEdgeFlags(motionEvent2.getEdgeFlags());
assertThat(motionEvent).hasDeviceId(motionEvent2.getDeviceId());
}
代码示例来源:origin: stackoverflow.com
private final Paint mPaint = new Paint();
private final Point mSize = new Point();
private final Point mStartPosition = new Point();
if(!mRegion.contains((int)event.getX(), (int)event.getY()))
if(event.getAction() == MotionEvent.ACTION_DOWN)
mStartPosition.x = (int)event.getX();
mStartPosition.y = (int)event.getY();
bringToFront();
onSelected();
return true;
else if(event.getAction() == MotionEvent.ACTION_MOVE)
x = (int)event.getX() - mStartPosition.x;
y = (int)event.getY() - mStartPosition.y;
代码示例来源:origin: stackoverflow.com
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
textView.setText("Touch coordinates : " +
String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
}
return true;
}
});
代码示例来源:origin: stackoverflow.com
float dX, dY;
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
dX = view.getX() - event.getRawX();
dY = view.getY() - event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
view.animate()
.x(event.getRawX() + dX)
.y(event.getRawY() + dY)
.setDuration(0)
.start();
break;
default:
return false;
}
return true;
}
代码示例来源:origin: k9mail/k-9
@Override
public boolean onTouchEvent(MotionEvent event) {
// Convert coordinates to our internal coordinate system
float x = event.getX() - mTranslationOffset;
float y = event.getY() - mTranslationOffset;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Check whether the user pressed on (or near) the pointer
float[] pointerPosition = calculatePointerPosition(mAngle);
if (x >= (pointerPosition[0] - 48) && x <= (pointerPosition[0] + 48)
&& y >= (pointerPosition[1] - 48) && y <= (pointerPosition[1] + 48)) {
mUserIsMovingPointer = true;
invalidate();
}
break;
case MotionEvent.ACTION_MOVE:
if (mUserIsMovingPointer) {
mAngle = (float) java.lang.Math.atan2(y, x);
mPointerColor.setColor(calculateColor(mAngle));
invalidate();
}
break;
case MotionEvent.ACTION_UP:
mUserIsMovingPointer = false;
break;
}
return true;
}
代码示例来源:origin: stackoverflow.com
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX() // or getRawX();
int y = event.getY();
switch(action){
case MotionEvent.ACTION_DOWN:
if (x >= xOfYourBitmap && x < (xOfYourBitmap + yourBitmap.getWidth())
&& y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight())) {
//tada, if this is true, you've started your click inside your bitmap
}
break;
}
}
代码示例来源:origin: stackoverflow.com
FrameLayout touchInterceptor = (FrameLayout)findViewById(R.id.touchInterceptor);
touchInterceptor.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (mEditText.isFocused()) {
Rect outRect = new Rect();
mEditText.getGlobalVisibleRect(outRect);
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
mEditText.clearFocus();
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return false;
}
});
代码示例来源:origin: stackoverflow.com
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFFFF0000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setColor(color);
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
代码示例来源:origin: stackoverflow.com
private Rect rect; // Variable rect to hold the bounds of the view
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
// Construct a rect of the view's bounds
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if(event.getAction() == MotionEvent.ACTION_MOVE){
if(!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())){
// User moved outside bounds
}
}
return false;
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
View v = getCurrentFocus();
boolean ret = super.dispatchTouchEvent(event);
if (v instanceof EditText) {
View w = getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = event.getRawX() + w.getLeft() - scrcoords[0];
float y = event.getRawY() + w.getTop() - scrcoords[1];
Log.d("Activity", "Touch event "+event.getRawX()+","+event.getRawY()+" "+x+","+y+" rect "+w.getLeft()+","+w.getTop()+","+w.getRight()+","+w.getBottom()+" coords "+scrcoords[0]+","+scrcoords[1]);
if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom()) ) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
return ret;
}
代码示例来源:origin: stackoverflow.com
private Paint paint = new Paint();
private float endRadius = 0;
private float rippleX = 0;
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
public boolean onTouchEvent(@NonNull MotionEvent event)
rippleX = event.getX();
rippleY = event.getY();
switch(event.getAction())
内容来源于网络,如有侵权,请联系作者删除!