WIP Start with hgihscores

This commit is contained in:
Ruben 2016-08-19 20:47:15 +01:00
parent c3a1773837
commit 383e9d9a9a
4 changed files with 68 additions and 1 deletions

View file

@ -28,4 +28,5 @@ dependencies {
compile 'com.android.support:support-v4:23.4.0'
compile 'com.affectiva.android:affdexsdk:3.1'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.4'
}

View file

@ -80,7 +80,6 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
}
});
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -0,0 +1,19 @@
package com.rubenvandeven.emotionhero;
import java.util.Date;
/**
* Created by ruben on 19/08/16.
*/
public class Highscore {
String level;
float score;
Date time;
public Highscore(String level, float score) {
this.level = level;
this.score = score;
this.time = new Date();
}
}

View file

@ -0,0 +1,48 @@
package com.rubenvandeven.emotionhero;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
/**
* Created by ruben on 19/08/16.
*/
public class Highscores extends ArrayList<Highscore>{
public static Highscores fromJson(String json) {
Gson gson = new Gson();
return gson.fromJson(json, Highscores.class);
}
public String toJson() {
Gson gson = new Gson();
return gson.toJson(this);
}
/**
* Get the n highest scores
*/
public ArrayList<Highscore> getTopN(int n) {
Collections.sort(this, new Comparator<Highscore>() {
@Override
public int compare(Highscore score1, Highscore score2)
{
return score1.score < score2.score ? -1 : score1.score == score2.score ? 0 : 1;
}
});
return this;
}
// public ArrayList<Highscore> getLastN(int n) {
//
// }
}