diff --git a/CHANGELOG b/CHANGELOG index 485e2e7..5d094b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +1.2.0 + * HTML/GWT support + * Android module comes with proguard settings included. + * minimum requirements are libGDX 1.9.3 + * GDXFacebookSystem.install() and GDXFacebookSystem.getFacebook() return now GDXFacebookIF instances. + * GDXFacebookSystem.install() is now deprecated. + 0.5.0 * facebook-android-sdk 4.4.0 * fixed bug on Android (Issued #2 and #3) diff --git a/android/proguard.txt b/android/proguard.txt index 60ad712..9e07699 100644 --- a/android/proguard.txt +++ b/android/proguard.txt @@ -23,6 +23,6 @@ -keep class com.badlogic.gdx.Gdx { *; } -keep class com.badlogic.gdx.backends.android.AndroidEventListener { *; } --keep class de.tomgrill.gdxfacebook.core.GDXFacebook { public protected *; } +-keep class de.tomgrill.gdxfacebook.core.GDXFacebookBasic { public protected *; } -keep class de.tomgrill.gdxfacebook.core.FallbackGDXFacebook { public protected *; } -keep class de.tomgrill.gdxfacebook.android.AndroidGDXFacebook{ public protected *; } \ No newline at end of file diff --git a/android/src/de/tomgrill/gdxfacebook/android/AndroidFacebookLoader.java b/android/src/de/tomgrill/gdxfacebook/android/AndroidFacebookLoader.java new file mode 100644 index 0000000..eed6b63 --- /dev/null +++ b/android/src/de/tomgrill/gdxfacebook/android/AndroidFacebookLoader.java @@ -0,0 +1,20 @@ +package de.tomgrill.gdxfacebook.android; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.backends.android.AndroidApplication; +import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.core.FacebookLoader; + +public class AndroidFacebookLoader implements FacebookLoader { + + @Override + public GDXFacebook load(GDXFacebookConfig config) { + + AndroidApplication androidApplication = (AndroidApplication) Gdx.app; + AndroidGDXFacebook androidGDXFacebook = new AndroidGDXFacebook(androidApplication, config); + androidApplication.addAndroidEventListener(androidGDXFacebook); + + return androidGDXFacebook; + } +} diff --git a/android/src/de/tomgrill/gdxfacebook/android/AndroidGDXFacebook.java b/android/src/de/tomgrill/gdxfacebook/android/AndroidGDXFacebook.java index 9d9b4e1..24733d1 100644 --- a/android/src/de/tomgrill/gdxfacebook/android/AndroidGDXFacebook.java +++ b/android/src/de/tomgrill/gdxfacebook/android/AndroidGDXFacebook.java @@ -1,12 +1,12 @@ /******************************************************************************* * 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. @@ -33,7 +33,8 @@ import java.util.ArrayList; import java.util.Collection; -public class AndroidGDXFacebook extends GDXFacebook implements AndroidEventListener { + +public class AndroidGDXFacebook extends GDXFacebookBasic implements AndroidEventListener { private Activity activity; private CallbackManager callbackManager; @@ -109,7 +110,7 @@ public void signIn(SignInMode mode, Array permissions, GDXFacebookCallba * If the user has Facebook App installed * AccessToken.getCurrentAccessToken() will not be NULL * - * Only when the Facebook App is not installed we need to load the token + * Only when the Facebook App is not installed we need to setup the token * manually. * */ loadAccessToken(); @@ -128,7 +129,13 @@ public void signIn(SignInMode mode, Array permissions, GDXFacebookCallba } @Override - public void showGameRequest(GDXFacebookGameRequest request, final GDXFacebookCallback gameRequestCallback) { + @Deprecated + public void showGameRequest(final 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."); GameRequestContent.Builder builder = new GameRequestContent.Builder(); @@ -213,7 +220,6 @@ public void onError(FacebookException error) { requestDialog.show(content); } - @Override protected void loadAccessToken() { super.loadAccessToken(); diff --git a/build.gradle b/build.gradle index bd9c8fd..886bdbb 100644 --- a/build.gradle +++ b/build.gradle @@ -63,6 +63,8 @@ project(":android") { compile project(':core') compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" compile "com.facebook.android:facebook-android-sdk:$androidSDKVersion" + +// compile fileTree(dir: 'libs', include: '*.jar') } } @@ -133,6 +135,14 @@ project(":html") { dependencies { compile project(':core') } + dependencies { + + compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion" + compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources" + compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources" + + + } } @@ -173,32 +183,26 @@ project(":ios") { -project(":tests-core") { - apply plugin: 'java' - - dependencies { - compile project(':core') - - compile "junit:junit:$jUnitVersion" - compile "org.mockito:mockito-all:$mockitoVersion" - compile "org.powermock:powermock-mockito-release-full:$powerMockVersion" - - testCompile "junit:junit:$jUnitVersion" - testCompile "org.mockito:mockito-all:$mockitoVersion" - testCompile "org.powermock:powermock-mockito-release-full:$powerMockVersion" - } - - - eclipse { - project { - name = appName + "-tests-core" - } - } -} - - - +//project(":tests-core") { +// apply plugin: 'java' +// +// dependencies { +// compile project(':core') +// +// compile "junit:junit:$jUnitVersion" +// compile "org.mockito:mockito-all:$mockitoVersion" +// compile "org.powermock:powermock-mockito-release-full:$powerMockVersion" +// +// testCompile "junit:junit:$jUnitVersion" +// testCompile "org.mockito:mockito-all:$mockitoVersion" +// testCompile "org.powermock:powermock-mockito-release-full:$powerMockVersion" +// } +// +// +// eclipse { +// project { +// name = appName + "-tests-core" +// } +// } +//} -tasks.eclipse.doLast { - delete ".project" -} diff --git a/core/build.gradle b/core/build.gradle index 492302f..34a185d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -3,7 +3,10 @@ apply plugin : 'java' targetCompatibility = 1.7 sourceCompatibility = 1.7 +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + sourceSets.main.java.srcDirs = [ "src/" ] +sourceSets.test.java.srcDirs = [ "test/" ] ext { diff --git a/core/src/de/tomgrill/gdxfacebook/core/FacebookLoader.java b/core/src/de/tomgrill/gdxfacebook/core/FacebookLoader.java new file mode 100644 index 0000000..92d8ecf --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/core/FacebookLoader.java @@ -0,0 +1,5 @@ +package de.tomgrill.gdxfacebook.core; + +public interface FacebookLoader { + GDXFacebook load(GDXFacebookConfig config); +} diff --git a/core/src/de/tomgrill/gdxfacebook/core/FallbackGDXFacebook.java b/core/src/de/tomgrill/gdxfacebook/core/FallbackGDXFacebook.java index 654d441..93a35bf 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/FallbackGDXFacebook.java +++ b/core/src/de/tomgrill/gdxfacebook/core/FallbackGDXFacebook.java @@ -20,11 +20,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.Array; -public class FallbackGDXFacebook extends GDXFacebook { - - public FallbackGDXFacebook(GDXFacebookConfig config) { - super(config); - } +public class FallbackGDXFacebook implements GDXFacebook { @Override public void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback) { @@ -38,31 +34,44 @@ public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback< callback.onError(new GDXFacebookError("Cannot show GameRequest." + GDXFacebookVars.LOG_TAG + " is not installed.")); } + @Override + public void gameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot show GameRequest. " + GDXFacebookVars.LOG_TAG + " is not installed."); + callback.onError(new GDXFacebookError("Cannot do graph API request." + GDXFacebookVars.LOG_TAG + " is not installed.")); + } @Override - public GDXFacebookAccessToken getAccessToken() { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot return accessToken. " + GDXFacebookVars.LOG_TAG + " is not installed."); - return null; + public void newGraphRequest(Request request, GDXFacebookCallback callback) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot do graph API request. " + GDXFacebookVars.LOG_TAG + " is not installed."); + callback.onError(new GDXFacebookError("Cannot show GameRequest." + GDXFacebookVars.LOG_TAG + " is not installed.")); } @Override - public void signOut() { + public void api(Request request, GDXFacebookCallback callback) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot do graph API request. " + GDXFacebookVars.LOG_TAG + " is not installed."); + callback.onError(new GDXFacebookError("Cannot do graph API request." + GDXFacebookVars.LOG_TAG + " is not installed.")); + } + + @Override + public void signOut(boolean keepSessionData) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot sign out. " + GDXFacebookVars.LOG_TAG + " is not installed."); } @Override - public boolean isSignedIn() { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "User is not signed in. " + GDXFacebookVars.LOG_TAG + " is not installed."); - return false; + @Deprecated + public GDXFacebookAccessToken getAccessToken() { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot return accessToken. " + GDXFacebookVars.LOG_TAG + " is not installed."); + return null; } @Override - protected void startGUISignIn() { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot start GUI sign in. " + GDXFacebookVars.LOG_TAG + " is not installed."); + public void signOut() { + signOut(true); } @Override - protected void startSilentSignIn() { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Cannot start silent sign in. " + GDXFacebookVars.LOG_TAG + " is not installed."); + public boolean isSignedIn() { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "User is not signed in. " + GDXFacebookVars.LOG_TAG + " is not installed."); + return false; } } diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebook.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebook.java index df0acf3..322a439 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebook.java +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebook.java @@ -1,45 +1,8 @@ -/******************************************************************************* - * 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.core; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Net; -import com.badlogic.gdx.Preferences; import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.JsonReader; -import com.badlogic.gdx.utils.JsonValue; - -import java.io.IOException; -import java.io.InputStream; - -public abstract class GDXFacebook { - - protected GDXFacebookConfig config; - protected Preferences preferences; - protected GDXFacebookAccessToken accessToken; - protected GDXFacebookCallback callback; - protected Array permissions; - - public GDXFacebook(GDXFacebookConfig config) { - this.config = config; - preferences = Gdx.app.getPreferences(config.PREF_FILENAME); - } +public interface GDXFacebook { /** * Opens the sign in dialog of the underlying Facebook SDK in the following cases: @@ -51,240 +14,52 @@ public GDXFacebook(GDXFacebookConfig config) { * - A existing token is loaded and still valid. * - The underlying Facebook SDK can handle the sign in silently. * - * @param mode - * @param permissions - * @param callback + * @param mode signIn mode + * @param permissions required permissions + * @param callback callback to handle result */ - abstract public void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback); + void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback); + /** * Make a Game Request which uses the underlaying Facebook SDK. More at: https://developers.facebook.com/docs/games/requests/ * - * @param request - * @param callback + * @param request the request + * @param callback callback to handle result + * + * @deprecated since v1.2.0 will be removed with v1.4.0. Use {@link #gameRequest(GDXFacebookGameRequest, GDXFacebookCallback)} instead. */ - abstract public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback); + @Deprecated + void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback); + /** - * Currently used accessToken. Null if user is not signed in. + * Make a Game Request which uses the underlaying Facebook SDK. More at: https://developers.facebook.com/docs/games/requests/ * - * @return accessToken + * @param request the request + * @param callback callback to handle result */ - public GDXFacebookAccessToken getAccessToken() { - return accessToken; - } - - abstract protected void startGUISignIn(); - - ; - - protected void startSilentSignIn() { - if (accessToken != null) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting silent sign in."); - GDXFacebookGraphRequest request = new GDXFacebookGraphRequest(); - request.setMethod(Net.HttpMethods.POST); - request.setNode(""); - request.putField("batch", "[{\"method\":\"GET\", \"relative_url\":\"me\"},{\"method\":\"GET\", \"relative_url\":\"me/permissions\"}]"); - request.putField("include_headers", "false"); - request.useCurrentAccessToken(); - newGraphRequest(request, new GDXFacebookCallback() { - - @Override - public void onSuccess(JsonResult result) { - JsonValue value = result.getJsonValue(); - if (value != null && value.isArray()) { - - JsonValue meValue = value.get(0); - JsonValue permissionsValue = value.get(1); - - - if (jsonHasCode200AndBody(meValue) && jsonHasCode200AndBody(permissionsValue)) { - - JsonReader reader = new JsonReader(); - JsonValue permissionBodyValue = reader.parse(permissionsValue.getString("body")); - JsonValue permissionArray = permissionBodyValue.get("data"); - - Array grantedPermissions = new Array(); - for (int i = 0; i < permissionArray.size; i++) { - JsonValue permission = permissionArray.get(i); - - if (permission.getString("status").equals("granted")) { - grantedPermissions.add(permission.getString("permission").toLowerCase()); - } - } - - - if (arePermissionsGranted(grantedPermissions)) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in successful. Current token is still valid."); - callback.onSuccess(new SignInResult(accessToken, "Silent sign in successful. Current token is still valid.")); - } else { - signOut(); - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Used access_token is valid but new permissions need to be granted. Need GUI sign in."); - callback.onError(new GDXFacebookError("Used access_token is valid but new permissions need to be granted. Need GUI sign in.")); - startGUISignIn(); - } - - - } else { - signOut(); - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + value.toString()); - callback.onError(new GDXFacebookError(value.toString())); - startGUISignIn(); - } - } else { - callback.onError(new GDXFacebookError("Unexpected error occurred while trying to sign in. Error unknown, possible timeout.")); - } - } - - private boolean arePermissionsGranted(Array grantedPermissions) { - for (int i = 0; i < permissions.size; i++) { - if (!grantedPermissions.contains(permissions.get(i).toLowerCase(), false)) { - return false; - } - } - return true; - } - - - @Override - public void onError(GDXFacebookError error) { - signOut(); - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + error.getErrorMessage()); - callback.onError(error); - startGUISignIn(); - } - - @Override - public void onFail(Throwable t) { - signOut(); - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in failed: " + t); - callback.onFail(t); - startGUISignIn(); - } - - @Override - public void onCancel() { - signOut(); - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in cancelled"); - callback.onCancel(); - startGUISignIn(); - } - }); - } else { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in cancelled. No existing access token."); - } - } + void gameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback); - protected void storeNewToken(GDXFacebookAccessToken token) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Storing new accessToken: " + token.getToken()); - preferences.putString("access_token", token.getToken()); - preferences.putLong("expires_at", token.getExpiresAt()); - preferences.flush(); - } - - protected void loadAccessToken() { - String token = preferences.getString("access_token", null); - long expiresAt = preferences.getLong("expires_at", 0); - - - if (token != null && expiresAt > 0) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Loaded existing accessToken: " + token); - accessToken = new GDXFacebookAccessToken(token, expiresAt); - } else { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Could not load existing accessToken"); - } - } /** - * Make a new Graph Request. View: https://developers.facebook.com/docs/graph-api/reference/request + * Make a new Graph API Request. View: https://developers.facebook.com/docs/graph-api/reference/request * - * @param request the request + * @param request the request * @param callback the callback + * + * @deprecated since v1.2.0 will be removed with v1.4.0 */ - public void newGraphRequest(Request request, final GDXFacebookCallback callback) { - String accessToken = null; - if (getAccessToken() != null) { - accessToken = getAccessToken().getToken(); - } - - if (request.isUseCurrentAccessToken() && accessToken != null) { - request.putField("access_token", accessToken); - } - - Net.HttpRequest httpRequest = new Net.HttpRequest(request.getMethod()); - - String url = request.getUrl() + config.GRAPH_API_VERSION + "/" + request.getNode(); - - httpRequest.setUrl(url); - - httpRequest.setTimeOut(request.getTimeout()); - - if (request.getHeaders() != null) { - for (int i = 0; i < request.getHeaders().size; i++) { - httpRequest.setHeader(request.getHeaders().getKeyAt(i), request.getHeaders().getValueAt(i)); - } - } - - if (request.getContent() != null) { - httpRequest.setContent(request.getContent()); - } else { - try { - InputStream stream = request.getContentStream(); -// System.out.println(getStringFromInputStream(stream)); - httpRequest.setContent(stream, stream.available()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { - - @Override - public void handleHttpResponse(Net.HttpResponse httpResponse) { - String resultString = httpResponse.getResultAsString(); - int statusCode = httpResponse.getStatus().getStatusCode(); - - if (statusCode == -1) { - GDXFacebookError error = new GDXFacebookError("Connection time out. Consider increasing timeout value by using setTimeout()"); - callback.onError(error); - } else if (statusCode >= 200 && statusCode < 300) { - callback.onSuccess(new JsonResult(resultString)); - } else { - GDXFacebookError error = new GDXFacebookError("Error: " + resultString); - callback.onError(error); - } - } - - @Override - public void failed(Throwable t) { - t.printStackTrace(); - callback.onFail(t); - } - - @Override - public void cancelled() { - callback.onCancel(); - } - }); - - } - - private boolean jsonHasCode200AndBody(JsonValue jsonValue) { - return jsonValue.has("code") && jsonValue.getInt("code") == 200 && jsonValue.has("body"); - } - - public boolean isSignedIn() { - return accessToken != null; - } - + @Deprecated + void newGraphRequest(Request request, final GDXFacebookCallback callback); /** - * Convenient method for signOut(true); + * Make a new Graph API Request. View: https://developers.facebook.com/docs/graph-api/reference/request + * + * @param request the request + * @param callback the callback */ - public void signOut() { - signOut(true); - } + void api(Request request, final GDXFacebookCallback callback); /** * Signs the user out. When keepSessionData is false then all session data for the current user @@ -293,16 +68,20 @@ public void signOut() { * NOTE: When the user has native Facebook App installed on his device keepSessionData = false does not always work. * In this cases you may want to give the user a hint that he needs to logout from Facebook App in order to be able to switch accounts. * - * @param keepSessionData + * @param keepSessionData whether to keep the user session data for later or not. + */ + void signOut(boolean keepSessionData); + + /** + * Convenient method for {@link #signOut(boolean)}. + * + * @deprecated since v1.2.0 will be removed with v1.4.0 */ - public void signOut(boolean keepSessionData) { - accessToken = null; - } + @Deprecated + void signOut(); - public final void deleteTokenData() { - preferences.remove("access_token"); - preferences.remove("expires_at"); - preferences.flush(); + boolean isSignedIn(); - } + @Deprecated + GDXFacebookAccessToken getAccessToken(); } diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookBasic.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookBasic.java new file mode 100644 index 0000000..47ee9f9 --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookBasic.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * 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.core; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Net; +import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.JsonReader; +import com.badlogic.gdx.utils.JsonValue; + +import java.io.IOException; +import java.io.InputStream; + + +public abstract class GDXFacebookBasic implements GDXFacebook { + + protected GDXFacebookConfig config; + protected Preferences preferences; + protected GDXFacebookAccessToken accessToken; + protected GDXFacebookCallback callback; + protected Array permissions; + + public GDXFacebookBasic(GDXFacebookConfig config) { + this.config = config; + preferences = Gdx.app.getPreferences(config.PREF_FILENAME); + } + + + /** + * Currently used accessToken. Null if user is not signed in. + * + * @return accessToken + */ + public GDXFacebookAccessToken getAccessToken() { + return accessToken; + } + + abstract protected void startGUISignIn(); + + protected void startSilentSignIn() { + if (accessToken != null) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting silent sign in."); + GDXFacebookGraphRequest request = new GDXFacebookGraphRequest(); + request.setMethod(Net.HttpMethods.POST); + request.setNode(""); + request.putField("batch", "[{\"method\":\"GET\", \"relative_url\":\"me\"},{\"method\":\"GET\", \"relative_url\":\"me/permissions\"}]"); + request.putField("include_headers", "false"); + request.useCurrentAccessToken(); + newGraphRequest(request, new GDXFacebookCallback() { + + @Override + public void onSuccess(JsonResult result) { + JsonValue value = result.getJsonValue(); + if (value != null && value.isArray()) { + + JsonValue meValue = value.get(0); + JsonValue permissionsValue = value.get(1); + + + if (jsonHasCode200AndBody(meValue) && jsonHasCode200AndBody(permissionsValue)) { + + JsonReader reader = new JsonReader(); + JsonValue permissionBodyValue = reader.parse(permissionsValue.getString("body")); + JsonValue permissionArray = permissionBodyValue.get("data"); + + Array grantedPermissions = new Array(); + for (int i = 0; i < permissionArray.size; i++) { + JsonValue permission = permissionArray.get(i); + + if (permission.getString("status").equals("granted")) { + grantedPermissions.add(permission.getString("permission").toLowerCase()); + } + } + + + if (arePermissionsGranted(grantedPermissions)) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in successful. Current token is still valid."); + callback.onSuccess(new SignInResult(accessToken, "Silent sign in successful. Current token is still valid.")); + } else { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Used access_token is valid but new permissions need to be granted. Need GUI sign in."); + callback.onError(new GDXFacebookError("Used access_token is valid but new permissions need to be granted. Need GUI sign in.")); + startGUISignIn(); + } + + + } else { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + value.toString()); + callback.onError(new GDXFacebookError(value.toString())); + startGUISignIn(); + } + } else { + callback.onError(new GDXFacebookError("Unexpected error occurred while trying to sign in. Error unknown, possible timeout.")); + } + } + + private boolean arePermissionsGranted(Array grantedPermissions) { + for (int i = 0; i < permissions.size; i++) { + if (!grantedPermissions.contains(permissions.get(i).toLowerCase(), false)) { + return false; + } + } + return true; + } + + + @Override + public void onError(GDXFacebookError error) { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + error.getErrorMessage()); + callback.onError(error); + startGUISignIn(); + } + + @Override + public void onFail(Throwable t) { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in failed: " + t); + callback.onFail(t); + startGUISignIn(); + } + + @Override + public void onCancel() { + signOut(); + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in cancelled"); + callback.onCancel(); + startGUISignIn(); + } + }); + } else { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in cancelled. No existing access token."); + } + } + + protected void storeNewToken(GDXFacebookAccessToken token) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Storing new accessToken: " + token.getToken()); + preferences.putString("access_token", token.getToken()); + preferences.putLong("expires_at", token.getExpiresAt()); + preferences.flush(); + } + + protected void loadAccessToken() { + String token = preferences.getString("access_token", null); + long expiresAt = preferences.getLong("expires_at", 0); + + + if (token != null && expiresAt > 0) { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Loaded existing accessToken: " + token); + accessToken = new GDXFacebookAccessToken(token, expiresAt); + } else { + Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Could not setup existing accessToken"); + } + } + + @Override + public void api(final Request request, final GDXFacebookCallback callback) { + String accessToken = null; + if (getAccessToken() != null) { + accessToken = getAccessToken().getToken(); + } + + if (request.isUseCurrentAccessToken() && accessToken != null) { + request.putField("access_token", accessToken); + } + + Net.HttpRequest httpRequest = new Net.HttpRequest(request.getMethod()); + + String url = request.getUrl() + config.GRAPH_API_VERSION + "/" + request.getNode(); + + httpRequest.setUrl(url); + + httpRequest.setTimeOut(request.getTimeout()); + + if (request.getHeaders() != null) { + for (int i = 0; i < request.getHeaders().size; i++) { + httpRequest.setHeader(request.getHeaders().getKeyAt(i), request.getHeaders().getValueAt(i)); + } + } + + if (request.getContent() != null) { + httpRequest.setContent(request.getContent()); + } else { + try { + InputStream stream = request.getContentStream(); +// System.out.println(getStringFromInputStream(stream)); + httpRequest.setContent(stream, stream.available()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { + + @Override + public void handleHttpResponse(Net.HttpResponse httpResponse) { + String resultString = httpResponse.getResultAsString(); + int statusCode = httpResponse.getStatus().getStatusCode(); + + if (statusCode == -1) { + GDXFacebookError error = new GDXFacebookError("Connection time out. Consider increasing timeout value by using setTimeout()"); + callback.onError(error); + } else if (statusCode >= 200 && statusCode < 300) { + callback.onSuccess(new JsonResult(resultString)); + } else { + GDXFacebookError error = new GDXFacebookError("Error: " + resultString); + callback.onError(error); + } + } + + @Override + public void failed(Throwable t) { + t.printStackTrace(); + callback.onFail(t); + } + + @Override + public void cancelled() { + callback.onCancel(); + } + }); + } + + @Override + public void newGraphRequest(Request request, final GDXFacebookCallback callback) { + api(request, callback); + } + + private boolean jsonHasCode200AndBody(JsonValue jsonValue) { + return jsonValue.has("code") && jsonValue.getInt("code") == 200 && jsonValue.has("body"); + } + + @Override + public boolean isSignedIn() { + return accessToken != null; + } + + + /** + * Convenient method for signOut(true); + */ + + public void signOut() { + signOut(true); + } + + @Override + public void signOut(boolean keepSessionData) { + accessToken = null; + } + + public final void deleteTokenData() { + preferences.remove("access_token"); + preferences.remove("expires_at"); + preferences.flush(); + + } +} diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookGraphRequest.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookGraphRequest.java index e47e154..c322b98 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookGraphRequest.java +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookGraphRequest.java @@ -27,10 +27,8 @@ /** * Build a proper Facebook Graph API request with this class. * - * @author Thomas Pronold (TomGrill) mail@tomgrill.de - * @see https://developers.facebook.com/docs/graph-api/using-graph-api/ - * for more information on how Facebook Graph API works. + * @author Thomas Pronold (TomGrill) mail@tomgrill.de * + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/ */ public class GDXFacebookGraphRequest extends AbstractRequest { @@ -57,7 +55,7 @@ public final ArrayMap getHeaders() { public String getContent() { StringBuffer convertedParameters = new StringBuffer(); - for(ObjectMap.Entry entry : fields){ + for (ObjectMap.Entry entry : fields) { convertedParameters.append(encode(entry.key, defaultEncoding)); convertedParameters.append(nameValueSeparator); convertedParameters.append(encode(entry.value, defaultEncoding)); diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookHandler.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookHandler.java new file mode 100644 index 0000000..665bbec --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookHandler.java @@ -0,0 +1,23 @@ +package de.tomgrill.gdxfacebook.core; + +public class GDXFacebookHandler { + + private static GDXFacebook gdxFacebook; + + + public static void setup(GDXFacebook facebook) { +// if (Gdx.app.getType() == Application.ApplicationType.Desktop) { +// try { +// ClassReflection.forName("com.badlogic.gdx.Gdx"); +// } catch (ReflectionException e) { +// e.printStackTrace(); +// } +// } + + GDXFacebookHandler.gdxFacebook = facebook; + } + + public static GDXFacebook FB() { + return GDXFacebookHandler.gdxFacebook; + } +} diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookMultiPartRequest.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookMultiPartRequest.java index eeaf122..ee94c77 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookMultiPartRequest.java +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookMultiPartRequest.java @@ -28,9 +28,8 @@ * Build a proper mulitpart Facebook Graph API request with this class. * * @author Thomas Pronold (TomGrill) mail@tomgrill.de - * @see https://developers.facebook.com/docs/graph-api/using-graph-api/ - * for more information on how Facebook Graph API works. + * @see https://developers.facebook.com/docs/graph-api/using-graph-api/ + * */ public class GDXFacebookMultiPartRequest extends AbstractRequest { diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookProvider.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookProvider.java new file mode 100644 index 0000000..3eb6bba --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookProvider.java @@ -0,0 +1,8 @@ +package de.tomgrill.gdxfacebook.core; + +public interface GDXFacebookProvider { + + GDXFacebook provideInstance(); + + GDXFacebookConfig provideConfig(); +} diff --git a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookSystem.java b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookSystem.java index b5a0f06..6a4457f 100644 --- a/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookSystem.java +++ b/core/src/de/tomgrill/gdxfacebook/core/GDXFacebookSystem.java @@ -1,188 +1,24 @@ -/******************************************************************************* - * 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.core; - import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.utils.reflect.ClassReflection; -import com.badlogic.gdx.utils.reflect.Method; -import com.badlogic.gdx.utils.reflect.ReflectionException; - +import de.tomgrill.gdxfacebook.html.HTMLFacebookLoader; public class GDXFacebookSystem { - - private static GDXFacebookSystem instance; - private GDXFacebook facebook; - private GDXFacebookConfig config; - - private GDXFacebookSystem(GDXFacebookConfig config) { - validateConfig(config); - this.config = config; - } - + private static GDXFacebook gdxFacebook; public static GDXFacebook install(GDXFacebookConfig config) { - instance = new GDXFacebookSystem(config); - instance.installSystem(); - return instance.getFacebook(); - } - - private void installSystem() { - - tryToLoadDesktopGDXFacebook(); - tryToLoadHTMLGDXFacebook(); - tryToLoadIOSGDXFacebook(); - tryToLoadAndroidGDXFacebook(); - - if (facebook == null) { - facebook = new FallbackGDXFacebook(config); - } - } - - - private void tryToLoadAndroidGDXFacebook() { - if (Gdx.app.getType() != Application.ApplicationType.Android) { - showDebugSkipInstall(Application.ApplicationType.Android.name()); - return; - } - - Class gdxClazz; - Object gdxAppObject; - - try { - gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx"); - gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null); - - } catch (ReflectionException e) { - throw new RuntimeException("No libGDX environment. \n"); - } - - try { - Class gdxAndroidEventListenerClazz = ClassReflection.forName("com.badlogic.gdx.backends.android.AndroidEventListener"); - Class activityClazz = ClassReflection.forName("android.app.Activity"); - final Class facebookClazz = ClassReflection.forName(GDXFacebookVars.CLASSNAME_ANDROID); - - Object activity = null; - if (ClassReflection.isAssignableFrom(activityClazz, gdxAppObject.getClass())) { - activity = gdxAppObject; - } else { - Class supportFragmentClass = findClass("android.support.v4.app.Fragment"); - if (supportFragmentClass != null && ClassReflection.isAssignableFrom(supportFragmentClass, gdxAppObject.getClass())) { - activity = ClassReflection.getMethod(supportFragmentClass, "getActivity").invoke(gdxAppObject); - - } else { - - Class fragmentClass = findClass("android.app.Fragment"); - - if (fragmentClass != null && ClassReflection.isAssignableFrom(fragmentClass, gdxAppObject.getClass())) { - activity = ClassReflection.getMethod(fragmentClass, "getActivity").invoke(gdxAppObject); - } - } - } - - if (activity == null) { - throw new RuntimeException("Can't find your gdx activity to instantiate libGDX Facebook. " + "Looks like you have implemented AndroidApplication without using " - + "Activity or Fragment classes or Activity is not available at the moment."); - } - - Object facebookObj = ClassReflection.getConstructor(facebookClazz, activityClazz, GDXFacebookConfig.class).newInstance(activity, config); - - Method gdxAppAddAndroidEventListenerMethod = ClassReflection.getMethod(gdxAppObject.getClass(), "addAndroidEventListener", gdxAndroidEventListenerClazz); - - gdxAppAddAndroidEventListenerMethod.invoke(gdxAppObject, facebookObj); - - facebook = (GDXFacebook) facebookObj; - - showDebugInstallSuccessful(Application.ApplicationType.Android.name()); - - } catch (ReflectionException e) { - showErrorInstall(Application.ApplicationType.Android.name(), "core"); - e.printStackTrace(); - } - } - - private void tryToLoadIOSGDXFacebook() { - if (Gdx.app.getType() != Application.ApplicationType.iOS) { - showDebugSkipInstall(Application.ApplicationType.iOS.name()); - return; - } - try { - - final Class facebookClazz = ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS); - - Object facebookObj = ClassReflection.getConstructor(facebookClazz, GDXFacebookConfig.class).newInstance(config); - - facebook = (GDXFacebook) facebookObj; - - showDebugInstallSuccessful(Application.ApplicationType.iOS.name()); - - } catch (ReflectionException e) { - showErrorInstall(Application.ApplicationType.iOS.name(), "ios"); - e.printStackTrace(); - } - } - private void tryToLoadHTMLGDXFacebook() { - if (Gdx.app.getType() != Application.ApplicationType.WebGL) { - showDebugSkipInstall(Application.ApplicationType.WebGL.name()); - return; - } - - try { - - final Class facebookClazz = ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML); - Object facebookObj = ClassReflection.getConstructor(facebookClazz, GDXFacebookConfig.class).newInstance(config); - - facebook = (GDXFacebook) facebookObj; - - showDebugInstallSuccessful(Application.ApplicationType.WebGL.name()); - - } catch (ReflectionException e) { - showErrorInstall(Application.ApplicationType.WebGL.name(), "html"); - e.printStackTrace(); + if(Gdx.app.getType() == Application.ApplicationType.WebGL) { + gdxFacebook = (new HTMLFacebookLoader()).load(config); + } else { + gdxFacebook = ReflectionLoader.load(config); } + return gdxFacebook; } - private void tryToLoadDesktopGDXFacebook() { - if (Gdx.app.getType() != Application.ApplicationType.Desktop) { - showDebugSkipInstall(Application.ApplicationType.Desktop.name()); - return; - } - - - try { - - final Class facebookClazz = ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP); - Object facebookObj = ClassReflection.getConstructor(facebookClazz, GDXFacebookConfig.class).newInstance(config); - - facebook = (GDXFacebook) facebookObj; - - showDebugInstallSuccessful(Application.ApplicationType.Desktop.name()); - - } catch (ReflectionException e) { - showErrorInstall(Application.ApplicationType.Desktop.name(), "desktop"); - } - } - - private void validateConfig(GDXFacebookConfig config) { + private static void validateConfig(GDXFacebookConfig config) { if (config == null) { throw new NullPointerException(GDXFacebookConfig.class.getSimpleName() + "may not be null."); } @@ -199,32 +35,10 @@ private void validateConfig(GDXFacebookConfig config) { throw new NullPointerException("GDXFacebookConfig.class.getSimpleName() + \": APP_ID may bot be null."); } - Long.valueOf(config.APP_ID); + Long.valueOf(config.APP_ID); // kinda stupid but simple way to check if APP_ID is a valid Long } - public GDXFacebook getFacebook() { - return facebook; - } - - private void showDebugSkipInstall(String os) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Skip installing " + GDXFacebookVars.LOG_TAG + " for " + os + ". Not running " + os + ". \n"); - } - - private void showErrorInstall(String os, String artifact) { - Gdx.app.error(GDXFacebookVars.LOG_TAG, "Error installing " + GDXFacebookVars.LOG_TAG + " for " + os + "\n"); - Gdx.app.error(GDXFacebookVars.LOG_TAG, "Did you add >> compile \"de.tomgrill.gdxfacebook:gdx-facebook-" + artifact + ":" + GDXFacebookVars.VERSION - + "\" << to your gradle dependencies? View https://github.com/TomGrill/gdx-facebook/wiki for more information.\n"); - } - - private void showDebugInstallSuccessful(String os) { - Gdx.app.debug(GDXFacebookVars.LOG_TAG, GDXFacebookVars.LOG_TAG + " for " + os + " installed successfully."); - } - - private static Class findClass(String name) { - try { - return ClassReflection.forName(name); - } catch (Exception e) { - return null; - } + public static GDXFacebook getFacebook() { + return gdxFacebook; } } diff --git a/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java b/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java new file mode 100644 index 0000000..4cd48c2 --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java @@ -0,0 +1,56 @@ +package de.tomgrill.gdxfacebook.core; + +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.utils.reflect.ClassReflection; +import com.badlogic.gdx.utils.reflect.ReflectionException; + +public class ReflectionLoader { + public static GDXFacebook load(GDXFacebookConfig config) { + + try { + Object loaderObj; + Class loaderCls = null; + + if (Gdx.app.getType() == Application.ApplicationType.Android) { + loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.android.AndroidFacebookLoader"); + } + + if (Gdx.app.getType() == Application.ApplicationType.Desktop) { + loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.desktop.DesktopFacebookLoader"); + } + + if (Gdx.app.getType() == Application.ApplicationType.iOS) { + loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSFacebookLoader"); + } + + if (loaderCls != null) { + loaderObj = ClassReflection.getConstructor(loaderCls).newInstance(); + + Gdx.app.debug(GDXFacebookVars.LOG_TAG, GDXFacebookVars.LOG_TAG + " for " + Gdx.app.getType() + " installed successfully."); + + return ((FacebookLoader) loaderObj).load(config); + } + + } catch (ReflectionException e) { + 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"); + } + + return new FallbackGDXFacebook(); + } + + private static String artifactByAppType(final Application.ApplicationType type) { + if (type == Application.ApplicationType.Android) { + return "android"; + } + if (type == Application.ApplicationType.iOS) { + return "ios"; + } + if (type == Application.ApplicationType.Desktop) { + return "desktop"; + } + return "unknown_type"; + } +} diff --git a/core/src/de/tomgrill/gdxfacebook/html/HTMLFacebookLoader.java b/core/src/de/tomgrill/gdxfacebook/html/HTMLFacebookLoader.java new file mode 100644 index 0000000..2123404 --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/html/HTMLFacebookLoader.java @@ -0,0 +1,15 @@ +package de.tomgrill.gdxfacebook.html; + +import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.core.FacebookLoader; + +public class HTMLFacebookLoader implements FacebookLoader { + @Override + public GDXFacebook load(GDXFacebookConfig config) { + + JSNIFacebookSDK.initSDK(config.APP_ID, config.GRAPH_API_VERSION); + + return new HTMLGDXFacebook(config); + } +} diff --git a/core/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java b/core/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java new file mode 100644 index 0000000..aa4cbf1 --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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.html; + +import com.badlogic.gdx.utils.Array; +import de.tomgrill.gdxfacebook.core.*; + +public class HTMLGDXFacebook implements GDXFacebook { + + private GDXFacebookConfig config; + + public HTMLGDXFacebook(GDXFacebookConfig config) { + this.config = config; + } + + @Override + public void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback) { + + JSNIFacebookSDK.FBLogin(); + JSNIJavascript.consoleLog("login"); + + + } + + @Override + public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { + + } + + @Override + public void gameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { + + } + + @Override + public void newGraphRequest(Request request, GDXFacebookCallback callback) { + + } + + @Override + public void api(Request request, GDXFacebookCallback callback) { + + } + + @Override + public void signOut(boolean keepSessionData) { + + } + + @Override + public void signOut() { + + } + + @Override + public boolean isSignedIn() { + return false; + } + + @Override + public GDXFacebookAccessToken getAccessToken() { + return null; + } + + +} \ No newline at end of file diff --git a/core/src/de/tomgrill/gdxfacebook/html/JSNIFacebookSDK.java b/core/src/de/tomgrill/gdxfacebook/html/JSNIFacebookSDK.java new file mode 100644 index 0000000..418dfe7 --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/html/JSNIFacebookSDK.java @@ -0,0 +1,46 @@ +package de.tomgrill.gdxfacebook.html; + +class JSNIFacebookSDK { + static native void FBLogin() /*-{ + + $wnd.FB.login(function(response) { + // handle the response + }, {scope: 'public_profile,email'}); + + + + + }-*/; + + + /** + * Nearly the same setup as recommend by the quick start guide: + * https://developers.facebook.com/docs/javascript/quickstart + * + * Notice: Usage of $wnd and $doc + */ + static native void initSDK(String appIdNr, String apiVersion) + /*-{ + $wnd.fbAsyncInit = function() { + $wnd.FB.init({ + appId : appIdNr, + cookie : true, + xfbml : false, + version : apiVersion, + }); + + }; + + // Load the SDK asynchronously + (function(d, s, id) { + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) return; + js = d.createElement(s); js.id = id; + js.src = "//connect.facebook.net/en_US/sdk/debug.js"; + fjs.parentNode.insertBefore(js, fjs); + }($doc, 'script', 'facebook-jssdk')); + + + + }-*/; +} diff --git a/core/src/de/tomgrill/gdxfacebook/html/JSNIJavascript.java b/core/src/de/tomgrill/gdxfacebook/html/JSNIJavascript.java new file mode 100644 index 0000000..44a433d --- /dev/null +++ b/core/src/de/tomgrill/gdxfacebook/html/JSNIJavascript.java @@ -0,0 +1,9 @@ +package de.tomgrill.gdxfacebook.html; + +class JSNIJavascript { + static native void consoleLog(String msg) + /*-{ + console.log(msg); + }-*/ + ; +} diff --git a/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopFacebookLoader.java b/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopFacebookLoader.java new file mode 100644 index 0000000..621b8f3 --- /dev/null +++ b/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopFacebookLoader.java @@ -0,0 +1,12 @@ +package de.tomgrill.gdxfacebook.desktop; + +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; +import de.tomgrill.gdxfacebook.core.FacebookLoader; + +public class DesktopFacebookLoader implements FacebookLoader { + @Override + public GDXFacebook load(GDXFacebookConfig config) { + return new DesktopGDXFacebook(config); + } +} diff --git a/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopGDXFacebook.java b/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopGDXFacebook.java index 73b81b1..ca7b440 100644 --- a/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopGDXFacebook.java +++ b/desktop/src/de/tomgrill/gdxfacebook/desktop/DesktopGDXFacebook.java @@ -27,7 +27,7 @@ import java.net.MalformedURLException; import java.net.URL; -public class DesktopGDXFacebook extends GDXFacebook implements JXBrowserCallbackHandler { +public class DesktopGDXFacebook extends GDXFacebookBasic implements JXBrowserCallbackHandler { public DesktopGDXFacebook(GDXFacebookConfig config) { @@ -52,6 +52,11 @@ public void signIn(SignInMode mode, final Array permissions, final GDXFa @Override public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { + gameRequest(request, callback); + } + + @Override + public void gameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Game Request not supported on Desktop"); } diff --git a/html/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java b/html/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java deleted file mode 100644 index d14872a..0000000 --- a/html/src/de/tomgrill/gdxfacebook/html/HTMLGDXFacebook.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.html; - -import com.badlogic.gdx.utils.Array; - -import de.tomgrill.gdxfacebook.core.GDXFacebookAccessToken; -import de.tomgrill.gdxfacebook.core.GDXFacebook; -import de.tomgrill.gdxfacebook.core.GDXFacebookCallback; -import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; -import de.tomgrill.gdxfacebook.core.GDXFacebookGameRequest; -import de.tomgrill.gdxfacebook.core.GameRequestResult; -import de.tomgrill.gdxfacebook.core.SignInResult; -import de.tomgrill.gdxfacebook.core.SignInMode; - -public class HTMLGDXFacebook extends GDXFacebook { - public HTMLGDXFacebook(GDXFacebookConfig config) { - super(config); - } - - @Override - public void signIn(SignInMode mode, Array permissions, GDXFacebookCallback callback) { - - } - - @Override - public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { - - } - - @Override - public GDXFacebookAccessToken getAccessToken() { - return null; - } - - @Override - public boolean isSignedIn() { - return false; - } - - @Override - protected void startGUISignIn() { - - } -} diff --git a/html/src/de/tomgrill/gdxfacebook/html/Placeholder.java b/html/src/de/tomgrill/gdxfacebook/html/Placeholder.java new file mode 100644 index 0000000..818bdb0 --- /dev/null +++ b/html/src/de/tomgrill/gdxfacebook/html/Placeholder.java @@ -0,0 +1,14 @@ +package de.tomgrill.gdxfacebook.html; + +public class Placeholder { + /* + + We do not need this module at all. JSNI can be written from core module. + + Putting JSNI to html module would probably be the cleaner method but this requires an extra step for the user to install the extension. + + Both has pros and cons. Note sure whats best. Let's start with usability and decide later. + + + */ +} diff --git a/ios/src/de/tomgrill/gdxfacebook/ios/IOSFacebookLoader.java b/ios/src/de/tomgrill/gdxfacebook/ios/IOSFacebookLoader.java new file mode 100644 index 0000000..44ab0b2 --- /dev/null +++ b/ios/src/de/tomgrill/gdxfacebook/ios/IOSFacebookLoader.java @@ -0,0 +1,12 @@ +package de.tomgrill.gdxfacebook.ios; + +import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.core.FacebookLoader; + +public class IOSFacebookLoader implements FacebookLoader { + @Override + public GDXFacebook load(GDXFacebookConfig config) { + return new IOSGDXFacebook(config); + } +} diff --git a/ios/src/de/tomgrill/gdxfacebook/ios/IOSGDXFacebook.java b/ios/src/de/tomgrill/gdxfacebook/ios/IOSGDXFacebook.java index 81f4103..ac1f589 100644 --- a/ios/src/de/tomgrill/gdxfacebook/ios/IOSGDXFacebook.java +++ b/ios/src/de/tomgrill/gdxfacebook/ios/IOSGDXFacebook.java @@ -1,12 +1,12 @@ /******************************************************************************* * 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. @@ -19,203 +19,200 @@ 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.FBSDKLoginBehavior; import org.robovm.pods.facebook.login.FBSDKLoginManager; import org.robovm.pods.facebook.login.FBSDKLoginManagerLoginResult; -import org.robovm.pods.facebook.share.FBSDKGameRequestActionType; -import org.robovm.pods.facebook.share.FBSDKGameRequestContent; -import org.robovm.pods.facebook.share.FBSDKGameRequestDialog; -import org.robovm.pods.facebook.share.FBSDKGameRequestDialogDelegateAdapter; -import org.robovm.pods.facebook.share.FBSDKGameRequestFilter; +import org.robovm.pods.facebook.share.*; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class IOSGDXFacebook extends GDXFacebook { - - private FBSDKLoginManager loginManager; - private SignInMode signInMode; - - public IOSGDXFacebook(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) { - - 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 cancelled."); - gameRequestCallback.onCancel(); - } - }); - - } - - @Override - public void signOut(boolean keepSessionData) { - super.signOut(keepSessionData); - loginManager.logOut(); - - if(keepSessionData == SignOutMode.DELETE_SESSION_DATA) { +public class IOSGDXFacebook extends GDXFacebookBasic { + + private FBSDKLoginManager loginManager; + private SignInMode signInMode; + + public IOSGDXFacebook(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 cancelled."); + gameRequestCallback.onCancel(); + } + }); + } + + @Override + public void signOut(boolean keepSessionData) { + super.signOut(keepSessionData); + loginManager.logOut(); + + if (keepSessionData == SignOutMode.DELETE_SESSION_DATA) { FBSDKAccessToken.setCurrentAccessToken(null); deleteTokenData(); - } - } - - @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 cancelled 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); - } - - - } + } + } + + @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 cancelled 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 486d156..4e7f6f7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,4 @@ include ':core' include ':desktop' include ':html' include ':ios' -include ':tests-core' + diff --git a/tests-core/build.gradle b/tests-core/build.gradle index 3bb137d..722e655 100644 --- a/tests-core/build.gradle +++ b/tests-core/build.gradle @@ -3,6 +3,7 @@ apply plugin: "java" targetCompatibility = 1.7 sourceCompatibility = 1.7 + sourceSets.test.java.srcDirs = [ "src/" ] diff --git a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccesTokenUnitTests.java b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccessTokenUnitTests.java similarity index 89% rename from tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccesTokenUnitTests.java rename to tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccessTokenUnitTests.java index d8b4c7b..56b04b6 100644 --- a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccesTokenUnitTests.java +++ b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/AccessTokenUnitTests.java @@ -1,12 +1,12 @@ /******************************************************************************* * 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. @@ -15,14 +15,12 @@ ******************************************************************************/ -package de.tomgrill.gdxfacebook.tests.core; +package de.tomgrill.gdxfacebook.core; import org.junit.Before; import org.junit.Test; -import de.tomgrill.gdxfacebook.core.GDXFacebookAccessToken; - -public class AccesTokenUnitTests { +public class AccessTokenUnitTests { GDXFacebookAccessToken fixture; @Before diff --git a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookLoaderUnitTests.java b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookLoaderUnitTests.java index fef14e1..3ca04ae 100644 --- a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookLoaderUnitTests.java +++ b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookLoaderUnitTests.java @@ -29,6 +29,7 @@ import com.badlogic.gdx.utils.reflect.Method; import com.badlogic.gdx.utils.reflect.ReflectionException; +import de.tomgrill.gdxfacebook.core.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,11 +38,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import de.tomgrill.gdxfacebook.android.AndroidGDXFacebook; -import de.tomgrill.gdxfacebook.core.FallbackGDXFacebook; import de.tomgrill.gdxfacebook.core.GDXFacebook; -import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; -import de.tomgrill.gdxfacebook.core.GDXFacebookSystem; -import de.tomgrill.gdxfacebook.core.GDXFacebookVars; import de.tomgrill.gdxfacebook.desktop.DesktopGDXFacebook; import de.tomgrill.gdxfacebook.html.HTMLGDXFacebook; import de.tomgrill.gdxfacebook.ios.IOSGDXFacebook; @@ -79,7 +76,7 @@ public void ifNoPlatformGDXFacebookCanBeFoundReturnFallbackGDXFacebook() { Gdx.app = mockApplication; facebook = GDXFacebookSystem.install(new GDXFacebookConfig()); - assertTrue(facebook instanceof FallbackGDXFacebook); + assertTrue(facebook instanceof FallbackGDXFacebookIF); } diff --git a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookUnitTests.java b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookUnitTests.java index ec9cb75..93d9134 100644 --- a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookUnitTests.java +++ b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/GDXFacebookUnitTests.java @@ -20,11 +20,11 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Net; +import de.tomgrill.gdxfacebook.core.GDXFacebook; +import de.tomgrill.gdxfacebook.tests.core.stubs.GDXFacebookStub; import org.junit.Before; -import de.tomgrill.gdxfacebook.core.GDXFacebook; import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; -import de.tomgrill.gdxfacebook.tests.core.stubs.GDXFacebookStub; import static org.mockito.Mockito.mock; diff --git a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/JsonResultUnitTests.java b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/JsonResultUnitTests.java index a6dfda9..b7ae9b2 100644 --- a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/JsonResultUnitTests.java +++ b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/JsonResultUnitTests.java @@ -15,7 +15,7 @@ ******************************************************************************/ -package de.tomgrill.gdxfacebook.tests.core; +package de.tomgrill.gdxfacebook.core; import com.badlogic.gdx.utils.JsonReader; import com.badlogic.gdx.utils.JsonValue; diff --git a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/stubs/GDXFacebookStub.java b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/stubs/GDXFacebookStub.java index f65096b..7e96726 100644 --- a/tests-core/src/de/tomgrill/gdxfacebook/tests/core/stubs/GDXFacebookStub.java +++ b/tests-core/src/de/tomgrill/gdxfacebook/tests/core/stubs/GDXFacebookStub.java @@ -19,14 +19,8 @@ import com.badlogic.gdx.utils.Array; -import de.tomgrill.gdxfacebook.core.GDXFacebookAccessToken; +import de.tomgrill.gdxfacebook.core.*; import de.tomgrill.gdxfacebook.core.GDXFacebook; -import de.tomgrill.gdxfacebook.core.GDXFacebookCallback; -import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; -import de.tomgrill.gdxfacebook.core.GDXFacebookGameRequest; -import de.tomgrill.gdxfacebook.core.GameRequestResult; -import de.tomgrill.gdxfacebook.core.SignInResult; -import de.tomgrill.gdxfacebook.core.SignInMode; public class GDXFacebookStub extends GDXFacebook { public GDXFacebookStub(GDXFacebookConfig config) { @@ -43,6 +37,11 @@ public void showGameRequest(GDXFacebookGameRequest request, GDXFacebookCallback< } + @Override + public void gameRequest(GDXFacebookGameRequest request, GDXFacebookCallback callback) { + + } + @Override public GDXFacebookAccessToken getAccessToken() {