1 package com.cooliris.media;
4 //import java.util.ArrayList;
5 //import java.util.List;
7 //import javax.microedition.khronos.opengles.GL11;
9 //import android.content.ActivityNotFoundException;
10 //import android.content.Context;
11 //import android.content.Intent;
12 //import android.content.pm.PackageManager;
13 //import android.content.pm.ResolveInfo;
14 //import android.net.Uri;
15 //import android.util.FloatMath;
16 //import android.util.Log;
17 //import android.view.MotionEvent;
18 //import android.widget.Toast;
20 //public final class SelectionMenu extends Layer {
21 // public static final int HEIGHT = 58;
23 // private static final int BUTTON_SHARE = 0;
24 // private static final int BUTTON_DELETE = 1;
25 // private static final int BUTTON_MORE = 2;
26 // private static final int BUTTON_SELECT_ALL = 3;
27 // private static final int BUTTON_DESELECT_ALL = 4;
29 // private static final int[] BUTTON_LABELS = { R.string.Share, R.string.Delete,
31 // private static final int[] BUTTON_ICONS = { R.drawable.icon_share,
32 // R.drawable.icon_delete, R.drawable.icon_more };
33 // private static final float BUTTON_ICON_SIZE = 34f;
35 // protected static final String TAG = "SelectionMenu";
37 // private final Context mContext;
38 // private final HudLayer mHud;
39 // private final Texture mLowerBackground = ResourceTexture.get(R.drawable.selection_lower_bg);
40 // private final ResourceTexture mDividerImage = ResourceTexture
41 // .get(R.drawable.selection_menu_divider);
42 // private final ResourceTexture mSelectionLeft = ResourceTexture
43 // .get(R.drawable.selection_menu_bg_pressed_left);
44 // private final ResourceTexture mSelectionFill = ResourceTexture
45 // .get(R.drawable.selection_menu_bg_pressed);
46 // private final ResourceTexture mSelectionRight = ResourceTexture
47 // .get(R.drawable.selection_menu_bg_pressed_right);
48 // private final Button[] mButtons = new Button[BUTTON_LABELS.length];
49 // private float mDividerSpacing = 0f;
50 // private boolean mDrawButtonIcons = true;
51 // private int mTouchButton = -1;
52 // private boolean mTouchOver = false;
53 // private final PopupMenu mPopupMenu;
55 // SelectionMenu(HudLayer hud, Context context) {
56 // mContext = context;
58 // mPopupMenu = new PopupMenu(context);
60 // // Prepare format for the small labels.
61 // StringTexture.Config smallLabelFormat = new StringTexture.Config();
62 // smallLabelFormat.fontSize = 14;
64 // // Prepare format for the large labels.
65 // StringTexture.Config largeLabelFormat = new StringTexture.Config();
66 // largeLabelFormat.fontSize = 20f;
68 // // Create icon and label textures.
69 // for (int i = 0; i < BUTTON_LABELS.length; ++i) {
70 // Button button = new Button();
71 // button.icon = ResourceTexture.get(BUTTON_ICONS[i]);
72 // button.smallLabel = new SimpleStringTexture(context.getString(BUTTON_LABELS[i]),
74 // button.largeLabel = new SimpleStringTexture(context.getString(BUTTON_LABELS[i]),
76 // mButtons[i] = button;
80 // private void layout() {
81 // // Perform layout with icons and text labels.
82 // final Button[] buttons = mButtons;
83 // final float width = mWidth;
84 // final float buttonWidth = width / buttons.length;
86 // boolean overflow = false;
88 // mDividerSpacing = buttonWidth;
90 // // Attempt layout with icons + labels.
91 // for (int i = 0; i != buttons.length; ++i) {
92 // final Button button = buttons[i];
93 // final float labelWidth = button.largeLabel.getWidth();
94 // final float iconLabelWidth = BUTTON_ICON_SIZE + labelWidth;
95 // if (iconLabelWidth > buttonWidth) {
99 // button.x = dx + FloatMath.floor(0.5f * (buttonWidth - iconLabelWidth));
100 // button.centerX = dx + FloatMath.floor(0.5f * buttonWidth);
101 // dx += buttonWidth;
105 // // In the case of overflow layout without icons.
108 // for (int i = 0; i != buttons.length; ++i) {
109 // final Button button = buttons[i];
110 // final float labelWidth = button.largeLabel.getWidth();
111 // button.x = dx + FloatMath.floor(0.5f * (buttonWidth - labelWidth));
112 // dx += buttonWidth;
115 // mDrawButtonIcons = !overflow;*/
116 // mDrawButtonIcons = true;
118 // // Layout the popup menu.
119 // mPopupMenu.setSize(230, 200);
123 // public void renderBlended(RenderView view, GL11 gl) {
124 // // TODO: only recompute layout when things have changed.
127 // if (view.bind(mLowerBackground)) {
128 // final float imageHeight = mLowerBackground.getHeight();
129 // view.draw2D(0f, mY, 0, mWidth, imageHeight);
132 // // Draw the selection highlight if needed.
134 // final float SELECTION_FILL_INSET = 10f;
135 // final float SELECTION_CAP_WIDTH = 21f;
136 // final int touchButton = mTouchButton;
137 // final float x = mDividerSpacing * touchButton + SELECTION_FILL_INSET;
138 // final float y = mY;
139 // final float insetWidth = mDividerSpacing + 1f - SELECTION_FILL_INSET -
140 // SELECTION_FILL_INSET;
141 // final float height = mSelectionFill.getHeight();
142 // if (view.bind(mSelectionLeft)) {
143 // view.draw2D(x - SELECTION_CAP_WIDTH, y, 0f, SELECTION_CAP_WIDTH, height);
145 // if (view.bind(mSelectionFill)) {
146 // view.draw2D(x, y, 0f, insetWidth, height);
148 // if (view.bind(mSelectionRight)) {
149 // view.draw2D(x + insetWidth, y, 0f, SELECTION_CAP_WIDTH, height);
153 // // Draw the button icon + labels.
154 // final float labelY = mY + 20f;
155 // final Button[] buttons = mButtons;
156 // for (int i = 0; i < buttons.length; ++i) {
157 // final Button button = buttons[i];
158 // float x = button.x;
159 // if (mDrawButtonIcons && view.bind(button.icon)) {
160 // view.draw2D(x, labelY, 0f, BUTTON_ICON_SIZE, BUTTON_ICON_SIZE);
161 // x += BUTTON_ICON_SIZE - 2f;
163 // if (view.bind(button.largeLabel)) {
164 // view.draw2D(x, labelY, 0f, button.largeLabel.getWidth(), button.largeLabel
169 // // Draw the inter-button dividers.
170 // final float dividerY = mY + 13f;
171 // float x = mDividerSpacing;
172 // if (view.bind(mDividerImage)) {
173 // for (int i = 1; i < buttons.length; ++i) {
174 // view.draw2D(x, dividerY, 0f, 1f, 60f);
175 // x += mDividerSpacing;
180 // private int hitTestButtons(float x) {
181 // final Button[] buttons = mButtons;
182 // for (int i = buttons.length - 1; i >= 0; --i) {
183 // if (buttons[i].x < x) {
191 // public boolean onTouchEvent(MotionEvent event) {
192 // final float x = event.getX();
193 // switch (event.getAction()) {
194 // case MotionEvent.ACTION_DOWN:
195 // mTouchButton = hitTestButtons(x);
196 // mTouchOver = mTouchButton != -1;
198 // case MotionEvent.ACTION_MOVE:
199 // mTouchOver = hitTestButtons(x) == mTouchButton;
201 // case MotionEvent.ACTION_UP:
202 // case MotionEvent.ACTION_CANCEL:
203 // performAction(mTouchButton, event.getX(), event.getY());
204 // mTouchButton = -1;
205 // mTouchOver = false;
211 // private void performAction(final int button, float touchX, float touchY) {
212 // // Gather the selection.
213 // ArrayList<MediaBucket> selection = mHud.getGridLayer().getSelectedBuckets();
215 // // Get the first item from the selection. TODO: support multiple items in Eclair.
216 // MediaItem item = null;
217 // if (!selection.isEmpty()) {
218 // MediaBucket bucket = selection.get(0);
219 // if (bucket.mediaItems != null && !bucket.mediaItems.isEmpty()) {
220 // item = bucket.mediaItems.get(0);
224 // // Perform the action on the selection.
225 // if (item != null) {
226 // Gallery gallery = (Gallery)mContext; // TODO: provide better context.
227 // final GridLayer gridLayer = mHud.getGridLayer();
228 // final MediaItem sharedItem = item;
229 // if (sharedItem.mimetype == null) {
230 // Toast.makeText(mContext, "Error: mime type is null", Toast.LENGTH_SHORT).show();
232 // if (sharedItem.contentUri == null) {
233 // Toast.makeText(mContext, "Error: content URI is null", Toast.LENGTH_SHORT).show();
235 // if (button == BUTTON_SELECT_ALL) {
236 // gridLayer.selectAll();
237 // } else if (button == BUTTON_DESELECT_ALL) {
238 // mHud.cancelSelection();
240 // // Get the target button and popup focus location.
241 // Button targetButton = mButtons[button];
242 // int popupX = (int)targetButton.centerX;
243 // int popupY = (int)mY;
245 // // Configure the popup depending on the button pressed.
246 // PopupMenu menu = mPopupMenu;
249 // case BUTTON_SHARE:
251 // PackageManager packageManager = mContext.getPackageManager();
252 // List<ResolveInfo> activities = packageManager.queryIntentActivities(
254 // PackageManager.MATCH_DEFAULT_ONLY);
255 // for (ResolveInfo activity: activities) {
257 // PopupMenu.Option option = new PopupMenu.Option(activit, name, action)
259 // menu.add(new PopupMenu.Option());*/
260 // mHud.cancelSelection();
262 // case BUTTON_DELETE:
267 // if (button != BUTTON_SHARE) {
268 // mPopupMenu.showAtPoint(popupX, popupY, (int)mHud.getWidth(), (int)mHud.getHeight());
271 // gallery.getHandler().post(new Runnable() {
272 // public void run() {
274 // case BUTTON_SHARE:
275 // Intent intent = new Intent();
276 // intent.setAction(Intent.ACTION_SEND);
277 // intent.setType(sharedItem.mimetype);
278 // intent.putExtra(Intent.EXTRA_STREAM, Uri
279 // .parse(sharedItem.contentUri));
281 // mContext.startActivity(Intent.createChooser(intent,
283 // } catch (ActivityNotFoundException e) {
284 // Toast.makeText(mContext, "Unable to share",
285 // Toast.LENGTH_SHORT).show();
289 // case BUTTON_DELETE:
290 // gridLayer.deleteSelection();
292 // // Show options for Set As, Details, Slideshow.
301 // // Exit selection mode.
302 // //mHud.cancelSelection();
306 // public void generate(RenderView view, RenderView.Lists lists) {
307 // lists.blendedList.add(this);
308 // lists.hitTestList.add(this);
309 // mPopupMenu.generate(view, lists);
313 // protected void onHiddenChanged() {
315 // mPopupMenu.close();
319 // private static final class Button {
320 // public Texture icon;
321 // public SimpleStringTexture smallLabel;
322 // public SimpleStringTexture largeLabel;
324 // public float centerX;