1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.cooliris.media; 18 19 // 20 //import java.util.ArrayList; 21 //import java.util.List; 22 // 23 //import javax.microedition.khronos.opengles.GL11; 24 // 25 //import android.content.ActivityNotFoundException; 26 //import android.content.Context; 27 //import android.content.Intent; 28 //import android.content.pm.PackageManager; 29 //import android.content.pm.ResolveInfo; 30 //import android.net.Uri; 31 //import android.util.FloatMath; 32 //import android.util.Log; 33 //import android.view.MotionEvent; 34 //import android.widget.Toast; 35 // 36 //public final class SelectionMenu extends Layer { 37 // public static final int HEIGHT = 58; 38 // 39 // private static final int BUTTON_SHARE = 0; 40 // private static final int BUTTON_DELETE = 1; 41 // private static final int BUTTON_MORE = 2; 42 // private static final int BUTTON_SELECT_ALL = 3; 43 // private static final int BUTTON_DESELECT_ALL = 4; 44 // 45 // private static final int[] BUTTON_LABELS = { Res.string.Share, Res.string.Delete, 46 // Res.string.More }; 47 // private static final int[] BUTTON_ICONS = { Res.drawable.icon_share, 48 // Res.drawable.icon_delete, Res.drawable.icon_more }; 49 // private static final float BUTTON_ICON_SIZE = 34f; 50 // 51 // protected static final String TAG = "SelectionMenu"; 52 // 53 // private final Context mContext; 54 // private final HudLayer mHud; 55 // private final Texture mLowerBackground = ResourceTexture.get(Res.drawable.selection_lower_bg); 56 // private final ResourceTexture mDividerImage = ResourceTexture 57 // .get(Res.drawable.selection_menu_divider); 58 // private final ResourceTexture mSelectionLeft = ResourceTexture 59 // .get(Res.drawable.selection_menu_bg_pressed_left); 60 // private final ResourceTexture mSelectionFill = ResourceTexture 61 // .get(Res.drawable.selection_menu_bg_pressed); 62 // private final ResourceTexture mSelectionRight = ResourceTexture 63 // .get(Res.drawable.selection_menu_bg_pressed_right); 64 // private final Button[] mButtons = new Button[BUTTON_LABELS.length]; 65 // private float mDividerSpacing = 0f; 66 // private boolean mDrawButtonIcons = true; 67 // private int mTouchButton = -1; 68 // private boolean mTouchOver = false; 69 // private final PopupMenu mPopupMenu; 70 // 71 // SelectionMenu(HudLayer hud, Context context) { 72 // mContext = context; 73 // mHud = hud; 74 // mPopupMenu = new PopupMenu(context); 75 // 76 // // Prepare format for the small labels. 77 // StringTexture.Config smallLabelFormat = new StringTexture.Config(); 78 // smallLabelFormat.fontSize = 14; 79 // 80 // // Prepare format for the large labels. 81 // StringTexture.Config largeLabelFormat = new StringTexture.Config(); 82 // largeLabelFormat.fontSize = 20f; 83 // 84 // // Create icon and label textures. 85 // for (int i = 0; i < BUTTON_LABELS.length; ++i) { 86 // Button button = new Button(); 87 // button.icon = ResourceTexture.get(BUTTON_ICONS[i]); 88 // button.smallLabel = new SimpleStringTexture(context.getString(BUTTON_LABELS[i]), 89 // smallLabelFormat); 90 // button.largeLabel = new SimpleStringTexture(context.getString(BUTTON_LABELS[i]), 91 // largeLabelFormat); 92 // mButtons[i] = button; 93 // } 94 // } 95 // 96 // private void layout() { 97 // // Perform layout with icons and text labels. 98 // final Button[] buttons = mButtons; 99 // final float width = mWidth; 100 // final float buttonWidth = width / buttons.length; 101 // float dx = 0f; 102 // boolean overflow = false; 103 // 104 // mDividerSpacing = buttonWidth; 105 // 106 // // Attempt layout with icons + labels. 107 // for (int i = 0; i != buttons.length; ++i) { 108 // final Button button = buttons[i]; 109 // final float labelWidth = button.largeLabel.getWidth(); 110 // final float iconLabelWidth = BUTTON_ICON_SIZE + labelWidth; 111 // if (iconLabelWidth > buttonWidth) { 112 // overflow = true; 113 // break; 114 // } 115 // button.x = dx + FloatMath.floor(0.5f * (buttonWidth - iconLabelWidth)); 116 // button.centerX = dx + FloatMath.floor(0.5f * buttonWidth); 117 // dx += buttonWidth; 118 // } 119 // 120 // /* 121 // // In the case of overflow layout without icons. 122 // if (overflow) { 123 // dx = 0f; 124 // for (int i = 0; i != buttons.length; ++i) { 125 // final Button button = buttons[i]; 126 // final float labelWidth = button.largeLabel.getWidth(); 127 // button.x = dx + FloatMath.floor(0.5f * (buttonWidth - labelWidth)); 128 // dx += buttonWidth; 129 // } 130 // } 131 // mDrawButtonIcons = !overflow;*/ 132 // mDrawButtonIcons = true; 133 // 134 // // Layout the popup menu. 135 // mPopupMenu.setSize(230, 200); 136 // } 137 // 138 // @Override 139 // public void renderBlended(RenderView view, GL11 gl) { 140 // // TODO: only recompute layout when things have changed. 141 // layout(); 142 // 143 // if (view.bind(mLowerBackground)) { 144 // final float imageHeight = mLowerBackground.getHeight(); 145 // view.draw2D(0f, mY, 0, mWidth, imageHeight); 146 // } 147 // 148 // // Draw the selection highlight if needed. 149 // if (mTouchOver) { 150 // final float SELECTION_FILL_INSET = 10f; 151 // final float SELECTION_CAP_WIDTH = 21f; 152 // final int touchButton = mTouchButton; 153 // final float x = mDividerSpacing * touchButton + SELECTION_FILL_INSET; 154 // final float y = mY; 155 // final float insetWidth = mDividerSpacing + 1f - SELECTION_FILL_INSET - 156 // SELECTION_FILL_INSET; 157 // final float height = mSelectionFill.getHeight(); 158 // if (view.bind(mSelectionLeft)) { 159 // view.draw2D(x - SELECTION_CAP_WIDTH, y, 0f, SELECTION_CAP_WIDTH, height); 160 // } 161 // if (view.bind(mSelectionFill)) { 162 // view.draw2D(x, y, 0f, insetWidth, height); 163 // } 164 // if (view.bind(mSelectionRight)) { 165 // view.draw2D(x + insetWidth, y, 0f, SELECTION_CAP_WIDTH, height); 166 // } 167 // } 168 // 169 // // Draw the button icon + labels. 170 // final float labelY = mY + 20f; 171 // final Button[] buttons = mButtons; 172 // for (int i = 0; i < buttons.length; ++i) { 173 // final Button button = buttons[i]; 174 // float x = button.x; 175 // if (mDrawButtonIcons && view.bind(button.icon)) { 176 // view.draw2D(x, labelY, 0f, BUTTON_ICON_SIZE, BUTTON_ICON_SIZE); 177 // x += BUTTON_ICON_SIZE - 2f; 178 // } 179 // if (view.bind(button.largeLabel)) { 180 // view.draw2D(x, labelY, 0f, button.largeLabel.getWidth(), button.largeLabel 181 // .getHeight()); 182 // } 183 // } 184 // 185 // // Draw the inter-button dividers. 186 // final float dividerY = mY + 13f; 187 // float x = mDividerSpacing; 188 // if (view.bind(mDividerImage)) { 189 // for (int i = 1; i < buttons.length; ++i) { 190 // view.draw2D(x, dividerY, 0f, 1f, 60f); 191 // x += mDividerSpacing; 192 // } 193 // } 194 // } 195 // 196 // private int hitTestButtons(float x) { 197 // final Button[] buttons = mButtons; 198 // for (int i = buttons.length - 1; i >= 0; --i) { 199 // if (buttons[i].x < x) { 200 // return i; 201 // } 202 // } 203 // return -1; 204 // } 205 // 206 // @Override 207 // public boolean onTouchEvent(MotionEvent event) { 208 // final float x = event.getX(); 209 // switch (event.getAction()) { 210 // case MotionEvent.ACTION_DOWN: 211 // mTouchButton = hitTestButtons(x); 212 // mTouchOver = mTouchButton != -1; 213 // break; 214 // case MotionEvent.ACTION_MOVE: 215 // mTouchOver = hitTestButtons(x) == mTouchButton; 216 // break; 217 // case MotionEvent.ACTION_UP: 218 // case MotionEvent.ACTION_CANCEL: 219 // performAction(mTouchButton, event.getX(), event.getY()); 220 // mTouchButton = -1; 221 // mTouchOver = false; 222 // break; 223 // } 224 // return true; 225 // } 226 // 227 // private void performAction(final int button, float touchX, float touchY) { 228 // // Gather the selection. 229 // ArrayList<MediaBucket> selection = mHud.getGridLayer().getSelectedBuckets(); 230 // 231 // // Get the first item from the selection. TODO: support multiple items in Eclair. 232 // MediaItem item = null; 233 // if (!selection.isEmpty()) { 234 // MediaBucket bucket = selection.get(0); 235 // if (bucket.mediaItems != null && !bucket.mediaItems.isEmpty()) { 236 // item = bucket.mediaItems.get(0); 237 // } 238 // } 239 // 240 // // Perform the action on the selection. 241 // if (item != null) { 242 // Gallery gallery = (Gallery)mContext; // TODO: provide better context. 243 // final GridLayer gridLayer = mHud.getGridLayer(); 244 // final MediaItem sharedItem = item; 245 // if (sharedItem.mimetype == null) { 246 // Toast.makeText(mContext, "Error: mime type is null", Toast.LENGTH_SHORT).show(); 247 // } 248 // if (sharedItem.contentUri == null) { 249 // Toast.makeText(mContext, "Error: content URI is null", Toast.LENGTH_SHORT).show(); 250 // } 251 // if (button == BUTTON_SELECT_ALL) { 252 // gridLayer.selectAll(); 253 // } else if (button == BUTTON_DESELECT_ALL) { 254 // mHud.cancelSelection(); 255 // } else { 256 // // Get the target button and popup focus location. 257 // Button targetButton = mButtons[button]; 258 // int popupX = (int)targetButton.centerX; 259 // int popupY = (int)mY; 260 // 261 // // Configure the popup depending on the button pressed. 262 // PopupMenu menu = mPopupMenu; 263 // menu.clear(); 264 // switch (button) { 265 // case BUTTON_SHARE: 266 // /* 267 // PackageManager packageManager = mContext.getPackageManager(); 268 // List<ResolveInfo> activities = packageManager.queryIntentActivities( 269 // intent, 270 // PackageManager.MATCH_DEFAULT_ONLY); 271 // for (ResolveInfo activity: activities) { 272 // activity.icon 273 // PopupMenu.Option option = new PopupMenu.Option(activit, name, action) 274 // } 275 // menu.add(new PopupMenu.Option());*/ 276 // mHud.cancelSelection(); 277 // break; 278 // case BUTTON_DELETE: 279 // 280 // case BUTTON_MORE: 281 // } 282 // 283 // if (button != BUTTON_SHARE) { 284 // mPopupMenu.showAtPoint(popupX, popupY, (int)mHud.getWidth(), (int)mHud.getHeight()); 285 // } 286 // 287 // gallery.getHandler().post(new Runnable() { 288 // public void run() { 289 // switch (button) { 290 // case BUTTON_SHARE: 291 // Intent intent = new Intent(); 292 // intent.setAction(Intent.ACTION_SEND); 293 // intent.setType(sharedItem.mimetype); 294 // intent.putExtra(Intent.EXTRA_STREAM, Uri 295 // .parse(sharedItem.contentUri)); 296 // try { 297 // mContext.startActivity(Intent.createChooser(intent, 298 // "Share via")); 299 // } catch (ActivityNotFoundException e) { 300 // Toast.makeText(mContext, "Unable to share", 301 // Toast.LENGTH_SHORT).show(); 302 // } 303 // 304 // break; 305 // case BUTTON_DELETE: 306 // gridLayer.deleteSelection(); 307 // case BUTTON_MORE: 308 // // Show options for Set As, Details, Slideshow. 309 // default: 310 // break; 311 // } 312 // } 313 // }); 314 // } 315 // } 316 // 317 // // Exit selection mode. 318 // //mHud.cancelSelection(); 319 // } 320 // 321 // @Override 322 // public void generate(RenderView view, RenderView.Lists lists) { 323 // lists.blendedList.add(this); 324 // lists.hitTestList.add(this); 325 // mPopupMenu.generate(view, lists); 326 // } 327 // 328 // @Override 329 // protected void onHiddenChanged() { 330 // if (mHidden) { 331 // mPopupMenu.close(); 332 // } 333 // } 334 // 335 // private static final class Button { 336 // public Texture icon; 337 // public SimpleStringTexture smallLabel; 338 // public SimpleStringTexture largeLabel; 339 // public float x; 340 // public float centerX; 341 // } 342 // } 343