2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.graphics.drawable.shapes;
19 import android.annotation.NonNull;
20 import android.graphics.Canvas;
21 import android.graphics.Paint;
22 import android.graphics.Path;
25 * Creates geometric paths, utilizing the {@link android.graphics.Path} class.
27 * The path can be drawn to a Canvas with its own draw() method,
28 * but more graphical control is available if you instead pass
29 * the PathShape to a {@link android.graphics.drawable.ShapeDrawable}.
31 public class PathShape extends Shape {
32 private final float mStdWidth;
33 private final float mStdHeight;
37 private float mScaleX; // cached from onResize
38 private float mScaleY; // cached from onResize
41 * PathShape constructor.
43 * @param path a Path that defines the geometric paths for this shape
44 * @param stdWidth the standard width for the shape. Any changes to the
45 * width with resize() will result in a width scaled based
46 * on the new width divided by this width.
47 * @param stdHeight the standard height for the shape. Any changes to the
48 * height with resize() will result in a height scaled based
49 * on the new height divided by this height.
51 public PathShape(@NonNull Path path, float stdWidth, float stdHeight) {
54 mStdHeight = stdHeight;
58 public void draw(Canvas canvas, Paint paint) {
60 canvas.scale(mScaleX, mScaleY);
61 canvas.drawPath(mPath, paint);
66 protected void onResize(float width, float height) {
67 mScaleX = width / mStdWidth;
68 mScaleY = height / mStdHeight;
72 public PathShape clone() throws CloneNotSupportedException {
73 final PathShape shape = (PathShape) super.clone();
74 shape.mPath = new Path(mPath);