Android Open Source - DecorateCalendarView Wrap Content Height View Pager






From Project

Back to project page DecorateCalendarView.

License

The source code is released under:

Apache License

If you think the Android project DecorateCalendarView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.zaim.decoratecalendarview.view;
//from  w w  w. j  a va2s  . c  om
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;

public class WrapContentHeightViewPager extends ViewPager {

    public WrapContentHeightViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public WrapContentHeightViewPager(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        View view = getChildAt(0);
        if (view != null) {
            view.measure(widthMeasureSpec, heightMeasureSpec);
        }

        setMeasuredDimension(getMeasuredWidth(), measureHeight(heightMeasureSpec, view));
    }

    private int measureHeight(int measureSpec, View view) {
        int result = 0;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);

        if (specMode == MeasureSpec.EXACTLY) {
            result = specSize;
        }
        else {
            if (view != null) {
                result = view.getMeasuredHeight();
            }
            if (specMode == MeasureSpec.AT_MOST) {
                result = Math.min(result, specSize);
            }
        }
        return result;
    }
}




Java Source Code List

net.zaim.decoratecalendarview.BaseGridView.java
net.zaim.decoratecalendarview.DecorateCalendarFragment.java
net.zaim.decoratecalendarview.DecorateCalendarPagerAdapter.java
net.zaim.decoratecalendarview.DecorateCalendarView.java
net.zaim.decoratecalendarview.sample.MainActivity.java
net.zaim.decoratecalendarview.view.WrapContentHeightViewPager.java