<?xml version="1.0" encoding="utf-8"?> <!-- Google Play game services IDs. Save this file as res/values/games-ids.xml in your project. --> <resources> <string name="app_id">310266082735</string> <string name="achievement_take_10_levels">HgkIr62KmoQJEAIQBg</string> <string name="achievement_take_30_levels">HgkIr62KmoQJEAIQBw</string> <string name="achievement_take_50_levels">HgkIr62KmoQJEAIQCA</string> <string name="achievement_take_70_levels">HgkIr62KmoQJEAIQCg</string> <string name="achievement_take_100_levels">HgkIr62KmoQJEAIQCQ</string> <string name="achievement_beginner_cutter">HgkIr62KmoQJEAIQDw</string> <string name="achievement_advanced_cutter">HgkIr62KmoQJEAIQEA</string> <string name="achievement_master_cutter">HgkIr62KmoQJEAIQEQ</string> <string name="achievement_lucky">HgkIr62KmoQJEAIQEg</string> <string name="achievement_cheerful">HgkIr62KmoQJEAIQEw</string> <string name="achievement_exceptional_joyous">HgkIr62KmoQJEAIQFA</string> <string name="achievement_thrust">HgkIr62KmoQJEAIQFQ</string> <string name="achievement_very_persistent">HgkIr62KmoQJEAIQFg</string> <string name="achievement_the_most_resistant">HgkIr62KmoQJEAIQFw</string> <string name="achievement_1_000_000">HgkIr62KmoQJEAIQGA</string> <string name="achievement_2_000_000">HgkIr62KmoQJEAIQGQ</string> <string name="achievement_3_000_000">HgkIr62KmoQJEAIQGg</string> <string name="achievement_unlucky">HgkIr62KmoQJEAIQGw</string> <string name="achievement_loyal">HgkIr62KmoQJEAIQHA</string> <string name="achievement_fan">HgkIr62KmoQJEAIQHQ</string> <string name="achievement_leader_of_mars">HgkIr62KmoQJEAIQHg</string> <string name="achievement_leader_of_neptune">HgkIr62KmoQJEAIQHw</string> <string name="achievement_unhurried">HgkIr62KmoQJEAIQIA</string> <string name="achievement_final_push">HgkIr62KmoQJEAIQIQ</string> <string name="leaderboard_leaderboard">HgkIr62KmoQJEAIQAQ</string> <string name="leaderboard_pack_1">HgkIr62KmoQJEAIQCw</string> <string name="leaderboard_pack_2">HgkIr62KmoQJEAIQDA</string> </resources>
<android-sdk>\extras\google\google_play_services\libproject\google-play-services_lib
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
public class MainActivity extends AndroidApplication implements GameHelperListener, ActionResolver
public interface GameHelperListener { /** * . * «Sign-in» */ void onSignInFailed(); /** */ void onSignInSucceeded(); }
public interface ActionResolver { /** */ public boolean getSignedInGPGS(); /** */ public void loginGPGS(); /** */ public void submitScoreGPGS(int score); /** * * * @param achievementId * ID . games-ids.xml */ public void unlockAchievementGPGS(String achievementId); /** Activity */ public void getLeaderboardGPGS(); /** Activity */ public void getAchievementsGPGS(); }
public class MainActivity extends AndroidApplication implements GameHelperListener, ActionResolver { // private GameHelper gameHelper; // private TestGame game; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // CLIENT_ALL API gameHelper = new GameHelper(this, GameHelper.CLIENT_ALL); // gameHelper.setConnectOnStart(false); gameHelper.enableDebugLog(true); // // ( – ) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // this ActionResolver. // - GPGS game = new TestGame(this); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); initialize(game, config); gameHelper.setup(this); } // gameHelper': onStart(), onStop() // GPGS android- @Override protected void onStart() { super.onStart(); gameHelper.onStart(this); } @Override protected void onStop() { super.onStop(); gameHelper.onStop(); } @Override protected void onDestroy() { super.onDestroy(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // gameHelper , // , // Activity gameHelper.onActivityResult(requestCode, resultCode, data); } @Override public boolean getSignedInGPGS() { // return gameHelper.isSignedIn(); } @Override public void loginGPGS() { try { runOnUiThread(new Runnable() { @Override public void run() { // . // . UI- gameHelper.beginUserInitiatedSignIn(); } }); } catch (Exception e) { e.printStackTrace(); } } @Override public void submitScoreGPGS(int score) { // ID // “HgkIr62KmoQJEAIQAQ” Games.Leaderboards.submitScore(gameHelper.getApiClient(), "HgkIr62KmoQJEAIQAQ", score); } @Override public void unlockAchievementGPGS(String achievementId) { // ID achievementId Games.Achievements.unlock(gameHelper.getApiClient(), achievementId); } @Override public void getLeaderboardGPGS() { // Activity . // Activity startActivityForResult( Games.Leaderboards.getAllLeaderboardsIntent(gameHelper .getApiClient()), 100); } @Override public void getAchievementsGPGS() { // Activity startActivityForResult( Games.Achievements.getAchievementsIntent(gameHelper .getApiClient()), 101); } @Override public void onSignInSucceeded() { } @Override public void onSignInFailed() { } }
public static void checkTotalPoints(int points) { ActionResolver res = getActionResolver(); if (!res.getSignedInGPGS()) { return; } if (points >= 1000000) { res.unlockAchievementGPGS("HgkIr62KmoQJEAIQGA"); } }
Source: https://habr.com/ru/post/238327/
All Articles