2012-07-13 18:07:43 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-08-02 17:33:44 +00:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
|
|
|
import org.mozilla.gecko.util.ActivityResultHandlerMap;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
2012-07-13 18:07:43 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
2014-02-14 20:02:05 +00:00
|
|
|
public class ActivityHandlerHelper {
|
2012-07-13 18:07:43 +00:00
|
|
|
private static final String LOGTAG = "GeckoActivityHandlerHelper";
|
2014-02-14 20:02:05 +00:00
|
|
|
private static final ActivityResultHandlerMap mActivityResultHandlerMap = new ActivityResultHandlerMap();
|
2012-07-13 18:07:43 +00:00
|
|
|
|
2014-02-14 20:02:05 +00:00
|
|
|
private static int makeRequestCode(ActivityResultHandler aHandler) {
|
2012-12-28 21:46:08 +00:00
|
|
|
return mActivityResultHandlerMap.put(aHandler);
|
|
|
|
}
|
|
|
|
|
2014-02-14 20:02:05 +00:00
|
|
|
public static void startIntent(Intent intent, ActivityResultHandler activityResultHandler) {
|
|
|
|
startIntentForActivity(GeckoAppShell.getGeckoInterface().getActivity(), intent, activityResultHandler);
|
2013-05-29 15:08:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 20:02:05 +00:00
|
|
|
public static void startIntentForActivity(Activity activity, Intent intent, ActivityResultHandler activityResultHandler) {
|
|
|
|
activity.startActivityForResult(intent, mActivityResultHandlerMap.put(activityResultHandler));
|
2013-05-29 15:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-14 20:02:05 +00:00
|
|
|
public static boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
2012-07-13 18:07:43 +00:00
|
|
|
ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode);
|
|
|
|
if (handler != null) {
|
|
|
|
handler.onActivityResult(resultCode, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|