Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ClipData; | |
| 8 import android.content.ContentResolver; | 9 import android.content.ContentResolver; |
| 9 import android.content.Intent; | 10 import android.content.Intent; |
| 10 import android.database.Cursor; | 11 import android.database.Cursor; |
| 11 import android.net.Uri; | 12 import android.net.Uri; |
| 12 import android.os.Environment; | 13 import android.os.Environment; |
| 13 import android.provider.MediaStore; | 14 import android.provider.MediaStore; |
| 14 import android.text.TextUtils; | 15 import android.text.TextUtils; |
| 15 | 16 |
| 16 import org.chromium.base.CalledByNative; | 17 import org.chromium.base.CalledByNative; |
| 17 import org.chromium.base.JNINamespace; | 18 import org.chromium.base.JNINamespace; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 43 private Uri mCameraOutputUri; | 44 private Uri mCameraOutputUri; |
| 44 | 45 |
| 45 private SelectFileDialog(long nativeSelectFileDialog) { | 46 private SelectFileDialog(long nativeSelectFileDialog) { |
| 46 mNativeSelectFileDialog = nativeSelectFileDialog; | 47 mNativeSelectFileDialog = nativeSelectFileDialog; |
| 47 } | 48 } |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * Creates and starts an intent based on the passed fileTypes and capture va lue. | 51 * Creates and starts an intent based on the passed fileTypes and capture va lue. |
| 51 * @param fileTypes MIME types requested (i.e. "image/*") | 52 * @param fileTypes MIME types requested (i.e. "image/*") |
| 52 * @param capture The capture value as described in http://www.w3.org/TR/htm l-media-capture/ | 53 * @param capture The capture value as described in http://www.w3.org/TR/htm l-media-capture/ |
| 54 * @param multiple Whether it should be possible to select multiple files. | |
| 53 * @param window The WindowAndroid that can show intents | 55 * @param window The WindowAndroid that can show intents |
| 54 */ | 56 */ |
| 55 @CalledByNative | 57 @CalledByNative |
| 56 private void selectFile(String[] fileTypes, boolean capture, WindowAndroid w indow) { | 58 private void selectFile( |
| 59 String[] fileTypes, boolean capture, boolean multiple, WindowAndroid window) { | |
| 57 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); | 60 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); |
| 58 mCapture = capture; | 61 mCapture = capture; |
| 59 | 62 |
| 60 Intent chooser = new Intent(Intent.ACTION_CHOOSER); | 63 Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
| 61 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 64 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 62 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); | 65 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); |
| 63 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); | 66 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); |
| 64 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | 67 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| 65 Intent soundRecorder = new Intent( | 68 Intent soundRecorder = new Intent( |
| 66 MediaStore.Audio.Media.RECORD_SOUND_ACTION); | 69 MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| 67 | 70 |
| 68 // Quick check - if the |capture| parameter is set and |fileTypes| has t he appropriate MIME | 71 // Quick check - if the |capture| parameter is set and |fileTypes| has t he appropriate MIME |
| 69 // type, we should just launch the appropriate intent. Otherwise build u p a chooser based on | 72 // type, we should just launch the appropriate intent. Otherwise build u p a chooser based on |
| 70 // the accept type and then display that to the user. | 73 // the accept type and then display that to the user. |
| 71 if (captureCamera()) { | 74 if (captureCamera()) { |
| 72 if (window.showIntent(camera, this, R.string.low_memory_error)) retu rn; | 75 if (window.showIntent(camera, this, R.string.low_memory_error)) retu rn; |
| 73 } else if (captureCamcorder()) { | 76 } else if (captureCamcorder()) { |
| 74 if (window.showIntent(camcorder, this, R.string.low_memory_error)) r eturn; | 77 if (window.showIntent(camcorder, this, R.string.low_memory_error)) r eturn; |
| 75 } else if (captureMicrophone()) { | 78 } else if (captureMicrophone()) { |
| 76 if (window.showIntent(soundRecorder, this, R.string.low_memory_error )) return; | 79 if (window.showIntent(soundRecorder, this, R.string.low_memory_error )) return; |
| 77 } | 80 } |
| 78 | 81 |
| 79 Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT); | 82 Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT); |
| 80 getContentIntent.addCategory(Intent.CATEGORY_OPENABLE); | 83 getContentIntent.addCategory(Intent.CATEGORY_OPENABLE); |
| 84 | |
| 85 if (multiple) | |
| 86 getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); | |
| 87 | |
| 81 ArrayList<Intent> extraIntents = new ArrayList<Intent>(); | 88 ArrayList<Intent> extraIntents = new ArrayList<Intent>(); |
| 82 if (!noSpecificType()) { | 89 if (!noSpecificType()) { |
| 83 // Create a chooser based on the accept type that was specified in t he webpage. Note | 90 // Create a chooser based on the accept type that was specified in t he webpage. Note |
| 84 // that if the web page specified multiple accept types, we will hav e built a generic | 91 // that if the web page specified multiple accept types, we will hav e built a generic |
| 85 // chooser above. | 92 // chooser above. |
| 86 if (shouldShowImageTypes()) { | 93 if (shouldShowImageTypes()) { |
| 87 extraIntents.add(camera); | 94 extraIntents.add(camera); |
| 88 getContentIntent.setType(ALL_IMAGE_TYPES); | 95 getContentIntent.setType(ALL_IMAGE_TYPES); |
| 89 } else if (shouldShowVideoTypes()) { | 96 } else if (shouldShowVideoTypes()) { |
| 90 extraIntents.add(camcorder); | 97 extraIntents.add(camcorder); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa th(), ""); | 183 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa th(), ""); |
| 177 | 184 |
| 178 // Broadcast to the media scanner that there's a new photo on the de vice so it will | 185 // Broadcast to the media scanner that there's a new photo on the de vice so it will |
| 179 // show up right away in the gallery (rather than waiting until the next time the media | 186 // show up right away in the gallery (rather than waiting until the next time the media |
| 180 // scanner runs). | 187 // scanner runs). |
| 181 window.sendBroadcast(new Intent( | 188 window.sendBroadcast(new Intent( |
| 182 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); | 189 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); |
| 183 return; | 190 return; |
| 184 } | 191 } |
| 185 | 192 |
| 193 // Path for when EXTRA_ALLOW_MULTIPLE Intent extra has been defined. Eac h of the selected | |
| 194 // files will be shared as an entry on the Intent's ClipData. | |
| 195 if (results.getData() == null && results.getClipData() != null) { | |
|
Miguel Garcia
2014/08/05 18:01:00
can you check that the |results| intent in fact co
Peter Beverloo
2014/08/05 18:44:53
|results| is the resulting Intent, not the content
| |
| 196 ClipData clipData = results.getClipData(); | |
| 197 | |
| 198 int itemCount = clipData.getItemCount(); | |
| 199 if (itemCount == 0) { | |
| 200 onFileNotSelected(); | |
| 201 return; | |
| 202 } | |
| 203 | |
| 204 String[] filePathArray = new String[itemCount]; | |
| 205 String[] displayNameArray = new String[itemCount]; | |
| 206 | |
| 207 for (int i = 0; i < itemCount; ++i) { | |
| 208 final Uri uri = clipData.getItemAt(i).getUri(); | |
| 209 | |
| 210 filePathArray[i] = uri.toString(); | |
| 211 displayNameArray[i] = resolveFileName(uri, contentResolver); | |
| 212 } | |
| 213 | |
| 214 nativeOnMultipleFilesSelected(mNativeSelectFileDialog, | |
| 215 filePathArray, displayNameArray); | |
| 216 return; | |
| 217 } | |
| 218 | |
| 186 if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) { | 219 if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) { |
| 187 nativeOnFileSelected(mNativeSelectFileDialog, | 220 nativeOnFileSelected(mNativeSelectFileDialog, |
| 188 results.getData().getSchemeSpecificPart(), ""); | 221 results.getData().getSchemeSpecificPart(), ""); |
| 189 return; | 222 return; |
| 190 } | 223 } |
| 191 | 224 |
| 192 if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) { | 225 if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) { |
| 193 nativeOnFileSelected(mNativeSelectFileDialog, | 226 nativeOnFileSelected(mNativeSelectFileDialog, |
| 194 results.getData().toString(), | 227 results.getData().toString(), |
| 195 resolveFileName(results.getData(), | 228 resolveFileName(results.getData(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 return false; | 288 return false; |
| 256 } | 289 } |
| 257 | 290 |
| 258 @CalledByNative | 291 @CalledByNative |
| 259 private static SelectFileDialog create(long nativeSelectFileDialog) { | 292 private static SelectFileDialog create(long nativeSelectFileDialog) { |
| 260 return new SelectFileDialog(nativeSelectFileDialog); | 293 return new SelectFileDialog(nativeSelectFileDialog); |
| 261 } | 294 } |
| 262 | 295 |
| 263 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, | 296 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, |
| 264 String filePath, String displayName); | 297 String filePath, String displayName); |
| 298 private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialo gImpl, | |
| 299 String[] filePathArray, String[] displayNameArray); | |
| 265 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; | 300 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; |
| 266 } | 301 } |
| OLD | NEW |