Bug 734382 - Don't show the list of activities if there is only one. r=blassey
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 14 Mar 2012 19:35:47 +0100
changeset 89663 7e8278f5e8142b0ca67473c1f94b5c155cfff921
parent 89662 b94319584a7a1e84a40d1e8f8316bb9856798874
child 89664 0b4e3c7608ab657bcfec929ffbc1ae3e6c659009
push id22269
push userphilringnalda@gmail.com
push dateSat, 17 Mar 2012 23:57:42 +0000
treeherdermozilla-central@8910001d4347 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs734382
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 734382 - Don't show the list of activities if there is only one. r=blassey
mobile/android/base/GeckoApp.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2451,47 +2451,63 @@ abstract public class GeckoApp
             return getString(R.string.filepicker_image_title);
         } else if (aMimeType.equals("video/*")) {
             return getString(R.string.filepicker_video_title);
         } else {
             return getString(R.string.filepicker_title);
         }
     }
 
-    private String mImageFilePath = "";
-    private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue<String>();
-
-    public String showFilePicker(String aMimeType) {
+    private Intent getFilePickerIntent(String aMimeType) {
         ArrayList<Intent> intents = new ArrayList<Intent>();
         PromptService.PromptListItem[] items = getItemsAndIntentsForFilePicker(aMimeType, intents);
 
+        if (intents.size() == 0) {
+            Log.i(LOGTAG, "no activities for the file picker!");
+            return null;
+        }
+
+        if (intents.size() == 1)
+            return intents.get(0);
+
         GeckoAppShell.getHandler().post(new FilePickerPromptRunnable(getFilePickerTitle(aMimeType), items));
 
         String promptServiceResult = "";
         try {
             promptServiceResult = PromptService.waitForReturn();
         } catch (InterruptedException e) {
             Log.e(LOGTAG, "showing prompt failed: ",  e);
-            return "";
+            return null;
         }
 
         int itemId = -1;
         try {
             itemId = new JSONObject(promptServiceResult).getInt("button");
 
             if (itemId == -1) {
-                return "";
+                return null;
             }
         } catch (org.json.JSONException e) {
             Log.e(LOGTAG, "result from promptservice was invalid: ", e);
+            return null;
+        }
+
+        return intents.get(itemId);
+    }
+
+    private String mImageFilePath = "";
+    private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue<String>();
+
+    public String showFilePicker(String aMimeType) {
+        Intent intent = getFilePickerIntent(aMimeType);
+
+        if (intent == null) {
             return "";
         }
 
-        Intent intent = intents.get(itemId);
-
         if (intent.getAction().equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE)) {
             startActivityForResult(intent, CAMERA_IMAGE_CAPTURE_REQUEST);
         } else if (intent.getAction().equals(android.provider.MediaStore.ACTION_VIDEO_CAPTURE)) {
             startActivityForResult(intent, CAMERA_VIDEO_CAPTURE_REQUEST);
         } else if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
             startActivityForResult(intent, FILE_PICKER_REQUEST);
         } else {
             Log.e(LOGTAG, "We should not get an intent with another action!");