[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052319.91652055109315381686715684138416:50510728022827:2800:FC952AFE185EDD3AE7790B2E6D1F1F98A09275B36E291D18F29BA650F3C16A85.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052319.91652055109315381686715684138416:50510728022827:2800:FC952AFE185EDD3AE7790B2E6D1F1F98A09275B36E291D18F29BA650F3C16A85.gif[/IMG]​

Introduction:

In this tutorial we will work through the steps you need to take to add achievements to a simple Tic Tac Toe Android game. We will define an achievement in the App Gallery Connect and implement the achievement interaction in the game.

Why do we need to add achievement in the game?

Basically all developers’ wants engage their users. To make sure user uses application all the time, Achievement is the great way to increase user’s engagement in the game. Achievement will have the badges or some points based progress so that user can compare their progress with the other game players so that they will get motivation to play game. Achievement encourages the users to play the game.

Achievement

Attributes:

· Id: A unique achievement string id generated by AGC.

· Name: Achievement short name max 100 characters.

· Description: This attribute which explains user how to earn this achievement. Maximum 500 characters.

· Icon: Image of achievement where it will be displayed after earning the achievement. Maximum resolution is 512x512

· State: There are 3 types of states.

o Hidden: A hidden achievement means that details about the achievement are hidden from the player. Such achievements are equipped with a generic placeholder description and icon while in a hidden state. If an achievement contains a spoiler about your game that you would like not to reveal, you may configure the achievement as hidden and reveal it to the payer after the game reaches a certain stage.

o Revealed: A revealed achievement means that the player knows about the achievement, but has not yet earned it. If you wish to show the achievement to the player at the start of the game, you can configure it to this state.

o Unlocked: An unlocked achievement means that the player has successfully earned the achievement. This state is unconfigurable and must be earned by the player. After the player achieves this state, a pop-up will display at the top of the game page. HMS SDK allows for an achievement to be unlocked offline. When a game comes back online, it synchronizes with the Huawei game server to update the achievement's unlocked state.

· Steps: Achievements can be designated as standard or incremental. An incremental achievement involves a player completing a number of steps to unlock the achievement. These predefined number of steps are known as the achievement steps.

· List order: The order in which the current achievement appears among all of the achievements. It is designated during achievement configuration.

HMS SDK allows apps to perform the following operations for achievements:

1. Directly jump to the achievements page of Huawei AppAssistant. (Note only released app achievements will be shown in AppAssistant application. As of now AppAssistant app is not available in the App Gallery)

2. Initialize achievement client and get data. So that game application show the list of the achievements. Using the custom design.

Adding achievement in AGC.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052452.22137515778597383137338552065690:50510728022827:2800:8A041F3E5BA997CF227F5A452841DF53D6417A3083041B6614A6017C1C2AFA65.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052452.22137515778597383137338552065690:50510728022827:2800:8A041F3E5BA997CF227F5A452841DF53D6417A3083041B6614A6017C1C2AFA65.png[/IMG]​

On AGC navigate to operate->Game Achievement then click create button.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052520.20426684606536202438806091692515:50510728022827:2800:75963A0623C8A46321A61ABE910DD1CA7605DD80F53D5266595B34A40D14B8C0.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052520.20426684606536202438806091692515:50510728022827:2800:75963A0623C8A46321A61ABE910DD1CA7605DD80F53D5266595B34A40D14B8C0.png[/IMG]​

Fill all the fields like name, description, Icon, steps, initial state and list of order.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052553.63493606013229864496856764142123:50510728022827:2800:5BFA6890639295936F499AE0705AD819F390C44A8170DDB0847C48DC6910EFAD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052553.63493606013229864496856764142123:50510728022827:2800:5BFA6890639295936F499AE0705AD819F390C44A8170DDB0847C48DC6910EFAD.png[/IMG]​

In the above image 2 achievements has already release and two more created and those can be released on clicking of release button which is marked in image. Another two achievements are testable. Using the sandbox test account game can be tested.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052622.21002683741392093767717904636331:50510728022827:2800:77DD7C7E8E985BFD2B60A5252FC34FD196FE245F78B01CECFD0759FE5B1496C4.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052622.21002683741392093767717904636331:50510728022827:2800:77DD7C7E8E985BFD2B60A5252FC34FD196FE245F78B01CECFD0759FE5B1496C4.png[/IMG]​

After releasing the achievements it will be waiting for review state. It takes some time to review from the Huawei reviewer. And then it will be approved.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052644.69601004548006560883383140466288:50510728022827:2800:2BD3C3DDB87B60B9349EF43FB05B9B5E81E6879AF9C939869CA022171A364CF2.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052644.69601004548006560883383140466288:50510728022827:2800:2BD3C3DDB87B60B9349EF43FB05B9B5E81E6879AF9C939869CA022171A364CF2.png[/IMG]​

If the achievements is under review state. Cannot add/modify the achievement. And achievement can delete only before release. And one more thing here is progress can be reset before release.

Now let’s come to android application. Please refer my previous article to android application set up and HMS game SDK configuration.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052709.03986937911156572768730763381449:50510728022827:2800:BFB0798A04255DB1033C89FFCBBA5FC1EF38DAE8B0A4E810C4BFCFFF2AADAE5E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052709.03986937911156572768730763381449:50510728022827:2800:BFB0798A04255DB1033C89FFCBBA5FC1EF38DAE8B0A4E810C4BFCFFF2AADAE5E.png[/IMG]​

The above screen is sign in screen. Once sign is success achievement button will be enabled.

​

When user clicks on my achievement it will redirect achievement screen.

private AchievementsClient client; private void getAchievementData() {client = Games.getAchievementsClient(this, authHuaweiId);
Task<List<Achievement>> task = client.getAchievementList(forceReload);
task.addOnSuccessListener(new OnSuccessListener<List<Achievement>>() {
@Override
public void onSuccess(List<Achievement> data) {
if (data == null) {
showLog("achievement data is null");
return;
}
Iterator<Achievement> iterator = data.iterator();
achievements.clear();
//Log.e("achievement","data :"+new Gson().toJson(data));
while (iterator.hasNext()) {
Achievement achievement = iterator.next();
achievements.add(achievement);

Log.e("achievement", "Data: " + " Display name: " + achievement.getDisplayName() + " Id: " + achievement.getId()
+ " Description " + achievement.getDescInfo() + " Locale All steps: " + achievement.getLocaleAllSteps()
+ " LocaleReachedSteps: " + achievement.getLocaleReachedSteps() + " describeContents: " + achievement.describeContents()
+ " AllSteps: " + achievement.getAllSteps() + " getReachedSteps: " + achievement.getReachedSteps() + " Player Name :" + achievement.getGamePlayer().getDisplayName()
+ "getReachedThumbnailUri : " + achievement.getReachedThumbnailUri().toString() + " getState : " + achievement.getState() + " getVisualizedThumbnailUri :" + achievement.getVisualizedThumbnailUri().toString() + "\n"
);
//Log.e("achievement","data :"+new Gson().toJson(achievement));
}
adapter.setData(achievements);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException) {
String result = "rtnCode:" + ((ApiException) e).getStatusCode();
showLog(result);
}
}
});
}

