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.ContentResolver; | 8 import android.content.ContentResolver; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.database.Cursor; | |
| 10 import android.net.Uri; | 11 import android.net.Uri; |
| 11 import android.os.Environment; | 12 import android.os.Environment; |
| 12 import android.provider.MediaStore; | 13 import android.provider.MediaStore; |
| 13 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 14 | 15 |
| 15 import org.chromium.base.CalledByNative; | 16 import org.chromium.base.CalledByNative; |
| 16 import org.chromium.base.JNINamespace; | 17 import org.chromium.base.JNINamespace; |
| 17 import org.chromium.ui.R; | 18 import org.chromium.ui.R; |
| 18 | 19 |
| 19 import java.io.File; | 20 import java.io.File; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 File.separator + CAPTURE_IMAGE_DIRECTORY); | 123 File.separator + CAPTURE_IMAGE_DIRECTORY); |
| 123 if (!cameraDataDir.exists() && !cameraDataDir.mkdirs()) { | 124 if (!cameraDataDir.exists() && !cameraDataDir.mkdirs()) { |
| 124 cameraDataDir = externalDataDir; | 125 cameraDataDir = externalDataDir; |
| 125 } | 126 } |
| 126 File photoFile = new File(cameraDataDir.getAbsolutePath() + | 127 File photoFile = new File(cameraDataDir.getAbsolutePath() + |
| 127 File.separator + System.currentTimeMillis() + ".jpg"); | 128 File.separator + System.currentTimeMillis() + ".jpg"); |
| 128 return photoFile; | 129 return photoFile; |
| 129 } | 130 } |
| 130 | 131 |
| 131 /** | 132 /** |
| 133 * @return the display name of the @code uri if present in the data base | |
| 134 * or an empty string otherwise. | |
| 135 */ | |
| 136 private String resolveFileName(Uri uri, ContentResolver contentResolver) { | |
| 137 Cursor cursor = null; | |
| 138 try { | |
| 139 cursor = contentResolver.query(uri, null, null, null, null); | |
| 140 | |
| 141 if (cursor != null && cursor.getCount() >= 1) { | |
| 142 cursor.moveToFirst(); | |
| 143 int index = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLA Y_NAME); | |
| 144 if (index > -1) { | |
| 145 return cursor.getString(index); | |
| 146 } | |
| 147 } | |
| 148 } finally { | |
| 149 if (cursor != null ) { | |
| 150 cursor.close(); | |
| 151 } | |
| 152 } | |
| 153 return ""; | |
| 154 } | |
| 155 | |
| 156 /** | |
| 132 * Callback method to handle the intent results and pass on the path to the native | 157 * Callback method to handle the intent results and pass on the path to the native |
| 133 * SelectFileDialog. | 158 * SelectFileDialog. |
| 134 * @param window The window that has access to the application activity. | 159 * @param window The window that has access to the application activity. |
| 135 * @param resultCode The result code whether the intent returned successfull y. | 160 * @param resultCode The result code whether the intent returned successfull y. |
| 136 * @param contentResolver The content resolver used to extract the path of t he selected file. | 161 * @param contentResolver The content resolver used to extract the path of t he selected file. |
| 137 * @param results The results of the requested intent. | 162 * @param results The results of the requested intent. |
| 138 */ | 163 */ |
| 139 @Override | 164 @Override |
| 140 public void onIntentCompleted(WindowAndroid window, int resultCode, | 165 public void onIntentCompleted(WindowAndroid window, int resultCode, |
| 141 ContentResolver contentResolver, Intent results) { | 166 ContentResolver contentResolver, Intent results) { |
| 142 if (resultCode != Activity.RESULT_OK) { | 167 if (resultCode != Activity.RESULT_OK) { |
| 143 onFileNotSelected(); | 168 onFileNotSelected(); |
| 144 return; | 169 return; |
| 145 } | 170 } |
| 146 | 171 |
| 147 if (results == null) { | 172 if (results == null) { |
| 148 // If we have a successful return but no data, then assume this is t he camera returning | 173 // If we have a successful return but no data, then assume this is t he camera returning |
| 149 // the photo that we requested. | 174 // the photo that we requested. |
| 150 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa th()); | 175 nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPa th(), ""); |
| 151 | 176 |
| 152 // Broadcast to the media scanner that there's a new photo on the de vice so it will | 177 // Broadcast to the media scanner that there's a new photo on the de vice so it will |
| 153 // show up right away in the gallery (rather than waiting until the next time the media | 178 // show up right away in the gallery (rather than waiting until the next time the media |
| 154 // scanner runs). | 179 // scanner runs). |
| 155 window.sendBroadcast(new Intent( | 180 window.sendBroadcast(new Intent( |
| 156 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); | 181 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraOutputUri)); |
| 157 return; | 182 return; |
| 158 } | 183 } |
| 159 | 184 |
| 160 if ("file".equals(results.getData().getScheme())) { | 185 if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) { |
| 161 nativeOnFileSelected(mNativeSelectFileDialog, | 186 nativeOnFileSelected(mNativeSelectFileDialog, |
| 162 results.getData().getSchemeSpecificPart()); | 187 results.getData().getSchemeSpecificPart(), ""); |
| 163 return; | 188 return; |
| 164 } | 189 } |
| 165 | 190 |
| 166 if (results.getScheme() != null | 191 if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) { |
| 167 && results.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { | 192 nativeOnFileSelected(mNativeSelectFileDialog, |
| 168 nativeOnFileSelected(mNativeSelectFileDialog, results.getData().toSt ring()); | 193 results.getData().toString(), |
|
qinmin
2014/01/31 16:17:29
nit: align with mNativeSelectFileDialog here and b
Miguel Garcia
2014/01/31 16:35:48
Done.
| |
| 194 resolveFileName(results.getData(), contentResolver)); | |
| 169 return; | 195 return; |
| 170 } | 196 } |
| 171 | 197 |
| 172 onFileNotSelected(); | 198 onFileNotSelected(); |
| 173 window.showError(R.string.opening_file_error); | 199 window.showError(R.string.opening_file_error); |
| 174 } | 200 } |
| 175 | 201 |
| 176 private void onFileNotSelected() { | 202 private void onFileNotSelected() { |
| 177 nativeOnFileNotSelected(mNativeSelectFileDialog); | 203 nativeOnFileNotSelected(mNativeSelectFileDialog); |
| 178 } | 204 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 } | 252 } |
| 227 return false; | 253 return false; |
| 228 } | 254 } |
| 229 | 255 |
| 230 @CalledByNative | 256 @CalledByNative |
| 231 private static SelectFileDialog create(long nativeSelectFileDialog) { | 257 private static SelectFileDialog create(long nativeSelectFileDialog) { |
| 232 return new SelectFileDialog(nativeSelectFileDialog); | 258 return new SelectFileDialog(nativeSelectFileDialog); |
| 233 } | 259 } |
| 234 | 260 |
| 235 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, | 261 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, |
| 236 String filePath); | 262 String filePath, String displayName); |
| 237 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; | 263 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; |
| 238 } | 264 } |
| OLD | NEW |