com.google.android.gms.games.achievement.Achievement Java Examples
The following examples show how to use
com.google.android.gms.games.achievement.Achievement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AchievementsLoadListener.java From ANE-Google-Play-Game-Services with Apache License 2.0 | 6 votes |
@Override public void onAchievementsLoaded(int statusCode, AchievementBuffer achBuffer) { if (statusCode == GamesClient.STATUS_OK) { Iterator<Achievement> iterator = achBuffer.iterator(); while(iterator.hasNext()){ Achievement achievement = iterator.next(); if(achievement.getType() == Achievement.TYPE_INCREMENTAL && achievement.getAchievementId().equals(achievementId)) { this.incrementAchievementWhenDataIsLoaded(achievement); } } } else{ //Achievements loading has failed } achBuffer.close(); }
Example #2
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
public boolean fetchAchievementsSync(IFetchAchievementsResponseListener callback) { if (!isSessionActive()) return false; Achievements.LoadAchievementsResult achievementsResult = Games.Achievements.load( mGoogleApiClient, forceRefresh).await(); if (!achievementsResult.getStatus().isSuccess()) { Gdx.app.log(GAMESERVICE_ID, "Failed to fetch achievements:" + achievementsResult.getStatus().getStatusMessage()); callback.onFetchAchievementsResponse(null); return false; } AchievementBuffer achievements = achievementsResult.getAchievements(); Array<IAchievement> gpgsAchs = new Array<IAchievement>(achievements.getCount()); for (Achievement ach : achievements) { GpgsAchievement gpgsAchievement = new GpgsAchievement(); gpgsAchievement.achievementId = ach.getAchievementId(); gpgsAchievement.achievementMapper = gpgsAchievementIdMapper; gpgsAchievement.description = ach.getDescription(); gpgsAchievement.title = ach.getName(); if (ach.getState() == Achievement.STATE_UNLOCKED) gpgsAchievement.percCompl = 1f; else if (ach.getType() == Achievement.TYPE_INCREMENTAL) gpgsAchievement.percCompl = (float) ach.getCurrentSteps() / ach.getTotalSteps(); gpgsAchs.add(gpgsAchievement); } achievements.release(); callback.onFetchAchievementsResponse(gpgsAchs); return true; }
Example #3
Source File: GooglePlay.java From ExtensionsPack with MIT License | 5 votes |
public void onAchievementsLoaded(int statusCode, AchievementBuffer buffer) { Log.i("trace", what + ": GooglePlayCallback.onAchievementsLoaded: " + statusCode); for(Achievement a : buffer) { String id = a.getAchievementId(); int state = a.getState(); int type = a.getType(); GooglePlay.connectionCallback.call("addAchievement", new Object[] {id, state, type}); } GooglePlay.connectionCallback.call("onAchievementsLoaded", new Object[]{}); }
Example #4
Source File: AchievementsLoadListener.java From ANE-Google-Play-Game-Services with Apache License 2.0 | 5 votes |
public void incrementAchievementWhenDataIsLoaded(Achievement achievement){ if(achievement != null){ int currentStep = achievement.getCurrentSteps(); percent -= currentStep; } if(percent <= 0) return; // Extension.context.getGamesClient().incrementAchievement(achievementId,percent); }
Example #5
Source File: GooglePlay.java From ExtensionsPack with MIT License | 4 votes |
public static void signIn(HaxeObject callback) { try { connectionCallback = callback; callback.call("initGamesClientErrors", new Object[] { ConnectionResult.DEVELOPER_ERROR, ConnectionResult.INTERNAL_ERROR, ConnectionResult.INVALID_ACCOUNT, ConnectionResult.LICENSE_CHECK_FAILED, ConnectionResult.NETWORK_ERROR, ConnectionResult.RESOLUTION_REQUIRED, ConnectionResult.SERVICE_DISABLED, ConnectionResult.SERVICE_INVALID, ConnectionResult.SERVICE_MISSING, ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED, ConnectionResult.SIGN_IN_REQUIRED, ConnectionResult.SUCCESS}); callback.call("initAppStateClientErrors", new Object[] { AppStateClient.STATUS_CLIENT_RECONNECT_REQUIRED, AppStateClient.STATUS_DEVELOPER_ERROR, AppStateClient.STATUS_INTERNAL_ERROR, AppStateClient.STATUS_NETWORK_ERROR_NO_DATA, AppStateClient.STATUS_NETWORK_ERROR_OPERATION_DEFERRED, AppStateClient.STATUS_NETWORK_ERROR_OPERATION_FAILED, AppStateClient.STATUS_NETWORK_ERROR_STALE_DATA, AppStateClient.STATUS_OK, AppStateClient.STATUS_STATE_KEY_LIMIT_EXCEEDED, AppStateClient.STATUS_STATE_KEY_NOT_FOUND, AppStateClient.STATUS_WRITE_OUT_OF_DATE_VERSION, AppStateClient.STATUS_WRITE_SIZE_EXCEEDED}); callback.call("initAchievementStates", new Object[] { Achievement.STATE_UNLOCKED, Achievement.STATE_REVEALED, Achievement.STATE_HIDDEN,}); callback.call("initAchievementTypes", new Object[] { Achievement.TYPE_STANDARD, Achievement.TYPE_INCREMENTAL,}); if(!gamesClient.isConnected() && !gamesClient.isConnecting()) { Log.i("trace", "Connecting to GamesClient"); // not sure should we run gamesClient.connect in thread // but unlock and increment achievement sould GLSurfaceView view = GameActivity.getMainView(); GameActivity.getInstance().runOnUiThread(new Runnable(){ public void run() { gamesClient.connect(); }}); } else if(gamesClient.isConnecting()) { Log.i("trace", "GamesClient already connecting"); } else if(gamesClient.isConnected()) { Log.i("trace", "GamesClient already connected"); connectionEstablished("GAMES_CLIENT"); } if(!appStateClient.isConnected() && !appStateClient.isConnected()) { Log.i("trace", "Connecting to AppStateClient"); GameActivity.getInstance().runOnUiThread(new Runnable(){ public void run() { appStateClient.connect(); }}); } else if(appStateClient.isConnecting()) { Log.i("trace", "AppStateClient already connecting"); } else if(appStateClient.isConnected()) { Log.i("trace", "AppStateClient already connected"); connectionEstablished("APP_STATE_CLIENT"); } } catch(Exception e) { handleException(e, "signIn"); } }