Above code gets the achievement data. And set the recyclerview adapter.

@Override
public void Unlock(String achievementId, boolean isChecked) {
if (!isChecked) {
client.reach(achievementId);
} else {
performUnlockImmediate(client, achievementId);
}
}

@Override
public void reveal(String achievementId, boolean isChecked) {
if (!isChecked) {
client.visualize(achievementId);
} else {
performRevealImmediate(client, achievementId);
}
}

@Override
public void increment(String achievementId, boolean isChecked) {
if (!isChecked) {
client.grow(achievementId, 1);
} else {
performIncrementImmediate(client, achievementId, 1);
}
}

@Override
public void setStep(String achievementId, boolean isChecked) {
if (!isChecked) {
client.makeSteps(achievementId, 3);
} else {
performSetStepsImmediate(client, achievementId, 3);
}
}

private void performSetStepsImmediate(AchievementsClient client, String achievementId, int stepsNum) {
Task<Boolean> task = client.makeStepsWithResult(achievementId, stepsNum);
task.addOnSuccessListener(new OnSuccessListener<Boolean>() {
@Override
public void onSuccess(Boolean isSucess) {
if (isSucess) {
Toast.makeText(AchievementListActivity.this, "setAchievementSteps is Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(AchievementListActivity.this, "achievement can not make steps", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException) {
String result = "rtnCode:" + ((ApiException) e).getStatusCode();
Toast.makeText(AchievementListActivity.this, "step num is invalid " + result, Toast.LENGTH_SHORT).show();
}
}
});
}

private void performIncrementImmediate(AchievementsClient client, String achievementId, int stepsNum) {
Task<Boolean> task = client.growWithResult(achievementId, stepsNum);

task.addOnSuccessListener(new OnSuccessListener<Boolean>() {
@Override
public void onSuccess(Boolean isSucess) {
if (isSucess) {
Toast.makeText(AchievementListActivity.this, "incrementAchievement is Success", Toast.LENGTH_SHORT).show();
getAchievementData();
} else {
Toast.makeText(AchievementListActivity.this, "achievement can not grow", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException) {
String result = "rtnCode:" + ((ApiException) e).getStatusCode();
Toast.makeText(AchievementListActivity.this, "has bean already unlocked " + result, Toast.LENGTH_SHORT).show();
}
}
});
}

private void performRevealImmediate(AchievementsClient client, String achievementId) {
Task<Void> task = client.visualizeWithResult(achievementId);
task.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void v) {
Toast.makeText(AchievementListActivity.this, "reveal Achievement is Success", Toast.LENGTH_SHORT).show();
getAchievementData();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException) {
String result = "rtnCode:" + ((ApiException) e).getStatusCode();
Toast.makeText(AchievementListActivity.this, "achievement is not hidden" + result, Toast.LENGTH_SHORT).show();
}
}
});
}

