1 /*
2  * Copyright (C) 2012 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 android.animation.cts;
18 
19 import android.graphics.Paint;
20 import android.graphics.RadialGradient;
21 import android.graphics.drawable.ShapeDrawable;
22 import android.graphics.drawable.shapes.Shape;
23 
24 /**
25  * A data structure that holds a Shape and various properties that can be used to define
26  * how the shape is drawn.
27  */
28 public class ShapeHolder {
29     private float mX = 0, mY = 0;
30     private ShapeDrawable mShape;
31     private int mColor;
32     private RadialGradient mGradient;
33     private float mAlpha = 1f;
34     private Paint mPaint;
35 
setPaint(Paint value)36     public void setPaint(Paint value) {
37         mPaint = value;
38     }
39 
getPaint()40     public Paint getPaint() {
41         return mPaint;
42     }
43 
setX(float value)44     public void setX(float value) {
45         mX = value;
46     }
47 
getX()48     public float getX() {
49         return mX;
50     }
51 
setY(float value)52     public void setY(float value) {
53         mY = value;
54     }
55 
getY()56     public float getY() {
57         return mY;
58     }
59 
setShape(ShapeDrawable value)60     public void setShape(ShapeDrawable value) {
61         mShape = value;
62     }
63 
getShape()64     public ShapeDrawable getShape() {
65         return mShape;
66     }
67 
getColor()68     public int getColor() {
69         return mColor;
70     }
71 
setColor(int value)72     public void setColor(int value) {
73         mShape.getPaint().setColor(value);
74         mColor = value;
75     }
76 
setGradient(RadialGradient value)77     public void setGradient(RadialGradient value) {
78         mGradient = value;
79     }
getGradient()80     public RadialGradient getGradient() {
81         return mGradient;
82     }
83 
setAlpha(float alpha)84     public void setAlpha(float alpha) {
85         this.mAlpha = alpha;
86         mShape.setAlpha((int)((alpha * 255f) + .5f));
87     }
88 
getWidth()89     public float getWidth() {
90         return mShape.getShape().getWidth();
91     }
92 
setWidth(float width)93     public void setWidth(float width) {
94         Shape s = mShape.getShape();
95         s.resize(width, s.getHeight());
96     }
97 
getHeight()98     public float getHeight() {
99         return mShape.getShape().getHeight();
100     }
101 
setHeight(float height)102     public void setHeight(float height) {
103         Shape s = mShape.getShape();
104         s.resize(s.getWidth(), height);
105     }
106 
ShapeHolder(ShapeDrawable s)107     public ShapeHolder(ShapeDrawable s) {
108         mShape = s;
109     }
110 }
111 
112