| 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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.ClipData; | 9 import android.content.ClipData; |
| 10 import android.content.ContentResolver; | 10 import android.content.ContentResolver; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 mNativeSelectFileDialog = nativeSelectFileDialog; | 49 mNativeSelectFileDialog = nativeSelectFileDialog; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Creates and starts an intent based on the passed fileTypes and capture va
lue. | 53 * Creates and starts an intent based on the passed fileTypes and capture va
lue. |
| 54 * @param fileTypes MIME types requested (i.e. "image/*") | 54 * @param fileTypes MIME types requested (i.e. "image/*") |
| 55 * @param capture The capture value as described in http://www.w3.org/TR/htm
l-media-capture/ | 55 * @param capture The capture value as described in http://www.w3.org/TR/htm
l-media-capture/ |
| 56 * @param multiple Whether it should be possible to select multiple files. | 56 * @param multiple Whether it should be possible to select multiple files. |
| 57 * @param window The WindowAndroid that can show intents | 57 * @param window The WindowAndroid that can show intents |
| 58 */ | 58 */ |
| 59 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) |
| 59 @CalledByNative | 60 @CalledByNative |
| 60 private void selectFile( | 61 private void selectFile( |
| 61 String[] fileTypes, boolean capture, boolean multiple, WindowAndroid
window) { | 62 String[] fileTypes, boolean capture, boolean multiple, WindowAndroid
window) { |
| 62 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); | 63 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); |
| 63 mCapture = capture; | 64 mCapture = capture; |
| 64 | 65 |
| 65 Intent chooser = new Intent(Intent.ACTION_CHOOSER); | 66 Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
| 66 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 67 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 67 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); | 68 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); |
| 68 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); | 69 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); |
| 69 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | 70 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| 70 Intent soundRecorder = new Intent( | 71 Intent soundRecorder = new Intent( |
| 71 MediaStore.Audio.Media.RECORD_SOUND_ACTION); | 72 MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| 72 | 73 |
| 73 // Quick check - if the |capture| parameter is set and |fileTypes| has t
he appropriate MIME | 74 // Quick check - if the |capture| parameter is set and |fileTypes| has t
he appropriate MIME |
| 74 // type, we should just launch the appropriate intent. Otherwise build u
p a chooser based on | 75 // type, we should just launch the appropriate intent. Otherwise build u
p a chooser based on |
| 75 // the accept type and then display that to the user. | 76 // the accept type and then display that to the user. |
| 76 if (captureCamera()) { | 77 if (captureCamera()) { |
| 77 if (window.showIntent(camera, this, R.string.low_memory_error)) retu
rn; | 78 if (window.showIntent(camera, this, R.string.low_memory_error)) retu
rn; |
| 78 } else if (captureCamcorder()) { | 79 } else if (captureCamcorder()) { |
| 79 if (window.showIntent(camcorder, this, R.string.low_memory_error)) r
eturn; | 80 if (window.showIntent(camcorder, this, R.string.low_memory_error)) r
eturn; |
| 80 } else if (captureMicrophone()) { | 81 } else if (captureMicrophone()) { |
| 81 if (window.showIntent(soundRecorder, this, R.string.low_memory_error
)) return; | 82 if (window.showIntent(soundRecorder, this, R.string.low_memory_error
)) return; |
| 82 } | 83 } |
| 83 | 84 |
| 84 Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT); | 85 Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT); |
| 85 getContentIntent.addCategory(Intent.CATEGORY_OPENABLE); | 86 getContentIntent.addCategory(Intent.CATEGORY_OPENABLE); |
| 86 | 87 |
| 87 if (multiple) | 88 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && multi
ple) |
| 88 getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); | 89 getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); |
| 89 | 90 |
| 90 ArrayList<Intent> extraIntents = new ArrayList<Intent>(); | 91 ArrayList<Intent> extraIntents = new ArrayList<Intent>(); |
| 91 if (!noSpecificType()) { | 92 if (!noSpecificType()) { |
| 92 // Create a chooser based on the accept type that was specified in t
he webpage. Note | 93 // Create a chooser based on the accept type that was specified in t
he webpage. Note |
| 93 // that if the web page specified multiple accept types, we will hav
e built a generic | 94 // that if the web page specified multiple accept types, we will hav
e built a generic |
| 94 // chooser above. | 95 // chooser above. |
| 95 if (shouldShowImageTypes()) { | 96 if (shouldShowImageTypes()) { |
| 96 extraIntents.add(camera); | 97 extraIntents.add(camera); |
| 97 getContentIntent.setType(ALL_IMAGE_TYPES); | 98 getContentIntent.setType(ALL_IMAGE_TYPES); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 private static SelectFileDialog create(long nativeSelectFileDialog) { | 299 private static SelectFileDialog create(long nativeSelectFileDialog) { |
| 299 return new SelectFileDialog(nativeSelectFileDialog); | 300 return new SelectFileDialog(nativeSelectFileDialog); |
| 300 } | 301 } |
| 301 | 302 |
| 302 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, | 303 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, |
| 303 String filePath, String displayName); | 304 String filePath, String displayName); |
| 304 private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialo
gImpl, | 305 private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialo
gImpl, |
| 305 String[] filePathArray, String[] displayNameArray); | 306 String[] filePathArray, String[] displayNameArray); |
| 306 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl)
; | 307 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl)
; |
| 307 } | 308 } |
| OLD | NEW |