Buttons rearanged and and Note High low size added

This commit is contained in:
Gongxter 2015-11-17 13:53:29 +01:00
parent ca73b34f3a
commit d3abad12a2
5 changed files with 177 additions and 139 deletions

View file

@ -23,12 +23,14 @@ import tu_darmstadt.sudoku.ui.view.R;
import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout; import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout;
import tu_darmstadt.sudoku.ui.view.SudokuButton; import tu_darmstadt.sudoku.ui.view.SudokuButton;
import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout; import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout;
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
GameController gameController; GameController gameController;
SudokuFieldLayout layout; SudokuFieldLayout layout;
SudokuKeyboardLayout keyboard; SudokuKeyboardLayout keyboard;
SudokuSpecialButtonLayout specialButtonLayout;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -76,12 +78,17 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout); keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout);
keyboard.removeAllViews(); keyboard.removeAllViews();
keyboard.setGameController(gameController); keyboard.setGameController(gameController);
keyboard.setColumnCount(Math.max(((gameController.getSize() / 2) + 1), keyboard.fixedButtonsCount)); keyboard.setColumnCount((gameController.getSize() / 2) + 1);
keyboard.setRowCount(3); keyboard.setRowCount(2);
Point p = new Point(); Point p = new Point();
getWindowManager().getDefaultDisplay().getSize(p); getWindowManager().getDefaultDisplay().getSize(p);
//int width = p.x; //int width = p.x;
keyboard.setKeyBoard(gameController.getSize(), p.x); keyboard.setKeyBoard(gameController.getSize(), p.x);
//set Special keys
specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout);
specialButtonLayout.setButtons(p.x,gameController,keyboard);
/* /*
// DEBUG // DEBUG
String debug = gameController.getFieldAsString(); String debug = gameController.getFieldAsString();

View file

@ -1,5 +1,8 @@
package tu_darmstadt.sudoku.ui.view; package tu_darmstadt.sudoku.ui.view;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by Chris on 15.11.2015. * Created by Chris on 15.11.2015.
*/ */
@ -12,5 +15,29 @@ public enum SudokuButtonType {
NoteToggle, NoteToggle,
NumberOrCellFirst, NumberOrCellFirst,
Delete, 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";
}
}
} }

View file

@ -19,49 +19,20 @@ public class SudokuKeyboardLayout extends GridLayout {
AttributeSet attrs; AttributeSet attrs;
SudokuButton [] buttons; SudokuButton [] buttons;
SudokuButton [] fixedButtons;
public int fixedButtonsCount = 6;
GameController gameController; GameController gameController;
boolean notesEnabled=false; 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() { OnClickListener listener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(v instanceof SudokuButton) { if(v instanceof SudokuButton) {
SudokuButton btn = (SudokuButton)v; SudokuButton btn = (SudokuButton)v;
if(notesEnabled) {
switch(btn.getType()) { gameController.toggleSelectedNote(btn.getValue());
case Value: } else {
if(notesEnabled) { gameController.setSelectedValue(btn.getValue());
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) { public void setKeyBoard(int size,int width) {
LayoutParams p ; LayoutParams p ;
buttons = new SudokuButton[size]; buttons = new SudokuButton[size];
fixedButtons = new SudokuButton[fixedButtonsCount];
int row = 0;
int number = 0; 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 = Math.max(torun,fixedButtonsCount); int realSize = torun;
for (int k = 0; k<2;k++){ for (int k = 0; k<2;k++){
for (int i = 0; i< torun; i++){ 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 = new LayoutParams(GridLayout.spec(k,1),GridLayout.spec(i, 1));
p.setMargins(0,0,0,0); p.setMargins(0,0,0,0);
int width2 =width/(realSize); int width2 =width/(realSize);
p.width= width2-15; p.width= width2-15;
buttons[i].setLayoutParams(p); buttons[number].setLayoutParams(p);
buttons[i].setGravity(Gravity.CENTER); buttons[number].setGravity(Gravity.CENTER);
buttons[i].setType(SudokuButtonType.Value); buttons[number].setType(SudokuButtonType.Value);
buttons[i].setText(String.valueOf(number + 1)); buttons[number].setText(String.valueOf(number + 1));
buttons[i].setValue(number + 1); buttons[number].setValue(number + 1);
buttons[i].setOnClickListener(listener); buttons[number].setOnClickListener(listener);
addView(buttons[number]);
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){ public void setGameController(GameController gc){
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 @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);

View file

@ -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++;
}
}
}

View file

@ -21,80 +21,21 @@
<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout <tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_alignParentBottom="true" android:minHeight="100dp"
android:layout_height="fill_parent" android:layout_height="wrap_content"
android:layout_below="@+id/sudokuLayout" android:layout_below="@+id/sudokuLayout"
android:id="@+id/sudokuKeyboardLayout" android:id="@+id/sudokuKeyboardLayout"
android:layout_centerVertical="true"> 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.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.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.SudokuSpecialButtonLayout>
</RelativeLayout> </RelativeLayout>