|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 package org.mozilla.gecko; |
|
6 |
|
7 import org.mozilla.gecko.util.ActivityResultHandler; |
|
8 import org.mozilla.gecko.util.ActivityResultHandlerMap; |
|
9 |
|
10 import android.app.Activity; |
|
11 import android.content.Intent; |
|
12 |
|
13 public class ActivityHandlerHelper { |
|
14 private static final String LOGTAG = "GeckoActivityHandlerHelper"; |
|
15 private static final ActivityResultHandlerMap mActivityResultHandlerMap = new ActivityResultHandlerMap(); |
|
16 |
|
17 private static int makeRequestCode(ActivityResultHandler aHandler) { |
|
18 return mActivityResultHandlerMap.put(aHandler); |
|
19 } |
|
20 |
|
21 public static void startIntent(Intent intent, ActivityResultHandler activityResultHandler) { |
|
22 startIntentForActivity(GeckoAppShell.getGeckoInterface().getActivity(), intent, activityResultHandler); |
|
23 } |
|
24 |
|
25 public static void startIntentForActivity(Activity activity, Intent intent, ActivityResultHandler activityResultHandler) { |
|
26 activity.startActivityForResult(intent, mActivityResultHandlerMap.put(activityResultHandler)); |
|
27 } |
|
28 |
|
29 |
|
30 public static boolean handleActivityResult(int requestCode, int resultCode, Intent data) { |
|
31 ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode); |
|
32 if (handler != null) { |
|
33 handler.onActivityResult(resultCode, data); |
|
34 return true; |
|
35 } |
|
36 return false; |
|
37 } |
|
38 } |