Created
August 17, 2015 13:55
-
-
Save ankit-lakhanpal/f20bfc5def903fa8c01f to your computer and use it in GitHub Desktop.
gestures
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.lakhanpal.ankit.gestures; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v4.view.GestureDetectorCompat; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.TextView; | |
import android.view.MotionEvent; | |
import android.view.GestureDetector; | |
import android.support.v4.view.GestureDetectorCompat; | |
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, | |
GestureDetector.OnDoubleTapListener { | |
private TextView Mgs; | |
private GestureDetectorCompat gestureDetector; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Mgs =(TextView)findViewById(R.id.Mgs); | |
this.gestureDetector=new GestureDetectorCompat(this,this); | |
gestureDetector.setOnDoubleTapListener(this); | |
} | |
@Override | |
public boolean onSingleTapConfirmed(MotionEvent e) { | |
Mgs.setText("onSingleTapConfirmed"); | |
return true; | |
} | |
@Override | |
public boolean onDoubleTap(MotionEvent e) { | |
Mgs.setText("onDoubleTap"); | |
return true; | |
} | |
@Override | |
public boolean onDoubleTapEvent(MotionEvent e) { | |
Mgs.setText("onDoubleTapEvent"); | |
return true; | |
} | |
@Override | |
public boolean onDown(MotionEvent e) { | |
Mgs.setText("onDown"); | |
return true; //event has uccered | |
} | |
@Override | |
public void onShowPress(MotionEvent e) { | |
Mgs.setText("onShowPress"); | |
} | |
@Override | |
public boolean onSingleTapUp(MotionEvent e) { | |
Mgs.setText("onSingleTapUp"); | |
return true; | |
} | |
@Override | |
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { | |
Mgs.setText("onScroll"); | |
return true; | |
} | |
@Override | |
public void onLongPress(MotionEvent e) { | |
Mgs.setText("onLongPress"); | |
} | |
@Override | |
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { | |
Mgs.setText("onFling"); | |
return true; | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { //// ankit added | |
this.gestureDetector.onTouchEvent(event); | |
return super.onTouchEvent(event); /// detect touch if itwas gesture | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
Mgs.setText("onOptionsItemSelected"); | |
// Handle action bar item clicks here. The action bar will | |
// automatically handle clicks on the Home/Up button, so long | |
// as you specify a parent activity in AndroidManifest.xml. | |
int id = item.getItemId(); | |
//noinspection SimplifiableIfStatement | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment