PieItem.java revision b5b59b88683823d70faac7b3454519d53c51180b
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 mCenter; 33 private float start; 34 private float sweep; 35 private float animate; 36 private int inner; 37 private int outer; 38 private boolean mSelected; 39 private boolean mEnabled; 40 private List<PieItem> mItems; 41 private Path mPath; 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 start = -1; 50 mCenter = -1; 51 } 52 53 public boolean hasItems() { 54 return mItems != null; 55 } 56 57 public List<PieItem> getItems() { 58 return mItems; 59 } 60 61 public void addItem(PieItem item) { 62 if (mItems == null) { 63 mItems = new ArrayList<PieItem>(); 64 } 65 mItems.add(item); 66 } 67 68 public void setPath(Path p) { 69 mPath = p; 70 } 71 72 public Path getPath() { 73 return mPath; 74 } 75 76 public void setAlpha(float alpha) { 77 if (mView != null) { 78 mView.setAlpha(alpha); 79 } 80 } 81 82 public float getAlpha() { 83 if (mView != null) { 84 return mView.getAlpha(); 85 } 86 return 1; 87 } 88 89 public void setAnimationAngle(float a) { 90 animate = a; 91 } 92 93 public float getAnimationAngle() { 94 return animate; 95 } 96 97 public void setEnabled(boolean enabled) { 98 mEnabled = enabled; 99 } 100 101 public boolean isEnabled() { 102 return mEnabled; 103 } 104 105 public void setSelected(boolean s) { 106 mSelected = s; 107 if (mView != null) { 108 mView.setSelected(s); 109 } 110 } 111 112 public boolean isSelected() { 113 return mSelected; 114 } 115 116 public int getLevel() { 117 return level; 118 } 119 120 public void setGeometry(float st, float sw, int inside, int outside) { 121 start = st; 122 sweep = sw; 123 inner = inside; 124 outer = outside; 125 } 126 127 public void setFixedSlice(float center, float sweep) { 128 mCenter = center; 129 this.sweep = sweep; 130 } 131 132 public float getCenter() { 133 return mCenter; 134 } 135 136 public float getStart() { 137 return start; 138 } 139 140 public float getStartAngle() { 141 return start + animate; 142 } 143 144 public float getSweep() { 145 return sweep; 146 } 147 148 public int getInnerRadius() { 149 return inner; 150 } 151 152 public int getOuterRadius() { 153 return outer; 154 } 155 156 public View getView() { 157 return mView; 158 } 159 160} 161