]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/definitions/WrapVerticalContentViewPager.java
Add a logcat activity. https://redmine.stoutner.com/issues/264
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / definitions / WrapVerticalContentViewPager.java
1 package com.stoutner.privacybrowser.definitions;
2
3 /*
4  * Copyright © 2017 Soren Stoutner <soren@stoutner.com>.
5  *
6  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
7  *
8  * Privacy Browser is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Privacy Browser is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 import android.content.Context;
23 import android.support.v4.view.ViewPager;
24 import android.util.AttributeSet;
25 import android.view.View;
26
27 public class WrapVerticalContentViewPager extends ViewPager {
28     // Setup the default constructors.
29     public WrapVerticalContentViewPager(Context context) {
30         super(context);
31     }
32
33     public WrapVerticalContentViewPager(Context context, AttributeSet attrs) {
34         super(context, attrs);
35     }
36
37     @Override
38     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
39         // Perform an initial `super.onMeasure`, which populates `getChildCount`.
40         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
41
42         // Initialize `maximumHeight`.
43         int maximumHeight = 0;
44
45         // Find the maximum height of each of the child views.
46         for (int i = 0; i < getChildCount(); i++) {
47             View childView = getChildAt(i);
48
49             // Measure the child view height with no constraints.
50             childView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
51
52             // Store the child's height if it is larger than `maximumHeight`.
53             if (childView.getMeasuredHeight() > maximumHeight) {
54                 maximumHeight = childView.getMeasuredHeight();
55             }
56         }
57
58         // Perform a final `super.onMeasure` to set the `maximumHeight`.
59         super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maximumHeight, MeasureSpec.EXACTLY));
60     }
61 }