<commit_before>package com.race604.flyrefresh;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Scroller;

import com.race604.flyrefresh.internal.ElasticOutInterpolator;
import com.race604.flyrefresh.internal.SimpleAnimatorListener;
import com.race604.utils.UIUtils;

/**
 * Created by Jing on 15/5/18.
 */
public class PullHeaderLayout extends ViewGroup {

    private static final String TAG = PullHeaderLayout.class.getCanonicalName();
    private static final boolean D = true;

    public static final int STATE_IDLE = 0;
    public static final int STATE_DRAGE = 1;
    public static final int STATE_FLING = 2;
    public static final int STATE_BOUNCE = 3;

    final static int ACTION_BUTTON_CENTER = UIUtils.dpToPx(40);
    final static int ACTION_ICON_SIZE = UIUtils.dpToPx(32);
    private final static int DEFAULT_EXPAND = UIUtils.dpToPx(300);
    private final static int DEFAULT_HEIGHT = UIUtils.dpToPx(240);
    private final static int DEFAULT_SHRINK = UIUtils.dpToPx(48);

    private int mHeaderId = 0;
    private int mContentId = 0;

    private int mPagingTouchSlop;

    private MotionEvent mDownEvent;
    private MotionEvent mLastMoveEvent;
    private boolean mHasSendCancelEvent = false;
    private boolean mPreventForHorizontal = false;
    private boolean mDisableWhenHorizontalMove = false;

    private Drawable mActionDrawable;
    private FloatingActionButton mActionView;
    private ImageView mFlyView;
    private View mHeaderView;
    private IPullHeader mPullHeaderView;
    protected View mContent;
    protected HeaderController mHeaderController;
    private IScrollHandler mScrollHandler;

    private ScrollChecker mScrollChecker;
    private VelocityTracker mVelocityTracker;
    private ValueAnimator mBounceAnim;
    private int mMaxVelocity;
    private int mPullState = STATE_IDLE;

    private OnPullListener mPullListener;

    public PullHeaderLayout(Context context) {
        super(context);
        init(context, null);
    }

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

    public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        int headerHeight = DEFAULT_HEIGHT;
        int headerExpandHeight = DEFAULT_EXPAND;
        int headerShrinkHeight = DEFAULT_SHRINK;

