UI changes.
This commit is contained in:
parent
c7402d1196
commit
add419fa01
6 changed files with 75 additions and 31 deletions
|
@ -5,7 +5,7 @@
|
|||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<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="modules">
|
||||
<set>
|
||||
|
|
|
@ -23,6 +23,7 @@ public class GameField implements Cloneable {
|
|||
this.size = size;
|
||||
|
||||
field = new GameCell[size][size];
|
||||
initCells(null);
|
||||
}
|
||||
|
||||
public void initCells(int[][] level) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package tu_darmstadt.sudoku.view;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
|
@ -21,15 +22,15 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
SudokuFieldLayout layout;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_game_view);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
//TODO: set view for game
|
||||
|
||||
|
||||
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
|
||||
layout.setGame(gameController);
|
||||
/*
|
||||
// DEBUG
|
||||
String debug = gameController.getFieldAsString();
|
||||
|
|
|
@ -6,14 +6,22 @@ import android.graphics.Paint;
|
|||
import android.provider.ContactsContract;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import java.util.jar.Attributes;
|
||||
|
||||
import tu_darmstadt.sudoku.game.GameCell;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 10.11.2015.
|
||||
*/
|
||||
public class SudokuCellView extends View {
|
||||
|
||||
GameCell mGameCell;
|
||||
int mWidth;
|
||||
|
||||
|
||||
public SudokuCellView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
@ -23,30 +31,30 @@ public class SudokuCellView extends View {
|
|||
|
||||
}
|
||||
|
||||
int pubx =0 ;
|
||||
int puby =0 ;
|
||||
|
||||
public void setPos(int x,int y) {
|
||||
//dpi = (width * 160)/density getRecourses().getDisplayMetrics().density
|
||||
|
||||
pubx = x;
|
||||
puby = y;
|
||||
|
||||
public void setValues (int width, GameCell gameCell) {
|
||||
mGameCell = gameCell;
|
||||
mWidth=width;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
int row = mGameCell.getRow();
|
||||
int col = mGameCell.getCol();
|
||||
|
||||
int width = getWidth() - getPaddingRight();
|
||||
int height = getHeight() - getPaddingBottom();
|
||||
|
||||
int paddingLeft = getPaddingLeft();
|
||||
int paddingTop = getPaddingTop();
|
||||
|
||||
canvas.drawRect(pubx,puby,pubx+100,puby+100,new Paint());
|
||||
|
||||
this.setLayoutParams(new RelativeLayout.LayoutParams(mWidth, mWidth));
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package tu_darmstadt.sudoku.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.GameController;
|
||||
|
||||
|
@ -13,31 +17,59 @@ import tu_darmstadt.sudoku.controller.GameController;
|
|||
public class SudokuFieldLayout extends RelativeLayout {
|
||||
|
||||
|
||||
private GameController gamecont;
|
||||
private GameController gameController;
|
||||
|
||||
public SudokuCellView [][] gamecells;
|
||||
AttributeSet attrs;
|
||||
|
||||
|
||||
|
||||
public SudokuFieldLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.attrs=attrs;
|
||||
}
|
||||
|
||||
public void setGame(GameController gc) {
|
||||
if (gc == null) throw new IllegalArgumentException("GameController may not be null.");
|
||||
gamecont = gc;
|
||||
gameController = gc;
|
||||
gamecells = new SudokuCellView[gc.getSize()][gc.getSize()];
|
||||
int width = (Math.min(getWidth(),getHeight()))/gc.getSize();
|
||||
|
||||
for (int i = 0; i < gc.getSize(); i++) {
|
||||
for (int j = 0; j < gc.getSize(); j++){
|
||||
OnClickListener listener = new OnClickListener() {
|
||||
@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);
|
||||
//gamecells[i][j].setValues(i,j,width,field);
|
||||
for (int i = 0; i < gameController.getSize(); i++) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
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:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.view.GameActivity">
|
||||
<tu_darmstadt.sudoku.view.SudokuFieldLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:id="@+id/sudokuLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</tu_darmstadt.sudoku.view.SudokuFieldLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue