Skip to content

Commit

Permalink
fix issue with autosignIn
Browse files Browse the repository at this point in the history
  • Loading branch information
FreshTiti committed Nov 15, 2013
1 parent 93aa4f6 commit cabaf6a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.freshplanet.ane.AirGooglePlayGames
{
import flash.display.BitmapData;
import flash.events.EventDispatcher;
import flash.events.StatusEvent;
import flash.external.ExtensionContext;
Expand Down Expand Up @@ -63,11 +62,11 @@ package com.freshplanet.ane.AirGooglePlayGames
return _instance ? _instance : new AirGooglePlayGames();
}

public function startAtLaunch(wasSignedIn:Boolean):void
public function startAtLaunch():void
{
if (AirGooglePlayGames.isSupported)
{
_context.call("startAtLaunch", wasSignedIn);
_context.call("startAtLaunch");
}
}

Expand Down
42 changes: 35 additions & 7 deletions android/src/com/freshplanet/googleplaygames/ExtensionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package com.freshplanet.googleplaygames;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
Expand All @@ -32,6 +34,7 @@
import com.freshplanet.googleplaygames.functions.AirGooglePlayGamesShowAchievementsFunction;
import com.freshplanet.googleplaygames.functions.AirGooglePlayGamesSignInFunction;
import com.freshplanet.googleplaygames.functions.AirGooglePlayGamesSignOutFunction;
import com.freshplanet.googleplaygames.functions.AirGooglePlayStartAtLaunch;
import com.google.android.gms.games.GamesClient;

public class ExtensionContext extends FREContext implements GameHelper.GameHelperListener
Expand All @@ -42,16 +45,14 @@ public class ExtensionContext extends FREContext implements GameHelper.GameHelpe

public static GameHelper mHelper;

public static boolean AUTOSIGNIN;

@Override
public void dispose() { }

@Override
public Map<String, FREFunction> getFunctions()
{
Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
functionMap.put("startAtLaunch", new AirGooglePlayGamesSignInFunction());
functionMap.put("startAtLaunch", new AirGooglePlayStartAtLaunch());
functionMap.put("signIn", new AirGooglePlayGamesSignInFunction());
functionMap.put("signOut", new AirGooglePlayGamesSignOutFunction());
functionMap.put("reportAchievemnt", new AirGooglePlayGamesReportAchievementFunction());
Expand Down Expand Up @@ -87,17 +88,22 @@ public GameHelper createHelperIfNeeded(Activity activity)
if (mHelper == null)
{
logEvent("create helper");
mHelper = new GameHelper(activity, AUTOSIGNIN);
mHelper = new GameHelper(activity);
logEvent("setup");
mHelper.setup(this, GameHelper.CLIENT_GAMES);
}
return mHelper;
}

private List<Activity> _activityInstances;

public void signIn()
public void registerActivity(Activity activity)
{
logEvent("signIn");
mHelper.beginUserInitiatedSignIn();
if (_activityInstances == null)
{
_activityInstances = new ArrayList<Activity>();
}
_activityInstances.add(activity);
}

public void signOut()
Expand Down Expand Up @@ -145,12 +151,34 @@ public void reportScore(String leaderboardId, int highScore)
public void onSignInFailed() {
logEvent("onSignInFailed");
dispatchEvent("ON_SIGN_IN_FAIL");
if (_activityInstances != null)
{
for (Activity activity : _activityInstances)
{
if (activity != null)
{
activity.finish();
}
}
_activityInstances = null;
}
}

