| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.android.camera; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
| 21 | import android.app.Dialog; |
| 22 | import android.content.Intent; |
| 23 | import android.content.SharedPreferences; |
| 24 | import android.net.Uri; |
| 25 | import android.os.Handler; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 26 | import android.provider.MediaStore; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 27 | import android.util.Config; |
| 28 | import android.util.Log; |
| 29 | import android.view.Menu; |
| 30 | import android.view.MenuItem; |
| 31 | import android.view.SubMenu; |
| 32 | import android.view.View; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 33 | import android.view.MenuItem.OnMenuItemClickListener; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | import android.widget.Button; |
| 35 | import android.widget.CheckBox; |
| 36 | import android.widget.EditText; |
| 37 | import android.widget.ImageView; |
| 38 | import android.widget.Spinner; |
| 39 | import android.widget.TextView; |
| 40 | import android.widget.Toast; |
| 41 | |
| 42 | import java.util.ArrayList; |
| 43 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 44 | import com.android.camera.ImageManager.IImage; |
| 45 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 46 | public class MenuHelper { |
| 47 | static private final String TAG = "MenuHelper"; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 48 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | static public final int GENERIC_ITEM = 1; |
| 50 | static public final int IMAGE_SAVING_ITEM = 2; |
| 51 | static public final int VIDEO_SAVING_ITEM = 3; |
| 52 | static public final int IMAGE_MODE_ITEM = 4; |
| 53 | static public final int VIDEO_MODE_ITEM = 5; |
| 54 | static public final int MENU_ITEM_MAX = 5; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 55 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 | static public final int INCLUDE_ALL = 0xFFFFFFFF; |
| 57 | static public final int INCLUDE_VIEWPLAY_MENU = (1 << 0); |
| 58 | static public final int INCLUDE_SHARE_MENU = (1 << 1); |
| 59 | static public final int INCLUDE_SET_MENU = (1 << 2); |
| 60 | static public final int INCLUDE_CROP_MENU = (1 << 3); |
| 61 | static public final int INCLUDE_DELETE_MENU = (1 << 4); |
| 62 | static public final int INCLUDE_ROTATE_MENU = (1 << 5); |
| 63 | static public final int INCLUDE_DETAILS_MENU = (1 << 5); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 64 | |
| 65 | static public final int MENU_SWITCH_CAMERA_MODE = 0; |
| 66 | static public final int MENU_CAPTURE_PICTURE = 1; |
| 67 | static public final int MENU_CAPTURE_VIDEO = 2; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | static public final int MENU_IMAGE_SHARE = 10; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | static public final int MENU_IMAGE_SET = 14; |
| 70 | static public final int MENU_IMAGE_SET_WALLPAPER = 15; |
| 71 | static public final int MENU_IMAGE_SET_CONTACT = 16; |
| 72 | static public final int MENU_IMAGE_SET_MYFAVE = 17; |
| 73 | static public final int MENU_IMAGE_CROP = 18; |
| 74 | static public final int MENU_IMAGE_ROTATE = 19; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 75 | static public final int MENU_IMAGE_ROTATE_LEFT = 20; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 76 | static public final int MENU_IMAGE_ROTATE_RIGHT = 21; |
| 77 | static public final int MENU_IMAGE_TOSS = 22; |
| 78 | static public final int MENU_VIDEO_PLAY = 23; |
| 79 | static public final int MENU_VIDEO_SHARE = 24; |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | static public final int MENU_VIDEO_TOSS = 27; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 81 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | public interface MenuItemsResult { |
| 83 | public void gettingReadyToOpen(Menu menu, ImageManager.IImage image); |
| 84 | public void aboutToCall(MenuItem item, ImageManager.IImage image); |
| 85 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 86 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | public interface MenuInvoker { |
| 88 | public void run(MenuCallback r); |
| 89 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 90 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 91 | public interface MenuCallback { |
| 92 | public void run(Uri uri, ImageManager.IImage image); |
| 93 | } |
| 94 | |
| 95 | static MenuItemsResult addImageMenuItems( |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 96 | Menu menu, |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | int inclusions, |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 98 | final boolean isImage, |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 99 | final Activity activity, |
| 100 | final Handler handler, |
| 101 | final Runnable onDelete, |
| 102 | final MenuInvoker onInvoke) { |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 103 | final ArrayList<MenuItem> requiresWriteAccessItems = new ArrayList<MenuItem>(); |
| 104 | final ArrayList<MenuItem> requiresNoDrmAccessItems = new ArrayList<MenuItem>(); |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 105 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 106 | if (isImage && ((inclusions & INCLUDE_ROTATE_MENU) != 0)) { |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 107 | SubMenu rotateSubmenu = menu.addSubMenu(IMAGE_SAVING_ITEM, MENU_IMAGE_ROTATE, |
| 108 | 40, R.string.rotate).setIcon(android.R.drawable.ic_menu_rotate); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 109 | // Don't show the rotate submenu if the item at hand is read only |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 110 | // since the items within the submenu won't be shown anyway. This is |
| 111 | // really a framework bug in that it shouldn't show the submenu if |
| 112 | // the submenu has no visible items. |
| 113 | requiresWriteAccessItems.add(rotateSubmenu.getItem()); |
| 114 | if (rotateSubmenu != null) { |
| 115 | requiresWriteAccessItems.add(rotateSubmenu.add(0, MENU_IMAGE_ROTATE_LEFT, 50, R.string.rotate_left).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 116 | public boolean onMenuItemClick(MenuItem item) { |
| 117 | onInvoke.run(new MenuCallback() { |
| 118 | public void run(Uri u, ImageManager.IImage image) { |
| 119 | if (image == null || image.isReadonly()) |
| 120 | return; |
| 121 | image.rotateImageBy(-90); |
| 122 | } |
| 123 | }); |
| 124 | return true; |
| 125 | } |
| 126 | }).setAlphabeticShortcut('l')); |
| 127 | requiresWriteAccessItems.add(rotateSubmenu.add(0, MENU_IMAGE_ROTATE_RIGHT, 60, R.string.rotate_right).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 128 | public boolean onMenuItemClick(MenuItem item) { |
| 129 | onInvoke.run(new MenuCallback() { |
| 130 | public void run(Uri u, ImageManager.IImage image) { |
| 131 | if (image == null || image.isReadonly()) |
| 132 | return; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 133 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | image.rotateImageBy(90); |
| 135 | } |
| 136 | }); |
| 137 | return true; |
| 138 | } |
| 139 | }).setAlphabeticShortcut('r')); |
| 140 | } |
| 141 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 142 | |
| 143 | if (isImage && ((inclusions & INCLUDE_CROP_MENU) != 0)) { |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 144 | MenuItem autoCrop = menu.add(IMAGE_SAVING_ITEM, MENU_IMAGE_CROP, 73, |
| 145 | R.string.camera_crop).setOnMenuItemClickListener( |
| 146 | new MenuItem.OnMenuItemClickListener() { |
| 147 | public boolean onMenuItemClick(MenuItem item) { |
| 148 | onInvoke.run(new MenuCallback() { |
| 149 | public void run(Uri u, ImageManager.IImage image) { |
| 150 | if (u == null) |
| 151 | return; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 152 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 153 | Intent cropIntent = new Intent(); |
| 154 | cropIntent.setClass(activity, CropImage.class); |
| 155 | cropIntent.setData(u); |
| 156 | activity.startActivity(cropIntent); |
| 157 | } |
| 158 | }); |
| 159 | return true; |
| 160 | } |
| 161 | }); |
| 162 | autoCrop.setIcon(android.R.drawable.ic_menu_crop); |
| 163 | requiresWriteAccessItems.add(autoCrop); |
| 164 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 165 | |
| 166 | if (isImage && ((inclusions & INCLUDE_SET_MENU) != 0)) { |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | MenuItem setMenu = menu.add(IMAGE_SAVING_ITEM, MENU_IMAGE_SET, 75, R.string.camera_set); |
| 168 | setMenu.setIcon(android.R.drawable.ic_menu_set_as); |
| 169 | |
| 170 | setMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 171 | public boolean onMenuItemClick(MenuItem item) { |
| 172 | onInvoke.run(new MenuCallback() { |
| 173 | public void run(Uri u, ImageManager.IImage image) { |
| 174 | if (u == null || image == null) |
| 175 | return; |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 176 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 177 | if (Config.LOGV) |
| 178 | Log.v(TAG, "in callback u is " + u + "; mime type is " + image.getMimeType()); |
| 179 | Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); |
| 180 | intent.setDataAndType(u, image.getMimeType()); |
| 181 | intent.putExtra("mimeType", image.getMimeType()); |
| 182 | activity.startActivity(Intent.createChooser(intent, activity.getText(R.string.setImage))); |
| 183 | } |
| 184 | }); |
| 185 | return true; |
| 186 | } |
| 187 | }); |
| 188 | } |
| 189 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 190 | if ((inclusions & INCLUDE_SHARE_MENU) != 0) { |
| 191 | if (Config.LOGV) |
| 192 | Log.v(TAG, ">>>>> add share"); |
| 193 | MenuItem item1 = menu.add(IMAGE_SAVING_ITEM, MENU_IMAGE_SHARE, 10, |
| 194 | R.string.camera_share).setOnMenuItemClickListener( |
| 195 | new MenuItem.OnMenuItemClickListener() { |
| 196 | public boolean onMenuItemClick(MenuItem item) { |
| 197 | onInvoke.run(new MenuCallback() { |
| 198 | public void run(Uri u, ImageManager.IImage image) { |
| 199 | if (image == null) |
| 200 | return; |
| 201 | Intent intent = new Intent(); |
| 202 | intent.setAction(Intent.ACTION_SEND); |
| 203 | String mimeType = image.getMimeType(); |
| 204 | intent.setType(mimeType); |
| 205 | intent.putExtra(Intent.EXTRA_STREAM, u); |
| 206 | boolean isImage = ImageManager.isImageMimeType(mimeType); |
| 207 | try { |
| 208 | activity.startActivity(Intent.createChooser(intent, |
| 209 | activity.getText( |
| 210 | isImage ? R.string.sendImage : R.string.sendVideo))); |
| 211 | } catch (android.content.ActivityNotFoundException ex) { |
| 212 | Toast.makeText(activity, |
| 213 | isImage ? R.string.no_way_to_share_image |
| 214 | : R.string.no_way_to_share_video, |
| 215 | Toast.LENGTH_SHORT).show(); |
| 216 | } |
| 217 | } |
| 218 | }); |
| 219 | return true; |
| 220 | } |
| 221 | }); |
| 222 | item1.setIcon(android.R.drawable.ic_menu_share); |
| 223 | MenuItem item = item1; |
| 224 | requiresNoDrmAccessItems.add(item); |
| 225 | } |
| 226 | |
| 227 | if ((inclusions & INCLUDE_DELETE_MENU) != 0) { |
| 228 | MenuItem deleteItem = menu.add(IMAGE_SAVING_ITEM, MENU_IMAGE_TOSS, 70, R.string.camera_toss); |
| 229 | requiresWriteAccessItems.add(deleteItem); |
| 230 | deleteItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 231 | public boolean onMenuItemClick(MenuItem item) { |
| 232 | deleteImageImpl(activity, onDelete, isImage); |
| 233 | return true; |
| 234 | } |
| 235 | }) |
| 236 | .setAlphabeticShortcut('d') |
| 237 | .setIcon(android.R.drawable.ic_menu_delete); |
| 238 | } |
| 239 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 240 | if ((inclusions & INCLUDE_DETAILS_MENU) != 0) { |
| 241 | MenuItem detailsMenu = menu.add(0, 0, 80, R.string.details).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 242 | public boolean onMenuItemClick(MenuItem item) { |
| 243 | onInvoke.run(new MenuCallback() { |
| 244 | public void run(Uri u, ImageManager.IImage image) { |
| 245 | if (image == null) |
| 246 | return; |
| 247 | |
| 248 | AlertDialog.Builder builder = new AlertDialog.Builder(activity); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 249 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 250 | final View d = View.inflate(activity, R.layout.detailsview, null); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 251 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 252 | ImageView imageView = (ImageView) d.findViewById(R.id.details_thumbnail_image); |
| 253 | imageView.setImageBitmap(image.miniThumbBitmap()); |
| 254 | |
| 255 | TextView textView = (TextView) d.findViewById(R.id.details_image_title); |
| 256 | textView.setText(image.getDisplayName()); |
| 257 | |
| 258 | java.io.InputStream data = image.fullSizeImageData(); |
| 259 | String lengthString = ""; |
| 260 | try { |
| 261 | long length = data.available(); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 262 | lengthString = |
| 263 | android.text.format.Formatter.formatFileSize(activity, length); |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 264 | data.close(); |
| 265 | } catch (java.io.IOException ex) { |
| 266 | |
| 267 | } finally { |
| 268 | } |
| 269 | ((TextView)d.findViewById(R.id.details_attrname_1)).setText(R.string.details_file_size); |
| 270 | ((TextView)d.findViewById(R.id.details_attrvalu_1)).setText(lengthString); |
| 271 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 272 | if (isImage) { |
| 273 | String dimensionsString = String.valueOf(image.getWidth() + " X " + image.getHeight()); |
| 274 | ((TextView)d.findViewById(R.id.details_attrname_2)).setText(R.string.details_image_resolution); |
| 275 | ((TextView)d.findViewById(R.id.details_attrvalu_2)).setText(dimensionsString); |
| 276 | } else { |
| 277 | d.findViewById(R.id.details_attrname_2).setVisibility(View.GONE); |
| 278 | d.findViewById(R.id.details_attrvalu_2).setVisibility(View.GONE); |
| 279 | } |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 280 | |
| 281 | String dateString = ""; |
| 282 | long dateTaken = image.getDateTaken(); |
| 283 | if (dateTaken != 0) { |
| 284 | java.util.Date date = new java.util.Date(image.getDateTaken()); |
| 285 | java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(); |
| 286 | dateString = dateFormat.format(date); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 287 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 288 | ((TextView)d.findViewById(R.id.details_attrname_3)).setText(R.string.details_date_taken); |
| 289 | ((TextView)d.findViewById(R.id.details_attrvalu_3)).setText(dateString); |
| 290 | } else { |
| 291 | d.findViewById(R.id.details_daterow).setVisibility(View.GONE); |
| 292 | } |
| 293 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 294 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | builder.setIcon(android.R.drawable.ic_dialog_info) |
| 296 | .setTitle(R.string.details_panel_title) |
| 297 | .setView(d) |
| 298 | .show(); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 299 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 300 | } |
| 301 | }); |
| 302 | return true; |
| 303 | } |
| 304 | }); |
| 305 | detailsMenu.setIcon(R.drawable.ic_menu_view_details); |
| 306 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 307 | |
| 308 | if ((!isImage) && ((inclusions & INCLUDE_VIEWPLAY_MENU) != 0)) { |
| 309 | menu.add(VIDEO_SAVING_ITEM, MENU_VIDEO_PLAY, 0, R.string.video_play) |
| 310 | .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 311 | public boolean onMenuItemClick(MenuItem item) { |
| 312 | onInvoke.run(new MenuCallback() { |
| 313 | public void run(Uri uri, IImage image) { |
| 314 | Intent intent = new Intent(Intent.ACTION_VIEW, |
| 315 | image.fullSizeImageUri()); |
| 316 | activity.startActivity(intent); |
| 317 | }}); |
| 318 | return true; |
| 319 | } |
| 320 | }); |
| 321 | } |
| 322 | |
| 323 | |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | return new MenuItemsResult() { |
| 325 | public void gettingReadyToOpen(Menu menu, ImageManager.IImage image) { |
| 326 | // protect against null here. this isn't strictly speaking required |
| 327 | // but if a client app isn't handling sdcard removal properly it |
| 328 | // could happen |
| 329 | if (image == null) { |
| 330 | return; |
| 331 | } |
| 332 | boolean readOnly = image.isReadonly(); |
| 333 | boolean isDrm = image.isDrm(); |
| 334 | if (Config.LOGV) |
| 335 | Log.v(TAG, "readOnly: " + readOnly + "; drm: " + isDrm); |
| 336 | for (MenuItem item: requiresWriteAccessItems) { |
| 337 | if (Config.LOGV) |
| 338 | Log.v(TAG, "item is " + item.toString()); |
| 339 | item.setVisible(!readOnly); |
| 340 | item.setEnabled(!readOnly); |
| 341 | } |
| 342 | for (MenuItem item: requiresNoDrmAccessItems) { |
| 343 | if (Config.LOGV) |
| 344 | Log.v(TAG, "item is " + item.toString()); |
| 345 | item.setVisible(!isDrm); |
| 346 | item.setEnabled(!isDrm); |
| 347 | } |
| 348 | } |
| 349 | public void aboutToCall(MenuItem menu, ImageManager.IImage image) { |
| 350 | } |
| 351 | }; |
| 352 | } |
| 353 | |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 354 | static void deletePhoto(Activity activity, Runnable onDelete) { |
| 355 | deleteImageImpl(activity, onDelete, true); |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 356 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 357 | |
| 358 | static void deleteImage(Activity activity, Runnable onDelete, IImage image) { |
| 359 | deleteImageImpl(activity, onDelete, ImageManager.isImage(image)); |
| 360 | } |
| 361 | |
| 362 | private static void deleteImageImpl(Activity activity, final Runnable onDelete, boolean isPhoto) { |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 363 | boolean confirm = android.preference.PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("pref_gallery_confirm_delete_key", true); |
| 364 | if (!confirm) { |
| 365 | if (onDelete != null) |
| 366 | onDelete.run(); |
| 367 | } else { |
| 368 | android.app.AlertDialog.Builder b = new android.app.AlertDialog.Builder(activity); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 369 | b.setIcon(android.R.drawable.ic_dialog_alert); |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 370 | b.setTitle(R.string.confirm_delete_title); |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 371 | b.setMessage(isPhoto? R.string.confirm_delete_message |
| 372 | : R.string.confirm_delete_video_message); |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 373 | b.setPositiveButton(android.R.string.ok, new android.content.DialogInterface.OnClickListener() { |
| 374 | public void onClick(android.content.DialogInterface v, int x) { |
| 375 | if (onDelete != null) |
| 376 | onDelete.run(); |
| 377 | } |
| 378 | }); |
| 379 | b.setNegativeButton(android.R.string.cancel, new android.content.DialogInterface.OnClickListener() { |
| 380 | public void onClick(android.content.DialogInterface v, int x) { |
| 381 | |
| 382 | } |
| 383 | }); |
| 384 | b.create().show(); |
| 385 | } |
| 386 | } |
| The Android Open Source Project | 0eaec58 | 2008-12-17 18:05:54 -0800 | [diff] [blame^] | 387 | |
| 388 | static void addSwitchModeMenuItem(Menu menu, final Activity activity, |
| 389 | final boolean switchToVideo) { |
| 390 | int group = switchToVideo ? MenuHelper.IMAGE_MODE_ITEM : MenuHelper.VIDEO_MODE_ITEM; |
| 391 | int labelId = switchToVideo ? R.string.switch_to_video_lable |
| 392 | : R.string.switch_to_camera_lable; |
| 393 | int iconId = switchToVideo ? R.drawable.ic_menu_camera_video_view |
| 394 | : R.drawable.ic_menu_camera; |
| 395 | MenuItem item = menu.add(group, MENU_SWITCH_CAMERA_MODE, 0, |
| 396 | labelId).setOnMenuItemClickListener( |
| 397 | new OnMenuItemClickListener() { |
| 398 | public boolean onMenuItemClick(MenuItem item) { |
| 399 | String action = switchToVideo ? MediaStore.INTENT_ACTION_VIDEO_CAMERA |
| 400 | : MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA; |
| 401 | Intent intent = new Intent(action); |
| 402 | intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); |
| 403 | activity.finish(); |
| 404 | activity.startActivity(intent); |
| 405 | return true; |
| 406 | } |
| 407 | }); |
| 408 | item.setIcon(iconId); |
| 409 | } |
| 410 | |
| 411 | static void addCaptureMenuItems(Menu menu, final Activity activity) { |
| 412 | |
| 413 | menu.add(0, MENU_CAPTURE_PICTURE, 1, R.string.capture_picture) |
| 414 | .setOnMenuItemClickListener( |
| 415 | new MenuItem.OnMenuItemClickListener() { |
| 416 | public boolean onMenuItemClick(MenuItem item) { |
| 417 | Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 418 | try { |
| 419 | activity.startActivity(intent); |
| 420 | } catch (android.content.ActivityNotFoundException e) { |
| 421 | // Ignore exception |
| 422 | } |
| 423 | return true; |
| 424 | } |
| 425 | }) |
| 426 | .setIcon(R.drawable.ic_menu_camera); |
| 427 | |
| 428 | menu.add(0, MENU_CAPTURE_VIDEO, 2, R.string.capture_video) |
| 429 | .setOnMenuItemClickListener( |
| 430 | new MenuItem.OnMenuItemClickListener() { |
| 431 | public boolean onMenuItemClick(MenuItem item) { |
| 432 | Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); |
| 433 | try { |
| 434 | activity.startActivity(intent); |
| 435 | } catch (android.content.ActivityNotFoundException e) { |
| 436 | // Ignore exception |
| 437 | } |
| 438 | return true; |
| 439 | } |
| 440 | }) |
| 441 | .setIcon(R.drawable.ic_menu_camera_video_view); |
| 442 | } |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 443 | static MenuItem addFlipOrientation(Menu menu, final Activity activity, final SharedPreferences prefs) { |
| 444 | // position 41 after rotate |
| 445 | return menu |
| 446 | .add(Menu.CATEGORY_SECONDARY, 304, 41, R.string.flip_orientation) |
| 447 | .setOnMenuItemClickListener( |
| 448 | new MenuItem.OnMenuItemClickListener() { |
| 449 | public boolean onMenuItemClick(MenuItem item) { |
| 450 | int current = activity.getRequestedOrientation(); |
| 451 | int newOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 452 | if (current == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { |
| 453 | newOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 454 | } |
| 455 | SharedPreferences.Editor editor = prefs.edit(); |
| 456 | editor.putInt("nuorientation", newOrientation); |
| 457 | editor.commit(); |
| 458 | requestOrientation(activity, prefs); |
| 459 | return true; |
| 460 | } |
| 461 | }) |
| 462 | .setIcon(android.R.drawable.ic_menu_always_landscape_portrait); |
| 463 | } |
| 464 | |
| 465 | static void requestOrientation(Activity activity, SharedPreferences prefs) { |
| 466 | int req = prefs.getInt("nuorientation", |
| 467 | android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 468 | // A little trick: use USER instead of UNSPECIFIED, so we ignore the |
| 469 | // orientation set by the activity below. It may have forced a landscape |
| 470 | // orientation, which the user has now cleared here. |
| 471 | activity.setRequestedOrientation( |
| 472 | req == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 473 | ? android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER |
| 474 | : req); |
| 475 | } |
| The Android Open Source Project | 1d4c750 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 476 | } |
| 477 | |