edit the notes location in a cell to an dynamic one added rotation for the drawable pen in note button Blue TU Theme should now be finished

This commit is contained in:
Gongxter 2015-12-10 13:37:04 +01:00
parent 3714a321d9
commit 97becd93e5
4 changed files with 30 additions and 29 deletions

View file

@ -344,7 +344,9 @@ public class GameController implements IModelChangedListener {
return selectedCol; return selectedCol;
} }
public int getSelectedValue() { public int getSelectedValue() {
return selectedValue; if(isValidCellSelected()){
return getValue(getSelectedRow(),getSelectedCol()); //selectedValue;
} else return 0;
} }
public void selectCell(int row, int col) { public void selectCell(int row, int col) {

View file

@ -25,6 +25,7 @@ public class SudokuCellView extends View {
int mSectionWidth; int mSectionWidth;
int mRow; int mRow;
int mCol; int mCol;
int size;
boolean selected; boolean selected;
CellHighlightTypes highlightType = CellHighlightTypes.Default; CellHighlightTypes highlightType = CellHighlightTypes.Default;
Symbol symbolsToUse = Symbol.Default; Symbol symbolsToUse = Symbol.Default;
@ -42,7 +43,7 @@ public class SudokuCellView extends View {
this.selected = b; this.selected = b;
} }
public void setValues (int width, int height, int sectionHeight, int sectionWidth, GameCell gameCell) { public void setValues (int width, int height, int sectionHeight, int sectionWidth, GameCell gameCell,int size) {
mSectionHeight = sectionHeight; mSectionHeight = sectionHeight;
mSectionWidth = sectionWidth; mSectionWidth = sectionWidth;
mGameCell = gameCell; mGameCell = gameCell;
@ -50,6 +51,7 @@ public class SudokuCellView extends View {
mHeight = height; mHeight = height;
mRow = gameCell.getRow(); mRow = gameCell.getRow();
mCol = gameCell.getCol(); mCol = gameCell.getCol();
this.size = size;
} }
public void setHighlightType(CellHighlightTypes highlightType) { public void setHighlightType(CellHighlightTypes highlightType) {
@ -123,24 +125,24 @@ public class SudokuCellView extends View {
public void drawValue(Canvas canvas) { public void drawValue(Canvas canvas) {
Paint p = new Paint(); Paint p = new Paint();
int j= 3; int root = (int) Math.sqrt(size);
int k = 3; int j= root+1;
int k = root;
if(mGameCell.getValue() == 0) { if(mGameCell.getValue() == 0) {
for (int i = 0; i < mGameCell.getNotes().length; i++) { for (int i = 0; i < mGameCell.getNotes().length; i++) {
if (mGameCell.getNotes()[i]) { if (mGameCell.getNotes()[i]) {
p.setTypeface(Typeface.SANS_SERIF); p.setTypeface(Typeface.SANS_SERIF);
p.setTextSize(mWidth / 4); p.setTextSize(mWidth / 4);
p.setTextAlign(Paint.Align.RIGHT); p.setTextAlign(Paint.Align.RIGHT);
// TODO settings: get SymbolEnum from settings canvas.drawText(Symbol.getSymbol(symbolsToUse, i),(mWidth*1/(size+root))*k,(mWidth*1/(size+root+1))*j,p);
canvas.drawText(Symbol.getSymbol(symbolsToUse, i),(mWidth*1/12)*k,(mWidth*1/12)*j,p);
/*canvas.drawText(String.valueOf(1), (mWidth * 1 / 12)*3, (mWidth* 1 / 12)*3, p); /*canvas.drawText(String.valueOf(1), (mWidth * 1 / 12)*3, (mWidth* 1 / 12)*3, p);
canvas.drawText(String.valueOf(2),(mWidth*1/12)*7, (mWidth* 1 / 12)*7,p ); canvas.drawText(String.valueOf(2),(mWidth*1/12)*7, (mWidth* 1 / 12)*7,p );
canvas.drawText(String.valueOf(3),(mWidth*1/12)*11, (mWidth* 1 / 12)*11,p );*/ canvas.drawText(String.valueOf(3),(mWidth*1/12)*11, (mWidth* 1 / 12)*11,p );*/
} }
k+=4; k+=root+1;
if (k > 11) { if (k > (size+root)) {
k = 3; k = root;
j +=4; j +=root+1;
} }
} }
return; return;

View file

@ -135,7 +135,7 @@ public class SudokuFieldLayout extends RelativeLayout {
for (int i = 0; i < gameController.getSize(); i++) { for (int i = 0; i < gameController.getSize(); i++) {
for (int j = 0; j < gameController.getSize(); j++) { for (int j = 0; j < gameController.getSize(); j++) {
gamecells[i][j].setValues(gameCellWidth, gameCellHeight, sectionHeight, sectionWidth, gameController.getGameCell(i, j)); gamecells[i][j].setValues(gameCellWidth, gameCellHeight, sectionHeight, sectionWidth, gameController.getGameCell(i, j),gameController.getSize());
} }
} }
} }

View file

@ -1,29 +1,16 @@
package tu_darmstadt.sudoku.ui.view; package tu_darmstadt.sudoku.ui.view;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RotateDrawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.LinkedList;
import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.controller.GameController;
import tu_darmstadt.sudoku.game.GameBoard;
/** /**
* Created by TMZ_LToP on 17.11.2015. * Created by TMZ_LToP on 17.11.2015.
@ -34,6 +21,8 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
public int fixedButtonsCount = SudokuButtonType.getSpecialButtons().size(); public int fixedButtonsCount = SudokuButtonType.getSpecialButtons().size();
GameController gameController; GameController gameController;
SudokuKeyboardLayout keyboard; SudokuKeyboardLayout keyboard;
Bitmap bitMap,bitResult;
Canvas canvas;
OnClickListener listener = new OnClickListener() { OnClickListener listener = new OnClickListener() {
@ -51,21 +40,29 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
break; break;
case NoteToggle: case NoteToggle:
//btn.setText(keyboard.notesEnabled ? "ON" : "OFF"); //btn.setText(keyboard.notesEnabled ? "ON" : "OFF");
//TODO: add rotation //Animation rotates whole button
/*AnimationSet aniset = new AnimationSet(true);
AnimationSet aniset = new AnimationSet(true);
aniset.setInterpolator(new DecelerateInterpolator()); aniset.setInterpolator(new DecelerateInterpolator());
aniset.setFillAfter(true); aniset.setFillAfter(true);
aniset.setFillEnabled(true); aniset.setFillEnabled(true);
RotateAnimation rotate = new RotateAnimation(0.0f,(keyboard.notesEnabled ? 90.0f:-90.0f), RotateAnimation rotate = new RotateAnimation(0.0f,(keyboard.notesEnabled ? 90.0f:0.0f),
RotateAnimation.RELATIVE_TO_SELF,0.5f, RotateAnimation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f); Animation.RELATIVE_TO_SELF,0.5f);
rotate.setDuration(1500); rotate.setDuration(1500);
rotate.setFillAfter(true); rotate.setFillAfter(true);
aniset.addAnimation(rotate); aniset.addAnimation(rotate);
btn.startAnimation(aniset); btn.startAnimation(aniset);*/
// rotates now only the Drawable
bitMap = BitmapFactory.decodeResource(getResources(), btn.getType().getResID());
bitResult = Bitmap.createBitmap(bitMap.getWidth(), bitMap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitResult);
canvas.rotate(keyboard.notesEnabled?0.0f:90.0f,bitMap.getWidth()/2,bitMap.getHeight()/2);
canvas.drawBitmap(bitMap,0,0,null);
btn.setImageBitmap(bitResult);
keyboard.toggleNotesEnabled(); keyboard.toggleNotesEnabled();
break; break;
case Do: case Do: