1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/ActivityHandlerHelper.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,38 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko; 1.9 + 1.10 +import org.mozilla.gecko.util.ActivityResultHandler; 1.11 +import org.mozilla.gecko.util.ActivityResultHandlerMap; 1.12 + 1.13 +import android.app.Activity; 1.14 +import android.content.Intent; 1.15 + 1.16 +public class ActivityHandlerHelper { 1.17 + private static final String LOGTAG = "GeckoActivityHandlerHelper"; 1.18 + private static final ActivityResultHandlerMap mActivityResultHandlerMap = new ActivityResultHandlerMap(); 1.19 + 1.20 + private static int makeRequestCode(ActivityResultHandler aHandler) { 1.21 + return mActivityResultHandlerMap.put(aHandler); 1.22 + } 1.23 + 1.24 + public static void startIntent(Intent intent, ActivityResultHandler activityResultHandler) { 1.25 + startIntentForActivity(GeckoAppShell.getGeckoInterface().getActivity(), intent, activityResultHandler); 1.26 + } 1.27 + 1.28 + public static void startIntentForActivity(Activity activity, Intent intent, ActivityResultHandler activityResultHandler) { 1.29 + activity.startActivityForResult(intent, mActivityResultHandlerMap.put(activityResultHandler)); 1.30 + } 1.31 + 1.32 + 1.33 + public static boolean handleActivityResult(int requestCode, int resultCode, Intent data) { 1.34 + ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode); 1.35 + if (handler != null) { 1.36 + handler.onActivityResult(resultCode, data); 1.37 + return true; 1.38 + } 1.39 + return false; 1.40 + } 1.41 +}