Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.android.browser.view;
     18 
     19 import android.view.View;
     20 
     21 import com.android.browser.view.PieMenu.PieView;
     22 
     23 import java.util.ArrayList;
     24 import java.util.List;
     25 
     26 /**
     27  * Pie menu item
     28  */
     29 public class PieItem {
     30 
     31     private View mView;
     32     private PieView mPieView;
     33     private int level;
     34     private float start;
     35     private float sweep;
     36     private float animate;
     37     private int inner;
     38     private int outer;
     39     private boolean mSelected;
     40     private boolean mEnabled;
     41     private List<PieItem> mItems;
     42 
     43     public PieItem(View view, int level) {
     44         mView = view;
     45         this.level = level;
     46         mEnabled = true;
     47         setAnimationAngle(getAnimationAngle());
     48         setAlpha(getAlpha());
     49     }
     50 
     51     public PieItem(View view, int level, PieView sym) {
     52         mView = view;
     53         this.level = level;
     54         mPieView = sym;
     55         mEnabled = false;
     56     }
     57 
     58     public boolean hasItems() {
     59         return mItems != null;
     60     }
     61 
     62     public List<PieItem> getItems() {
     63         return mItems;
     64     }
     65 
     66     public void addItem(PieItem item) {
     67         if (mItems == null) {
     68             mItems = new ArrayList<PieItem>();
     69         }
     70         mItems.add(item);
     71     }
     72 
     73     public void setAlpha(float alpha) {
     74         if (mView != null) {
     75             mView.setAlpha(alpha);
     76         }
     77     }
     78 
     79     public float getAlpha() {
     80         if (mView != null) {
     81             return mView.getAlpha();
     82         }
     83         return 1;
     84     }
     85 
     86     public void setAnimationAngle(float a) {
     87         animate = a;
     88     }
     89 
     90     public float getAnimationAngle() {
     91         return animate;
     92     }
     93 
     94     public void setEnabled(boolean enabled) {
     95         mEnabled = enabled;
     96     }
     97 
     98     public void setSelected(boolean s) {
     99         mSelected = s;
    100         if (mView != null) {
    101             mView.setSelected(s);
    102         }
    103     }
    104 
    105     public boolean isSelected() {
    106         return mSelected;
    107     }
    108 
    109     public int getLevel() {
    110         return level;
    111     }
    112 
    113     public void setGeometry(float st, float sw, int inside, int outside) {
    114         start = st;
    115         sweep = sw;
    116         inner = inside;
    117         outer = outside;
    118     }
    119 
    120     public float getStart() {
    121         return start;
    122     }
    123 
    124     public float getStartAngle() {
    125         return start + animate;
    126     }
    127 
    128     public float getSweep() {
    129         return sweep;
    130     }
    131 
    132     public int getInnerRadius() {
    133         return inner;
    134     }
    135 
    136     public int getOuterRadius() {
    137         return outer;
    138     }
    139 
    140     public boolean isPieView() {
    141         return (mPieView != null);
    142     }
    143 
    144     public View getView() {
    145         return mView;
    146     }
    147 
    148     public void setPieView(PieView sym) {
    149         mPieView = sym;
    150     }
    151 
    152     public PieView getPieView() {
    153         if (mEnabled) {
    154             return mPieView;
    155         }
    156         return null;
    157     }
    158 
    159 }
    160