keyboard now with linear layout

This commit is contained in:
Gongxter 2016-01-21 13:55:46 +01:00
parent b6787846e6
commit 01b3e37ce1
5 changed files with 53 additions and 23 deletions

View file

@ -105,8 +105,8 @@ 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((gameController.getSize() / 2) + 1); //keyboard.setColumnCount((gameController.getSize() / 2) + 1);
keyboard.setRowCount(2); //keyboard.setRowCount(2);
Point p = new Point(); Point p = new Point();
getWindowManager().getDefaultDisplay().getSize(p); getWindowManager().getDefaultDisplay().getSize(p);
@ -243,6 +243,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
return true; return true;
} }
@Override @Override
public void onSolved() { public void onSolved() {
gameSolved = true; gameSolved = true;

View file

@ -210,9 +210,9 @@ public class StatsActivity extends AppCompatActivity {
} }
private void updateGeneralIfo(int time, int games, int hints){ private void updateGeneralIfo(int time, int games, int hints){
totalHints =hints; totalHints +=hints;
totalGames =games; totalGames +=games;
totalTime =time; totalTime +=time;
} }
private void setGeneralInfo(){ private void setGeneralInfo(){
TextView generalInfoView; TextView generalInfoView;

View file

@ -11,8 +11,13 @@ import android.graphics.Canvas;
import android.os.Bundle; import android.os.Bundle;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.GridLayout; import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import java.util.LinkedList; import java.util.LinkedList;
@ -26,13 +31,14 @@ import tu_darmstadt.sudoku.ui.listener.IDeleteDialogFragmentListener;
*/ */
public class SudokuKeyboardLayout extends GridLayout implements IHighlightChangedListener { public class SudokuKeyboardLayout extends LinearLayout implements IHighlightChangedListener {
AttributeSet attrs; AttributeSet attrs;
SudokuButton [] buttons; SudokuButton [] buttons;
GameController gameController; GameController gameController;
Symbol symbolsToUse = Symbol.Default; Symbol symbolsToUse = Symbol.Default;
float normalTextSize = 0; float normalTextSize = 0;
LinearLayout [] layouts = new LinearLayout[2];
OnClickListener listener = new OnClickListener() { OnClickListener listener = new OnClickListener() {
@Override @Override
@ -51,7 +57,6 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange
public SudokuKeyboardLayout(Context context, AttributeSet attrs) { public SudokuKeyboardLayout(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.attrs = attrs; this.attrs = attrs;
} }
public void setSymbols(Symbol s) { public void setSymbols(Symbol s) {
@ -62,20 +67,39 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange
} }
public void setKeyBoard(int size,int width, int height) { public void setKeyBoard(int size,int width, int height) {
LayoutParams p ; LayoutParams p;
buttons = new SudokuButton[size]; buttons = new SudokuButton[size];
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 = torun; int realSize = torun;
//set layout parameters and init Layouts
for (int i = 0; i < 2; i++) {
p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1);
//if (i == 0) p.bottomMargin=10; else p.topMargin=10;
p.setMargins(0,5,0,5);
layouts[i] = new LinearLayout(getContext(),null);
layouts[i].setLayoutParams(p);
layouts[i].setWeightSum(torun);
layouts[i].setOrientation(LinearLayout.HORIZONTAL);
addView(layouts[i]);
}
//int width2 =(width-(realSize*30))/(realSize); //int width2 =(width-(realSize*30))/(realSize);
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++){
if (number == size) { if (number == size) {
break; break;
} }
buttons[number] = new SudokuButton(getContext(),null); buttons[number] = new SudokuButton(getContext(),null);
p = new LayoutParams(0, LayoutParams.MATCH_PARENT,1);
p.setMargins(5,5,5,5);
buttons[number].setLayoutParams(p);
/* removed GridLayout because of bad scaling will use now a Linearlayout
Spec rowSpec = spec(k,1); Spec rowSpec = spec(k,1);
Spec colSpec = spec(i,1); Spec colSpec = spec(i,1);
@ -85,17 +109,20 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange
p.setMargins((i == 0) ? 0 : 5,5,5,5); p.setMargins((i == 0) ? 0 : 5,5,5,5);
p.width = (width - (int)((getResources().getDimension(R.dimen.activity_horizontal_margin))*2)) / realSize; p.width = (width - (int)((getResources().getDimension(R.dimen.activity_horizontal_margin))*2)) / realSize;
p.width = p.width - 10; p.width = p.width - 10;
p.setGravity(LayoutParams.WRAP_CONTENT); //p.setGravity(Gravity.FILL_VERTICAL);
//p.setGravity(Gravity.FILL);
// p.setGravity(LayoutParams.WRAP_CONTENT);
*/
// buttons[number].setLayoutParams(p);
buttons[number].setLayoutParams(p);
//buttons[number].setGravity(Gravity.CENTER); //buttons[number].setGravity(Gravity.CENTER);
buttons[number].setType(SudokuButtonType.Value); buttons[number].setType(SudokuButtonType.Value);
buttons[number].setTextColor(getResources().getColor(R.color.white));
buttons[number].setBackgroundResource(R.drawable.mnenomic_numpad_button); buttons[number].setBackgroundResource(R.drawable.mnenomic_numpad_button);
buttons[number].setText(Symbol.getSymbol(symbolsToUse, number)); buttons[number].setText(Symbol.getSymbol(symbolsToUse, number));
buttons[number].setValue(number + 1); buttons[number].setValue(number + 1);
buttons[number].setOnClickListener(listener); buttons[number].setOnClickListener(listener);
addView(buttons[number]); layouts[k].addView(buttons[number]);
number++; number++;
} }
} }
@ -158,4 +185,9 @@ public class SudokuKeyboardLayout extends GridLayout implements IHighlightChange
} }
} }
} }
public void fixHeight (){
int i = getHeight();
i = buttons[0].getHeight();
i = buttons[5].getHeight();
}
} }

View file

@ -100,6 +100,7 @@
android:stepSize="1" /> android:stepSize="1" />
<Button <Button
android:textColor="@color/white"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginLeft="30dp" android:layout_marginLeft="30dp"
@ -116,6 +117,7 @@
android:background="@drawable/mnenomic_numpad_button"/> android:background="@drawable/mnenomic_numpad_button"/>
<Button <Button
android:textColor="@color/white"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"

View file

@ -25,24 +25,19 @@
android:weightSum="3"> android:weightSum="3">
<tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout <tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="0px" android:layout_height="0dp"
android:id="@+id/sudokuKeyboardLayout" android:id="@+id/sudokuKeyboardLayout"
android:useDefaultMargins="true" android:orientation="vertical"
android:alignmentMode="alignBounds" android:layout_weight="2"
android:columnOrderPreserved="false" android:weightSum="2">
android:columnCount="6"
android:rowCount="2"
android:alwaysDrawnWithCache="true"
android:foregroundGravity="fill_horizontal"
android:layout_weight="2">
</tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout> </tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout>
<tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout <tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout
android:id="@+id/sudokuSpecialLayout" android:id="@+id/sudokuSpecialLayout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0px" android:layout_height="0dp"
android:layout_weight="1"> android:layout_weight="1">
</tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout> </tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout>