Buttons rearanged and and Note High low size added
This commit is contained in:
parent
ca73b34f3a
commit
d3abad12a2
5 changed files with 177 additions and 139 deletions
|
@ -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();
|
||||
|
|
|
@ -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<SudokuButtonType> getSpecialButtons() {
|
||||
ArrayList<SudokuButtonType> result = new ArrayList<SudokuButtonType>();
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<SudokuButtonType> type = (ArrayList<SudokuButtonType>) 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++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -21,80 +21,21 @@
|
|||
|
||||
<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_height="fill_parent"
|
||||
android:minHeight="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/sudokuLayout"
|
||||
android:id="@+id/sudokuKeyboardLayout"
|
||||
android:layout_centerVertical="true">
|
||||
<!-- <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"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center">
|
||||
<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.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:text="3"/>
|
||||
<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.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.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.ui.view.SudokuSpecialButtonLayout
|
||||
android:id="@+id/sudokuSpecialLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/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.ui.view.SudokuKeyboardLayout>
|
||||
</tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue