| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.firstrun; | 5 package org.chromium.chrome.browser.firstrun; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.util.AttributeSet; | 8 import android.util.AttributeSet; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 import android.widget.FrameLayout; | 10 import android.widget.FrameLayout; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 mImageAndContent = (LinearLayout) findViewById(R.id.fre_image_and_conten
t); | 41 mImageAndContent = (LinearLayout) findViewById(R.id.fre_image_and_conten
t); |
| 42 mContentWrapper = (LinearLayout) findViewById(R.id.fre_content_wrapper); | 42 mContentWrapper = (LinearLayout) findViewById(R.id.fre_content_wrapper); |
| 43 | 43 |
| 44 | 44 |
| 45 } | 45 } |
| 46 | 46 |
| 47 protected boolean isHorizontalModeEnabled() { | 47 protected boolean isHorizontalModeEnabled() { |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 protected boolean isDynamicPaddingEnabled() { | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 @Override | 51 @Override |
| 56 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 52 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 53 // There was a requirement to have the titles and images of all of the f
irst run experience |
| 54 // pages to be vertically aligned so the transitions between pages look
nice. |
| 55 // The other requirement is for an alternate layout in horizontal mode f
or screens of a |
| 56 // certain size. These are why the padding is set manually. |
| 57 |
| 57 // This assumes that view's layout_width is set to match_parent. | 58 // This assumes that view's layout_width is set to match_parent. |
| 58 assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; | 59 assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; |
| 59 | 60 |
| 60 int width = MeasureSpec.getSize(widthMeasureSpec); | 61 int width = MeasureSpec.getSize(widthMeasureSpec); |
| 61 int height = MeasureSpec.getSize(heightMeasureSpec); | 62 int height = MeasureSpec.getSize(heightMeasureSpec); |
| 62 | 63 |
| 63 MarginLayoutParams contentWrapperLayout = | 64 MarginLayoutParams contentWrapperLayout = |
| 64 (MarginLayoutParams) mContentWrapper.getLayoutParams(); | 65 (MarginLayoutParams) mContentWrapper.getLayoutParams(); |
| 65 | 66 |
| 66 int imageAndContentPaddingStart = 0; | 67 int imageAndContentPaddingStart = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 contentWrapperLayout.topMargin = | 90 contentWrapperLayout.topMargin = |
| 90 getResources().getDimensionPixelSize(R.dimen.fre_vertical_sp
acing); | 91 getResources().getDimensionPixelSize(R.dimen.fre_vertical_sp
acing); |
| 91 | 92 |
| 92 halfContentHeight = getResources().getDimensionPixelSize(R.dimen.fre
_title_text_size) | 93 halfContentHeight = getResources().getDimensionPixelSize(R.dimen.fre
_title_text_size) |
| 93 + getResources().getDimensionPixelSize(R.dimen.fre_vertical_
spacing) | 94 + getResources().getDimensionPixelSize(R.dimen.fre_vertical_
spacing) |
| 94 + getResources().getDimensionPixelSize(R.dimen.fre_image_hei
ght) | 95 + getResources().getDimensionPixelSize(R.dimen.fre_image_hei
ght) |
| 95 + getResources().getDimensionPixelSize(R.dimen.fre_vertical_
spacing); | 96 + getResources().getDimensionPixelSize(R.dimen.fre_vertical_
spacing); |
| 96 } | 97 } |
| 97 | 98 |
| 98 // Add padding to get it roughly centered. | 99 // Add padding to get it roughly centered. |
| 99 if (isDynamicPaddingEnabled()) { | 100 int topPadding = Math.max(0, (height / 2) - halfContentHeight); |
| 100 int topPadding = Math.max(0, (height / 2) - halfContentHeight); | |
| 101 | 101 |
| 102 mMainLayout.setPadding(mMainLayout.getPaddingLeft(), topPadding, | 102 mMainLayout.setPadding(mMainLayout.getPaddingLeft(), topPadding, |
| 103 mMainLayout.getPaddingRight(), mMainLayout.getPaddingBottom(
)); | 103 mMainLayout.getPaddingRight(), mMainLayout.getPaddingBottom()); |
| 104 } | |
| 105 | 104 |
| 106 ApiCompatibilityUtils.setPaddingRelative(mImageAndContent, | 105 ApiCompatibilityUtils.setPaddingRelative(mImageAndContent, |
| 107 imageAndContentPaddingStart, | 106 imageAndContentPaddingStart, |
| 108 mImageAndContent.getPaddingTop(), | 107 mImageAndContent.getPaddingTop(), |
| 109 ApiCompatibilityUtils.getPaddingEnd(mImageAndContent), | 108 ApiCompatibilityUtils.getPaddingEnd(mImageAndContent), |
| 110 mImageAndContent.getPaddingBottom()); | 109 mImageAndContent.getPaddingBottom()); |
| 111 | 110 |
| 112 mContentWrapper.setLayoutParams(contentWrapperLayout); | 111 mContentWrapper.setLayoutParams(contentWrapperLayout); |
| 113 | 112 |
| 114 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 113 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 115 } | 114 } |
| 116 | 115 |
| 117 } | 116 } |
| 118 | 117 |
| OLD | NEW |