Bug 860879 - Make file picker use public PromptService.getResponse method; r=wesj
authorJim Chen <nchen@mozilla.com>
Thu, 09 May 2013 21:47:59 -0400
changeset 142413 397da5eb63b23d9b76a3b2f38b9c74dd30f2efac
parent 142412 73316004a0494bdd91752a0053fa3f6ac906f74a
child 142414 3c189f66a528ba6edd8e01dd4a6c018557205818
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs860879
milestone23.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 860879 - Make file picker use public PromptService.getResponse method; r=wesj
mobile/android/base/ActivityHandlerHelper.java
--- a/mobile/android/base/ActivityHandlerHelper.java
+++ b/mobile/android/base/ActivityHandlerHelper.java
@@ -136,38 +136,40 @@ public class ActivityHandlerHelper {
             return context.getString(R.string.filepicker_video_title);
         } else {
             return context.getString(R.string.filepicker_title);
         }
     }
 
     private Intent getFilePickerIntent(Context context, String aMimeType) {
         ArrayList<Intent> intents = new ArrayList<Intent>();
-        PromptService.PromptListItem[] items = getItemsAndIntentsForFilePicker(context, aMimeType, intents);
+        final PromptService.PromptListItem[] items =
+            getItemsAndIntentsForFilePicker(context, 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);
         }
 
-        Runnable filePicker = new FilePickerPromptRunnable(getFilePickerTitle(context, aMimeType), items);
-        ThreadUtils.postToUiThread(filePicker);
+        final PromptService ps = GeckoApp.mAppContext.getPromptService();
+        final String title = getFilePickerTitle(context, aMimeType);
 
-        String promptServiceResult = "";
-        try {
-            promptServiceResult = PromptService.waitForReturn();
-        } catch (InterruptedException e) {
-            Log.e(LOGTAG, "showing prompt failed: ",  e);
-            return null;
-        }
+        // Runnable has to be called to show an intent-like
+        // context menu UI using the PromptService.
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override public void run() {
+                ps.show(title, "", items, false);
+            }
+        });
 
+        String promptServiceResult = ps.getResponse();
         int itemId = -1;
         try {
             itemId = new JSONObject(promptServiceResult).getInt("button");
 
             if (itemId == -1) {
                 return null;
             }
         } catch (JSONException e) {
@@ -222,28 +224,9 @@ public class ActivityHandlerHelper {
     boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
         ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode);
         if (handler != null) {
             handler.onActivityResult(resultCode, data);
             return true;
         }
         return false;
     }
-
-    /**
-     * The FilePickerPromptRunnable has to be called to show an intent-like
-     * context menu UI using the PromptService.
-     */
-    private static class FilePickerPromptRunnable implements Runnable {
-        private final String mTitle;
-        private final PromptService.PromptListItem[] mItems;
-
-        public FilePickerPromptRunnable(String aTitle, PromptService.PromptListItem[] aItems) {
-            mTitle = aTitle;
-            mItems = aItems;
-        }
-
-        @Override
-        public void run() {
-            GeckoApp.mAppContext.getPromptService().show(mTitle, "", mItems, false);
-        }
-    }
 }