Android:GestureDetector Demo
package com.example.widgettest;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.GestureDetector;import android.view.GestureDetector.OnGestureListener;import android.view.MotionEvent;import android.widget.Toast;public class TouchTest extends Activity implements OnGestureListener { public int verticalMinDistance=100; public int minVelocity=50; private GestureDetector mGestureDetector; public String tag="TouchTest"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mGestureDetector=new GestureDetector(this); } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub Log.d(tag, "onDown"); return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO Auto-generated method stub Log.d(tag, "onFling"); if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) { Toast.makeText(this, "to left", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) { Toast.makeText(this, "to right", Toast.LENGTH_SHORT).show(); } return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub Log.d(tag, "onLongPress"); } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub Log.d(tag, "onScroll"); return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub Log.d(tag, "onShowPress"); } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub Log.d(tag, "onSingleTapUp"); return false; } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return mGestureDetector.onTouchEvent(event); }}
You must Sign up as a member of Effecthub to view the content.
ChOw
2013-11-06
A PHP Error was encountered
Severity: Notice
Message: Undefined index: HTTP_ACCEPT_LANGUAGE
Filename: helpers/time_helper.php
Line Number: 22
Latest Posts
- Android: CookieManager removeAllCookie() Crash
- XlistView: A listview which can pull to refresh and load more (1)
- Millions of Android Phones Could Be Affected by the Heartbleed Bug. Check to See if Yours Is One of Them
- TOP 10 ANDROID GAMES FOR MARCH 2014
- Android:Button with different textcolor and background in different states
1836 views 0 comments
You must Sign up as a member of Effecthub to join the conversation.