X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdefinitions%2FWrapVerticalContentViewPager.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdefinitions%2FWrapVerticalContentViewPager.java;h=8b1d9782e4930759fcebcbb88594b432371bcb13;hb=5fb34c1fa70b7c42a0fc3c0b5af8e856d3af2695;hp=0000000000000000000000000000000000000000;hpb=500012f6332dee70b77f7a2c3f69a78cdac435af;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/definitions/WrapVerticalContentViewPager.java b/app/src/main/java/com/stoutner/privacybrowser/definitions/WrapVerticalContentViewPager.java new file mode 100644 index 00000000..8b1d9782 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/definitions/WrapVerticalContentViewPager.java @@ -0,0 +1,61 @@ +package com.stoutner.privacybrowser.definitions; + +/* + * Copyright © 2017 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser. If not, see . + */ + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.View; + +public class WrapVerticalContentViewPager extends ViewPager { + // Setup the default constructors. + public WrapVerticalContentViewPager(Context context) { + super(context); + } + + public WrapVerticalContentViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // Perform an initial `super.onMeasure`, which populates `getChildCount`. + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + // Initialize `maximumHeight`. + int maximumHeight = 0; + + // Find the maximum height of each of the child views. + for (int i = 0; i < getChildCount(); i++) { + View childView = getChildAt(i); + + // Measure the child view height with no constraints. + childView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + + // Store the child's height if it is larger than `maximumHeight`. + if (childView.getMeasuredHeight() > maximumHeight) { + maximumHeight = childView.getMeasuredHeight(); + } + } + + // Perform a final `super.onMeasure` to set the `maximumHeight`. + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maximumHeight, MeasureSpec.EXACTLY)); + } +} \ No newline at end of file