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 90564 ec0e723221aea85b7256a6f10510ccad08cd56fd
parent 90563 6b966ab71091c8a1373a5020e8006101be939c64
child 90565 884288acf326baa0b67133feb50cb5d686cf8701
push id1017
push userblassey@mozilla.com
push dateSat, 24 Mar 2012 05:27:08 +0000
treeherdermozilla-aurora@e14e81432a54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs734382
milestone13.0a2
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
@@ -2449,47 +2449,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!");