PieItem.java revision 1373b98135b2854578111dd535e24d39c8853f14
1/*
2 * Copyright (C) 2012 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
17package com.android.camera.ui;
18
19import android.graphics.Path;
20import android.view.View;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Pie menu item
27 */
28public class PieItem {
29
30    private View mView;
31    private int level;
32    private float start;
33    private float sweep;
34    private float animate;
35    private int inner;
36    private int outer;
37    private boolean mSelected;
38    private boolean mEnabled;
39    private List<PieItem> mItems;
40    private Path mPath;
41
42    public PieItem(View view, int level) {
43        mView = view;
44        this.level = level;
45        mEnabled = true;
46        setAnimationAngle(getAnimationAngle());
47        setAlpha(getAlpha());
48    }
49
50    public boolean hasItems() {
51        return mItems != null;
52    }
53
54    public List<PieItem> getItems() {
55        return mItems;
56    }
57
58    public void addItem(PieItem item) {
59        if (mItems == null) {
60            mItems = new ArrayList<PieItem>();
61        }
62        mItems.add(item);
63    }
64
65    public void setPath(Path p) {
66        mPath = p;
67    }
68
69    public Path getPath() {
70        return mPath;
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 boolean isEnabled() {
99        return mEnabled;
100    }
101
102    public void setSelected(boolean s) {
103        mSelected = s;
104        if (mView != null) {
105            mView.setSelected(s);
106        }
107    }
108
109    public boolean isSelected() {
110        return mSelected;
111    }
112
113    public int getLevel() {
114        return level;
115    }
116
117    public void setGeometry(float st, float sw, int inside, int outside) {
118        start = st;
119        sweep = sw;
120        inner = inside;
121        outer = outside;
122    }
123
124    public float getStart() {
125        return start;
126    }
127
128    public float getStartAngle() {
129        return start + animate;
130    }
131
132    public float getSweep() {
133        return sweep;
134    }
135
136    public int getInnerRadius() {
137        return inner;
138    }
139
140    public int getOuterRadius() {
141        return outer;
142    }
143
144    public View getView() {
145        return mView;
146    }
147
148}
149