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; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 * @param contentResolver The content resolver used to extract the path of t
he selected file. | 137 * @param contentResolver The content resolver used to extract the path of t
he selected file. |
138 * @param results The results of the requested intent. | 138 * @param results The results of the requested intent. |
139 */ | 139 */ |
140 @Override | 140 @Override |
141 public void onIntentCompleted(WindowAndroid window, int resultCode, | 141 public void onIntentCompleted(WindowAndroid window, int resultCode, |
142 ContentResolver contentResolver, Intent results) { | 142 ContentResolver contentResolver, Intent results) { |
143 if (resultCode != Activity.RESULT_OK) { | 143 if (resultCode != Activity.RESULT_OK) { |
144 onFileNotSelected(); | 144 onFileNotSelected(); |
145 return; | 145 return; |
146 } | 146 } |
147 boolean success = false; | 147 |
148 if (results == null) { | 148 if (results == null) { |
149 // If we have a successful return but no data, then assume this is t
he camera returning | 149 // If we have a successful return but no data, then assume this is t
he camera returning |
150 // the photo that we requested. | 150 // the photo that we requested. |
151 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa
th()); | 151 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa
th()); |
152 success = true; | |
153 | 152 |
154 // Broadcast to the media scanner that there's a new photo on the de
vice so it will | 153 // Broadcast to the media scanner that there's a new photo on the de
vice so it will |
155 // show up right away in the gallery (rather than waiting until the
next time the media | 154 // show up right away in the gallery (rather than waiting until the
next time the media |
156 // scanner runs). | 155 // scanner runs). |
157 window.sendBroadcast(new Intent( | 156 window.sendBroadcast(new Intent( |
158 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); | 157 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); |
159 } else { | 158 return; |
| 159 } |
| 160 |
| 161 if ("file".equals(results.getData().getScheme())) { |
| 162 nativeOnFileSelected(mNativeSelectFileDialog, |
| 163 results.getData().getSchemeSpecificPart()); |
| 164 return; |
| 165 } |
| 166 |
| 167 Cursor cursor = null; |
| 168 try { |
160 // We get back a content:// URI from the system if the user picked a
file from the | 169 // We get back a content:// URI from the system if the user picked a
file from the |
161 // gallery. The ContentView has functionality that will convert that
content:// URI to | 170 // gallery. The ContentView has functionality that will convert that
content:// URI to |
162 // a file path on disk that Chromium understands. | 171 // a file path on disk that Chromium understands. |
163 Cursor c = contentResolver.query(results.getData(), | 172 cursor = contentResolver.query(results.getData(), |
164 new String[] { MediaStore.MediaColumns.DATA }, null, null, n
ull); | 173 new String[] { MediaStore.MediaColumns.DATA }, null, null, n
ull); |
165 if (c != null) { | 174 if (cursor != null) { |
166 if (c.getCount() == 1) { | 175 if (cursor.getCount() == 1) { |
167 c.moveToFirst(); | 176 cursor.moveToFirst(); |
168 String path = c.getString(0); | 177 String path = cursor.getString(0); |
169 if (path != null) { | 178 if (path != null) { |
170 // Not all providers support the MediaStore.DATA column.
For example, | 179 // Not all providers support the MediaStore.DATA column.
For example, |
171 // Gallery3D (com.android.gallery3d.provider) does not s
upport it for | 180 // Gallery3D (com.android.gallery3d.provider) does not s
upport it for |
172 // Picasa Web Album images. | 181 // Picasa Web Album images. |
173 nativeOnFileSelected(mNativeSelectFileDialog, path); | 182 nativeOnFileSelected(mNativeSelectFileDialog, path); |
174 success = true; | 183 return; |
175 } | 184 } |
176 } | 185 } |
177 c.close(); | |
178 } | 186 } |
179 } | 187 } finally { if (cursor != null) { cursor.close(); } } |
180 if (!success) { | 188 |
181 onFileNotSelected(); | 189 onFileNotSelected(); |
182 window.showError(R.string.opening_file_error); | 190 window.showError(R.string.opening_file_error); |
183 } | |
184 } | 191 } |
185 | 192 |
186 private void onFileNotSelected() { | 193 private void onFileNotSelected() { |
187 nativeOnFileNotSelected(mNativeSelectFileDialog); | 194 nativeOnFileNotSelected(mNativeSelectFileDialog); |
188 } | 195 } |
189 | 196 |
190 private boolean noSpecificType() { | 197 private boolean noSpecificType() { |
191 // We use a single Intent to decide the type of the file chooser we disp
lay to the user, | 198 // We use a single Intent to decide the type of the file chooser we disp
lay to the user, |
192 // which means we can only give it a single type. If there are multiple
accept types | 199 // which means we can only give it a single type. If there are multiple
accept types |
193 // specified, we will fallback to a generic chooser (unless a capture pa
rameter has been | 200 // specified, we will fallback to a generic chooser (unless a capture pa
rameter has been |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 246 |
240 @CalledByNative | 247 @CalledByNative |
241 private static SelectFileDialog create(int nativeSelectFileDialog) { | 248 private static SelectFileDialog create(int nativeSelectFileDialog) { |
242 return new SelectFileDialog(nativeSelectFileDialog); | 249 return new SelectFileDialog(nativeSelectFileDialog); |
243 } | 250 } |
244 | 251 |
245 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, | 252 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, |
246 String filePath); | 253 String filePath); |
247 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); | 254 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); |
248 } | 255 } |
OLD | NEW |