private void performUnlockImmediate(AchievementsClient client, String achievementId) {
Task<Void> task = client.reachWithResult(achievementId);

task.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void v) {
Toast.makeText(AchievementListActivity.this, "Unlock Achievement is Success", Toast.LENGTH_SHORT).show();
getAchievementData();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException) {
String result = "rtnCode:" + ((ApiException) e).getStatusCode();
Toast.makeText(AchievementListActivity.this, "achievement has been already unlocked" + result, Toast.LENGTH_SHORT).show();
}
}
});
}

The above code does the Increment, Reveal, Unlock, SetStep. In the Tic Tac Toe game when user wins will increment step once step is reached the steps which is set while creating achievement, Then achievement will be unlocked. When user win the game achievement step will increment. Once the hidden achievement step is reached then achievement will be revealed. If you want to set increment manually setIncrement will be used.

Result:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052752.86831562345749326282793836025587:50510728023818:2800:03B13C68D42D5D2E7C5E00278E0D5AA4880B833F6E7A949256FB02539870982A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052752.86831562345749326282793836025587:50510728023818:2800:03B13C68D42D5D2E7C5E00278E0D5AA4880B833F6E7A949256FB02539870982A.png[/IMG]​

This is to show the list of achievements.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052803.45884409692548913150796616013685:50510728023818:2800:BD6E580B282748E4A52F866831AF6971B3F14282C2C4A2BE146408B88345E1C0.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052803.45884409692548913150796616013685:50510728023818:2800:BD6E580B282748E4A52F866831AF6971B3F14282C2C4A2BE146408B88345E1C0.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052822.03110040869172702215885448094172:50510728024616:2800:BD05FB308AC6283E8C1FAD7936B87E2A0ACECBE63B61FFA0EF53710C160818C1.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052822.03110040869172702215885448094172:50510728024616:2800:BD05FB308AC6283E8C1FAD7936B87E2A0ACECBE63B61FFA0EF53710C160818C1.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052837.82186507210292882236414248829513:50510728023818:2800:737B1C88370A96AA8A0F58682D5AE7FBFB17AD186E128C5069FC563AA0FBB7FD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052837.82186507210292882236414248829513:50510728023818:2800:737B1C88370A96AA8A0F58682D5AE7FBFB17AD186E128C5069FC563AA0FBB7FD.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052852.92021132970935816751869623437800:50510728023818:2800:5307FCBE466D27E5537261354037A32ABA6284060C4E77D5A017383ED8254EB8.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200616052852.92021132970935816751869623437800:50510728023818:2800:5307FCBE466D27E5537261354037A32ABA6284060C4E77D5A017383ED8254EB8.png[/IMG]​