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.Manifest; | 7 import android.Manifest; |
| 8 import android.annotation.SuppressLint; | 8 import android.annotation.SuppressLint; |
| 9 import android.annotation.TargetApi; | 9 import android.annotation.TargetApi; |
| 10 import android.app.Activity; | 10 import android.app.Activity; |
| 11 import android.content.ClipData; | 11 import android.content.ClipData; |
| 12 import android.content.ContentResolver; | 12 import android.content.ContentResolver; |
| 13 import android.content.Context; | 13 import android.content.Context; |
| 14 import android.content.Intent; | 14 import android.content.Intent; |
| 15 import android.content.pm.PackageManager; | 15 import android.content.pm.PackageManager; |
| 16 import android.net.Uri; | 16 import android.net.Uri; |
| 17 import android.os.AsyncTask; | 17 import android.os.AsyncTask; |
| 18 import android.os.Build; | 18 import android.os.Build; |
| 19 import android.provider.MediaStore; | 19 import android.provider.MediaStore; |
| 20 import android.text.TextUtils; | 20 import android.text.TextUtils; |
| 21 import android.webkit.MimeTypeMap; | |
| 21 | 22 |
| 22 import org.chromium.base.ApiCompatibilityUtils; | 23 import org.chromium.base.ApiCompatibilityUtils; |
| 23 import org.chromium.base.ContentUriUtils; | 24 import org.chromium.base.ContentUriUtils; |
| 24 import org.chromium.base.ContextUtils; | 25 import org.chromium.base.ContextUtils; |
| 25 import org.chromium.base.Log; | 26 import org.chromium.base.Log; |
| 26 import org.chromium.base.ThreadUtils; | 27 import org.chromium.base.ThreadUtils; |
| 27 import org.chromium.base.VisibleForTesting; | 28 import org.chromium.base.VisibleForTesting; |
| 28 import org.chromium.base.annotations.CalledByNative; | 29 import org.chromium.base.annotations.CalledByNative; |
| 29 import org.chromium.base.annotations.JNINamespace; | 30 import org.chromium.base.annotations.JNINamespace; |
| 30 import org.chromium.base.annotations.MainDex; | 31 import org.chromium.base.annotations.MainDex; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 if (extraIntents.isEmpty()) { | 245 if (extraIntents.isEmpty()) { |
| 245 // We couldn't resolve an accept type, so fallback to a generic choo ser. | 246 // We couldn't resolve an accept type, so fallback to a generic choo ser. |
| 246 getContentIntent.setType(ANY_TYPES); | 247 getContentIntent.setType(ANY_TYPES); |
| 247 if (camera != null) extraIntents.add(camera); | 248 if (camera != null) extraIntents.add(camera); |
| 248 if (camcorder != null) extraIntents.add(camcorder); | 249 if (camcorder != null) extraIntents.add(camcorder); |
| 249 if (soundRecorder != null) extraIntents.add(soundRecorder); | 250 if (soundRecorder != null) extraIntents.add(soundRecorder); |
| 250 } | 251 } |
| 251 | 252 |
| 252 // Use new photo picker, if available. | 253 // Use new photo picker, if available. |
| 253 Activity activity = mWindowAndroid.getActivity().get(); | 254 Activity activity = mWindowAndroid.getActivity().get(); |
| 254 if (activity != null && UiUtils.showPhotoPicker(activity, this, mAllowMu ltiple)) { | 255 if (activity != null && usePhotoPicker() |
|
Ted C
2017/05/26 20:21:14
Could usePhotoPicker() be:
TextUtils.equals(getCo
Finnur
2017/05/29 15:18:36
I don't see how that can work.
There's two ways
Ted C
2017/05/30 04:20:52
If that is the case, then I'd argue the previous/e
Finnur
2017/05/30 11:16:10
I tend to agree with you. I suspect the previous b
| |
| 256 && UiUtils.showPhotoPicker(activity, this, mAllowMultiple)) { | |
| 255 return; | 257 return; |
| 256 } | 258 } |
| 257 | 259 |
| 258 Intent chooser = new Intent(Intent.ACTION_CHOOSER); | 260 Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
| 259 if (!extraIntents.isEmpty()) { | 261 if (!extraIntents.isEmpty()) { |
| 260 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, | 262 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, |
| 261 extraIntents.toArray(new Intent[] { })); | 263 extraIntents.toArray(new Intent[] { })); |
| 262 } | 264 } |
| 263 chooser.putExtra(Intent.EXTRA_INTENT, getContentIntent); | 265 chooser.putExtra(Intent.EXTRA_INTENT, getContentIntent); |
| 264 | 266 |
| 265 if (!mWindowAndroid.showIntent(chooser, this, R.string.low_memory_error) ) { | 267 if (!mWindowAndroid.showIntent(chooser, this, R.string.low_memory_error) ) { |
| 266 onFileNotSelected(); | 268 onFileNotSelected(); |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 | 271 |
| 272 /** | |
| 273 * Determines if a photo picker can be used instead of the stock Android pic ker. | |
| 274 * @return True if only images types are being requested. | |
| 275 * | |
|
Ted C
2017/05/26 20:21:14
remove extra blank line
Finnur
2017/05/29 15:18:36
Done.
| |
| 276 */ | |
| 277 private boolean usePhotoPicker() { | |
| 278 boolean usePhotoPicker = false; | |
| 279 for (String type : mFileTypes) { | |
| 280 String mimeType; | |
| 281 if (type.startsWith(".")) { | |
| 282 String extension = type.substring(1, type.length()); | |
| 283 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(e xtension); | |
| 284 } else { | |
| 285 mimeType = type; | |
| 286 } | |
| 287 usePhotoPicker = mimeType != null && mimeType.startsWith("image/"); | |
| 288 } | |
| 289 return usePhotoPicker; | |
| 290 } | |
| 291 | |
| 270 @Override | 292 @Override |
| 271 public void onPickerUserAction(Action action, String[] photos) { | 293 public void onPickerUserAction(Action action, String[] photos) { |
| 272 UiUtils.dismissPhotoPicker(); | 294 UiUtils.dismissPhotoPicker(); |
| 273 | 295 |
| 274 switch (action) { | 296 switch (action) { |
| 275 case CANCEL: | 297 case CANCEL: |
| 276 onFileNotSelected(); | 298 onFileNotSelected(); |
| 277 break; | 299 break; |
| 278 | 300 |
| 279 case PHOTOS_SELECTED: | 301 case PHOTOS_SELECTED: |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 static SelectFileDialog create(long nativeSelectFileDialog) { | 674 static SelectFileDialog create(long nativeSelectFileDialog) { |
| 653 return new SelectFileDialog(nativeSelectFileDialog); | 675 return new SelectFileDialog(nativeSelectFileDialog); |
| 654 } | 676 } |
| 655 | 677 |
| 656 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, | 678 private native void nativeOnFileSelected(long nativeSelectFileDialogImpl, |
| 657 String filePath, String displayName); | 679 String filePath, String displayName); |
| 658 private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialo gImpl, | 680 private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialo gImpl, |
| 659 String[] filePathArray, String[] displayNameArray); | 681 String[] filePathArray, String[] displayNameArray); |
| 660 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; | 682 private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl) ; |
| 661 } | 683 } |
| OLD | NEW |