UI changes.

This commit is contained in:
Gongxter 2015-11-11 18:20:02 +01:00
parent c7402d1196
commit add419fa01
6 changed files with 75 additions and 31 deletions

View file

@ -5,7 +5,7 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="LOCAL" /> <option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.4" /> <option name="gradleHome" value="D:\Program Files\Android\Android Studio\gradle\gradle-2.4" />
<option name="gradleJvm" value="1.8" /> <option name="gradleJvm" value="1.8" />
<option name="modules"> <option name="modules">
<set> <set>

View file

@ -23,6 +23,7 @@ public class GameField implements Cloneable {
this.size = size; this.size = size;
field = new GameCell[size][size]; field = new GameCell[size][size];
initCells(null);
} }
public void initCells(int[][] level) { public void initCells(int[][] level) {

View file

@ -2,6 +2,7 @@ package tu_darmstadt.sudoku.view;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
@ -21,15 +22,15 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
SudokuFieldLayout layout; SudokuFieldLayout layout;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_view); setContentView(R.layout.activity_game_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
//TODO: set view for game layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
layout.setGame(gameController);
/* /*
// DEBUG // DEBUG
String debug = gameController.getFieldAsString(); String debug = gameController.getFieldAsString();

View file

@ -6,14 +6,22 @@ import android.graphics.Paint;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import tu_darmstadt.sudoku.game.GameCell;
/** /**
* Created by TMZ_LToP on 10.11.2015. * Created by TMZ_LToP on 10.11.2015.
*/ */
public class SudokuCellView extends View { public class SudokuCellView extends View {
GameCell mGameCell;
int mWidth;
public SudokuCellView(Context context) { public SudokuCellView(Context context) {
super(context); super(context);
} }
@ -23,30 +31,30 @@ public class SudokuCellView extends View {
} }
int pubx =0 ; public void setValues (int width, GameCell gameCell) {
int puby =0 ; mGameCell = gameCell;
mWidth=width;
public void setPos(int x,int y) {
//dpi = (width * 160)/density getRecourses().getDisplayMetrics().density
pubx = x;
puby = y;
} }
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
int row = mGameCell.getRow();
int col = mGameCell.getCol();
int width = getWidth() - getPaddingRight(); this.setLayoutParams(new RelativeLayout.LayoutParams(mWidth, mWidth));
int height = getHeight() - getPaddingBottom();
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
canvas.drawRect(pubx,puby,pubx+100,puby+100,new Paint());
canvas.drawRect(col*mWidth, row*mWidth, (col+1)*mWidth+1, (row+1)*mWidth+1,new Paint());
} }
public int getColumn() {
return mGameCell.getCol();
}
public int getRow() {
return mGameCell.getRow();
}
} }

View file

@ -1,9 +1,13 @@
package tu_darmstadt.sudoku.view; package tu_darmstadt.sudoku.view;
import android.content.Context; import android.content.Context;
import android.support.design.widget.Snackbar;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Toast;
import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.controller.GameController;
@ -13,31 +17,59 @@ import tu_darmstadt.sudoku.controller.GameController;
public class SudokuFieldLayout extends RelativeLayout { public class SudokuFieldLayout extends RelativeLayout {
private GameController gamecont; private GameController gameController;
public SudokuCellView [][] gamecells; public SudokuCellView [][] gamecells;
AttributeSet attrs;
public SudokuFieldLayout(Context context, AttributeSet attrs) { public SudokuFieldLayout(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.attrs=attrs;
} }
public void setGame(GameController gc) { public void setGame(GameController gc) {
if (gc == null) throw new IllegalArgumentException("GameController may not be null."); if (gc == null) throw new IllegalArgumentException("GameController may not be null.");
gamecont = gc; gameController = gc;
gamecells = new SudokuCellView[gc.getSize()][gc.getSize()]; gamecells = new SudokuCellView[gc.getSize()][gc.getSize()];
int width = (Math.min(getWidth(),getHeight()))/gc.getSize();
for (int i = 0; i < gc.getSize(); i++) { OnClickListener listener = new OnClickListener() {
for (int j = 0; j < gc.getSize(); j++){ @Override
public void onClick(View v) {
if (v instanceof SudokuCellView) {
SudokuCellView view = (SudokuCellView) v;
Toast t = Toast.makeText(getContext(), "(" + view.getRow() + " " + view.getColumn() + ")", Toast.LENGTH_SHORT);
t.show();
}
}
};
gamecells[i][j] = new SudokuCellView(getContext(), null); for (int i = 0; i < gameController.getSize(); i++) {
//gamecells[i][j].setValues(i,j,width,field); for (int j = 0; j < gameController.getSize(); j++) {
gamecells[i][j] = new SudokuCellView(getContext(), attrs);
gamecells[i][j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
gamecells[i][j].setOnClickListener(listener);
if(i != 8 || j != 7) continue;
addView(gamecells[i][j]);
} }
} }
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed,l,t,r,b);
if(changed) {
int width = (Math.min(getWidth(), getHeight())) / gameController.getSize();
//width -= 20;
for (int i = 0; i < gameController.getSize(); i++) {
for (int j = 0; j < gameController.getSize(); j++) {
gamecells[i][j].setValues(width, gameController.getGameCell(i, j));
}
}
}
} }
} }

View file

@ -2,15 +2,17 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.view.GameActivity"> tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.view.GameActivity">
<tu_darmstadt.sudoku.view.SudokuFieldLayout <tu_darmstadt.sudoku.view.SudokuFieldLayout
android:layout_width="fill_parent" android:id="@+id/sudokuLayout"
android:layout_height="fill_parent"> android:layout_width="wrap_content"
android:layout_height="wrap_content">
</tu_darmstadt.sudoku.view.SudokuFieldLayout> </tu_darmstadt.sudoku.view.SudokuFieldLayout>
</RelativeLayout> </RelativeLayout>