package com.gh.gamecenter.common.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;

import com.gh.gamecenter.common.view.autoscrollviewpager.AutoScrollViewPager;

import com.gh.gamecenter.common.R;


/**
 * @author CsHeng
 * @Date 17/06/2017
 * @Time 12:24 PM
 */

public class ScaleAutoScrollViewPager extends AutoScrollViewPager {

    private boolean mMeasureByHeight = false; // default width
    private float mScale = 1f;// default square

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

    public ScaleAutoScrollViewPager(Context context, AttributeSet set) {
        super(context, set);
        TypedArray a = context.obtainStyledAttributes(set, R.styleable.ScaleView);
        int enumV = a.getInt(R.styleable.ScaleView_measureBy, 0);
        mScale = a.getFloat(R.styleable.ScaleView_fractionValue, mScale);
        if (enumV != 0) {
            mMeasureByHeight = true;
        }
        a.recycle();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = View.MeasureSpec.getSize(widthMeasureSpec);
        int height = View.MeasureSpec.getSize(heightMeasureSpec);
        if (mMeasureByHeight) {
            setMeasuredDimension((int) (height * mScale), height);
        } else {
            setMeasuredDimension(width, (int) (width * mScale));
        }

    }
}
