PathsCacheActivity.java revision 96ebc6b5097ab73eef45e094241e444f4c21bfcc
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.test.hwui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.graphics.Path;
24import android.os.Bundle;
25import android.util.Log;
26import android.view.View;
27
28import java.util.ArrayList;
29import java.util.Random;
30
31@SuppressWarnings({"UnusedDeclaration"})
32public class PathsCacheActivity extends Activity {
33    private Path mPath;
34
35    private final Random mRandom = new Random();
36    private final ArrayList<Path> mPathList = new ArrayList<Path>();
37
38    @Override
39    protected void onCreate(Bundle savedInstanceState) {
40        super.onCreate(savedInstanceState);
41
42        mPath = makePath();
43
44        final PathsView view = new PathsView(this);
45        setContentView(view);
46    }
47
48    private Path makePath() {
49        Path path = new Path();
50        buildPath(path);
51        return path;
52    }
53
54    private void buildPath(Path path) {
55        path.moveTo(0.0f, 0.0f);
56        path.cubicTo(0.0f, 0.0f, 100.0f, 150.0f, 100.0f, 200.0f);
57        path.cubicTo(100.0f, 200.0f, 50.0f, 300.0f, -80.0f, 200.0f);
58        path.cubicTo(-80.0f, 200.0f, 100.0f, 200.0f, 200.0f, 0.0f);
59    }
60
61    public class PathsView extends View {
62        private final Paint mMediumPaint;
63
64        public PathsView(Context c) {
65            super(c);
66
67            mMediumPaint = new Paint();
68            mMediumPaint.setAntiAlias(true);
69            mMediumPaint.setColor(0xe00000ff);
70            mMediumPaint.setStrokeWidth(10.0f);
71            mMediumPaint.setStyle(Paint.Style.STROKE);
72        }
73
74        @Override
75        protected void onDraw(Canvas canvas) {
76            super.onDraw(canvas);
77
78            Log.d("OpenGLRenderer", "Start frame");
79
80            canvas.drawARGB(255, 255, 255, 255);
81
82            canvas.save();
83            canvas.translate(550.0f, 60.0f);
84            canvas.drawPath(mPath, mMediumPaint);
85
86            mPath.reset();
87            buildPath(mPath);
88
89            canvas.translate(30.0f, 30.0f);
90            canvas.drawPath(mPath, mMediumPaint);
91            canvas.drawPath(mPath, mMediumPaint);
92
93            canvas.restore();
94
95//            Path path = makePath();
96//            int r = mRandom.nextInt(10);
97//            if (r == 5 || r == 3) {
98//                mPathList.add(path);
99//            } else if (r == 9) {
100//                mPathList.clear();
101//            }
102//
103//            canvas.save();
104//            canvas.translate(550.0f + mRandom.nextInt(50), 60.0f + mRandom.nextInt(50));
105//            canvas.drawPath(path, mMediumPaint);
106//            canvas.restore();
107//
108            invalidate();
109        }
110    }
111}
112