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 f898bb5..1b8fb29 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -23,12 +23,14 @@ import tu_darmstadt.sudoku.ui.view.R; import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout; import tu_darmstadt.sudoku.ui.view.SudokuButton; import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout; +import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout; public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { GameController gameController; SudokuFieldLayout layout; SudokuKeyboardLayout keyboard; + SudokuSpecialButtonLayout specialButtonLayout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -76,12 +78,17 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout); keyboard.removeAllViews(); keyboard.setGameController(gameController); - keyboard.setColumnCount(Math.max(((gameController.getSize() / 2) + 1), keyboard.fixedButtonsCount)); - keyboard.setRowCount(3); + keyboard.setColumnCount((gameController.getSize() / 2) + 1); + keyboard.setRowCount(2); Point p = new Point(); getWindowManager().getDefaultDisplay().getSize(p); //int width = p.x; keyboard.setKeyBoard(gameController.getSize(), p.x); + + + //set Special keys + specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout); + specialButtonLayout.setButtons(p.x,gameController,keyboard); /* // DEBUG String debug = gameController.getFieldAsString(); diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java index 4a2ee55..88939b7 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java @@ -1,5 +1,8 @@ package tu_darmstadt.sudoku.ui.view; +import java.util.ArrayList; +import java.util.List; + /** * Created by Chris on 15.11.2015. */ @@ -12,5 +15,29 @@ public enum SudokuButtonType { NoteToggle, NumberOrCellFirst, Delete, - Reset + Reset; + + public static List getSpecialButtons() { + ArrayList result = new ArrayList(); + result.add(Do); + result.add(Undo); + result.add(Hint); + result.add(NoteToggle); + result.add(NumberOrCellFirst); + result.add(Delete); + return result; + } + public static String getName(SudokuButtonType type) { + switch (type) { + case Do: return "Do"; + case Undo: return "Un"; + case Hint: return "Hnt"; + case NoteToggle: return "On"; + case NumberOrCellFirst: return "Cel"; + case Delete: return "Del"; + default:return "NotSet"; + } + } } + + 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 2c2b2eb..f09a254 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 @@ -19,49 +19,20 @@ public class SudokuKeyboardLayout extends GridLayout { AttributeSet attrs; SudokuButton [] buttons; - SudokuButton [] fixedButtons; - public int fixedButtonsCount = 6; GameController gameController; boolean notesEnabled=false; - SudokuButtonType [] fixedTypes = {SudokuButtonType.Do,SudokuButtonType.Undo,SudokuButtonType.NoteToggle,SudokuButtonType.Delete,SudokuButtonType.NumberOrCellFirst,SudokuButtonType.Hint}; - String [] s = {"Do","Un","fal","Del","Sh**","Hi"}; + OnClickListener listener = new OnClickListener() { @Override public void onClick(View v) { if(v instanceof SudokuButton) { SudokuButton btn = (SudokuButton)v; - - switch(btn.getType()) { - case Value: - if(notesEnabled) { - gameController.toggleSelectedNote(btn.getValue()); - } else { - gameController.setSelectedValue(btn.getValue()); - } - break; - case Delete: - gameController.deleteSelectedValue(); - break; - case NoteToggle: - notesEnabled = !notesEnabled; - btn.setText(notesEnabled ? "ON" : "OFF"); - break; - case Do: - // TODO: not implemented - break; - case Undo: - // TODO: not implemented - break; - case Hint: - // TODO: not implemented - break; - case NumberOrCellFirst: - // TODO: not implemented - break; - default: - break; - } + if(notesEnabled) { + gameController.toggleSelectedNote(btn.getValue()); + } else { + gameController.setSelectedValue(btn.getValue()); + } } } @@ -79,56 +50,50 @@ public class SudokuKeyboardLayout extends GridLayout { public void setKeyBoard(int size,int width) { LayoutParams p ; buttons = new SudokuButton[size]; - fixedButtons = new SudokuButton[fixedButtonsCount]; - int row = 0; int number = 0; int torun = ((size)%2==0) ? (size)/2 :(size+1)/2 ; - int realSize = Math.max(torun,fixedButtonsCount); + int realSize = torun; for (int k = 0; k<2;k++){ for (int i = 0; i< torun; i++){ - buttons[i] = new SudokuButton(getContext(),null); + if (number == size) { + break; + } + buttons[number] = new SudokuButton(getContext(),null); p = new LayoutParams(GridLayout.spec(k,1),GridLayout.spec(i, 1)); p.setMargins(0,0,0,0); int width2 =width/(realSize); p.width= width2-15; - buttons[i].setLayoutParams(p); - buttons[i].setGravity(Gravity.CENTER); - buttons[i].setType(SudokuButtonType.Value); - buttons[i].setText(String.valueOf(number + 1)); - buttons[i].setValue(number + 1); - buttons[i].setOnClickListener(listener); - + buttons[number].setLayoutParams(p); + buttons[number].setGravity(Gravity.CENTER); + buttons[number].setType(SudokuButtonType.Value); + buttons[number].setText(String.valueOf(number + 1)); + buttons[number].setValue(number + 1); + buttons[number].setOnClickListener(listener); + addView(buttons[number]); number++; - if (number > size) { - break; - } - addView(buttons[i]); + + + } } - for (int i = 0; i < fixedButtonsCount; i++){ - fixedButtons[i] = new SudokuButton(getContext(),null); - p = new LayoutParams(GridLayout.spec(2,1),GridLayout.spec(i, 1)); - p.setMargins(0,0,0,0); - int width2 =width/(fixedButtonsCount); - p.width= width2-15; - fixedButtons[i].setLayoutParams(p); - fixedButtons[i].setGravity(Gravity.CENTER); - fixedButtons[i].setType(fixedTypes[i]); - fixedButtons[i].setText(s[i]); - fixedButtons[i].setOnClickListener(listener); - addView(fixedButtons[i]); - - - } - - } public void setGameController(GameController gc){ gameController=gc; } + public void setNotesEnabled(boolean b) { + notesEnabled = b; + } + + public void setValueSize (float size){ + for (int i = 0; i< buttons.length;i++){ + buttons[i].setTextSize(size); + } + } + + @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuSpecialButtonLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuSpecialButtonLayout.java new file mode 100644 index 0000000..3165608 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuSpecialButtonLayout.java @@ -0,0 +1,98 @@ +package tu_darmstadt.sudoku.ui.view; + +import android.content.Context; +import android.text.style.TextAppearanceSpan; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.GridLayout; +import android.widget.LinearLayout; + +import java.awt.font.TextAttribute; +import java.util.ArrayList; + +import tu_darmstadt.sudoku.controller.GameController; + +/** + * Created by TMZ_LToP on 17.11.2015. + */ +public class SudokuSpecialButtonLayout extends LinearLayout { + + SudokuButton [] fixedButtons; + public int fixedButtonsCount = SudokuButtonType.getSpecialButtons().size(); + String [] s = {"Do","Un","off","Del","Sh**","Hi"}; + GameController gameController; + boolean notesEnabled=false; + SudokuKeyboardLayout keyboard; + + + OnClickListener listener = new OnClickListener() { + @Override + public void onClick(View v) { + if(v instanceof SudokuButton) { + SudokuButton btn = (SudokuButton)v; + + switch(btn.getType()) { + case Delete: + gameController.deleteSelectedValue(); + break; + case NoteToggle: + notesEnabled = !notesEnabled; + btn.setText(notesEnabled ? "ON" : "OFF"); + keyboard.setNotesEnabled(notesEnabled); + keyboard.setValueSize(notesEnabled ?btn.getTextSize()/4: btn.getTextSize()/2 ); + break; + case Do: + // TODO: not implemented + break; + case Undo: + // TODO: not implemented + break; + case Hint: + // TODO: not implemented + break; + case NumberOrCellFirst: + // TODO: not implemented + break; + default: + break; + } + } + } + }; + + + public SudokuSpecialButtonLayout(Context context, AttributeSet attrs) { + super(context, attrs); + setWeightSum(fixedButtonsCount); + } + + + public void setButtons(int width, GameController gc,SudokuKeyboardLayout key) { + keyboard=key; + gameController = gc; + fixedButtons = new SudokuButton[fixedButtonsCount]; + LayoutParams p; + int i = 0; + ArrayList type = (ArrayList) SudokuButtonType.getSpecialButtons(); + for (SudokuButtonType t : SudokuButtonType.getSpecialButtons()){ + fixedButtons[i] = new SudokuButton(getContext(),null); + p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,1); + p.setMargins(0,0,0,0); + int width2 =width/(fixedButtonsCount); + p.width= width2-15; + fixedButtons[i].setLayoutParams(p); + fixedButtons[i].setGravity(Gravity.CENTER); + fixedButtons[i].setType(t); + fixedButtons[i].setText(SudokuButtonType.getName(t)); + fixedButtons[i].setOnClickListener(listener); + addView(fixedButtons[i]); + i++; + + + } + + } +} diff --git a/app/src/main/res/layout/content_game_view.xml b/app/src/main/res/layout/content_game_view.xml index b7a58c0..35883cd 100644 --- a/app/src/main/res/layout/content_game_view.xml +++ b/app/src/main/res/layout/content_game_view.xml @@ -21,80 +21,21 @@ - - - + + +