Created
January 24, 2017 05:54
-
-
Save abduakhatov/91f392b95226829758d70f4e3de8aca4 to your computer and use it in GitHub Desktop.
Identify User Gesture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.shohruh.eventhandling; | |
import android.graphics.Color; | |
import android.support.v4.view.GestureDetectorCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, | |
GestureDetector.OnDoubleTapListener{ | |
private GestureDetectorCompat gestureDetector; | |
private TextView textView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
textView = (TextView) findViewById(R.id.txtGesture); | |
gestureDetector = new GestureDetectorCompat(this,this); | |
gestureDetector.setOnDoubleTapListener(this); | |
// | |
// final TextView txtView = (TextView)findViewById(R.id.txthello); | |
// Button btnClick = (Button) findViewById(R.id.btnClick); | |
// | |
// btnClick.setOnClickListener( | |
// new View.OnClickListener() { | |
// @Override | |
// public void onClick(View v) { | |
// txtView.setText("Hello World"); | |
// txtView.setTextColor(Color.RED); | |
// } | |
// } | |
// ); | |
// | |
// | |
// | |
// btnClick.setOnLongClickListener( | |
// new Button.OnLongClickListener(){ | |
// | |
// @Override | |
// public boolean onLongClick(View v) { | |
// txtView.setText("Long pressed Hello World!"); | |
// | |
// | |
// return true; | |
// } | |
// } | |
// ); | |
// | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
this.gestureDetector.onTouchEvent(event); | |
return super.onTouchEvent(event); | |
} | |
@Override | |
public boolean onSingleTapConfirmed(MotionEvent e) { | |
textView.setText("Single Tap Confirmed"); | |
return true; | |
} | |
@Override | |
public boolean onDoubleTap(MotionEvent e) { | |
textView.setText("Double Tap"); | |
return true; | |
} | |
@Override | |
public boolean onDoubleTapEvent(MotionEvent e) { | |
textView.setText("Double Tap Event - Strange"); | |
return true; | |
} | |
@Override | |
public boolean onDown(MotionEvent e) { | |
textView.setText("Down \\/"); | |
return true; | |
} | |
@Override | |
public void onShowPress(MotionEvent e) { | |
textView.setText("When Pressed"); | |
} | |
@Override | |
public boolean onSingleTapUp(MotionEvent e) { | |
textView.setText("Up /\\"); | |
return true; | |
} | |
@Override | |
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { | |
textView.setText("Scroll"); | |
return true; | |
} | |
@Override | |
public void onLongPress(MotionEvent e) { | |
textView.setText("Long Pressed"); | |
} | |
@Override | |
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { | |
textView.setText("Fling - Fast"); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment