| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.test.hwui; |
| 18 |
|
| 19 |
import android.app.Activity; |
| 20 |
import android.content.Context; |
| 21 |
import android.graphics.Canvas; |
| 22 |
import android.graphics.Color; |
| 23 |
import android.graphics.Paint; |
| 24 |
import android.graphics.Path; |
| 25 |
import android.os.Bundle; |
| 26 |
import android.view.MotionEvent; |
| 27 |
import android.view.View; |
| 28 |
|
| 29 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 30 |
public class PathOffsetActivity extends Activity { |
| 31 |
@Override |
| 32 |
protected void onCreate(Bundle savedInstanceState) { |
| 33 |
super.onCreate(savedInstanceState); |
| 34 |
final PathsView view = new PathsView(this); |
| 35 |
setContentView(view); |
| 36 |
} |
| 37 |
|
| 38 |
public class PathsView extends View { |
| 39 |
private Path mPath; |
| 40 |
private Paint mPaint; |
| 41 |
|
| 42 |
public PathsView(Context context) { |
| 43 |
super(context); |
| 44 |
|
| 45 |
mPaint = new Paint(); |
| 46 |
mPaint.setStyle(Paint.Style.STROKE); |
| 47 |
mPaint.setStrokeWidth(3); |
| 48 |
|
| 49 |
mPath = new Path(); |
| 50 |
mPath.lineTo(100, 100); |
| 51 |
mPath.lineTo(200, 300); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
protected void onDraw(Canvas canvas) { |
| 56 |
mPath.offset(1, 1); |
| 57 |
mPaint.setColor(Color.RED); |
| 58 |
canvas.drawPath(mPath, mPaint); |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public boolean onTouchEvent(MotionEvent event) { |
| 63 |
invalidate(); |
| 64 |
return super.onTouchEvent(event); |
| 65 |
} |
| 66 |
} |
| 67 |
} |