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 9943a1d..84fba05 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -2,6 +2,7 @@ package tu_darmstadt.sudoku.ui; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Point; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.design.widget.NavigationView; @@ -12,17 +13,19 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.widget.GridLayout; import tu_darmstadt.sudoku.controller.GameController; -import tu_darmstadt.sudoku.game.*; import tu_darmstadt.sudoku.ui.view.R; import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout; -import tu_darmstadt.sudoku.view.SudokuButton; +import tu_darmstadt.sudoku.ui.view.SudokuButton; +import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout; public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { GameController gameController; SudokuFieldLayout layout; + SudokuKeyboardLayout keyboard; SudokuButton [] buttons; @Override @@ -34,12 +37,23 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On setContentView(R.layout.activity_game_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); + //Create new GameField + layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); gameController = new GameController(sharedPref); layout.setGame(gameController); - buttons = new SudokuButton[12]; layout.setSettings(sharedPref); + + //set KeyBoard + keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout); + keyboard.removeAllViews(); + keyboard.setGameController(gameController); + 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); /* // DEBUG String debug = gameController.getFieldAsString(); diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuButton.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java similarity index 61% rename from app/src/main/java/tu_darmstadt/sudoku/view/SudokuButton.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java index c785e18..90abcb1 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuButton.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui.view; import android.content.Context; import android.util.AttributeSet; @@ -7,8 +7,23 @@ import android.widget.Button; /** * Created by TMZ_LToP on 12.11.2015. */ + + + public class SudokuButton extends Button { + + private int i = 100; + public SudokuButton(Context context, AttributeSet attrs) { super(context, attrs); } + + public void setVal(int i){ + this.i = i; + } + public int getValue () { + return i; + } } + + 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 new file mode 100644 index 0000000..daaa6eb --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java @@ -0,0 +1,93 @@ +package tu_darmstadt.sudoku.ui.view; + +import android.content.Context; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.view.Display; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.GridLayout; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import tu_darmstadt.sudoku.controller.GameController; + +/** + * Created by TMZ_LToP on 12.11.2015. + */ + + +public class SudokuKeyboardLayout extends GridLayout { + + AttributeSet attrs; + SudokuButton [] buttons; + GameController gameController; + boolean notesEnabled=false; + + OnClickListener listener = new OnClickListener() { + @Override + public void onClick(View v) { + SudokuButton btn = (SudokuButton)v; + int i = btn.getValue(); + if(notesEnabled) { + //TODO: set notes funktion erst noch im GameController Schreiben + }else { + gameController.setSelectedValue(btn.getValue()); + } + } + }; + + + + + public SudokuKeyboardLayout(Context context, AttributeSet attrs) { + super(context, attrs); + this.attrs = attrs; + + } + + + public void setKeyBoard(int size,int width) { + LayoutParams p ; + int fixedButtons = 0; + buttons = new SudokuButton[size+1]; + int row = 0; + int number = 0; + int torun = ((size+fixedButtons)%2==0) ? (size+fixedButtons)/2 :(size+fixedButtons+1)/2 ; + + for (int k = 0; k<2;k++){ + for (int i = 0; i< torun; i++){ + buttons[i] = new SudokuButton(getContext(),null); + p = new LayoutParams(GridLayout.spec(k,1),GridLayout.spec(i, 1)); + p.setMargins(0,0,0,0); + int width2 =width/(torun); + p.width= width2-15; + buttons[i].setLayoutParams(p); + buttons[i].setGravity(Gravity.CENTER); + if (number - - + --> + + - - - +