Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
980 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Playtomic/out/* |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+52 Bytes
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/GameVars.class
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/Leaderboards$1.class
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/Leaderboards$2.class
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/Leaderboards$3.class
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/Leaderboards.class
Binary file not shown.
Binary file modified
BIN
+1.82 KB
(300%)
Playtomic/out/production/Playtomic/com/playtomic/android/PResponse.class
Binary file not shown.
Binary file modified
BIN
+25 Bytes
(100%)
Playtomic/out/production/Playtomic/com/playtomic/android/PlayerScore.class
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
Playtomic/out/production/Playtomic/com/playtomic/tests/PTest.class
Binary file not shown.
Binary file modified
BIN
+6 Bytes
(100%)
Playtomic/out/production/Playtomic/com/playtomic/tests/PTestLeaderboards.class
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
Playtomic/out/production/Playtomic/com/playtomic/tests/PTests$15.class
Binary file not shown.
Binary file modified
BIN
+479 Bytes
(120%)
Playtomic/out/production/Playtomic/com/playtomic/tests/PTests.class
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
Playtomic/src/com/playtomic/android/AchievementListHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.playtomic.android; | ||
|
||
import java.util.ArrayList; | ||
|
||
public interface AchievementListHandler { | ||
void onSuccess(ArrayList<PlayerAchievement> achievements, PResponse response); | ||
void onFailure(PResponse response); | ||
} |
6 changes: 6 additions & 0 deletions
6
Playtomic/src/com/playtomic/android/AchievementSaveHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.playtomic.android; | ||
|
||
public interface AchievementSaveHandler { | ||
void onSuccess(PResponse response); | ||
void onFailure(PResponse response); | ||
} |
8 changes: 8 additions & 0 deletions
8
Playtomic/src/com/playtomic/android/AchievementStreamHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.playtomic.android; | ||
|
||
import java.util.ArrayList; | ||
|
||
public interface AchievementStreamHandler { | ||
void onSuccess(ArrayList<PlayerAward> achievements, int numachievements, PResponse response); | ||
void onFailure(PResponse response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.playtomic.android; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.json.JSONArray; | ||
import java.util.ArrayList; | ||
|
||
public class Achievements { | ||
|
||
private static String SECTION = "achievements"; | ||
private static String LIST = "list"; | ||
private static String STREAM = "stream"; | ||
private static String SAVE = "save"; | ||
|
||
/** | ||
* Loads all achievements | ||
* @parma options ListOptions or JSONObject of options | ||
* @param callback AchievementListHandler for receiving the response and data | ||
*/ | ||
public static void list(ListOptions options, final AchievementListHandler callback) { | ||
PRequest.load(SECTION, LIST, options, new PResponseHandler() { | ||
@Override | ||
public void onResponse(PResponse response, JSONObject data) { | ||
if(response.getSuccess()) | ||
{ | ||
ArrayList<PlayerAchievement> achievements = new ArrayList<PlayerAchievement>(); | ||
JSONArray acharray = data.optJSONArray("achievements"); | ||
|
||
for(int i=0; i<acharray.length(); i++) { | ||
JSONObject achjson = null; | ||
try { | ||
achjson = (JSONObject) acharray.get(i); | ||
} catch (JSONException e) { | ||
continue; | ||
} | ||
achievements.add(new PlayerAchievement(achjson)); | ||
} | ||
|
||
callback.onSuccess(achievements, response); | ||
} | ||
else | ||
{ | ||
callback.onFailure(response); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Loads a stream of achievements by players | ||
* @parma options ListOptions or JSONObject of options | ||
* @param callback AchievementStreamHandler for receiving the response and data | ||
*/ | ||
public static void stream(ListOptions options, final AchievementStreamHandler callback) { | ||
PRequest.load(SECTION, STREAM, options, new PResponseHandler() { | ||
@Override | ||
public void onResponse(PResponse response, JSONObject data) { | ||
if(response.getSuccess()) | ||
{ | ||
ArrayList<PlayerAward> achievements = new ArrayList<PlayerAward>(); | ||
JSONArray acharray = data.optJSONArray("achievements"); | ||
int numachievements = data.optInt("numachievements"); | ||
|
||
for(int i=0; i<acharray.length(); i++) { | ||
JSONObject achjson = null; | ||
try { | ||
achjson = (JSONObject) acharray.get(i); | ||
} catch (JSONException e) { | ||
continue; | ||
} | ||
achievements.add(new PlayerAward(achjson)); | ||
} | ||
|
||
callback.onSuccess(achievements, numachievements, response); | ||
} | ||
else | ||
{ | ||
callback.onFailure(response); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Saves the level | ||
* @param achievement The PlayerAchievement to save | ||
* @param callback AchievementSaveHandler for receiving the response and data | ||
*/ | ||
public static void save(PlayerAchievement achievement, final AchievementSaveHandler callback) { | ||
|
||
PRequest.load(SECTION, SAVE, achievement, new PResponseHandler() { | ||
@Override | ||
public void onResponse(PResponse response, JSONObject data) { | ||
if(response.getSuccess()) | ||
{ | ||
callback.onSuccess(response); | ||
} | ||
else | ||
{ | ||
callback.onFailure(response); | ||
} | ||
} | ||
}); | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
Playtomic/src/com/playtomic/android/PlayerAchievement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.playtomic.android; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.Locale; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import org.json.JSONObject; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
public class PlayerAchievement extends JSONObject { | ||
|
||
public PlayerAchievement() { | ||
|
||
} | ||
|
||
public PlayerAchievement(JSONObject data) { | ||
|
||
if(data == null) { | ||
return; | ||
} | ||
|
||
Iterator<?> keys = data.keys(); | ||
|
||
while (keys.hasNext()) { | ||
String key = keys.next().toString(); | ||
setValue(key, data.opt(key)); | ||
} | ||
} | ||
|
||
public PlayerAward getPlayer() | ||
{ | ||
if(!has("player")) { | ||
return null; | ||
} | ||
|
||
return new PlayerAward((JSONObject) opt("player")); | ||
} | ||
|
||
public ArrayList<PlayerAward> getFriends() | ||
{ | ||
if(!has("friends")) { | ||
return null; | ||
} | ||
|
||
ArrayList<PlayerAward> friends = new ArrayList<PlayerAward>(); | ||
JSONArray friendsraw = optJSONArray("friends"); | ||
|
||
if(friendsraw == null) { | ||
return null; | ||
} | ||
|
||
for(int i = 0; i<friendsraw.length(); i++) { | ||
JSONObject friendobj = (JSONObject)friendsraw.opt(i); | ||
PlayerAward award = new PlayerAward(friendobj); | ||
friends.add(award); | ||
} | ||
|
||
return friends; | ||
} | ||
|
||
public String getPlayerId() { | ||
return optString("playerid", ""); | ||
} | ||
|
||
public void setPlayerId(String playerid) { | ||
setValue("playerid", playerid); | ||
} | ||
|
||
public String getPlayerName() { | ||
return optString("playername", ""); | ||
} | ||
|
||
public void setPlayerName(String name) { | ||
setValue("playername", name); | ||
} | ||
|
||
public String getAchievement() { | ||
return optString("achievement", ""); | ||
} | ||
|
||
public void setAchievement(String name) { | ||
setValue("achievement", name); | ||
} | ||
|
||
public void setAchievementKey(String name) { | ||
setValue("achievementkey", name); | ||
} | ||
|
||
public String getSource() { | ||
return optString("source", ""); | ||
} | ||
|
||
public void setSource(String source) { | ||
setValue("source", source); | ||
} | ||
|
||
public void setAllowDuplicates() { | ||
setValue("allowduplicates", true); | ||
} | ||
|
||
public void setOverwrite() { | ||
setValue("overwrite", true); | ||
} | ||
|
||
public JSONObject fields() { | ||
|
||
if(!has("fields")) { | ||
setValue("fields", new JSONObject()); | ||
} | ||
|
||
return optJSONObject("fields"); | ||
} | ||
|
||
public void setField(String name, Object value) { | ||
if(!has("fields")) { | ||
setValue("fields", new JSONObject()); | ||
} | ||
|
||
try { | ||
fields().put(name, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
|
||
public String getRDate() { | ||
return optString("rdate", "Just now"); | ||
} | ||
|
||
public Date getDate() { | ||
SimpleDateFormat dateparser = new SimpleDateFormat("yyyy/mm/dd", Locale.US); | ||
String datestring = optString("date", dateparser.format(new Date())); | ||
try { | ||
return dateparser.parse(datestring); | ||
} catch (ParseException e) { | ||
return new Date(); | ||
} | ||
} | ||
|
||
private void setValue(String key, Object value) | ||
{ | ||
try { | ||
put(key, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.playtomic.android; | ||
|
||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.Locale; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import org.json.JSONObject; | ||
import org.json.JSONException; | ||
|
||
public class PlayerAward extends JSONObject { | ||
|
||
public PlayerAward() { | ||
|
||
} | ||
|
||
public PlayerAward(JSONObject data) { | ||
|
||
if(data == null) { | ||
return; | ||
} | ||
|
||
Iterator<?> keys = data.keys(); | ||
|
||
while (keys.hasNext()) { | ||
String key = keys.next().toString(); | ||
setValue(key, data.opt(key)); | ||
} | ||
} | ||
|
||
public String getPlayerId() { | ||
return optString("playerid", ""); | ||
} | ||
|
||
public void setPlayerId(String playerid) { | ||
setValue("playerid", playerid); | ||
} | ||
|
||
public String getPlayerName() { | ||
return optString("playername", ""); | ||
} | ||
|
||
public void setPlayerName(String name) { | ||
setValue("playername", name); | ||
} | ||
|
||
public String getSource() { | ||
return optString("source", ""); | ||
} | ||
|
||
public void setSource(String source) { | ||
setValue("source", source); | ||
} | ||
|
||
public JSONObject fields() { | ||
|
||
if(!has("fields")) { | ||
setValue("fields", new JSONObject()); | ||
} | ||
|
||
return optJSONObject("fields"); | ||
} | ||
|
||
public void setField(String name, Object value) { | ||
if(!has("fields")) { | ||
setValue("fields", new JSONObject()); | ||
} | ||
|
||
try { | ||
fields().put(name, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
|
||
public PlayerAchievement getAwarded() { | ||
if(!has("awarded")) { | ||
return null; | ||
} | ||
|
||
JSONObject awardobj = (JSONObject)optJSONObject("awarded"); | ||
return new PlayerAchievement(awardobj); | ||
} | ||
|
||
public long getAwards() { | ||
return optLong("awards"); | ||
} | ||
|
||
public String getRDate() { | ||
return optString("rdate", "Just now"); | ||
} | ||
|
||
public Date getDate() { | ||
SimpleDateFormat dateparser = new SimpleDateFormat("yyyy/mm/dd", Locale.US); | ||
String datestring = optString("date", dateparser.format(new Date())); | ||
try { | ||
return dateparser.parse(datestring); | ||
} catch (ParseException e) { | ||
return new Date(); | ||
} | ||
} | ||
|
||
private void setValue(String key, Object value) | ||
{ | ||
try { | ||
put(key, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.