diff options
author | Romain Guy <romainguy@google.com> | 2013-07-29 19:17:59 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2013-07-30 10:51:24 -0700 |
commit | 8018c8db8221aa604b3c083e09d173cc27e53d83 (patch) | |
tree | 60cbc26ddde4fa65a476a7e869d88f358b734210 /tests/HwAccelerationTest | |
parent | 93d34a61dbdfd9ece9ac4a53d78e896638172895 (diff) | |
download | frameworks_base-8018c8db8221aa604b3c083e09d173cc27e53d83.zip frameworks_base-8018c8db8221aa604b3c083e09d173cc27e53d83.tar.gz frameworks_base-8018c8db8221aa604b3c083e09d173cc27e53d83.tar.bz2 |
Add path ops API
Path ops can be used to combine two paths instances in a single path
object. The following operations can be used:
- Difference
- Reverse difference
- Union
- XOR
- Intersection
To use the API:
Path p1 = createCircle();
Path p2 = createRect();
Path result = new Path();
result.op(p1, p2, Path.Op.DIFFERENCE);
This code will subtract the rectangle from the circle and generate
the resulting path in "result."
Change-Id: Ic25244665b6691a7df0b0002a09da73d937b553b
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 12 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/PathOpsActivity.java | 87 |
2 files changed, 98 insertions, 1 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index bdd8aa6..1bb0db0 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -41,6 +41,16 @@ </activity> <activity + android:name="PathOpsActivity" + android:label="Path/Ops" + android:theme="@android:style/Theme.Holo.Light"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.hwui.TEST" /> + </intent-filter> + </activity> + + <activity android:name="AssetsAtlasActivity" android:label="Atlas/Framework" android:theme="@android:style/Theme.Holo.Light"> @@ -735,7 +745,7 @@ android:name="PathsCacheActivity" android:label="Path/Cache"> <intent-filter> - <action android:name="android.intent.action.MAIN" /> + <action android:name="android.intent.action.MAIN" />` <category android:name="com.android.test.hwui.TEST" /> </intent-filter> </activity> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PathOpsActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PathOpsActivity.java new file mode 100644 index 0000000..b9927ac --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PathOpsActivity.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +@SuppressWarnings({"UnusedDeclaration"}) +public class PathOpsActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final PathsView view = new PathsView(this); + setContentView(view); + } + + public static class PathsView extends View { + private final Paint mPaint; + private Path[] mPaths; + private float mSize; + + + public PathsView(Context c) { + super(c); + + mPaint = new Paint(); + mPaint.setAntiAlias(true); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setColor(Color.RED); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + Path.Op[] ops = Path.Op.values(); + mPaths = new Path[ops.length]; + + mSize = w / (ops.length * 2.0f); + + Path p1 = new Path(); + p1.addRect(0.0f, 0.0f, mSize, mSize, Path.Direction.CW); + + Path p2 = new Path(); + p2.addCircle(mSize, mSize, mSize / 2.0f, Path.Direction.CW); + + for (int i = 0; i < ops.length; i++) { + mPaths[i] = new Path(); + if (!mPaths[i].op(p1, p2, ops[i])) { + Log.d("PathOps", ops[i].name() + " failed!"); + } + } + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + canvas.translate(mSize * 0.2f, getHeight() / 2.0f); + for (Path path : mPaths) { + canvas.drawPath(path, mPaint); + canvas.translate(mSize * 1.8f, 0.0f); + } + } + } +} |