Debian Codegraph @

tests/HwAccelerationTest/src/com/android/test/hwui/PathOpsActivity.java

raw symbols SCIP
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
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.util.Log;
27 import android.view.View;
28
29 @SuppressWarnings({"UnusedDeclaration"})
30 public class PathOpsActivity 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 static class PathsView extends View {
39 private final Paint mPaint;
40 private Path[] mPaths;
41 private float mSize;
42
43
44 public PathsView(Context c) {
45 super(c);
46
47 mPaint = new Paint();
48 mPaint.setAntiAlias(true);
49 mPaint.setStyle(Paint.Style.FILL);
50 mPaint.setColor(Color.RED);
51 }
52
53 @Override
54 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
55 super.onSizeChanged(w, h, oldw, oldh);
56
57 Path.Op[] ops = Path.Op.values();
58 mPaths = new Path[ops.length];
59
60 mSize = w / (ops.length * 2.0f);
61
62 Path p1 = new Path();
63 p1.addRect(0.0f, 0.0f, mSize, mSize, Path.Direction.CW);
64
65 Path p2 = new Path();
66 p2.addCircle(mSize, mSize, mSize / 2.0f, Path.Direction.CW);
67
68 for (int i = 0; i < ops.length; i++) {
69 mPaths[i] = new Path();
70 if (!mPaths[i].op(p1, p2, ops[i])) {
71 Log.d("PathOps", ops[i].name() + " failed!");
72 }
73 }
74 }
75
76 @Override
77 protected void onDraw(Canvas canvas) {
78 super.onDraw(canvas);
79
80 canvas.translate(mSize * 0.2f, getHeight() / 2.0f);
81 for (Path path : mPaths) {
82 canvas.drawPath(path, mPaint);
83 canvas.translate(mSize * 1.8f, 0.0f);
84 }
85 }
86 }
87 }