android and ios achievements.

This commit is contained in:
Bryce Covert
2018-01-04 21:54:21 -08:00
parent c4e4a14be3
commit e95d6c4be1
24 changed files with 379 additions and 24 deletions

View File

@@ -15,6 +15,8 @@
android:hardwareAccelerated="true"
android:largeHeap="true"
android:label="Tick's Tales">
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id"/>
<activity android:name="advent.core.SplashActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:screenOrientation="landscape"

View File

@@ -14,34 +14,42 @@
[com.android.billingclient/billing "dp-1" :extension "aar"]
[org.clojure/tools.logging "0.3.1"]
[com.google.android.gms/play-services-games "11.6.2" :extension "aar" :exclusions [com.android.support/support-annotations]]
[com.google.android.gms/play-services-auth "11.6.2" :extension "aar" :exclusions [com.android.support/support-annotations]]
#_[com.google.android.gms/play-services "11.6.2" :extension "aar" :exclusions [com.android.support/support-annotations]]
[org.clojure/tools.logging "0.3.1" :exclusions [org.clojure/clojure]]
[org.clojure-android/clojure "1.7.0-r4"]
[org.im4java/im4java "1.4.0"]
[org.clojure/tools.nrepl "0.2.7"]
[play-clj "0.4.6-BRYCE"]
[play-clj "0.4.6-BRYCE" :exclusions [org.clojure/clojure]]
[org.clojure/data.priority-map "0.0.5"]
[org.clojure/core.async "0.2.371"]]
:plugins [[lein-droid "0.4.6"]]
:repositories [["jCenter" "https://jcenter.bintray.com/"]]
[org.clojure/core.async "0.2.371" :exclusions [org.clojure/clojure]]]
:plugins [[lein-droid "0.4.6" :exclusions [org.clojure/clojure] ]]
:repositories [["jCenter" "https://jcenter.bintray.com/"]
["google" "https://maven.google.com"]]
:profiles {:dev {:dependencies [[android/tools.nrepl "0.2.0-bigstack"]
[compliment "0.1.3"]]
[compliment "0.1.3"]
[org.clojure/tools.nrepl "0.2.7" :exclusions [org.clojure/clojure]]]
:jvm-opts ["-Dplatform=android"]
:android {:aot :all-with-unused
:rename-manifest-package "tickstales.core.debug"
:manifest-options {:app-name "ticks tales (debug)"}
:aot-exclude-ns ["clojure.core.memoize" "core.async"]}}
:release {:android
:release {
:jvm-opts ["-Dplatform=android"]
:android
{;; Specify the path to your private
;; keystore and the the alias of the
;; key you want to sign APKs with.
;; :keystore-path "ticks-talkes-release.jks"
;; :key-alias "ticks-tales-release"
:jvm-opts ["-Dplatform=android"]
:build-type :release
:aot :all-with-unused
:aot-exclude-ns [cljs.core.async.macros cljs.core.impl-ioc-macros cljs.core.impl.ioc_macros]}}}

View File

@@ -2,5 +2,6 @@
<resources>
<string name="app_name">advent</string>
<string name="app_id">891208148801</string>
</resources>

View File

@@ -0,0 +1,88 @@
package advent.core;
import clojure.lang.RT;
import clojure.lang.Symbol;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.backends.android.AndroidApplication;
import android.support.annotation.NonNull;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.assets.AssetManager;
import com.google.android.gms.games.*;
import com.google.android.gms.auth.api.signin.*;
import android.app.Activity;
import android.content.Intent;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
public class GooglePlay {
static GoogleSignInAccount mAccount;
public void signIn(Activity act) {
GoogleSignInClient signInClient = GoogleSignIn.getClient(act, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
Intent intent = signInClient.getSignInIntent();
act.startActivityForResult(intent, 14562);
}
public void signInSilently(Activity act) {
GoogleSignInClient signInClient = GoogleSignIn.getClient(act, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
System.out.println("trying silent sign in");
signInClient.silentSignIn().addOnCompleteListener(act,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
System.out.println("silent sign in succeeded.");
signedIn(task.getResult());
} else {
}
}
});
}
public static void signedIn(GoogleSignInAccount acct) {
mAccount = acct;
}
public void showAchievements(final Activity act) {
if (mAccount != null) {
com.google.android.gms.games.Games.getAchievementsClient(act, mAccount).getAchievementsIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
System.out.println("SUCCESS");
act.startActivityForResult(intent, 0);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
System.out.println("FAIL");
System.out.println(e.toString());
}
});
} else {
signIn(act);
}
}
public void setAchievement(Activity act, String a) {
System.out.println("TRYING TO UNLOCK");
System.out.println(a);
if (mAccount != null) {
System.out.println(mAccount.toString());
com.google.android.gms.games.Games.getAchievementsClient(act, mAccount).unlock(a);
}
}
}

View File

@@ -16,7 +16,16 @@ import com.android.billingclient.api.BillingClient.SkuType;
import com.android.billingclient.api.SkuDetails.SkuDetailsResult;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.BillingFlowParams.Builder;
import android.content.Intent;
import com.google.android.gms.common.api.ApiException;
import android.content.pm.*;
import com.google.android.gms.games.*;
import com.google.android.gms.auth.api.signin.*;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import android.app.AlertDialog;
public class MainActivity extends AndroidApplication {
public boolean triggerPurchase() {
@@ -25,6 +34,43 @@ public class MainActivity extends AndroidApplication {
int returnValue = mBillingClient.launchBillingFlow(this, builder.build());
return returnValue == BillingClient.BillingResponse.OK || returnValue == BillingClient.BillingResponse.ITEM_ALREADY_OWNED;
}
@Override
protected void onResume() {
super.onResume();
// Since the state of the signed in user can change when the activity is not active
// it is recommended to try and sign in silently from when the app resumes.
new GooglePlay().signInSilently(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 14562) {
System.out.println("LOGIN RESULT");
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
System.out.println("GOT ACCOUNT");
System.out.println(account.toString());
GooglePlay.signedIn(account);
new GooglePlay().showAchievements(this);
} catch (ApiException apiException) {
System.out.println("NOT GOT ACCOUNT");
System.out.println(apiException.toString());
new AlertDialog.Builder(this)
.setMessage("Could not sign in to Google Play")
.setNeutralButton("Ok", null)
.show();
}
}
}
private BillingClient mBillingClient;