Home | History | Annotate | Download | only in animation
      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.example.android.apis.animation;
     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 import android.view.View;
     24 
     25 /**
     26  * A data structure that holds a Shape and various properties that can be used to define
     27  * how the shape is drawn.
     28  */
     29 public class ShapeHolder {
     30     private float x = 0, y = 0;
     31     private ShapeDrawable shape;
     32     private int color;
     33     private RadialGradient gradient;
     34     private float alpha = 1f;
     35     private Paint paint;
     36 
     37     public void setPaint(Paint value) {
     38         paint = value;
     39     }
     40     public Paint getPaint() {
     41         return paint;
     42     }
     43 
     44     public void setX(float value) {
     45         x = value;
     46     }
     47     public float getX() {
     48         return x;
     49     }
     50     public void setY(float value) {
     51         y = value;
     52     }
     53     public float getY() {
     54         return y;
     55     }
     56     public void setShape(ShapeDrawable value) {
     57         shape = value;
     58     }
     59     public ShapeDrawable getShape() {
     60         return shape;
     61     }
     62     public int getColor() {
     63         return color;
     64     }
     65     public void setColor(int value) {
     66         shape.getPaint().setColor(value);
     67         color = value;
     68     }
     69     public void setGradient(RadialGradient value) {
     70         gradient = value;
     71     }
     72     public RadialGradient getGradient() {
     73         return gradient;
     74     }
     75 
     76     public void setAlpha(float alpha) {
     77         this.alpha = alpha;
     78         shape.setAlpha((int)((alpha * 255f) + .5f));
     79     }
     80 
     81     public float getWidth() {
     82         return shape.getShape().getWidth();
     83     }
     84     public void setWidth(float width) {
     85         Shape s = shape.getShape();
     86         s.resize(width, s.getHeight());
     87     }
     88 
     89     public float getHeight() {
     90         return shape.getShape().getHeight();
     91     }
     92     public void setHeight(float height) {
     93         Shape s = shape.getShape();
     94         s.resize(s.getWidth(), height);
     95     }
     96 
     97     public ShapeHolder(ShapeDrawable s) {
     98         shape = s;
     99     }
    100 }
    101