@Override
public void onSignInSucceeded() {
logEvent("onSignInSucceeded");
dispatchEvent("ON_SIGN_IN_SUCCESS");
if (_activityInstances != null)
{
for (Activity activity : _activityInstances)
{
if (activity != null)
{
activity.finish();
}
}
_activityInstances = null;
}
}

}
11 changes: 6 additions & 5 deletions android/src/com/freshplanet/googleplaygames/GameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ public interface GameHelperListener {
public GameHelper(Activity activity) {
mActivity = activity;
}

public GameHelper(Activity activity, boolean autoSignin) {
mActivity = activity;
mAutoSignIn = autoSignin;
}

static private final int TYPE_DEVELOPER_ERROR = 1001;
static private final int TYPE_GAMEHELPER_BUG = 1002;
Expand Down Expand Up @@ -351,6 +346,11 @@ public SignInFailureReason getSignInError() {
return mSignInFailureReason;
}

public void onStart(Activity act, boolean tryAutoSignIn) {
mAutoSignIn = tryAutoSignIn;
onStart(act);
}

/** Call this method from your Activity's onStart(). */
public void onStart(Activity act) {
mActivity = act;
Expand Down Expand Up @@ -860,6 +860,7 @@ public void onConnectionFailed(ConnectionResult result) {
// sign in.
debugLog("onConnectionFailed: since user didn't initiate sign-in, failing now.");
mConnectionResult = result;
//mAutoSignIn = false;
setState(STATE_DISCONNECTED);
notifyListener(false);
return;
Expand Down
37 changes: 34 additions & 3 deletions android/src/com/freshplanet/googleplaygames/SignInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,45 @@
import android.content.Intent;
import android.os.Bundle;

public class SignInActivity extends Activity {
public class SignInActivity extends Activity implements GameHelper.GameHelperListener {

private GameHelper mHelper;

private boolean shouldStartSignInFlow;


@Override
protected void onCreate(Bundle savedInstanceState)
{
Extension.context.logEvent("sign in activiy started");
super.onCreate(savedInstanceState);

Bundle extras = getIntent().getExtras();
shouldStartSignInFlow = true;

if (extras != null)
{
Extension.context.logEvent("hasExtra");
shouldStartSignInFlow = extras.getBoolean("shouldStartSignInFlow"); // this will prevent prompting the UI at launch if the user hasn't register yet with Google Play
Extension.context.logEvent("shouldStartSignInFlow : " +Boolean.toString(shouldStartSignInFlow));
}
Extension.context.logEvent("shouldStartSignInFlow2 : " +Boolean.toString(shouldStartSignInFlow));
mHelper = Extension.context.createHelperIfNeeded(this);
Extension.context.signIn();

Extension.context.registerActivity(this);
}

@Override
protected void onStart()
{
super.onStart();
mHelper.onStart(this);
Extension.context.logEvent("autosignIn");
mHelper.onStart(this, !shouldStartSignInFlow);
if (shouldStartSignInFlow)
{
Extension.context.logEvent("signIn");
mHelper.beginUserInitiatedSignIn();
}
}


Expand All @@ -33,4 +54,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data)
finish();
}

@Override
public void onSignInFailed() {
Extension.context.onSignInFailed();
}

@Override
public void onSignInSucceeded() {
Extension.context.onSignInSucceeded();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,18 @@

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;
import com.freshplanet.googleplaygames.Extension;
import com.freshplanet.googleplaygames.SignInActivity;

public class AirGooglePlayStartAtLaunch implements FREFunction {

@Override
public FREObject call(FREContext arg0, FREObject[] arg1) {
boolean autoSignIn = false;

try {
arg1[0].getAsBool();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (FRETypeMismatchException e) {
e.printStackTrace();
} catch (FREInvalidObjectException e) {
e.printStackTrace();
} catch (FREWrongThreadException e) {
e.printStackTrace();
}

Extension.context.AUTOSIGNIN = autoSignIn;


if (autoSignIn)
{
Intent intent = new Intent(arg0.getActivity().getApplicationContext(), SignInActivity.class);
arg0.getActivity().startActivity(intent);
}
Extension.context.logEvent("AirGooglePlayStartAtLaunch");
Intent intent = new Intent(arg0.getActivity().getApplicationContext(), SignInActivity.class);
intent.putExtra("shouldStartSignInFlow", false);
arg0.getActivity().startActivity(intent);

return null;
}
Expand Down
Binary file modified bin/AirGooglePlayGamesService.ane
Binary file not shown.

0 comments on commit cabaf6a

Please sign in to comment.