From 7cc9c8538c451ea14ddfac035404c49132ae4fa1 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Sun, 31 Dec 2017 15:10:19 +0100 Subject: [PATCH] Fixes #34. Worked on Issue #18. The lines are now drawn correctly. --- .../ui/view/SudokuCellView.java | 8 ++++- .../ui/view/SudokuFieldLayout.java | 22 +++++++++---- .../main/res/layout-land/activity_about.xml | 29 +++++++++++++++-- .../res/layout-xlarge-land/activity_about.xml | 31 ++++++++++++++++--- .../main/res/layout-xlarge/activity_about.xml | 30 ++++++++++++++++-- .../main/res/layout/activity_game_view.xml | 11 +++++-- 6 files changed, 111 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuCellView.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuCellView.java index c22df6e..6f7fa62 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuCellView.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuCellView.java @@ -29,6 +29,7 @@ public class SudokuCellView extends View { boolean selected; CellHighlightTypes highlightType = CellHighlightTypes.Default; Symbol symbolsToUse = Symbol.Default; + RelativeLayout.LayoutParams params; public SudokuCellView(Context context) { @@ -77,8 +78,13 @@ public class SudokuCellView extends View { public void onDraw(Canvas canvas) { super.onDraw(canvas); + if(this.params == null) { + params = new RelativeLayout.LayoutParams(mWidth, mHeight); + } + // Set Layout - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mWidth, mHeight); + params.width = mWidth; + params.height = mHeight; params.topMargin = mRow*mHeight; params.leftMargin = mCol*mWidth; this.setLayoutParams(params); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuFieldLayout.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuFieldLayout.java index 7b997fd..a52e044 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuFieldLayout.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuFieldLayout.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -50,6 +51,7 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang public SudokuCellView [][] gamecells; AttributeSet attrs; + private boolean isWidthLimiting; public SudokuFieldLayout(Context context, AttributeSet attrs) { super(context, attrs); @@ -89,7 +91,6 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang gamecells[i][j].setOnTouchListener(null); } } - return; } @Override @@ -99,19 +100,26 @@ public class SudokuFieldLayout extends RelativeLayout implements IHighlightChang if(gameController == null) return; p.setColor(Color.BLACK); - p.setStrokeWidth(2); + p.setStrokeWidth(5); int horizontalSections = gameController.getSize() / sectionWidth; for(int i = 0; i <= horizontalSections; i++) { - for(int j = -2; j < 2; j++) { - canvas.drawLine((i * getWidth() / horizontalSections) + j, 0, (i * getWidth() / horizontalSections) + j, getHeight(), p); + int offset = 0; + 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); for(int i = 0; i <= verticalSections; i++) { - for(int j = -2; j < 2; j++) { - canvas.drawLine(0, (i * getHeight() / verticalSections) + j, getHeight(), (i * getHeight() / verticalSections) + j, p); + int offset = 0; + 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) { super.onLayout(changed,l,t,r,b); + isWidthLimiting = r-l == Math.min(r-l, b-t); + if(changed && gameController != null) { gameCellWidth = (Math.min(r-l, b-t)) / gameController.getSize(); gameCellHeight = (Math.min(r-l, b-t)) / gameController.getSize(); diff --git a/app/src/main/res/layout-land/activity_about.xml b/app/src/main/res/layout-land/activity_about.xml index ea2259a..97b5716 100644 --- a/app/src/main/res/layout-land/activity_about.xml +++ b/app/src/main/res/layout-land/activity_about.xml @@ -30,6 +30,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" + android:paddingEnd="50dp" + android:paddingStart="50dp" android:src="@drawable/privacyfriendlyappslogo" /> @@ -42,13 +44,32 @@ android:layout_marginTop="15dp" android:text="@string/app_name_long" /> - + android:gravity="center"> + + + + + + + @@ -42,13 +44,32 @@ android:layout_marginTop="15dp" android:text="@string/app_name_long" /> - + android:gravity="center"> + + + + + + + @@ -42,13 +45,32 @@ android:layout_marginTop="15dp" android:text="@string/app_name_long" /> - + android:gravity="center"> + + + + + + + diff --git a/app/src/main/res/layout/activity_game_view.xml b/app/src/main/res/layout/activity_game_view.xml index 2e33c3f..25f58e3 100644 --- a/app/src/main/res/layout/activity_game_view.xml +++ b/app/src/main/res/layout/activity_game_view.xml @@ -5,8 +5,8 @@ android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" - tools:openDrawer="start"> + android:fitsSystemWindows="true"> +