OSDN Git Service

Initial commit of 3D gallery source code to project.
[android-x86/packages-apps-Gallery2.git] / src / com / cooliris / media / SelectionMenu.java
1 package com.cooliris.media;
2
3 //
4 //import java.util.ArrayList;
5 //import java.util.List;
6 //
7 //import javax.microedition.khronos.opengles.GL11;
8 //
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;
19 //
20 //public final class SelectionMenu extends Layer {
21 //    public static final int HEIGHT = 58;
22 //
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;
28 //
29 //    private static final int[] BUTTON_LABELS = { R.string.Share, R.string.Delete,
30 //                                                R.string.More };
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;
34 //
35 //    protected static final String TAG = "SelectionMenu";
36 //
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;
54 //
55 //    SelectionMenu(HudLayer hud, Context context) {
56 //        mContext = context;
57 //        mHud = hud;
58 //        mPopupMenu = new PopupMenu(context);
59 //
60 //        // Prepare format for the small labels.
61 //        StringTexture.Config smallLabelFormat = new StringTexture.Config();
62 //        smallLabelFormat.fontSize = 14;
63 //
64 //        // Prepare format for the large labels.
65 //        StringTexture.Config largeLabelFormat = new StringTexture.Config();
66 //        largeLabelFormat.fontSize = 20f;
67 //
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]),
73 //                                                        smallLabelFormat);
74 //            button.largeLabel = new SimpleStringTexture(context.getString(BUTTON_LABELS[i]),
75 //                                                        largeLabelFormat);
76 //            mButtons[i] = button;
77 //        }
78 //    }
79 //
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;
85 //        float dx = 0f;
86 //        boolean overflow = false;
87 //
88 //        mDividerSpacing = buttonWidth;
89 //
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) {
96 //                overflow = true;
97 //                break;
98 //            }
99 //            button.x = dx + FloatMath.floor(0.5f * (buttonWidth - iconLabelWidth));
100 //            button.centerX = dx + FloatMath.floor(0.5f * buttonWidth);
101 //            dx += buttonWidth;
102 //        }
103 //
104 //        /*
105 //        // In the case of overflow layout without icons.
106 //        if (overflow) {
107 //            dx = 0f;
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;
113 //            }
114 //        }
115 //        mDrawButtonIcons = !overflow;*/
116 //        mDrawButtonIcons = true;
117 //        
118 //        // Layout the popup menu.
119 //        mPopupMenu.setSize(230, 200);
120 //    }
121 //
122 //    @Override
123 //    public void renderBlended(RenderView view, GL11 gl) {
124 //        // TODO: only recompute layout when things have changed.
125 //        layout();
126 //
127 //        if (view.bind(mLowerBackground)) {
128 //            final float imageHeight = mLowerBackground.getHeight();
129 //            view.draw2D(0f, mY, 0, mWidth, imageHeight);
130 //        }
131 //
132 //        // Draw the selection highlight if needed.
133 //        if (mTouchOver) {
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);
144 //            }
145 //            if (view.bind(mSelectionFill)) {
146 //                view.draw2D(x, y, 0f, insetWidth, height);
147 //            }
148 //            if (view.bind(mSelectionRight)) {
149 //                view.draw2D(x + insetWidth, y, 0f, SELECTION_CAP_WIDTH, height);
150 //            }
151 //        }
152 //
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;
162 //            }
163 //            if (view.bind(button.largeLabel)) {
164 //                view.draw2D(x, labelY, 0f, button.largeLabel.getWidth(), button.largeLabel
165 //                                .getHeight());
166 //            }
167 //        }
168 //
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;
176 //            }
177 //        }
178 //    }
179 //
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) {
184 //                return i;
185 //            }
186 //        }
187 //        return -1;
188 //    }
189 //
190 //    @Override
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;
197 //                break;
198 //            case MotionEvent.ACTION_MOVE:
199 //                mTouchOver = hitTestButtons(x) == mTouchButton;
200 //                break;
201 //            case MotionEvent.ACTION_UP:
202 //            case MotionEvent.ACTION_CANCEL:
203 //                performAction(mTouchButton, event.getX(), event.getY());
204 //                mTouchButton = -1;
205 //                mTouchOver = false;
206 //                break;
207 //        }
208 //        return true;
209 //    }
210 //
211 //    private void performAction(final int button, float touchX, float touchY) {
212 //        // Gather the selection.
213 //        ArrayList<MediaBucket> selection = mHud.getGridLayer().getSelectedBuckets();
214 //
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);
221 //            }
222 //        }
223 //
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();
231 //            }
232 //            if (sharedItem.contentUri == null) {
233 //                Toast.makeText(mContext, "Error: content URI is null", Toast.LENGTH_SHORT).show();
234 //            }
235 //            if (button == BUTTON_SELECT_ALL) {
236 //                gridLayer.selectAll();
237 //            } else if (button == BUTTON_DESELECT_ALL) {
238 //                mHud.cancelSelection();
239 //            } else {
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;
244 //                
245 //                // Configure the popup depending on the button pressed.
246 //                PopupMenu menu = mPopupMenu;
247 //                menu.clear();
248 //                switch (button) {
249 //                    case BUTTON_SHARE:
250 //                        /*
251 //                        PackageManager packageManager = mContext.getPackageManager();
252 //                        List<ResolveInfo> activities = packageManager.queryIntentActivities(
253 //                                                               intent,
254 //                                                               PackageManager.MATCH_DEFAULT_ONLY);
255 //                        for (ResolveInfo activity: activities) {
256 //                            activity.icon
257 //                            PopupMenu.Option option = new PopupMenu.Option(activit, name, action)
258 //                        }
259 //                        menu.add(new PopupMenu.Option());*/
260 //                        mHud.cancelSelection();
261 //                        break;
262 //                    case BUTTON_DELETE:
263 //                        
264 //                    case BUTTON_MORE:
265 //                }
266 //                
267 //                if (button != BUTTON_SHARE) {
268 //                    mPopupMenu.showAtPoint(popupX, popupY, (int)mHud.getWidth(), (int)mHud.getHeight());
269 //                }
270 //                
271 //                gallery.getHandler().post(new Runnable() {
272 //                    public void run() {
273 //                        switch (button) {
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));
280 //                                try {
281 //                                    mContext.startActivity(Intent.createChooser(intent,
282 //                                                                                "Share via"));
283 //                                } catch (ActivityNotFoundException e) {
284 //                                    Toast.makeText(mContext, "Unable to share",
285 //                                                   Toast.LENGTH_SHORT).show();
286 //                                }
287 //
288 //                                break;
289 //                            case BUTTON_DELETE:
290 //                                gridLayer.deleteSelection();
291 //                            case BUTTON_MORE:
292 //                                // Show options for Set As, Details, Slideshow.
293 //                            default:
294 //                                break;
295 //                        }
296 //                    }
297 //                });
298 //            }
299 //        }
300 //
301 //        // Exit selection mode.
302 //        //mHud.cancelSelection();
303 //    }
304 //
305 //    @Override
306 //    public void generate(RenderView view, RenderView.Lists lists) {
307 //        lists.blendedList.add(this);
308 //        lists.hitTestList.add(this);
309 //        mPopupMenu.generate(view, lists);
310 //    }
311 //    
312 //    @Override
313 //    protected void onHiddenChanged() {
314 //        if (mHidden) {
315 //            mPopupMenu.close();
316 //        }
317 //    }
318 //
319 //    private static final class Button {
320 //        public Texture icon;
321 //        public SimpleStringTexture smallLabel;
322 //        public SimpleStringTexture largeLabel;
323 //        public float x;
324 //        public float centerX;
325 //    }
326 // }