Skip to content

Instantly share code, notes, and snippets.

@MarshalW
Created April 18, 2013 03:29
Show Gist options
  • Save MarshalW/5409859 to your computer and use it in GitHub Desktop.
Save MarshalW/5409859 to your computer and use it in GitHub Desktop.
package com.example.touch;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
public class MyActivity extends Activity {
private Handler handler = new Handler();
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View myView =findViewById(R.id.myView);
myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
Log.d("autotouch", "on touch: " + event);
return true;
}
});
handler.postDelayed(new Runnable() {
@Override
public void run() {
MotionEvent event = MotionEvent.obtain(System.currentTimeMillis(),
System.currentTimeMillis() + 100,
MotionEvent.ACTION_DOWN, 10, 10, 1, 1, 0, 1, 1, 6, 0);
myView.dispatchTouchEvent(event);
handler.postDelayed(new Runnable() {
@Override
public void run() {
MotionEvent event = MotionEvent.obtain(System.currentTimeMillis(),
System.currentTimeMillis() + 100,
MotionEvent.ACTION_UP, 10, 10, 1, 1, 0, 1, 1, 6, 0);
myView.dispatchTouchEvent(event);
}
}, 100);
}
}, 2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment