From 29028c39f50acdf9ad309f712b9586cd3dd12b08 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Sun, 20 Dec 2015 16:26:41 +0100 Subject: [PATCH] Symbol Map selectable in settings. --- .../tu_darmstadt/sudoku/ui/GameActivity.java | 6 +++ .../sudoku/ui/view/SudokuCellView.java | 4 ++ .../sudoku/ui/view/SudokuFieldLayout.java | 9 ++++ .../sudoku/ui/view/SudokuKeyboardLayout.java | 24 +++++++--- .../main/res/layout/activity_main_menu.xml | 2 +- app/src/main/res/layout/content_game_view.xml | 45 ++++++++++--------- app/src/main/res/values/strings.xml | 19 +++++++- app/src/main/res/xml/pref_general.xml | 11 ++++- 8 files changed, 90 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java index 70907c0..ed1d820 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -22,6 +22,7 @@ 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.Symbol; import tu_darmstadt.sudoku.controller.helper.GameInfoContainer; import tu_darmstadt.sudoku.game.GameDifficulty; import tu_darmstadt.sudoku.game.GameType; @@ -154,6 +155,11 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On if(!gameSolved) { gameController.startTimer(); } + + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + Symbol s = Symbol.valueOf(Symbol.class, sharedPref.getString("pref_symbols", "Default")); + layout.setSymbols(s); + keyboard.setSymbols(s); } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java index d47b777..03fba04 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java @@ -54,6 +54,10 @@ public class SudokuCellView extends View { this.size = size; } + public void setSymbols(Symbol s) { + symbolsToUse = s; + } + public void setHighlightType(CellHighlightTypes highlightType) { this.highlightType = highlightType; } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java index 7795df5..4b50699 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java @@ -14,6 +14,7 @@ import android.widget.RelativeLayout; import java.util.LinkedList; import tu_darmstadt.sudoku.controller.GameController; +import tu_darmstadt.sudoku.controller.Symbol; import tu_darmstadt.sudoku.game.GameCell; import tu_darmstadt.sudoku.game.ICellAction; import tu_darmstadt.sudoku.game.listener.IHighlightChangedListener; @@ -103,6 +104,14 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang } } + public void setSymbols(Symbol s) { + for(int i = 0; i < gamecells.length ; i++) { + for(int j = 0; j < gamecells[i].length; j++) { + gamecells[i][j].setSymbols(s); + } + } + } + @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed,l,t,r,b); diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java index becbaf0..990b2d3 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java @@ -44,14 +44,22 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange } + public void setSymbols(Symbol s) { + symbolsToUse = s; + for(SudokuButton b : buttons) { + b.setText(Symbol.getSymbol(symbolsToUse, b.getValue()-1)); + } + } + public void setKeyBoard(int size,int width, int height) { LayoutParams p ; buttons = new SudokuButton[size]; int number = 0; - int torun = ((size)%2==0) ? (size)/2 :(size+1)/2 ; + int torun = (size % 2 == 0) ? size/2 :(size+1)/2 ; int realSize = torun; - int width2 =(width-(realSize*30))/(realSize); + //int width2 =(width-(realSize*30))/(realSize); + for (int k = 0; k<2;k++){ for (int i = 0; i< torun; i++){ if (number == size) { @@ -65,8 +73,8 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange //p = new LayoutParams(rowSpec,colSpec); p.setMargins((i == 0) ? 0 : 5,5,5,5); - p.width= (width-(int)((getResources().getDimension(R.dimen.activity_horizontal_margin))*2))/realSize; - p.width= p.width-10; + p.width = (width - (int)((getResources().getDimension(R.dimen.activity_horizontal_margin))*2)) / realSize; + p.width = p.width - 10; p.setGravity(LayoutParams.WRAP_CONTENT); @@ -99,10 +107,13 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange } public void updateNotesEnabled() { - if (normalTextSize == 0) {normalTextSize = buttons[0].getTextSize();} + if (normalTextSize == 0) { + normalTextSize = buttons[0].getTextSize(); + } + if(gameController.getNoteStatus()) { setTextSize(normalTextSize*0.6f); - }else { + } else { setTextSize(normalTextSize); } } @@ -119,7 +130,6 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); - } @Override diff --git a/app/src/main/res/layout/activity_main_menu.xml b/app/src/main/res/layout/activity_main_menu.xml index 26e6430..5ba5152 100644 --- a/app/src/main/res/layout/activity_main_menu.xml +++ b/app/src/main/res/layout/activity_main_menu.xml @@ -135,7 +135,7 @@