From 306609e340ff27650f046e8bccb2e21a62c990cb Mon Sep 17 00:00:00 2001 From: Synced Synapse Date: Fri, 15 Sep 2017 16:01:13 +0100 Subject: [PATCH] Revert "Removed dependency on GridLayout in SquareGridLayout" (#446) * Revert "Removed dependency on GridLayout in SquareGridLayout (#445)" This reverts commit 876db1802379bb4a650fe949ed6d216e1dd53bc1. --- app/build.gradle | 1 + .../kore/ui/viewgroups/SquareGridLayout.java | 109 +++--------------- .../main/res/layout/remote_control_pad.xml | 30 ++++- app/src/main/res/values/attr.xml | 18 ++- 4 files changed, 54 insertions(+), 104 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3b85641..753b4fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,6 +115,7 @@ dependencies { compile "com.android.support:cardview-v7:${supportLibVersion}" compile "com.android.support:preference-v14:${supportLibVersion}" compile "com.android.support:support-v13:${supportLibVersion}" + compile "com.android.support:gridlayout-v7:${supportLibVersion}" compile 'com.fasterxml.jackson.core:jackson-databind:2.5.2' compile 'com.jakewharton:butterknife:6.1.0' diff --git a/app/src/main/java/org/xbmc/kore/ui/viewgroups/SquareGridLayout.java b/app/src/main/java/org/xbmc/kore/ui/viewgroups/SquareGridLayout.java index 4d51f1f..c2bab55 100644 --- a/app/src/main/java/org/xbmc/kore/ui/viewgroups/SquareGridLayout.java +++ b/app/src/main/java/org/xbmc/kore/ui/viewgroups/SquareGridLayout.java @@ -15,121 +15,46 @@ */ package org.xbmc.kore.ui.viewgroups; + import android.content.Context; -import android.content.res.TypedArray; +import android.support.v7.widget.GridLayout; import android.util.AttributeSet; -import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.view.ViewTreeObserver; import android.widget.RelativeLayout; -import org.xbmc.kore.R; +import org.xbmc.kore.utils.LogUtils; /** * The square grid layout creates a square layout that will fit inside - * the boundaries provided by the parent layout. Note that all cells - * will have the same size. - * - * The attribute columnCount is available to specify the amount of columns - * when using SquareGridLayout in a XML layout file. + * the boundaries provided by the parent layout. */ -public class SquareGridLayout extends ViewGroup { - - private int columnCount = 1; - private int cellSize; +public class SquareGridLayout extends GridLayout { public SquareGridLayout(Context context) { - this(context, null); + super(context); + fixForRelativeLayout(); } public SquareGridLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); + super(context, attrs); + fixForRelativeLayout(); } public SquareGridLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SquareGridLayout, 0, 0); - setColumnCount(a.getInt(R.styleable.SquareGridLayout_columnCount, 1)); - a.recycle(); fixForRelativeLayout(); } - public void setColumnCount(int columnCount) { - if (columnCount < 1) throw new IllegalArgumentException("Column count must be 1 or more"); - this.columnCount = columnCount; - } - - /** - * Methods overridden to make sure we pass in the correct layout parameters for the child views - */ @Override - protected LayoutParams generateLayoutParams(LayoutParams p) { - return new MarginLayoutParams(p); - } + protected void onMeasure(int widthSpec, int heightSpec) { + int width = MeasureSpec.getSize(widthSpec); + int height = MeasureSpec.getSize(heightSpec); + int size = Math.min(width, height); - @Override - public LayoutParams generateLayoutParams(AttributeSet attrs) { - return new MarginLayoutParams(getContext(), attrs); - } - - @Override - protected LayoutParams generateDefaultLayoutParams() { - return new MarginLayoutParams(MarginLayoutParams.WRAP_CONTENT, - MarginLayoutParams.WRAP_CONTENT); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int width = MeasureSpec.getSize(widthMeasureSpec); - int height = MeasureSpec.getSize(heightMeasureSpec); - - int paddingWidth = getPaddingLeft() + getPaddingRight(); - int paddingHeight = getPaddingTop() + getPaddingBottom(); - - int size; - int padding; - if ((width - paddingWidth) < (height - paddingHeight)) { - size = width; - padding = size - paddingWidth; - } else { - size = height; - padding = size - paddingHeight; - } - - for (int y = 0; y < columnCount; y++) { - for (int x = 0; x < columnCount; x++) { - View child = getChildAt(y * size + x); - if (child != null) { - measureChildWithMargins(child, - MeasureSpec.makeMeasureSpec((padding + x) / columnCount, MeasureSpec.EXACTLY), - 0, - MeasureSpec.makeMeasureSpec((padding + y) / columnCount, MeasureSpec.EXACTLY), - 0); - } - } - } - - setMeasuredDimension(size, size); - cellSize = padding; - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - // top left is used to position child views - left = getPaddingLeft(); - top = getPaddingTop(); - - for (int y = 0; y < columnCount; y++) { - for (int x = 0; x < columnCount; x++) { - View child = getChildAt(y * columnCount + x); - MarginLayoutParams childLayoutParams = (MarginLayoutParams) child.getLayoutParams(); - child.layout(left + (cellSize * x) / columnCount + childLayoutParams.leftMargin, - top + (cellSize * y) / columnCount + childLayoutParams.topMargin, - left + (cellSize * (x+1)) / columnCount - childLayoutParams.rightMargin, - top + (cellSize * (y+1)) / columnCount - childLayoutParams.bottomMargin - ); - } - } + super.onMeasure(MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY)); } /** @@ -153,4 +78,4 @@ public class SquareGridLayout extends ViewGroup { } }); } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/remote_control_pad.xml b/app/src/main/res/layout/remote_control_pad.xml index 243e60c..c250284 100644 --- a/app/src/main/res/layout/remote_control_pad.xml +++ b/app/src/main/res/layout/remote_control_pad.xml @@ -14,23 +14,33 @@ See the License for the specific language governing permissions and limitations under the License. --> - + @@ -38,18 +48,27 @@ android:id="@+id/left" android:layout_width="0dp" android:layout_height="0dp" + app:layout_columnWeight="1" + app:layout_rowWeight="1" + app:layout_gravity="fill" android:src="?attr/iconLeft" android:contentDescription="@string/left"/> @@ -57,18 +76,27 @@ android:id="@+id/back" android:layout_width="0dp" android:layout_height="0dp" + app:layout_columnWeight="1" + app:layout_rowWeight="1" + app:layout_gravity="fill" android:src="?attr/iconBack" android:contentDescription="@string/back"/> \ No newline at end of file diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index 8f45760..8dd3f65 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -38,20 +38,20 @@ - + - - + + - - - - + + + + @@ -113,8 +113,4 @@ - - - - \ No newline at end of file