Skip to content

Commit

Permalink
Enforce page margin.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahmedre committed Mar 9, 2015
1 parent 30c58ef commit 292d03d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<dimen name="toolbar_item_width">42dp</dimen>
<dimen name="toolbar_total_height">54dp</dimen>
<dimen name="juz_overlay_text_size">12sp</dimen>
<dimen name="page_margin">8dp</dimen>

<!-- page overlay text -->
<dimen name="max_overlay_font_size">10sp</dimen>
Expand Down

0 comments on commit 292d03d

Please sign in to comment.