Fixes #34. Worked on Issue #18. The lines are now drawn correctly.

This commit is contained in:
Christopher Beckmann 2017-12-31 15:10:19 +01:00
parent 838c5c8675
commit 7cc9c8538c
6 changed files with 111 additions and 20 deletions

View file

@ -29,6 +29,7 @@ public class SudokuCellView extends View {
boolean selected; boolean selected;
CellHighlightTypes highlightType = CellHighlightTypes.Default; CellHighlightTypes highlightType = CellHighlightTypes.Default;
Symbol symbolsToUse = Symbol.Default; Symbol symbolsToUse = Symbol.Default;
RelativeLayout.LayoutParams params;
public SudokuCellView(Context context) { public SudokuCellView(Context context) {
@ -77,8 +78,13 @@ public class SudokuCellView extends View {
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if(this.params == null) {
params = new RelativeLayout.LayoutParams(mWidth, mHeight);
}
// Set Layout // Set Layout
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mWidth, mHeight); params.width = mWidth;
params.height = mHeight;
params.topMargin = mRow*mHeight; params.topMargin = mRow*mHeight;
params.leftMargin = mCol*mWidth; params.leftMargin = mCol*mWidth;
this.setLayoutParams(params); this.setLayoutParams(params);

View file

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -50,6 +51,7 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang
public SudokuCellView [][] gamecells; public SudokuCellView [][] gamecells;
AttributeSet attrs; AttributeSet attrs;
private boolean isWidthLimiting;
public SudokuFieldLayout(Context context, AttributeSet attrs) { public SudokuFieldLayout(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -89,7 +91,6 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang
gamecells[i][j].setOnTouchListener(null); gamecells[i][j].setOnTouchListener(null);
} }
} }
return;
} }
@Override @Override
@ -99,19 +100,26 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang
if(gameController == null) return; if(gameController == null) return;
p.setColor(Color.BLACK); p.setColor(Color.BLACK);
p.setStrokeWidth(2); p.setStrokeWidth(5);
int horizontalSections = gameController.getSize() / sectionWidth; int horizontalSections = gameController.getSize() / sectionWidth;
for(int i = 0; i <= horizontalSections; i++) { for(int i = 0; i <= horizontalSections; i++) {
for(int j = -2; j < 2; j++) { int offset = 0;
canvas.drawLine((i * getWidth() / horizontalSections) + j, 0, (i * getWidth() / horizontalSections) + j, getHeight(), p); if(!isWidthLimiting) {
offset = (-2 + Math.round(i * 4f / (float)horizontalSections)) * -1;
} }
int w = (i * getWidth() / horizontalSections) + offset;
canvas.drawLine(w, 0, w, getHeight(), p);
} }
int verticalSections = (gameController.getSize()/sectionHeight); int verticalSections = (gameController.getSize()/sectionHeight);
for(int i = 0; i <= verticalSections; i++) { for(int i = 0; i <= verticalSections; i++) {
for(int j = -2; j < 2; j++) { int offset = 0;
canvas.drawLine(0, (i * getHeight() / verticalSections) + j, getHeight(), (i * getHeight() / verticalSections) + j, p); if(isWidthLimiting) {
offset = (-2 + Math.round(i * 4f / (float)verticalSections)) * -1;
} }
int h = (i * getHeight() / verticalSections) + offset;
canvas.drawLine(0, h, getWidth(), h, p);
} }
} }
@ -127,6 +135,8 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed,l,t,r,b); super.onLayout(changed,l,t,r,b);
isWidthLimiting = r-l == Math.min(r-l, b-t);
if(changed && gameController != null) { if(changed && gameController != null) {
gameCellWidth = (Math.min(r-l, b-t)) / gameController.getSize(); gameCellWidth = (Math.min(r-l, b-t)) / gameController.getSize();
gameCellHeight = (Math.min(r-l, b-t)) / gameController.getSize(); gameCellHeight = (Math.min(r-l, b-t)) / gameController.getSize();

View file

@ -30,6 +30,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:paddingEnd="50dp"
android:paddingStart="50dp"
android:src="@drawable/privacyfriendlyappslogo" /> android:src="@drawable/privacyfriendlyappslogo" />
</LinearLayout> </LinearLayout>
@ -42,13 +44,32 @@
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
android:text="@string/app_name_long" /> android:text="@string/app_name_long" />
<TextView <RelativeLayout
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:text="@string/version_number" /> android:gravity="center">
<TextView
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/version_number" />
<TextView
android:id="@+id/textFieldVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/textFieldVersion"
android:layout_toEndOf="@+id/textFieldVersion" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/textFieldAuthor" android:id="@+id/textFieldAuthor"
@ -86,6 +107,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:paddingEnd="50dp"
android:paddingStart="50dp"
android:src="@drawable/secuso_logo_blau_blau" /> android:src="@drawable/secuso_logo_blau_blau" />
<TextView <TextView

View file

@ -22,7 +22,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_weight="0.36"> android:layout_weight="0.36">
<ImageView <ImageView
@ -30,6 +30,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:paddingEnd="100dp"
android:paddingStart="100dp"
android:src="@drawable/privacyfriendlyappslogo" /> android:src="@drawable/privacyfriendlyappslogo" />
</LinearLayout> </LinearLayout>
@ -42,13 +44,32 @@
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
android:text="@string/app_name_long" /> android:text="@string/app_name_long" />
<TextView <RelativeLayout
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:text="@string/version_number" /> android:gravity="center">
<TextView
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/version_number" />
<TextView
android:id="@+id/textFieldVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/textFieldVersion"
android:layout_toEndOf="@+id/textFieldVersion" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/textFieldAuthor" android:id="@+id/textFieldAuthor"
@ -86,6 +107,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:paddingEnd="200dp"
android:paddingStart="200dp"
android:src="@drawable/secuso_logo_blau_blau" /> android:src="@drawable/secuso_logo_blau_blau" />
<TextView <TextView

View file

@ -29,6 +29,9 @@
android:id="@+id/barcodeLogo" android:id="@+id/barcodeLogo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="100dp"
android:layout_marginStart="100dp"
android:layout_marginTop="20dp"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:src="@drawable/privacyfriendlyappslogo" /> android:src="@drawable/privacyfriendlyappslogo" />
@ -42,13 +45,32 @@
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
android:text="@string/app_name_long" /> android:text="@string/app_name_long" />
<TextView <RelativeLayout
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:text="@string/version_number" /> android:gravity="center">
<TextView
android:id="@+id/textFieldVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/version_number" />
<TextView
android:id="@+id/textFieldVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/textFieldVersion"
android:layout_toEndOf="@+id/textFieldVersion" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/textFieldAuthor" android:id="@+id/textFieldAuthor"
@ -85,6 +107,8 @@
android:id="@+id/imageView1" android:id="@+id/imageView1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="100dp"
android:layout_marginStart="100dp"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:src="@drawable/secuso_logo_blau_blau" /> android:src="@drawable/secuso_logo_blau_blau" />

View file

@ -5,8 +5,8 @@
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="true">
tools:openDrawer="start"> <!-- tools:openDrawer="start" -->
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
@ -20,17 +20,20 @@
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:clipChildren="false"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:clipChildren="false"
app:popupTheme="@style/AppTheme.PopupOverlay" > app:popupTheme="@style/AppTheme.PopupOverlay" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:weightSum="14" android:weightSum="14"
android:clipChildren="false"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
@ -44,6 +47,7 @@
<RelativeLayout <RelativeLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="5" android:layout_weight="5"
android:clipChildren="false"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -55,10 +59,11 @@
<RatingBar <RatingBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:numStars="3" android:numStars="4"
android:clickable="false" android:clickable="false"
android:id="@+id/gameModeStar" android:id="@+id/gameModeStar"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/difficultyText" android:layout_below="@+id/difficultyText"
style="?android:attr/ratingBarStyleSmall"/> style="?android:attr/ratingBarStyleSmall"/>
</RelativeLayout> </RelativeLayout>