package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;
public class Test extends Activity implements OnTouchListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout1);
layout1.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
String myTag = v.getTag().toString();
Log.v(myTag, describeEvent(event));
logAction(event);
if( "true".equals(myTag.substring(0, 4))) {
return true;
}
else {
return false;
}
}
protected static String describeEvent(MotionEvent event) {
StringBuilder result = new StringBuilder(500);
result.append("Action: ").append(event.getAction()).append("\n");
int numPointers = event.getPointerCount();
result.append("Number of pointers: ").append(numPointers).append("\n");
int ptrIdx = 0;
while (ptrIdx < numPointers) {
int ptrId = event.getPointerId(ptrIdx);
result.append("Pointer Index: ").append(ptrIdx);
result.append(", Pointer Id: ").append(ptrId).append("\n");
result.append(" Location: ").append(event.getX(ptrIdx));
result.append(" x ").append(event.getY(ptrIdx)).append("\n");
result.append(" Pressure: ").append(event.getPressure(ptrIdx));
result.append(" Size: ").append(event.getSize(ptrIdx)).append("\n");
ptrIdx++;
}
result.append("Downtime: ").append(event.getDownTime()).append("ms\n");
result.append("Event time: ").append(event.getEventTime()).append("ms");
result.append(" Elapsed: ").append(event.getEventTime()-event.getDownTime());
result.append(" ms\n");
return result.toString();
}
private void logAction(MotionEvent event) {
final String TAG = "Action";
int ptrIndex = event.getActionIndex();
int ptrId = event.getPointerId(ptrIndex);
int action = event.getActionMasked();
Log.v(TAG, "Pointer index: " + ptrIndex);
Log.v(TAG, "Pointer Id: " + ptrId);
Log.v(TAG, "True action value: " + action);
}
}
//main.xml
android:id="@+id/layout1" android:tag="trueLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" >
android:id="@+id/message" android:tag="trueText"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />