From c4d299968056aba3bb551efa9feeea12d6b33925 Mon Sep 17 00:00:00 2001 From: Gongxter Date: Sat, 30 Jan 2016 23:20:05 +0100 Subject: [PATCH] winscreen and helppage created --- app/app.iml | 15 +++-- .../controller/SaveLoadStatistics.java | 1 + .../ui/GameActivity.java | 59 +++++++++++++---- .../ui/HelpActivity.java | 2 +- .../ui/MainActivity.java | 6 +- .../ui/view/DialogActivity.java | 48 ++++++++++++++ app/src/main/res/layout/win_screen_layout.xml | 57 ++++++++++++++--- app/src/main/res/values/strings.xml | 26 ++++++++ app/src/main/res/values/styles.xml | 9 ++- app/src/main/res/xml/pref_help_general.xml | 63 ++++++++++--------- 10 files changed, 223 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DialogActivity.java diff --git a/app/app.iml b/app/app.iml index 7932f75..74d7e06 100644 --- a/app/app.iml +++ b/app/app.iml @@ -67,25 +67,28 @@ - + - + + - + + + + - + + - - diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/SaveLoadStatistics.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/SaveLoadStatistics.java index 95c818e..7819531 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/SaveLoadStatistics.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/SaveLoadStatistics.java @@ -36,6 +36,7 @@ public class SaveLoadStatistics implements ITimerListener, IHintListener { public void setGameController(GameController gc) { this.gc = gc; gc.registerTimerListener(this); + gc.registerHintListener(this); } public HighscoreInfoContainer loadStats(GameType t, GameDifficulty gd){ diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index d5c2561..dd54f50 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -21,7 +21,9 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Gravity; import android.view.MenuItem; +import android.view.View; import android.view.WindowManager; +import android.widget.Button; import android.widget.RatingBar; import android.widget.TextView; import android.widget.Toast; @@ -40,6 +42,7 @@ import org.secuso.privacyfriendlysudoku.game.listener.IGameSolvedListener; import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener; import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener; import org.secuso.privacyfriendlysudoku.ui.listener.IResetDialogFragmentListener; +import org.secuso.privacyfriendlysudoku.ui.view.DialogActivity; import org.secuso.privacyfriendlysudoku.ui.view.DialogWinScreen; import org.secuso.privacyfriendlysudoku.ui.view.R; import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout; @@ -57,6 +60,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On RatingBar ratingBar; private boolean gameSolved = false; SaveLoadStatistics statistics = new SaveLoadStatistics(this); + DialogActivity dialog = null; @Override protected void onCreate(Bundle savedInstanceState) { @@ -238,8 +242,10 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On case R.id.menu_help: //open about page - //intent = new Intent(this,HelpActivity.class); - //startActivity(intent); + intent = new Intent(this,HelpActivity.class); + intent.putExtra( HelpActivity.EXTRA_SHOW_FRAGMENT, HelpActivity.HelpFragment.class.getName() ); + intent.putExtra( HelpActivity.EXTRA_NO_HEADERS, true ); + startActivity(intent); break; default: } @@ -261,25 +267,48 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On statistics.saveGameStats(); - Dialog dialog = new Dialog(this); + + if (gameController.getUsedHints() == 0){ + if (statistics.loadStats(gameController.getGameType(),gameController.getDifficulty()).getMinTime() >= gameController.getTime()) { + // ((TextView) dialog.findViewById(R.id.win_new_besttime)).setVisibility(View.VISIBLE); + dialog = new DialogActivity(this,R.style.WinDialog,timeToString(gameController.getTime()),String.valueOf(gameController.getUsedHints()),true); + } + }else dialog = new DialogActivity(this,R.style.WinDialog,timeToString(gameController.getTime()),String.valueOf(gameController.getUsedHints()),true); + + dialog.getWindow().setContentView(R.layout.win_screen_layout); //dialog.setContentView(getLayoutInflater().inflate(R.layout.win_screen_layout,null)); - dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); //dialog.setContentView(R.layout.win_screen_layout); dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL); - dialog.getWindow().setContentView(R.layout.win_screen_layout); dialog.getWindow().setBackgroundDrawableResource(R.color.transparent); + + //((TextView)dialog.findViewById(R.id.win_hints)).setText(gameController.getUsedHints()); + //((TextView)dialog.findViewById(R.id.win_time)).setText(timeToString(gameController.getTime())); + dialog.show(); + final Activity activity = this; + ((Button)dialog.findViewById(R.id.win_button)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + activity.finish(); + startActivity(new Intent(activity,MainActivity.class)); + } + }); + ((Button)dialog.findViewById(R.id.win_button2)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + }); + + layout.setEnabled(false); keyboard.setButtonsEnabled(false); specialButtonLayout.setButtonsEnabled(false); } - @Override - public void onTick(int time) { - if(gameSolved) return; - - //do something not so awesome + public String timeToString(int time) { int seconds = time % 60; int minutes = ((time -seconds)/60)%60 ; int hours = (time - minutes - seconds)/(3600); @@ -287,7 +316,15 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On 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); - timerView.setText(h + ":" + m + ":" + s); + return h + ":" + m + ":" + s; + } + + @Override + public void onTick(int time) { + if(gameSolved) return; + + //do something not so awesome + timerView.setText(timeToString(time)); // save time gameController.saveGame(this); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/HelpActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/HelpActivity.java index 9106d72..840760c 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/HelpActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/HelpActivity.java @@ -184,7 +184,7 @@ public class HelpActivity extends AppCompatPreferenceActivity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); + getActivity().finish(); return true; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java index b9f5661..67c110d 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java @@ -244,8 +244,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On case R.id.menu_help_main: //open about page - //intent = new Intent(this,HelpActivity.class); - //startActivity(intent); + intent = new Intent(this,HelpActivity.class); + intent.putExtra( HelpActivity.EXTRA_SHOW_FRAGMENT, HelpActivity.HelpFragment.class.getName() ); + intent.putExtra( HelpActivity.EXTRA_NO_HEADERS, true ); + startActivity(intent); break; default: } diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DialogActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DialogActivity.java new file mode 100644 index 0000000..a85bc35 --- /dev/null +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DialogActivity.java @@ -0,0 +1,48 @@ +package org.secuso.privacyfriendlysudoku.ui.view; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +/** + * Created by TMZ_LToP on 30.01.2016. + */ +public class DialogActivity extends Dialog { + + private String time=""; + private String hints=""; + private boolean newBest=false; + + public DialogActivity(Context context, int themeResId) { + super(context, themeResId); + } + + public DialogActivity(Context context,int themeResId,String t,String h, boolean newB) { + super(context,themeResId); + setParam(t,h,newB); + } + + + public void setParam(String t,String h, boolean newB){ + time = t; + hints=h; + newBest=newB; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + + ((TextView)findViewById(R.id.win_hints)).setText(hints); + ((TextView)findViewById(R.id.win_time)).setText(time); + if(newBest){ + ((TextView)findViewById(R.id.win_new_besttime)).setVisibility(View.VISIBLE); + } + + } + + +} diff --git a/app/src/main/res/layout/win_screen_layout.xml b/app/src/main/res/layout/win_screen_layout.xml index 6dc33e6..0196ebd 100644 --- a/app/src/main/res/layout/win_screen_layout.xml +++ b/app/src/main/res/layout/win_screen_layout.xml @@ -1,8 +1,10 @@ + android:background="@color/white" + android:layout_gravity="center" + > + android:layout_gravity="center_horizontal"/> + + + + android:layout_marginTop="20dp" + android:weightSum="2">