2012-07-13 11:07:43 -07: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 10:33:44 -07:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
|
|
|
import org.mozilla.gecko.util.ActivityResultHandlerMap;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-07-13 11:07:43 -07:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2014-02-14 12:02:05 -08:00
|
|
|
public class ActivityHandlerHelper {
|
2012-07-13 11:07:43 -07:00
|
|
|
private static final String LOGTAG = "GeckoActivityHandlerHelper";
|
2014-02-14 12:02:05 -08:00
|
|
|
private static final ActivityResultHandlerMap mActivityResultHandlerMap = new ActivityResultHandlerMap();
|
2012-07-13 11:07:43 -07:00
|
|
|
|
2014-02-14 12:02:05 -08:00
|
|
|
private static int makeRequestCode(ActivityResultHandler aHandler) {
|
2012-12-28 13:46:08 -08:00
|
|
|
return mActivityResultHandlerMap.put(aHandler);
|
|
|
|
}
|
|
|
|
|
2014-02-14 12:02:05 -08:00
|
|
|
public static void startIntent(Intent intent, ActivityResultHandler activityResultHandler) {
|
|
|
|
startIntentForActivity(GeckoAppShell.getGeckoInterface().getActivity(), intent, activityResultHandler);
|
2013-05-29 08:08:55 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 12:02:05 -08:00
|
|
|
public static void startIntentForActivity(Activity activity, Intent intent, ActivityResultHandler activityResultHandler) {
|
|
|
|
activity.startActivityForResult(intent, mActivityResultHandlerMap.put(activityResultHandler));
|
2013-05-29 08:08:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-14 12:02:05 -08:00
|
|
|
public static boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
2012-07-13 11:07:43 -07:00
|
|
|
ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode);
|
|
|
|
if (handler != null) {
|
|
|
|
handler.onActivityResult(resultCode, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|