Merge "Add in-app tracepoints to TouchLatency app."
This commit is contained in:
@@ -30,6 +30,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -42,6 +43,7 @@ class TouchLatencyView extends View implements View.OnTouchListener {
|
|||||||
|
|
||||||
public TouchLatencyView(Context context, AttributeSet attrs) {
|
public TouchLatencyView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
Trace.beginSection("TouchLatencyView constructor");
|
||||||
setOnTouchListener(this);
|
setOnTouchListener(this);
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
mBluePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mBluePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
@@ -63,27 +65,31 @@ class TouchLatencyView extends View implements View.OnTouchListener {
|
|||||||
mBallY = 100.0f;
|
mBallY = 100.0f;
|
||||||
mVelocityX = 7.0f;
|
mVelocityX = 7.0f;
|
||||||
mVelocityY = 7.0f;
|
mVelocityY = 7.0f;
|
||||||
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent event) {
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
|
Trace.beginSection("TouchLatencyView onTouch");
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
|
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
|
||||||
mTouching = true;
|
mTouching = true;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
|
mTouchX = event.getX();
|
||||||
|
mTouchY = event.getY();
|
||||||
} else if (action == MotionEvent.ACTION_UP) {
|
} else if (action == MotionEvent.ACTION_UP) {
|
||||||
mTouching = false;
|
mTouching = false;
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
mTouchX = event.getX();
|
Trace.endSection();
|
||||||
mTouchY = event.getY();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTouch(Canvas canvas) {
|
private void drawTouch(Canvas canvas) {
|
||||||
|
Trace.beginSection("TouchLatencyView drawTouch");
|
||||||
|
|
||||||
|
try {
|
||||||
if (!mTouching) {
|
if (!mTouching) {
|
||||||
Log.d(LOG_TAG, "Filling background");
|
Log.d(LOG_TAG, "Filling background");
|
||||||
canvas.drawColor(BACKGROUND_COLOR);
|
canvas.drawColor(BACKGROUND_COLOR);
|
||||||
@@ -102,9 +108,13 @@ class TouchLatencyView extends View implements View.OnTouchListener {
|
|||||||
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS + 2 * scaleFactor, mYellowPaint);
|
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS + 2 * scaleFactor, mYellowPaint);
|
||||||
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS + scaleFactor, mGreenPaint);
|
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS + scaleFactor, mGreenPaint);
|
||||||
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS, mBluePaint);
|
canvas.drawCircle(mTouchX, mTouchY, INNER_RADIUS, mBluePaint);
|
||||||
|
} finally {
|
||||||
|
Trace.endSection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBall(Canvas canvas) {
|
private void drawBall(Canvas canvas) {
|
||||||
|
Trace.beginSection("TouchLatencyView drawBall");
|
||||||
int width = canvas.getWidth();
|
int width = canvas.getWidth();
|
||||||
int height = canvas.getHeight();
|
int height = canvas.getHeight();
|
||||||
|
|
||||||
@@ -141,25 +151,29 @@ class TouchLatencyView extends View implements View.OnTouchListener {
|
|||||||
canvas.drawColor(BACKGROUND_COLOR);
|
canvas.drawColor(BACKGROUND_COLOR);
|
||||||
canvas.drawOval(left, top, right, bottom, mYellowPaint);
|
canvas.drawOval(left, top, right, bottom, mYellowPaint);
|
||||||
invalidate();
|
invalidate();
|
||||||
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
Trace.beginSection("TouchLatencyView onDraw");
|
||||||
if (mMode == 0) {
|
if (mMode == 0) {
|
||||||
drawTouch(canvas);
|
drawTouch(canvas);
|
||||||
} else {
|
} else {
|
||||||
drawBall(canvas);
|
drawBall(canvas);
|
||||||
}
|
}
|
||||||
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeMode(MenuItem item) {
|
public void changeMode(MenuItem item) {
|
||||||
|
Trace.beginSection("TouchLatencyView changeMode");
|
||||||
final int NUM_MODES = 2;
|
final int NUM_MODES = 2;
|
||||||
final String modes[] = {"Touch", "Ball"};
|
final String modes[] = {"Touch", "Ball"};
|
||||||
mMode = (mMode + 1) % NUM_MODES;
|
mMode = (mMode + 1) % NUM_MODES;
|
||||||
invalidate();
|
invalidate();
|
||||||
item.setTitle(modes[mMode]);
|
item.setTitle(modes[mMode]);
|
||||||
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paint mBluePaint, mGreenPaint, mYellowPaint, mRedPaint;
|
private Paint mBluePaint, mGreenPaint, mYellowPaint, mRedPaint;
|
||||||
@@ -178,21 +192,26 @@ public class TouchLatencyActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Trace.beginSection("TouchLatencyActivity onCreate");
|
||||||
setContentView(R.layout.activity_touch_latency);
|
setContentView(R.layout.activity_touch_latency);
|
||||||
|
|
||||||
mTouchView = findViewById(R.id.canvasView);
|
mTouchView = findViewById(R.id.canvasView);
|
||||||
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
Trace.beginSection("TouchLatencyActivity onCreateOptionsMenu");
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
getMenuInflater().inflate(R.menu.menu_touch_latency, menu);
|
getMenuInflater().inflate(R.menu.menu_touch_latency, menu);
|
||||||
|
Trace.endSection();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
Trace.beginSection("TouchLatencyActivity onOptionsItemSelected");
|
||||||
// Handle action bar item clicks here. The action bar will
|
// Handle action bar item clicks here. The action bar will
|
||||||
// automatically handle clicks on the Home/Up button, so long
|
// automatically handle clicks on the Home/Up button, so long
|
||||||
// as you specify a parent activity in AndroidManifest.xml.
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
@@ -203,6 +222,7 @@ public class TouchLatencyActivity extends Activity {
|
|||||||
mTouchView.changeMode(item);
|
mTouchView.changeMode(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Trace.endSection();
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user