Stats added
This commit is contained in:
parent
ab152917d1
commit
5e8c1bd2b1
14 changed files with 948 additions and 26 deletions
|
@ -14,6 +14,7 @@
|
|||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
@ -32,6 +33,11 @@
|
|||
</activity>
|
||||
<activity android:name="tu_darmstadt.sudoku.ui.LoadGameActivity" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="tu_darmstadt.sudoku.ui.StatsActivity"
|
||||
android:label="@string/title_activity_stats"
|
||||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -28,6 +28,7 @@ public class GameController implements IModelChangedListener {
|
|||
private int size;
|
||||
private int sectionHeight;
|
||||
private int sectionWidth;
|
||||
private int numbOfHints=0;
|
||||
private GameBoard gameBoard;
|
||||
private int[] solution;
|
||||
private GameType gameType;
|
||||
|
@ -143,6 +144,21 @@ public class GameController implements IModelChangedListener {
|
|||
return solution;
|
||||
}
|
||||
|
||||
/*public boolean loadLevel(GameBoard level) {
|
||||
if(GameBoard.isValid(level)) {
|
||||
gameBoard = level;
|
||||
}
|
||||
}*/
|
||||
|
||||
public void hint(){
|
||||
|
||||
int[] solved = solve();
|
||||
// TODO test every placed value so far
|
||||
// and reveal the selected value.
|
||||
selectValue(solved[selectedRow * getSize() + selectedCol]);
|
||||
numbOfHints++;
|
||||
}
|
||||
|
||||
private void setGameType(GameType type) {
|
||||
this.gameType = type;
|
||||
this.size = type.getSize();
|
||||
|
@ -441,6 +457,9 @@ public class GameController implements IModelChangedListener {
|
|||
timerListeners.add(listener);
|
||||
}
|
||||
}
|
||||
public int getNumbOfHints(){
|
||||
return numbOfHints;
|
||||
}
|
||||
|
||||
private void initTimer() {
|
||||
timerTask = new TimerTask() {
|
||||
|
|
|
@ -1,14 +1,135 @@
|
|||
package tu_darmstadt.sudoku.controller;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.helper.TimeContainer;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||
import tu_darmstadt.sudoku.controller.helper.HighscoreInfoContainer;
|
||||
import tu_darmstadt.sudoku.game.GameDifficulty;
|
||||
import tu_darmstadt.sudoku.game.GameType;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 19.11.2015.
|
||||
*/
|
||||
public class SaveLoadStatistics {
|
||||
//GameDifficulty, time, gamemode, #hints, AvTime, amountOf Games per GameDifficulty,
|
||||
public SaveLoadStatistics(TimeContainer t,GameDifficulty difficulty,int hints){
|
||||
|
||||
|
||||
private static String FILE_EXTENSION = ".txt";
|
||||
private static String SAVE_PREFIX = "stat";
|
||||
private static String SAVES_DIR = "stats";
|
||||
|
||||
Context context;
|
||||
private int numberOfArguents = 2;
|
||||
|
||||
//GameDifficulty, time, gamemode, #hints, AvTime, amountOf Games per GameDifficulty,
|
||||
public SaveLoadStatistics(Context context){
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public List<HighscoreInfoContainer> loadStats(GameType t) {
|
||||
File dir = context.getDir(SAVES_DIR, 0);
|
||||
List<GameDifficulty> difficulties = GameDifficulty.getValidDifficultyList();
|
||||
List<HighscoreInfoContainer> result = new ArrayList<>();
|
||||
HighscoreInfoContainer infos;
|
||||
byte[] bytes;
|
||||
FileInputStream inputStream;
|
||||
File file;
|
||||
for (GameDifficulty dif : difficulties){
|
||||
file = new File(dir,SAVE_PREFIX+t.name()+"_"+dif.name()+FILE_EXTENSION);
|
||||
bytes = new byte[(int)file.length()];
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
try {
|
||||
inputStream.read(bytes);
|
||||
}finally {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e("Failed to read file","File could not be read");
|
||||
}
|
||||
infos = new HighscoreInfoContainer(t,dif);
|
||||
infos.setInfosFromFile(new String(bytes));
|
||||
result.add(infos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void resetStats(Context context) {
|
||||
|
||||
|
||||
File dir = context.getDir(SAVES_DIR, 0);
|
||||
File file;
|
||||
for(GameType t: GameType.getValidGameTypes()){
|
||||
for(GameDifficulty d : GameDifficulty.getValidDifficultyList()){
|
||||
file = new File(dir,SAVE_PREFIX+t.name()+"_"+d.name()+FILE_EXTENSION);
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void saveGameStats(GameController gameController) {
|
||||
|
||||
|
||||
HighscoreInfoContainer infoContainer = new HighscoreInfoContainer();
|
||||
|
||||
// Read existing stats
|
||||
File dir = context.getDir(SAVES_DIR, 0);
|
||||
|
||||
File file = new File(dir, SAVE_PREFIX+gameController.getGameType().name()+"_"+gameController.getDifficulty().name()+FILE_EXTENSION);
|
||||
|
||||
|
||||
if (file.isFile()){
|
||||
byte[] bytes = new byte[(int)file.length()];
|
||||
try {
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
stream.read(bytes);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}catch (IOException e) {
|
||||
Log.e("Stats load to save game","error while load old game Stats");
|
||||
}
|
||||
|
||||
String fileStats = new String(bytes);
|
||||
if (!fileStats.isEmpty()) {
|
||||
try {
|
||||
infoContainer.setInfosFromFile(fileStats);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e("Parse Error","Illegal Atgumanet");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//add stats of current game stats or create init stats
|
||||
infoContainer.add(gameController);
|
||||
|
||||
String stats = infoContainer.getActualStats();
|
||||
try {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
try {
|
||||
stream.write(stats.getBytes());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
Log.e("File Manager", "Could not save game. IOException occured.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,137 @@
|
|||
package tu_darmstadt.sudoku.controller.helper;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.GameController;
|
||||
import tu_darmstadt.sudoku.game.GameDifficulty;
|
||||
import tu_darmstadt.sudoku.game.GameType;
|
||||
|
||||
/**
|
||||
* Created by Chris on 18.11.2015.
|
||||
*/
|
||||
|
||||
public class HighscoreInfoContainer {
|
||||
//TODO: Holds the data for Highscores.
|
||||
|
||||
private GameType type = null;
|
||||
private GameDifficulty difficulty = null;
|
||||
private int minTime = Integer.MAX_VALUE;
|
||||
private int time=0;
|
||||
private int numberOfHintsUsed =0;
|
||||
private int numberOfGames=0;
|
||||
|
||||
private int amountOfSavedArguments = 6;
|
||||
|
||||
public HighscoreInfoContainer(){
|
||||
|
||||
}
|
||||
public HighscoreInfoContainer(GameType t, GameDifficulty diff){
|
||||
type =(type == null)?t:type;
|
||||
difficulty = (difficulty == null)?diff: difficulty;
|
||||
}
|
||||
|
||||
public void add(GameController gc){
|
||||
//add all wanted Game Stats
|
||||
difficulty = (difficulty== null)?gc.getDifficulty():difficulty;
|
||||
type = (type == null)?gc.getGameType():type;
|
||||
time += gc.getTime();
|
||||
numberOfHintsUsed += gc.getNumbOfHints();
|
||||
numberOfGames++;
|
||||
minTime = (gc.getTime()< minTime) ? gc.getTime() : minTime;
|
||||
}
|
||||
|
||||
public void setInfosFromFile(String s){
|
||||
if(s.isEmpty()) return;
|
||||
String [] strings = s.split("/");
|
||||
if (strings.length != amountOfSavedArguments) {
|
||||
throw new IllegalArgumentException("Argument Exception");
|
||||
}
|
||||
try {
|
||||
time = parseTime(strings[0]);
|
||||
numberOfHintsUsed = parseHints(strings[1]);
|
||||
numberOfGames = parseNumberOfGames(strings[2]);
|
||||
minTime = parseTime(strings[3]);
|
||||
type = parseGameType(strings[4]);
|
||||
difficulty = parsDifficulty(strings[5]);
|
||||
} catch (IllegalArgumentException e){
|
||||
throw new IllegalArgumentException("Could not set Infoprmation illegal Arguments");
|
||||
}
|
||||
}
|
||||
|
||||
public GameDifficulty getDifficulty(){
|
||||
return difficulty;
|
||||
}
|
||||
public GameType getGameType(){
|
||||
return type;
|
||||
}
|
||||
public int getTime(){
|
||||
return time;
|
||||
}
|
||||
public int getMinTime(){
|
||||
return minTime;
|
||||
}
|
||||
public int getNumberOfHintsUsed(){
|
||||
return numberOfHintsUsed;
|
||||
}
|
||||
public int getNumberOfGames(){
|
||||
return numberOfGames;
|
||||
}
|
||||
|
||||
private GameType parseGameType(String s){
|
||||
return GameType.valueOf(s);
|
||||
}
|
||||
private GameDifficulty parsDifficulty(String s) {
|
||||
return GameDifficulty.valueOf(s);
|
||||
}
|
||||
|
||||
private int parseTime(String s){
|
||||
int ret = Integer.valueOf(s);
|
||||
if (ret<0){
|
||||
throw new IllegalArgumentException("Parser Exception wrong Integer");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
private int parseHints(String s){
|
||||
int ret = Integer.valueOf(s);
|
||||
if (ret<0){
|
||||
throw new IllegalArgumentException("Parser Exception wrong Integer");
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
private int parseNumberOfGames(String s) {
|
||||
int ret = Integer.valueOf(s);
|
||||
if (ret<0){
|
||||
throw new IllegalArgumentException("Parser Exception wrong Integer");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getActualStats(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(time);
|
||||
sb.append("/");
|
||||
sb.append(numberOfHintsUsed);
|
||||
sb.append("/");
|
||||
sb.append(numberOfGames);
|
||||
sb.append("/");
|
||||
sb.append(minTime);
|
||||
sb.append("/");
|
||||
sb.append(type.name());
|
||||
sb.append("/");
|
||||
sb.append(difficulty.name());
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getStats(int time,GameDifficulty gd, int numberOfHints, GameType gt){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(time);
|
||||
sb.append("/");
|
||||
sb.append(gd.name());
|
||||
sb.append("/");
|
||||
sb.append(numberOfHints);
|
||||
sb.append("/");
|
||||
sb.append(gt.name());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package tu_darmstadt.sudoku.controller.helper;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 19.11.2015.
|
||||
*/
|
||||
public class TimeContainer {
|
||||
int hours,minutes,seconds;
|
||||
public TimeContainer(int hours, int minutes, int seconds){
|
||||
this.hours=hours;
|
||||
this.minutes=minutes;
|
||||
this.seconds=seconds;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package tu_darmstadt.sudoku.game.listeners;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 25.11.2015.
|
||||
*/
|
||||
public interface IStatsListener {
|
||||
public void refresh();
|
||||
}
|
|
@ -20,8 +20,10 @@ import java.util.List;
|
|||
|
||||
import tu_darmstadt.sudoku.controller.GameStateManager;
|
||||
import tu_darmstadt.sudoku.controller.GameController;
|
||||
import tu_darmstadt.sudoku.controller.SaveLoadStatistics;
|
||||
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||
import tu_darmstadt.sudoku.game.GameDifficulty;
|
||||
import tu_darmstadt.sudoku.game.GameStatus;
|
||||
import tu_darmstadt.sudoku.game.GameType;
|
||||
import tu_darmstadt.sudoku.game.listener.IGameSolvedListener;
|
||||
import tu_darmstadt.sudoku.game.listener.ITimerListener;
|
||||
|
@ -198,8 +200,9 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
|
||||
case R.id.nav_highscore:
|
||||
// see highscore list
|
||||
//intent = new Intent(this, HighscoreActivity.class);
|
||||
//startActivity(intent);
|
||||
|
||||
intent = new Intent(this, StatsActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
|
||||
case R.id.menu_about:
|
||||
|
@ -225,6 +228,8 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
public void onSolved() {
|
||||
Toast t = Toast.makeText(this,"Congratulations you have solved the puzzle!", Toast.LENGTH_SHORT);
|
||||
t.show();
|
||||
SaveLoadStatistics s = new SaveLoadStatistics(this);
|
||||
s.saveGameStats(gameController);
|
||||
// TODO: WE WON.. do something awesome :)
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
i = new Intent(this, LoadGameActivity.class);
|
||||
break;
|
||||
case R.id.highscoreButton:
|
||||
// TODO: create highscore screen
|
||||
i = new Intent(this,StatsActivity.class);
|
||||
break;
|
||||
case R.id.settingsButton:
|
||||
i = new Intent(this, SettingsActivity.class);
|
||||
|
|
272
app/src/main/java/tu_darmstadt/sudoku/ui/StatsActivity.java
Normal file
272
app/src/main/java/tu_darmstadt/sudoku/ui/StatsActivity.java
Normal file
|
@ -0,0 +1,272 @@
|
|||
package tu_darmstadt.sudoku.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.SaveLoadStatistics;
|
||||
import tu_darmstadt.sudoku.controller.helper.HighscoreInfoContainer;
|
||||
import tu_darmstadt.sudoku.game.GameType;
|
||||
import tu_darmstadt.sudoku.ui.view.R;
|
||||
|
||||
public class StatsActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_stats);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_stats, menu);
|
||||
//getMenuInflater().inflate(R.menu.menu_stats, menu);
|
||||
return true;
|
||||
//return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_reset) {
|
||||
SaveLoadStatistics.resetStats(this);
|
||||
mSectionsPagerAdapter.refresh(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
|
||||
private FragmentManager fm;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
this.fm = fm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
// Return a PlaceholderFragment (defined as a static inner class below).
|
||||
|
||||
return PlaceholderFragment.newInstance(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return GameType.getValidGameTypes().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return getString(GameType.getValidGameTypes().get(position).getStringResID());
|
||||
}
|
||||
public void refresh(Context context){
|
||||
for (Fragment f : fm.getFragments()){
|
||||
if(f instanceof PlaceholderFragment){
|
||||
((PlaceholderFragment) f).refresh(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class PlaceholderFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the section number for this
|
||||
* fragment.
|
||||
*/
|
||||
private static final String ARG_SECTION_NUMBER = "section_number";
|
||||
private View rootView;
|
||||
private TextView difficultyView,averageTimeView,minTimeView;
|
||||
private RatingBar difficultyBarView;
|
||||
private String s;
|
||||
private int totalTime =0;
|
||||
private int totalGames =0;
|
||||
private int totalHints =0;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static PlaceholderFragment newInstance(int sectionNumber) {
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void refresh(Context context){
|
||||
resetGeneral();
|
||||
SaveLoadStatistics s = new SaveLoadStatistics(context);
|
||||
List<HighscoreInfoContainer> stats = s.loadStats(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)));
|
||||
int j =0;
|
||||
for (HighscoreInfoContainer i : stats){
|
||||
updateGeneralIfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
||||
setStats(i,j++);
|
||||
}
|
||||
setGeneralInfo();
|
||||
}
|
||||
|
||||
private void resetGeneral(){
|
||||
totalTime=0;
|
||||
totalHints=0;
|
||||
totalGames=0;
|
||||
}
|
||||
|
||||
public PlaceholderFragment() {
|
||||
}
|
||||
|
||||
|
||||
private String formatTime(int totalTime){
|
||||
int seconds = totalTime % 60;
|
||||
int minutes = ((totalTime -seconds)/60)%60 ;
|
||||
int hours = (totalTime - minutes - seconds)/(3600);
|
||||
String h,m,s;
|
||||
s = (seconds< 10)? "0"+String.valueOf(seconds):String.valueOf(seconds);
|
||||
m = (minutes< 10)? "0"+String.valueOf(minutes):String.valueOf(minutes);
|
||||
h = (hours< 10)? "0"+String.valueOf(hours):String.valueOf(hours);
|
||||
return (h + ":" + m + ":" + s);
|
||||
|
||||
}
|
||||
private void updateGeneralIfo(int time, int games, int hints){
|
||||
totalHints +=hints;
|
||||
totalGames +=games;
|
||||
totalTime +=time;
|
||||
}
|
||||
private void setGeneralInfo(){
|
||||
TextView generalInfoView;
|
||||
|
||||
generalInfoView = (TextView)rootView.findViewById(R.id.numb_of_hints);
|
||||
generalInfoView.setText(String.valueOf(totalHints));
|
||||
generalInfoView = (TextView)rootView.findViewById(R.id.numb_of_total_games);
|
||||
generalInfoView.setText(String.valueOf(totalGames));
|
||||
generalInfoView = (TextView)rootView.findViewById(R.id.numb_of_total_time);
|
||||
generalInfoView.setText(formatTime(totalTime));
|
||||
|
||||
}
|
||||
|
||||
private void setStats(HighscoreInfoContainer infos, int pos){
|
||||
|
||||
switch (pos) {
|
||||
case 0 :
|
||||
difficultyBarView = (RatingBar) rootView.findViewById(R.id.first_diff_bar);
|
||||
difficultyView = (TextView) rootView.findViewById(R.id.first_diff_text);
|
||||
averageTimeView = (TextView) rootView.findViewById(R.id.first_ava_time);
|
||||
minTimeView = (TextView) rootView.findViewById(R.id.first_min_time);
|
||||
break;
|
||||
case 1:
|
||||
difficultyBarView = (RatingBar) rootView.findViewById(R.id.second_diff_bar);
|
||||
difficultyView = (TextView) rootView.findViewById(R.id.second_diff_text);
|
||||
averageTimeView = (TextView) rootView.findViewById(R.id.second_ava_time);
|
||||
minTimeView = (TextView) rootView.findViewById(R.id.second_min_time);
|
||||
break;
|
||||
case 2:
|
||||
difficultyBarView = (RatingBar) rootView.findViewById(R.id.third_diff_bar);
|
||||
difficultyView = (TextView) rootView.findViewById(R.id.third_diff_text);
|
||||
averageTimeView = (TextView) rootView.findViewById(R.id.third_ava_time);
|
||||
minTimeView = (TextView) rootView.findViewById(R.id.third_min_time);
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
difficultyBarView.setRating(pos+1);
|
||||
difficultyView.setText(rootView.getResources().getString(infos.getDifficulty().getStringResID()));
|
||||
s= (infos.getTime() == 0)?"/":String.valueOf(infos.getTime() / infos.getNumberOfGames());
|
||||
averageTimeView.setText(s);
|
||||
s = (infos.getMinTime()==Integer.MAX_VALUE)? "/":String.valueOf(infos.getMinTime());
|
||||
minTimeView.setText(s);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_stats, container, false);
|
||||
this.rootView = rootView;
|
||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||
|
||||
SaveLoadStatistics s = new SaveLoadStatistics(this.getContext());
|
||||
List<HighscoreInfoContainer> stats = s.loadStats(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)));
|
||||
|
||||
|
||||
int j =0;
|
||||
for (HighscoreInfoContainer i : stats){
|
||||
updateGeneralIfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
||||
setStats(i,j++);
|
||||
}
|
||||
setGeneralInfo();
|
||||
|
||||
ImageView imageView = (ImageView) rootView.findViewById(R.id.statistic_image);
|
||||
imageView.setImageResource(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)).getResIDImage());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,11 +51,7 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
|
|||
break;
|
||||
case Hint:
|
||||
if(gameController.isValidCellSelected()) {
|
||||
int[] solved = gameController.solve();
|
||||
// TODO test every placed value so far? Or just reveal current selected?
|
||||
|
||||
// and reveal the selected value.
|
||||
gameController.selectValue(solved[row * gameController.getSize() + col]);
|
||||
gameController.hint();
|
||||
}
|
||||
break;
|
||||
case NumberOrCellFirst:
|
||||
|
|
31
app/src/main/res/layout/activity_stats.xml
Normal file
31
app/src/main/res/layout/activity_stats.xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true" tools:context="tu_darmstadt.sudoku.ui.StatsActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout android:id="@+id/appbar"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/appbar_padding_top"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:layout_scrollFlags="scroll|enterAlways">
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<android.support.design.widget.TabLayout android:id="@+id/tabs"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.v4.view.ViewPager android:id="@+id/container"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
327
app/src/main/res/layout/fragment_stats.xml
Normal file
327
app/src/main/res/layout/fragment_stats.xml
Normal file
|
@ -0,0 +1,327 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:weightSum="11"
|
||||
android:orientation="vertical"
|
||||
tools:context="tu_darmstadt.sudoku.ui.StatsActivity$PlaceholderFragment">
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats_name"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="4"
|
||||
android:weightSum="5">
|
||||
<ImageView
|
||||
android:layout_weight="2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/statistic_image"
|
||||
android:src="@drawable/icon_default_9x9"
|
||||
android:adjustViewBounds="true"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
<View
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:foregroundGravity="center_vertical"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="@color/colorPrimary"
|
||||
android:layout_marginTop="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:weightSum="6"
|
||||
android:layout_weight="2"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/activity_horizontal_margin">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/number_of_hints"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="0"
|
||||
android:id="@+id/numb_of_hints"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/number_of_games"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="0"
|
||||
android:id="@+id/numb_of_total_games"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/total_of_time"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="0"
|
||||
android:id="@+id/numb_of_total_time"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:foregroundGravity="center_vertical"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="@color/colorPrimary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="4"
|
||||
android:weightSum="3"
|
||||
android:orientation="vertical">
|
||||
<!-- ### first row -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="3">
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<RatingBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:numStars="3"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/first_diff_bar"
|
||||
android:layout_below="@+id/first_diff_text"
|
||||
style="?android:attr/ratingBarStyleSmall"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="diffi"
|
||||
android:id="@+id/first_diff_text"
|
||||
android:gravity="center_vertical"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/average_time"
|
||||
android:id="@+id/first_av_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/first_ava_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/first_av_text"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/min_time"
|
||||
android:id="@+id/first_min_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/first_min_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/first_min_text"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<!-- ### second row -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="3">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<RatingBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:numStars="3"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/second_diff_bar"
|
||||
android:layout_below="@+id/second_diff_text"
|
||||
style="?android:attr/ratingBarStyleSmall"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="diffi"
|
||||
android:id="@+id/second_diff_text"
|
||||
android:gravity="center_vertical"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/average_time"
|
||||
android:id="@+id/second_av_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/second_ava_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/second_av_text"/>
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/min_time"
|
||||
android:id="@+id/second_min_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/second_min_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/second_min_text"/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<RatingBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:numStars="3"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/third_diff_bar"
|
||||
android:layout_below="@+id/third_diff_text"
|
||||
style="?android:attr/ratingBarStyleSmall"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="diffi"
|
||||
android:id="@+id/third_diff_text"
|
||||
android:gravity="center_vertical"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/average_time"
|
||||
android:id="@+id/third_av_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/third_ava_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/third_av_text"/>
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/min_time"
|
||||
android:id="@+id/third_min_text"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/third_min_time"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_below="@+id/third_min_text"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
9
app/src/main/res/menu/menu_stats.xml
Normal file
9
app/src/main/res/menu/menu_stats.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="tu_darmstadt.sudoku.ui.StatsActivity">
|
||||
<item android:id="@+id/action_reset" android:title="@string/reset_stats"
|
||||
android:icon="@drawable/ic_sync_black_24dp"
|
||||
android:orderInCategory="100" app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
|
@ -61,11 +61,24 @@
|
|||
<string name="gametype_default_12x12">Standart Sudoku 12x12</string>
|
||||
<string name="gametype_x_9x9">X Sudoku 9x9</string>
|
||||
<string name="gametype_hyper_9x9">Hyper Sudoku 9x9</string>
|
||||
<string name="title_activity_stats_game">StatsGameActivity</string>
|
||||
<string name="section_format">Hello World from section: %1$d</string>
|
||||
|
||||
<!-- ### Continue Game ### -->
|
||||
<string name="loadgame_delete_confirmation">Are you sure you want to delete this save?</string>
|
||||
<string name="loadgame_delete_confirm">Delete</string>
|
||||
<string name="loadgame_delete_cancel">Cancel</string>
|
||||
<string name="title_activity_stats">StatsActivity</string>
|
||||
|
||||
<!-- ### Stats ###-->
|
||||
<string name="stats_name">Statistics</string>
|
||||
<string name="number_of_hints">Number of Hints Used:</string>
|
||||
<string name="number_of_games">#Games:</string>
|
||||
<string name="total_of_time">Total time Played:</string>
|
||||
<string name="average_time">Av time:</string>
|
||||
<string name="min_time">Min time:</string>
|
||||
<string name="reset_stats">reset stats</string>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue