Page 127 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 127
24 JAM!! Pintar Pemrograman Android
67:
68: private class SampleView extends View {
69: private Paint mPaint = new Paint();
70: private Path mPath = new Path();
71: private boolean mAnimate;
72:
73: public SampleView(Context context) {
74: super(context);
75:
76: // Construct a wedge-shaped path
77: mPath.moveTo(0, -50);
78: mPath.lineTo(-20, 60);
79: mPath.lineTo(0, 50);
80: mPath.lineTo(20, 60);
81: mPath.close();
82: }
83:
84: @Override
85: protected void onDraw(Canvas canvas) {
86: Paint paint = mPaint;
87:
88: canvas.drawColor(Color.WHITE);
89:
90: paint.setAntiAlias(true);
91: paint.setColor(Color.BLACK);
92: paint.setStyle(Paint.Style.FILL);
93:
94: int w = canvas.getWidth();
95: int h = canvas.getHeight();
96: int cx = w / 2;
97: int cy = h / 2;
98:
99: canvas.translate(cx, cy);
100: if (mValues != null) {
101: canvas.rotate(-mValues[0]);
102: }
103: canvas.drawPath(mPath, mPaint);
104: }
105:
106: @Override
107: protected void onAttachedToWindow() {
108: mAnimate = true;
109: if (Config.DEBUG)
110: Log.d(TAG,
"onAttachedToWindow. mAnimate=" + mAnimate);
111: super.onAttachedToWindow();
112: }
113:
114: @Override
115: protected void onDetachedFromWindow() {
116: mAnimate = false;
117: if (Config.DEBUG)
118: Log.d(TAG,
"onDetachedFromWindow. mAnimate=" + mAnimate);
119: super.onDetachedFromWindow();
120: }
121: }
122:
123: }
Dapatkan materi terbaru di 127
www.omayib.com

