Fixed field layout on tablets and small screens

Fixed #42
This commit is contained in:
Christopher Beckmann 2020-10-09 17:29:57 +02:00
parent ce071e2c2e
commit 7c5fc7996b
6 changed files with 158 additions and 135 deletions

View file

@ -22,6 +22,7 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import org.secuso.privacyfriendlysudoku.controller.GameController;
@ -81,7 +82,7 @@ public class SudokuKeyboardLayout extends LinearLayout implements IHighlightChan
if(orientation == LinearLayout.HORIZONTAL) {
p = new LayoutParams(LayoutParams.MATCH_PARENT, 0, 1);
} else {
p = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);
}
//if (i == 0) p.bottomMargin=10; else p.topMargin=10;
p.setMargins(0, 5, 0, 5);
@ -128,6 +129,7 @@ public class SudokuKeyboardLayout extends LinearLayout implements IHighlightChan
buttons[buttonIndex].setBackgroundResource(R.drawable.mnenomic_numpad_button);
buttons[buttonIndex].setPadding(0, 0, 0, 0);
buttons[buttonIndex].setGravity(Gravity.CENTER);
buttons[buttonIndex].setMinHeight((int) (normalTextSize * 2));
buttons[buttonIndex].setText(Symbol.getSymbol(symbolsToUse, buttonIndex));
buttons[buttonIndex].setTextSize(TypedValue.COMPLEX_UNIT_SP, normalTextSize);
buttons[buttonIndex].setValue(buttonIndex + 1);

View file

@ -136,11 +136,11 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
for (SudokuButtonType t : getSpecialButtons()){
fixedButtons[i] = new SudokuSpecialButton(getContext(),null);
if(orientation == LinearLayout.HORIZONTAL) {
p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
p = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
} else {
p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
fixedButtons[i].setPadding(25, 0, 25, 0);
p = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1);
}
fixedButtons[i].setPadding(25, 0, 25, 0);
p.setMargins(5, 5, 5, 5);
//int width2 =width/(fixedButtonsCount);
@ -148,28 +148,16 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
if(t == Spacer) {
fixedButtons[i].setVisibility(View.INVISIBLE);
}
/*if(t == SudokuButtonType.Do && !gameController.isRedoAvailable()) {
fixedButtons[i].setEnabled(false);
}
if(t == SudokuButtonType.Undo && !gameController.isUndoAvailable()) {
fixedButtons[i].setEnabled(false);
}*/
fixedButtons[i].setLayoutParams(p);
fixedButtons[i].setType(t);
fixedButtons[i].setImageDrawable(getResources().getDrawable(t.getResID()));
// fixedButtons[i].setText(SudokuButtonType.getName(t));
fixedButtons[i].setScaleType(ImageView.ScaleType.CENTER);
fixedButtons[i].setImageDrawable(ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID()));
fixedButtons[i].setScaleType(ImageView.ScaleType.FIT_XY);
fixedButtons[i].setAdjustViewBounds(true);
fixedButtons[i].setOnClickListener(listener);
fixedButtons[i].setBackgroundResource(R.drawable.numpad_highlighted_four);
addView(fixedButtons[i]);
if(fixedButtons[i].getVisibility() == View.VISIBLE) {
Drawable drawable = ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID());
setUpVectorDrawable(drawable);
drawable.draw(canvas);
fixedButtons[i].setImageBitmap(bitResult);
}
i++;
}

View file

