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())) { | |
aurimas (slooooooooow)
2013/11/05 20:52:07
Should pull "file" out as a constant.
Miguel Garcia
2013/11/06 18:07:51
Really? In this case it just seems an overkill. I
Ted C
2013/11/08 17:00:13
I hit this same issue anytime I want to check agai
Miguel Garcia
2013/11/09 07:09:08
Ok, will leave it as is then.
On 2013/11/08 17:00
| |
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(); | 186 } |
187 } finally { | |
188 if (cursor != null) { | |
189 cursor.close(); | |
Ted C
2013/11/08 17:00:13
this could all fit on one line
Miguel Garcia
2013/11/09 07:09:08
Done.
| |
178 } | 190 } |
179 } | 191 } |
180 if (!success) { | 192 |
181 onFileNotSelected(); | 193 onFileNotSelected(); |
182 window.showError(R.string.opening_file_error); | 194 window.showError(R.string.opening_file_error); |
183 } | |
184 } | 195 } |
185 | 196 |
186 private void onFileNotSelected() { | 197 private void onFileNotSelected() { |
187 nativeOnFileNotSelected(mNativeSelectFileDialog); | 198 nativeOnFileNotSelected(mNativeSelectFileDialog); |
188 } | 199 } |
189 | 200 |
190 private boolean noSpecificType() { | 201 private boolean noSpecificType() { |
191 // We use a single Intent to decide the type of the file chooser we disp lay to the user, | 202 // 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 | 203 // 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 | 204 // 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 | 250 |
240 @CalledByNative | 251 @CalledByNative |
241 private static SelectFileDialog create(int nativeSelectFileDialog) { | 252 private static SelectFileDialog create(int nativeSelectFileDialog) { |
242 return new SelectFileDialog(nativeSelectFileDialog); | 253 return new SelectFileDialog(nativeSelectFileDialog); |
243 } | 254 } |
244 | 255 |
245 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, | 256 private native void nativeOnFileSelected(int nativeSelectFileDialogImpl, |
246 String filePath); | 257 String filePath); |
247 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); | 258 private native void nativeOnFileNotSelected(int nativeSelectFileDialogImpl); |
248 } | 259 } |
OLD | NEW |