From 0a8683739ca6feb45a37fa4d7350a7f6b8d5a366 Mon Sep 17 00:00:00 2001 From: Thomas Pronold Date: Sun, 10 Jul 2016 20:16:08 +0200 Subject: [PATCH] ios-moe setup --- build.gradle | 30 +++ .../gdxfacebook/core/ReflectionLoader.java | 13 +- ios-moe/build.gradle | 9 + .../iosmoe/IOSMOEFacebookLoader.java | 28 +++ .../gdxfacebook/iosmoe/IOSMOEGDXFacebook.java | 223 ++++++++++++++++++ settings.gradle | 1 + 6 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 ios-moe/build.gradle create mode 100644 ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEFacebookLoader.java create mode 100644 ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEGDXFacebook.java diff --git a/build.gradle b/build.gradle index 84f9c49..1c91f91 100644 --- a/build.gradle +++ b/build.gradle @@ -9,11 +9,13 @@ buildscript { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() + maven { url uri(System.getenv("INTEL_MULTI_OS_ENGINE_HOME") + "/gradle") } } dependencies { classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' classpath 'com.android.tools.build:gradle:1.5.0' classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT' + classpath 'com.intel.gradle:moeGradlePlugin:1.1.0.final-1' } } @@ -178,7 +180,35 @@ project(":ios") { } +project(":ios-moe") { + apply plugin: 'java' + apply plugin: 'moe' + + + apply from: '../publish.gradle' + + configurations { + custom + compile.extendsFrom custom + natives + } + + eclipse { + project { + name = appName + "-ios-moe" + } + } + dependencies { + + compile project(':core') + + compile "com.badlogicgames.gdx:gdx-backend-moe:$gdxVersion" + natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios" + + compile "org.robovm:robopods-facebook-ios:$facebookRoboPodsVersion" + } +} diff --git a/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java b/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java index b07a086..aebb128 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java +++ b/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java @@ -37,7 +37,12 @@ public static GDXFacebook load(GDXFacebookConfig config) { } if (Gdx.app.getType() == Application.ApplicationType.iOS) { - loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSFacebookLoader"); + // tell robovm and moe apart + try { + loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSFacebookLoader"); + } catch (ReflectionException e) { + loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSMOEFacebookLoader"); + } } if (loaderCls != null) { @@ -52,6 +57,12 @@ public static GDXFacebook load(GDXFacebookConfig config) { Gdx.app.error(GDXFacebookVars.LOG_TAG, "Error installing " + GDXFacebookVars.LOG_TAG + " for " + Gdx.app.getType() + "\n"); Gdx.app.error(GDXFacebookVars.LOG_TAG, "Did you add >> compile \"de.tomgrill.gdxfacebook:gdx-facebook-" + artifactByAppType(Gdx.app.getType()) + ":" + GDXFacebookVars.VERSION + "\" << to your gradle dependencies? View https://github.com/TomGrill/gdx-facebook/wiki for more information.\n"); + + if (Gdx.app.getType() == Application.ApplicationType.iOS) { + Gdx.app.error(GDXFacebookVars.LOG_TAG, "or in cas you use multi-os-engine >> compile \"de.tomgrill.gdxfacebook:gdx-facebook-ios-moe:" + GDXFacebookVars.VERSION + + "\" <<\n"); + + } } return new FallbackGDXFacebook(); diff --git a/ios-moe/build.gradle b/ios-moe/build.gradle new file mode 100644 index 0000000..f2a9bbb --- /dev/null +++ b/ios-moe/build.gradle @@ -0,0 +1,9 @@ +targetCompatibility = 1.7 +sourceCompatibility = 1.7 + +sourceSets.main.java.srcDirs = [ "src/" ] + + +ext { + ARTIFACTID = 'gdx-facebook-ios-moe' +} diff --git a/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEFacebookLoader.java b/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEFacebookLoader.java new file mode 100644 index 0000000..ab211ad --- /dev/null +++ b/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEFacebookLoader.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright 2015 See AUTHORS file. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package de.tomgrill.gdxfacebook.iosmoe; + +import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.core.FacebookLoader; + +public class IOSMOEFacebookLoader implements FacebookLoader { + @Override + public GDXFacebook load(GDXFacebookConfig config) { + return new IOSMOEGDXFacebook(config); + } +} diff --git a/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEGDXFacebook.java b/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEGDXFacebook.java new file mode 100644 index 0000000..6c8c01a --- /dev/null +++ b/ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEGDXFacebook.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright 2015 See AUTHORS file. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + + +package de.tomgrill.gdxfacebook.iosmoe; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.utils.Array; +import de.tomgrill.gdxfacebook.core.*; +import org.robovm.apple.foundation.NSDictionary; +import org.robovm.apple.foundation.NSError; +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.block.VoidBlock2; +import org.robovm.pods.facebook.core.FBSDKAccessToken; +import org.robovm.pods.facebook.login.FBSDKLoginManager; +import org.robovm.pods.facebook.login.FBSDKLoginManagerLoginResult; +import org.robovm.pods.facebook.share.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class IOSMOEGDXFacebook extends GDXFacebookBasic { + + private FBSDKLoginManager loginManager; + private SignInMode signInMode; + + public IOSMOEGDXFacebook(GDXFacebookConfig config) { + super(config); + + loginManager = new FBSDKLoginManager(); + } + + @Override + public void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback) { + this.callback = callback; + this.permissions = permissions; + this.signInMode = mode; + + loadAccessToken(); + + if (accessToken == null && FBSDKAccessToken.getCurrentAccessToken() != null) { + accessToken = new GDXFacebookAccessToken(FBSDKAccessToken.getCurrentAccessToken().getTokenString(), FBSDKAccessToken.getCurrentAccessToken().getExpirationDate().toDate().getTime()); + } + + + if (accessToken != null) { + startSilentSignIn(); + } else { + startGUISignIn(); + } + } + + @Override + public void showGameRequest(GDXFacebookGameRequest request, final GDXFacebookCallback gameRequestCallback) { + gameRequest(request, gameRequestCallback); + } + + @Override + public void gameRequest(final GDXFacebookGameRequest request, final GDXFacebookCallback gameRequestCallback) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting Game Request dialog."); + + FBSDKGameRequestContent gameRequestContent = new FBSDKGameRequestContent(); + + + if (request.getMessage() != null) gameRequestContent.setMessage(request.getMessage()); + if (request.getData() != null) gameRequestContent.setData(request.getData()); + if (request.getTitle() != null) gameRequestContent.setTitle(request.getTitle()); + if (request.getObjectId() != null) gameRequestContent.setObjectID(request.getObjectId()); + + Array suggestions = request.getSuggestions(); + if (suggestions != null && suggestions.size > 0) { + ArrayList suggestionList = new ArrayList(); + for (int i = 0; i < suggestions.size; i++) { + suggestionList.add(suggestions.get(i)); + } + gameRequestContent.setRecipientSuggestions(suggestionList); + } + + Array recipients = request.getRecipients(); + if (recipients != null && recipients.size > 0) { + ArrayList recipientsList = new ArrayList(); + for (int i = 0; i < recipients.size; i++) { + recipientsList.add(recipients.get(i)); + } + gameRequestContent.setRecipients(recipientsList); + } + + + if (request.getActionType() != null) { + switch (request.getActionType()) { + case ASKFOR: + gameRequestContent.setActionType(FBSDKGameRequestActionType.AskFor); + break; + case SEND: + gameRequestContent.setActionType(FBSDKGameRequestActionType.Send); + break; + case TURN: + gameRequestContent.setActionType(FBSDKGameRequestActionType.Turn); + break; + } + } + + if (request.getFilters() != null) { + switch (request.getFilters()) { + case APP_NON_USERS: + gameRequestContent.setFilters(FBSDKGameRequestFilter.AppNonUsers); + break; + case APP_USERS: + gameRequestContent.setFilters(FBSDKGameRequestFilter.AppUsers); + break; + } + } + + FBSDKGameRequestDialog.show(gameRequestContent, new FBSDKGameRequestDialogDelegateAdapter() { + @Override + public void didComplete(FBSDKGameRequestDialog gameRequestDialog, NSDictionary results) { + Array recipients = new Array(); + + String requestId = ""; + + for (Map.Entry entry : results.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + + if (key.equals("request")) { + requestId = value; + } else { + recipients.add(value); + } + } + + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "User finished Game Request dialog successful."); + gameRequestCallback.onSuccess(new GameRequestResult(requestId, recipients)); + } + + @Override + public void didFail(FBSDKGameRequestDialog gameRequestDialog, NSError error) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Game Request finished with error: " + error.getLocalizedDescription()); + gameRequestCallback.onError(new GDXFacebookError(error.getLocalizedDescription())); + } + + @Override + public void didCancel(FBSDKGameRequestDialog gameRequestDialog) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Game Request has been fail."); + gameRequestCallback.onCancel(); + } + }); + } + + @Override + public void signOut(boolean keepSessionData) { + super.signOut(keepSessionData); + loginManager.logOut(); + + if (keepSessionData == SignOutMode.DELETE_SESSION_DATA) { + FBSDKAccessToken.setCurrentAccessToken(null); + + deleteTokenData(); + } + } + + @Override + public boolean isLoaded() { + return true; + } + + @Override + protected void startGUISignIn() { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting GUI sign in."); + + VoidBlock2 result = new VoidBlock2() { + + @Override + public void invoke(FBSDKLoginManagerLoginResult loginResult, NSError nsError) { + if (nsError != null) { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Error while trying to sign in: " + nsError.getLocalizedDescription()); + callback.onError(new GDXFacebookError(nsError.getLocalizedDescription())); + } else if (loginResult.isCancelled()) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Sign fail by user."); + signOut(); + callback.onCancel(); + } else { + accessToken = new GDXFacebookAccessToken(FBSDKAccessToken.getCurrentAccessToken().getTokenString(), FBSDKAccessToken.getCurrentAccessToken().getExpirationDate().toDate().getTime()); + storeNewToken(accessToken); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Sign successful. User token: " + accessToken.getToken()); + callback.onSuccess(new SignInResult(accessToken, "Sign in successful.")); + } + + } + + }; + + List listPermissions = new ArrayList(); + + for (int i = 0; i < permissions.size; i++) { + listPermissions.add(permissions.get(i)); + } + + if (this.signInMode == SignInMode.PUBLISH) { + loginManager.logInWithPublishPermissions(listPermissions, result); + } else { + loginManager.logInWithReadPermissions(listPermissions, result); + } + + + } + +} diff --git a/settings.gradle b/settings.gradle index 4e7f6f7..65dd7b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,5 @@ include ':core' include ':desktop' include ':html' include ':ios' +include ':ios-moe'