From 292d03d61d7099318575d973c66349dedaf9b92e Mon Sep 17 00:00:00 2001 From: ahmedre Date: Sun, 8 Mar 2015 17:43:11 -0700 Subject: [PATCH] Enforce page margin. Whereas before, we were only placing a margin on the sides with borders, this causes a problem where on the pages with only one border, we have a page that isn't centered. --- .../androidquran/widgets/QuranPageLayout.java | 26 ++++++++++--------- app/src/main/res/values/dimens.xml | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/widgets/QuranPageLayout.java b/app/src/main/java/com/quran/labs/androidquran/widgets/QuranPageLayout.java index 5b2c847eae..48ddfbf5cb 100644 --- a/app/src/main/java/com/quran/labs/androidquran/widgets/QuranPageLayout.java +++ b/app/src/main/java/com/quran/labs/androidquran/widgets/QuranPageLayout.java @@ -8,12 +8,14 @@ import android.content.Context; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.PaintDrawable; import android.os.Build; import android.support.annotation.StringRes; import android.support.v4.view.GravityCompat; import android.view.Display; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -39,25 +41,30 @@ public abstract class QuranPageLayout extends FrameLayout private View mErrorLayout; private TextView mErrorText; private View mInnerView; + private int mViewPadding; public QuranPageLayout(Context context) { super(context); mContext = context; + Resources resources = context.getResources(); final boolean isLandscape = - context.getResources().getConfiguration().orientation == + resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; mInnerView = generateContentView(context); + mViewPadding = resources.getDimensionPixelSize(R.dimen.page_margin); + + FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + lp.gravity = Gravity.CENTER; if (isLandscape && shouldWrapWithScrollView()) { mScrollView = new ObservableScrollView(context); mScrollView.setFillViewport(true); - addView(mScrollView, - LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + addView(mScrollView, lp); mScrollView.addView(mInnerView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mScrollView.setOnScrollListener(this); } else { - addView(mInnerView, LayoutParams.MATCH_PARENT, - LayoutParams.MATCH_PARENT); + addView(mInnerView, lp); } if (sAreGradientsLandscape != isLandscape) { @@ -151,13 +158,8 @@ public void updateView(boolean nightMode, boolean useNewBackground) { final View innerView = mScrollView == null ? mInnerView : mScrollView; final LayoutParams params = (FrameLayout.LayoutParams) innerView.getLayoutParams(); - if (mRightBorder != null) { - params.rightMargin = mRightBorder.getBackground().getIntrinsicWidth(); - } - - if (mLeftBorder != null) { - params.leftMargin = mLeftBorder.getBackground().getIntrinsicWidth(); - } + params.leftMargin = mViewPadding; + params.rightMargin = mViewPadding; // this calls requestLayout innerView.setLayoutParams(params); diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index ea631e17fb..3447ba46e5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -18,6 +18,7 @@ 42dp 54dp 12sp + 8dp 10sp