@ -1,54 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layoutDirection="ltr"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_content"
android:layout_marginTop="?android:actionBarSize"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
tools:context="org.secuso.privacyfriendlysudoku.ui.GameActivity">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout
android:id="@+id/sudokuSpecialLayout"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginRight="30dp"
android:layout_marginEnd="30dp"
android:orientation="vertical"
android:layoutDirection="ltr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"/>
android:layout_weight="1"
android:layout_marginStart="0dp"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sudokuLayout"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="0dp" />
<org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout
android:id="@+id/sudokuLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/sudokuSpecialLayout"
android:layout_toEndOf="@+id/sudokuSpecialLayout"
android:minWidth="100dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:clickable="true"
android:gravity="center" />
android:focusable="true"
android:gravity="center"
app:layout_constraintHorizontal_weight="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintEnd_toStartOf="@+id/sudokuKeyboardLayout"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/sudokuSpecialLayout"
app:layout_constraintTop_toTopOf="parent" />
<org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/sudokuLayout"
android:layout_toEndOf="@+id/sudokuLayout"
android:id="@+id/sudokuKeyboardLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:minWidth="50dp"
android:minHeight="50dp"
android:orientation="horizontal"
android:weightSum="2"/>
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="2"
app:layout_constraintStart_toEndOf="@+id/sudokuLayout"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,57 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layoutDirection="ltr"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_content"
android:layout_marginTop="?android:actionBarSize"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout
android:id="@+id/sudokuLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/createSudokuLayout"
android:layout_toEndOf="@+id/createSudokuLayout"
android:minWidth="100dp"
android:clickable="true"
android:gravity="center" />
<org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/sudokuLayout"
android:layout_toEndOf="@+id/sudokuLayout"
android:id="@+id/sudokuKeyboardLayout"
android:orientation="horizontal"
android:weightSum="2">
</org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout>
tools:context="org.secuso.privacyfriendlysudoku.ui.GameActivity">
<org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuSpecialButtonLayout
android:id="@+id/createSudokuLayout"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginRight="30dp"
android:layout_marginEnd="30dp"
android:orientation="vertical"
android:layoutDirection="ltr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center">
</org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuSpecialButtonLayout>
android:layout_weight="1"
android:layout_marginStart="0dp"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sudokuLayout"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="0dp" />
</RelativeLayout>
<org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout
android:id="@+id/sudokuLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
app:layout_constraintHorizontal_weight="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintEnd_toStartOf="@+id/sudokuKeyboardLayout"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/createSudokuLayout"
app:layout_constraintTop_toTopOf="parent" />
<org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout
android:id="@+id/sudokuKeyboardLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:minWidth="50dp"
android:minHeight="50dp"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="2"
app:layout_constraintStart_toEndOf="@+id/sudokuLayout"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,50 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/main_content"
android:layout_marginTop="?android:actionBarSize"
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:context="org.secuso.privacyfriendlysudoku.ui.GameActivity">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout
android:id="@+id/sudokuLayout"
android:layout_width="match_parent"
android:layoutDirection="ltr"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:gravity="center" />
android:focusable="true"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/sudokuButtonLayout"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/sudokuLayout"
android:id="@+id/sudokuButtonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:orientation="vertical"
android:weightSum="3">
android:weightSum="3"
app:layout_constraintTop_toBottomOf="@id/sudokuLayout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout
android:id="@+id/sudokuKeyboardLayout"
android:layout_width="fill_parent"
android:layout_height="0px"
android:id="@+id/sudokuKeyboardLayout"
android:orientation="vertical"
android:layout_weight="2"
android:weightSum="2">
</org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout>
android:orientation="vertical"
android:weightSum="2" />
<org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout
android:id="@+id/sudokuSpecialLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout>
android:layout_weight="1"
android:weightSum="1" />
</LinearLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,50 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/main_content"
android:layout_marginTop="?android:actionBarSize"
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:context="org.secuso.privacyfriendlysudoku.ui.GameActivity">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout
android:id="@+id/sudokuLayout"
android:layout_width="match_parent"
android:layoutDirection="ltr"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:gravity="center" />
android:focusable="true"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/sudokuButtonLayout"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/sudokuLayout"
android:id="@+id/sudokuButtonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:orientation="vertical"
android:weightSum="3">
android:weightSum="3"
app:layout_constraintTop_toBottomOf="@id/sudokuLayout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout
android:id="@+id/sudokuKeyboardLayout"
android:layout_width="fill_parent"
android:layout_height="0px"
android:id="@+id/sudokuKeyboardLayout"
android:orientation="vertical"
android:layout_weight="2"
android:weightSum="2">
</org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout>
android:orientation="vertical"
android:weightSum="2" />
<org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuSpecialButtonLayout
android:id="@+id/createSudokuLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuSpecialButtonLayout>
android:layout_weight="1"
android:weightSum="1" />
</LinearLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>