        if (attrs != null) {
            TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PullHeaderLayout);
            headerHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_height,
                    DEFAULT_HEIGHT);
            headerExpandHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_expand_height,
                    DEFAULT_EXPAND);
            headerShrinkHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_shrink_height,
                    DEFAULT_SHRINK);

            mHeaderId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_header, mHeaderId);
            mContentId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_content, mContentId);

            mActionDrawable = arr.getDrawable(R.styleable.PullHeaderLayout_phl_action);

            arr.recycle();
        }

        mHeaderController = new HeaderController(headerHeight, headerExpandHeight, headerShrinkHeight);

        final ViewConfiguration conf = ViewConfiguration.get(getContext());
        mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
        mScrollHandler = new DefalutScrollHandler();

        mScrollChecker = new ScrollChecker();
        mMaxVelocity = conf.getScaledMaximumFlingVelocity();
    }

    public void setHeaderSize(int height, int maxHeight, int minHeight) {
        mHeaderController.setSize(height, maxHeight, minHeight);
        if (isLayoutRequested()) {
            requestLayout();
        }
    }

    public void setScrollHandler(IScrollHandler handler) {
        mScrollHandler = handler;
    }

    public void setOnPullListener(OnPullListener listener) {
        mPullListener = listener;
    }

    public void setActionDrawable(Drawable actionDrawable) {
        mActionDrawable = actionDrawable;
        if (mActionDrawable != null) {
            if (mActionView == null) {
                final int bgColor = UIUtils.getThemeColorFromAttrOrRes(getContext(), R.attr.colorAccent, R.color.accent);
                final int pressedColor = UIUtils.darkerColor(bgColor, 0.8f);

                final ShapeDrawable bgDrawable = new ShapeDrawable(new OvalShape());
                bgDrawable.getPaint().setColor(bgColor);
                mActionView = new FloatingActionButton(getContext());
                mActionView.setRippleColor(pressedColor);
                mActionView.setBackgroundDrawable(bgDrawable);
                addView(mActionView, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            }

            if (mFlyView == null) {
                mFlyView = new ImageView(getContext());
                mFlyView.setScaleType(ImageView.ScaleType.FIT_XY);
                addView(mFlyView, new LayoutParams(ACTION_ICON_SIZE, ACTION_ICON_SIZE));
            }
            mFlyView.setImageDrawable(mActionDrawable);
        } else {
            if (mActionView != null) {
                removeView(mActionView);
                removeView(mFlyView);
                mActionView = null;
                mFlyView = null;
            }
        }
    }<commit_msg>fix action icon not visiable on lollipop+<commit_after>package com.race604.flyrefresh;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Scroller;

import com.race604.flyrefresh.internal.ElasticOutInterpolator;
import com.race604.flyrefresh.internal.SimpleAnimatorListener;
import com.race604.utils.UIUtils;

/**
 * Created by Jing on 15/5/18.
 */
public class PullHeaderLayout extends ViewGroup {

    private static final String TAG = PullHeaderLayout.class.getCanonicalName();
    private static final boolean D = true;

    public static final int STATE_IDLE = 0;
    public static final int STATE_DRAGE = 1;
    public static final int STATE_FLING = 2;
    public static final int STATE_BOUNCE = 3;

    final static int ACTION_BUTTON_CENTER = UIUtils.dpToPx(40);
    final static int ACTION_ICON_SIZE = UIUtils.dpToPx(32);
    private final static int DEFAULT_EXPAND = UIUtils.dpToPx(300);
    private final static int DEFAULT_HEIGHT = UIUtils.dpToPx(240);
    private final static int DEFAULT_SHRINK = UIUtils.dpToPx(48);

    private int mHeaderId = 0;
    private int mContentId = 0;

    private int mPagingTouchSlop;

    private MotionEvent mDownEvent;
    private MotionEvent mLastMoveEvent;
    private boolean mHasSendCancelEvent = false;
    private boolean mPreventForHorizontal = false;
    private boolean mDisableWhenHorizontalMove = false;

    private Drawable mActionDrawable;
    private FloatingActionButton mActionView;
    private ImageView mFlyView;
    private View mHeaderView;
    private IPullHeader mPullHeaderView;
    protected View mContent;
    protected HeaderController mHeaderController;
    private IScrollHandler mScrollHandler;

    private ScrollChecker mScrollChecker;
    private VelocityTracker mVelocityTracker;
    private ValueAnimator mBounceAnim;
    private int mMaxVelocity;
    private int mPullState = STATE_IDLE;

    private OnPullListener mPullListener;

    public PullHeaderLayout(Context context) {
        super(context);
        init(context, null);
    }

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

    public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public PullHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        int headerHeight = DEFAULT_HEIGHT;
        int headerExpandHeight = DEFAULT_EXPAND;
        int headerShrinkHeight = DEFAULT_SHRINK;

        if (attrs != null) {
            TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PullHeaderLayout);
            headerHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_height,
                    DEFAULT_HEIGHT);
            headerExpandHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_expand_height,
                    DEFAULT_EXPAND);
            headerShrinkHeight = arr.getDimensionPixelOffset(R.styleable.PullHeaderLayout_phl_header_shrink_height,
                    DEFAULT_SHRINK);

            mHeaderId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_header, mHeaderId);
            mContentId = arr.getResourceId(R.styleable.PullHeaderLayout_phl_content, mContentId);

            mActionDrawable = arr.getDrawable(R.styleable.PullHeaderLayout_phl_action);

            arr.recycle();
        }

        mHeaderController = new HeaderController(headerHeight, headerExpandHeight, headerShrinkHeight);

        final ViewConfiguration conf = ViewConfiguration.get(getContext());
        mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
        mScrollHandler = new DefalutScrollHandler();

        mScrollChecker = new ScrollChecker();
        mMaxVelocity = conf.getScaledMaximumFlingVelocity();
    }

    public void setHeaderSize(int height, int maxHeight, int minHeight) {
        mHeaderController.setSize(height, maxHeight, minHeight);
        if (isLayoutRequested()) {
            requestLayout();
        }
    }

    public void setScrollHandler(IScrollHandler handler) {
        mScrollHandler = handler;
    }

    public void setOnPullListener(OnPullListener listener) {
        mPullListener = listener;
    }

    public void setActionDrawable(Drawable actionDrawable) {
        mActionDrawable = actionDrawable;
        if (mActionDrawable != null) {
            if (mActionView == null) {
                final int bgColor = UIUtils.getThemeColorFromAttrOrRes(getContext(), R.attr.colorAccent, R.color.accent);
                final int pressedColor = UIUtils.darkerColor(bgColor, 0.8f);

                final ShapeDrawable bgDrawable = new ShapeDrawable(new OvalShape());
                bgDrawable.getPaint().setColor(bgColor);
                mActionView = new FloatingActionButton(getContext());
                mActionView.setRippleColor(pressedColor);
                mActionView.setBackgroundDrawable(bgDrawable);
                addView(mActionView, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            }

            if (mFlyView == null) {
                mFlyView = new ImageView(getContext());
                mFlyView.setScaleType(ImageView.ScaleType.FIT_XY);
                addView(mFlyView, new LayoutParams(ACTION_ICON_SIZE, ACTION_ICON_SIZE));
                mFlyView.bringToFront();
                float elevation = ViewCompat.getElevation(mActionView);
                ViewCompat.setElevation(mFlyView, elevation + 1);
            }
            mFlyView.setImageDrawable(mActionDrawable);

        } else {
            if (mActionView != null) {
                removeView(mActionView);
                removeView(mFlyView);
                mActionView = null;
                mFlyView = null;
            }
        }
    }
{'fraction_non_alphanumeric': 0.07490045826759822, 'fraction_numerical': 0.005859815190443994, 'mean_word_length': 3.2233502538071064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '138686', 'n_tokens_mistral': 3803, 'n_tokens_neox': 3631, 'n_words': 779}