OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.tab; | 5 package org.chromium.chrome.browser.tab; |
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.Gravity; | 9 import android.view.Gravity; |
10 import android.widget.LinearLayout; | 10 import android.widget.LinearLayout; |
(...skipping 18 matching lines...) Expand all Loading... |
29 mThresholdPx = (int) (mDensity * MAX_BUTTON_WIDTH_DP); | 29 mThresholdPx = (int) (mDensity * MAX_BUTTON_WIDTH_DP); |
30 } | 30 } |
31 | 31 |
32 @Override | 32 @Override |
33 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 33 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
34 // This assumes that view's layout_width is set to match_parent. | 34 // This assumes that view's layout_width is set to match_parent. |
35 assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; | 35 assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; |
36 int width = MeasureSpec.getSize(widthMeasureSpec); | 36 int width = MeasureSpec.getSize(widthMeasureSpec); |
37 int height = MeasureSpec.getSize(heightMeasureSpec); | 37 int height = MeasureSpec.getSize(heightMeasureSpec); |
38 | 38 |
39 final ButtonCompat mReloadButton = (ButtonCompat) findViewById(R.id.sad_
tab_reload_button); | 39 final ButtonCompat mButton = (ButtonCompat) findViewById(R.id.sad_tab_bu
tton); |
40 | 40 |
41 final LinearLayout.LayoutParams mReloadButtonParams = | 41 final LinearLayout.LayoutParams mButtonParams = |
42 (LinearLayout.LayoutParams) mReloadButton.getLayoutParams(); | 42 (LinearLayout.LayoutParams) mButton.getLayoutParams(); |
43 | 43 |
44 if ((width > height || width > mThresholdPx) && mReloadButton.getWidth()
<= width) { | 44 if ((width > height || width > mThresholdPx) && mButton.getWidth() <= wi
dth) { |
45 // Orientation is landscape | 45 // Orientation is landscape |
46 mReloadButtonParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; | 46 mButtonParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; |
47 mReloadButtonParams.gravity = Gravity.END; | 47 mButtonParams.gravity = Gravity.END; |
48 } else { | 48 } else { |
49 // Orientation is portrait | 49 // Orientation is portrait |
50 mReloadButtonParams.width = LinearLayout.LayoutParams.MATCH_PARENT; | 50 mButtonParams.width = LinearLayout.LayoutParams.MATCH_PARENT; |
51 mReloadButtonParams.gravity = Gravity.FILL_HORIZONTAL; | 51 mButtonParams.gravity = Gravity.FILL_HORIZONTAL; |
52 } | 52 } |
53 | 53 |
54 mReloadButton.setLayoutParams(mReloadButtonParams); | 54 mButton.setLayoutParams(mButtonParams); |
55 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 55 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
56 } | 56 } |
57 } | 57 } |
OLD | NEW |