diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java index 90215244..13cd2dc7 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java @@ -18,10 +18,12 @@ import android.widget.BaseAdapter; import android.widget.TextView; import android.widget.Toast; +import com.cradle.iitc_mobile.IITC_Mobile.ResponseHandler; + /** * this class manages automatic login using the Google account stored on the device */ -public class IITC_DeviceAccountLogin implements AccountManagerCallback { +public class IITC_DeviceAccountLogin implements AccountManagerCallback, ResponseHandler { /** * Adapter to show available accounts in a ListView. Accounts are read from mAccounts */ @@ -126,6 +128,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback { /** * called by IITC_Mobile when the authentication activity has finished. */ + @Override public void onActivityResult(int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) // authentication activity succeeded, request token again @@ -149,7 +152,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback { // There is a reason we need to start the given activity if we want an // authentication token. (Could be user confirmation or something else. Whatever, // we have to start it) IITC_Mobile will call it using startActivityForResult - mActivity.startLoginActivity(launch); + mActivity.startActivityForResult(launch, this); return; } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 561bd420..a64a0087 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -42,10 +42,9 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.Stack; +import java.util.Vector; public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener { - - private static final int REQUEST_LOGIN = 1; private static final String mIntelUrl = "https://www.ingress.com/intel"; private SharedPreferences mSharedPrefs; @@ -55,6 +54,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis private IITC_NavigationHelper mNavigationHelper; private IITC_MapSettings mMapSettings; private IITC_DeviceAccountLogin mLogin; + private Vector mResponseHandlers = new Vector(); private boolean mDesktopMode = false; private boolean mAdvancedMenu = false; private MenuItem mSearchMenuItem; @@ -572,23 +572,25 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis return this.mIitcWebView; } - /** - * It can occur that in order to authenticate, an external activity has to be launched. - * (This could for example be a confirmation dialog.) - */ - public void startLoginActivity(Intent launch) { - startActivityForResult(launch, REQUEST_LOGIN); // REQUEST_LOGIN is to recognize the result + public void startActivityForResult(Intent launch, ResponseHandler handler) { + int index = mResponseHandlers.indexOf(handler); + if (index == -1) { + mResponseHandlers.add(handler); + index = mResponseHandlers.indexOf(handler); + } + + startActivityForResult(launch, RESULT_FIRST_USER + index); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_LOGIN: - // authentication activity has returned. mLogin will continue authentication - mLogin.onActivityResult(resultCode, data); - break; - default: - super.onActivityResult(requestCode, resultCode, data); + int index = requestCode - RESULT_FIRST_USER; + + try { + ResponseHandler handler = mResponseHandlers.get(index); + handler.onActivityResult(resultCode, data); + } catch (ArrayIndexOutOfBoundsException e) { + super.onActivityResult(requestCode, resultCode, data); } } @@ -764,4 +766,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis public IITC_UserLocation getUserLocation() { return mUserLocation; } + + public interface ResponseHandler { + void onActivityResult(int resultCode, Intent data); + } }