OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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; | 5 package org.chromium.ui; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ContentResolver; | 8 import android.content.ContentResolver; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.database.Cursor; | 10 import android.database.Cursor; |
11 import android.net.Uri; | 11 import android.net.Uri; |
12 import android.os.Environment; | 12 import android.os.Environment; |
13 import android.provider.MediaStore; | 13 import android.provider.MediaStore; |
14 | 14 |
15 import java.io.File; | 15 import java.io.File; |
16 import java.util.ArrayList; | 16 import java.util.ArrayList; |
17 import java.util.Arrays; | 17 import java.util.Arrays; |
18 import java.util.List; | 18 import java.util.List; |
19 | 19 |
20 import org.chromium.base.CalledByNative; | 20 import org.chromium.base.CalledByNative; |
21 import org.chromium.base.JNINamespace; | 21 import org.chromium.base.JNINamespace; |
22 import org.chromium.ui.gfx.NativeWindow; | 22 import org.chromium.ui.gfx.WindowAndroid; |
23 | 23 |
24 /** | 24 /** |
25 * A dialog that is triggered from a file input field that allows a user to sele
ct a file based on | 25 * A dialog that is triggered from a file input field that allows a user to sele
ct a file based on |
26 * a set of accepted file types. The path of the selected file is passed to the
native dialog. | 26 * a set of accepted file types. The path of the selected file is passed to the
native dialog. |
27 */ | 27 */ |
28 @JNINamespace("ui") | 28 @JNINamespace("ui") |
29 class SelectFileDialog implements NativeWindow.IntentCallback{ | 29 class SelectFileDialog implements WindowAndroid.IntentCallback{ |
30 private static final String IMAGE_TYPE = "image/"; | 30 private static final String IMAGE_TYPE = "image/"; |
31 private static final String VIDEO_TYPE = "video/"; | 31 private static final String VIDEO_TYPE = "video/"; |
32 private static final String AUDIO_TYPE = "audio/"; | 32 private static final String AUDIO_TYPE = "audio/"; |
33 private static final String ALL_IMAGE_TYPES = IMAGE_TYPE + "*"; | 33 private static final String ALL_IMAGE_TYPES = IMAGE_TYPE + "*"; |
34 private static final String ALL_VIDEO_TYPES = VIDEO_TYPE + "*"; | 34 private static final String ALL_VIDEO_TYPES = VIDEO_TYPE + "*"; |
35 private static final String ALL_AUDIO_TYPES = AUDIO_TYPE + "*"; | 35 private static final String ALL_AUDIO_TYPES = AUDIO_TYPE + "*"; |
36 private static final String ANY_TYPES = "*/*"; | 36 private static final String ANY_TYPES = "*/*"; |
37 private static final String CAPTURE_CAMERA = "camera"; | 37 private static final String CAPTURE_CAMERA = "camera"; |
38 private static final String CAPTURE_CAMCORDER = "camcorder"; | 38 private static final String CAPTURE_CAMCORDER = "camcorder"; |
39 private static final String CAPTURE_MICROPHONE = "microphone"; | 39 private static final String CAPTURE_MICROPHONE = "microphone"; |
40 private static final String CAPTURE_FILESYSTEM = "filesystem"; | 40 private static final String CAPTURE_FILESYSTEM = "filesystem"; |
41 private static final String CAPTURE_IMAGE_DIRECTORY = "browser-photos"; | 41 private static final String CAPTURE_IMAGE_DIRECTORY = "browser-photos"; |
42 | 42 |
43 private final int mNativeSelectFileDialog; | 43 private final int mNativeSelectFileDialog; |
44 private List<String> mFileTypes; | 44 private List<String> mFileTypes; |
45 private String mCapture; // May be null if no capture parameter was set. | 45 private String mCapture; // May be null if no capture parameter was set. |
46 private Uri mCameraOutputUri; | 46 private Uri mCameraOutputUri; |
47 | 47 |
48 private SelectFileDialog(int nativeSelectFileDialog) { | 48 private SelectFileDialog(int nativeSelectFileDialog) { |
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 window The NativeWindow that can show intents | 56 * @param window The WindowAndroid that can show intents |
57 */ | 57 */ |
58 @CalledByNative | 58 @CalledByNative |
59 private void selectFile(String[] fileTypes, String capture, NativeWindow win
dow) { | 59 private void selectFile(String[] fileTypes, String capture, WindowAndroid wi
ndow) { |
60 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); | 60 mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); |
61 mCapture = capture; | 61 mCapture = capture; |
62 | 62 |
63 Intent chooser = new Intent(Intent.ACTION_CHOOSER); | 63 Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
64 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 64 Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
65 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); | 65 mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); |
66 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); | 66 camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); |
67 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | 67 Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
68 Intent soundRecorder = new Intent( | 68 Intent soundRecorder = new Intent( |
69 MediaStore.Audio.Media.RECORD_SOUND_ACTION); | 69 MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 /** | 134 /** |
135 * Callback method to handle the intent results and pass on the path to the
native | 135 * Callback method to handle the intent results and pass on the path to the
native |
136 * SelectFileDialog. | 136 * SelectFileDialog. |
137 * @param window The window that has access to the application activity. | 137 * @param window The window that has access to the application activity. |
138 * @param resultCode The result code whether the intent returned successfull
y. | 138 * @param resultCode The result code whether the intent returned successfull
y. |
139 * @param contentResolver The content resolver used to extract the path of t
he selected file. | 139 * @param contentResolver The content resolver used to extract the path of t
he selected file. |
140 * @param results The results of the requested intent. | 140 * @param results The results of the requested intent. |
141 */ | 141 */ |
142 @Override | 142 @Override |
143 public void onIntentCompleted(NativeWindow window, int resultCode, | 143 public void onIntentCompleted(WindowAndroid window, int resultCode, |
144 ContentResolver contentResolver, Intent results) { | 144 ContentResolver contentResolver, Intent results) { |
145 if (resultCode != Activity.RESULT_OK) { | 145 if (resultCode != Activity.RESULT_OK) { |
146 onFileNotSelected(); | 146 onFileNotSelected(); |
147 return; | 147 return; |
148 } | 148 } |
149 boolean success = false; | 149 boolean success = false; |
150 if (results == null) { | 150 if (results == null) { |
151 // If we have a successful return but no data, then assume this is t
he camera returning | 151 // If we have a successful return but no data, then assume this is t
he camera returning |
152 // the photo that we requested. | 152 // the photo that we requested. |
153 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa
th()); | 153 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa
th()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 @CalledByNative | 245 @CalledByNative |
246 private static SelectFileDialog create(int nativeSelectFileDialog) { | 246 private static SelectFileDialog create(int nativeSelectFileDialog) { |
247 return new SelectFileDialog(nativeSelectFileDialog); | 247 return new SelectFileDialog(nativeSelectFileDialog); |
248 } | 248 } |
249 | 249 |
250 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, | 250 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, |
251 String filePath); | 251 String filePath); |
252 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); | 252 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); |
253 } | 253 } |
OLD | NEW |