Added KeyBoard and is now Playable
This commit is contained in:
parent
403522c5b3
commit
163e64810e
5 changed files with 159 additions and 88 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<size) {
|
||||
buttons[i].setText(String.valueOf(number + 1));
|
||||
buttons[i].setVal(number + 1);
|
||||
buttons[i].setOnClickListener(listener);
|
||||
} else {
|
||||
//TODO: Set Enum for fixed Buttons maybe also pictures
|
||||
}
|
||||
number++;
|
||||
addView(buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setGameController(GameController gc){
|
||||
gameController=gc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package tu_darmstadt.sudoku.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 12.11.2015.
|
||||
*/
|
||||
|
||||
|
||||
public class SudokuKeyboardLayout extends RelativeLayout {
|
||||
|
||||
public SudokuKeyboardLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
}
|
|
@ -12,20 +12,35 @@
|
|||
tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.activity.GameActivity">
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuFieldLayout
|
||||
android:id="@+id/sudokuLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="200dp"
|
||||
android:clickable="true"
|
||||
android:gravity="center"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuKeyboardLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:id="@+id/sudokuKeyboardLayout"
|
||||
android:orientation="vertical"
|
||||
android:gravity="top"
|
||||
|
||||
android:layout_centerVertical="true"
|
||||
>
|
||||
<tu_darmstadt.sudoku.view.SudokuKeyboardLayout
|
||||
<!-- <tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="2"/>
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:layout_marginLeft="100dp"
|
||||
android:text="3"/>-->
|
||||
|
||||
<!--<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
|
@ -33,94 +48,53 @@
|
|||
android:paddingRight="16dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center">
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button1"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="1"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="2"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="3"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button4"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="4"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button5"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="5"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuButton
|
||||
android:id="@+id/button6"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="6"/>
|
||||
|
||||
</tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout>
|
||||
|
||||
|
||||
|
||||
</tu_darmstadt.sudoku.view.SudokuKeyboardLayout>
|
||||
|
||||
<tu_darmstadt.sudoku.view.SudokuKeyboardLayout
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="top"
|
||||
android:layout_weight="1">
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/button7"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="7"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/button8"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="8"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/button9"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="9"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/buttonNote"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="not"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/buttonDel"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="Del"/>
|
||||
<tu_darmstadt.sudoku.view.SudokuButton
|
||||
android:id="@+id/buttonDum"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_weight="6"
|
||||
android:text="dum"/>
|
||||
android:layout_weight="1"/>-->
|
||||
|
||||
</tu_darmstadt.sudoku.view.SudokuKeyboardLayout>
|
||||
|
||||
</tu_darmstadt.sudoku.view.SudokuKeyboardLayout>
|
||||
</tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue