106 lines
3.8 KiB
Java
106 lines
3.8 KiB
Java
package com.rubenvandeven.emotionhero;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Typeface;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.os.Bundle;
|
|
import android.support.v7.widget.Toolbar;
|
|
import android.util.Log;
|
|
import android.view.MenuItem;
|
|
import android.view.WindowManager;
|
|
import android.widget.TextView;
|
|
|
|
import org.ocpsoft.prettytime.PrettyTime;
|
|
|
|
public class ReviewActivity extends AppCompatActivity {
|
|
|
|
|
|
public final static String INTENT_EXTRA_GAME_ID = "com.rubenvandeven.emotionhero.GAME_ID";
|
|
public final static String INTENT_EXTRA_FROM_GAME = "com.rubenvandeven.emotionhero.FROM_GAME";
|
|
|
|
|
|
protected Player player;
|
|
|
|
protected Game game;
|
|
/**
|
|
* Whether this activity is loaded from the game (else from highscores)
|
|
*/
|
|
protected boolean fromGame;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
setContentView(R.layout.activity_review);
|
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
setSupportActionBar(toolbar);
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
getSupportActionBar().setTitle("Score");
|
|
|
|
|
|
player = Player.getInstance(getApplicationContext());
|
|
|
|
// get game from Intent
|
|
long gameId = getIntent().getLongExtra(INTENT_EXTRA_GAME_ID, 0);
|
|
fromGame = getIntent().getBooleanExtra(INTENT_EXTRA_FROM_GAME, false);
|
|
Log.d("Review", "gameid:" + gameId);
|
|
if(gameId != 0) {
|
|
game = player.getGameOpenHelper().getGameByid(gameId);
|
|
if(game == null) {
|
|
Log.e("Highscore", "CANNOT FIND GAME!! " + gameId);
|
|
throw new RuntimeException("Cannot find specified game");
|
|
} else {
|
|
Log.i("Highscore", "FOUND GAME" + game.id + " " + game.score);
|
|
Log.i("Highscore", "RANK " + player.getGameOpenHelper().getLocalRankOfGame(game));
|
|
player.api.syncGame(game); // sync game if that is not already done
|
|
}
|
|
} else {
|
|
// no game specified??? SHould not be possible so finish
|
|
finish();
|
|
}
|
|
|
|
TextView lvlNameText = (TextView) findViewById(R.id.lvlNameText);
|
|
TextView dateText = (TextView) findViewById(R.id.dateText);
|
|
TextView scoreText= (TextView) findViewById(R.id.scoreText);
|
|
TextView overallScorePercText= (TextView) findViewById(R.id.overallScorePercText);
|
|
TextView improveArrow = (TextView) findViewById(R.id.improveArrow);
|
|
TextView retryArrow = (TextView) findViewById(R.id.retryArrow);
|
|
|
|
|
|
|
|
Typeface font = Typeface.createFromAsset(getAssets(), "unifont-9.0.02.ttf");
|
|
lvlNameText.setTypeface(font);
|
|
overallScorePercText.setTypeface(font);
|
|
retryArrow.setTypeface(font);
|
|
improveArrow.setTypeface(font);
|
|
|
|
lvlNameText.setText("\""+game.scenario.toString()+"\"");
|
|
PrettyTime p = new PrettyTime();
|
|
dateText.setText(p.format(game.time));
|
|
scoreText.setText(String.format("%1$.3f", game.score));
|
|
overallScorePercText.setText(String.format("%1$.0f%%", 30f));
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem menuItem)
|
|
{
|
|
switch (menuItem.getItemId()) {
|
|
case android.R.id.home:
|
|
if(fromGame) {
|
|
Intent intent = new Intent(getApplicationContext(), HighscoreActivity.class);
|
|
intent.putExtra(HighscoreActivity.INTENT_EXTRA_GAME_ID, game.id);
|
|
finish();
|
|
startActivity(intent);
|
|
} else {
|
|
onBackPressed();
|
|
}
|
|
return true;
|
|
default:
|
|
return super.onOptionsItemSelected(menuItem);
|
|
}
|
|
}
|
|
}
|