10860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb/*
20860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * Copyright (C) 2011 The Android Open Source Project
30860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb *
40860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * Licensed under the Apache License, Version 2.0 (the "License"); you may not
50860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * use this file except in compliance with the License. You may obtain a copy of
60860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * the License at
70860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb *
80860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * http://www.apache.org/licenses/LICENSE-2.0
90860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb *
100860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * Unless required by applicable law or agreed to in writing, software
110860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
120860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
130860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * License for the specific language governing permissions and limitations under
140860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * the License.
150860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb */
160860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
170860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolbpackage com.android.browser.view;
180860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport android.view.View;
2080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
211acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport com.android.browser.view.PieMenu.PieView;
221acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb
2380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport java.util.ArrayList;
2480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolbimport java.util.List;
250860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
260860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb/**
270860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb * Pie menu item
280860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb */
290860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolbpublic class PieItem {
300860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
310860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private View mView;
321acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    private PieView mPieView;
330860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private int level;
340860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private float start;
350860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private float sweep;
3680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private float animate;
370860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private int inner;
380860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private int outer;
390860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    private boolean mSelected;
4080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private boolean mEnabled;
4180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    private List<PieItem> mItems;
420860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
430860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public PieItem(View view, int level) {
440860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        mView = view;
450860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        this.level = level;
4680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mEnabled = true;
4780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        setAnimationAngle(getAnimationAngle());
4880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        setAlpha(getAlpha());
490860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
500860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
511acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    public PieItem(View view, int level, PieView sym) {
521acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        mView = view;
531acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        this.level = level;
541acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        mPieView = sym;
5580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mEnabled = false;
5680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
5780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
5880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public boolean hasItems() {
5980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return mItems != null;
6080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
6180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
6280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public List<PieItem> getItems() {
6380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return mItems;
6480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
6580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
6680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void addItem(PieItem item) {
6780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mItems == null) {
6880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mItems = new ArrayList<PieItem>();
6980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
7080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mItems.add(item);
7180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
7280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
7380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void setAlpha(float alpha) {
7480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mView != null) {
7580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            mView.setAlpha(alpha);
7680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
7780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
7880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
7980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public float getAlpha() {
8080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mView != null) {
8180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return mView.getAlpha();
8280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
8380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return 1;
8480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
8580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
8680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void setAnimationAngle(float a) {
8780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        animate = a;
8880f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
8980f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
9080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public float getAnimationAngle() {
9180f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return animate;
9280f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
9380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
9480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void setEnabled(boolean enabled) {
9580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        mEnabled = enabled;
961acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    }
971acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb
980860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public void setSelected(boolean s) {
990860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        mSelected = s;
1000860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        if (mView != null) {
1010860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb            mView.setSelected(s);
1020860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        }
1030860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1040860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1050860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public boolean isSelected() {
1060860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return mSelected;
1070860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1080860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1090860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public int getLevel() {
1100860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return level;
1110860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1120860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
11380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public void setGeometry(float st, float sw, int inside, int outside) {
1140860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        start = st;
1150860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        sweep = sw;
1160860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        inner = inside;
1170860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        outer = outside;
1180860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1190860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
12080f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public float getStart() {
1210860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return start;
1220860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1230860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
12480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    public float getStartAngle() {
12580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return start + animate;
12680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb    }
12780f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb
1280860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public float getSweep() {
1290860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return sweep;
1300860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1310860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1320860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public int getInnerRadius() {
1330860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return inner;
1340860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1350860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1360860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public int getOuterRadius() {
1370860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return outer;
1380860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1390860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1401acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    public boolean isPieView() {
1411acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        return (mPieView != null);
1421acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    }
1431acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb
1440860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    public View getView() {
1450860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb        return mView;
1460860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb    }
1470860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb
1481acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    public void setPieView(PieView sym) {
1491acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        mPieView = sym;
1501acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    }
1511acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb
1521acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    public PieView getPieView() {
15380f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        if (mEnabled) {
15480f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb            return mPieView;
15580f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        }
15680f750852edf43c6b09e5633f2c6ebdb2ed94a5bMichael Kolb        return null;
157565752e1025129ad16c030ceca9dee7a695ed73eMichael Kolb    }
158565752e1025129ad16c030ceca9dee7a695ed73eMichael Kolb
1590860d99a463f7645bcc9aaa246fd8852e90dbb5dMichael Kolb}
160