<commit_before>package fast.glibrary.weight;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import fast.glibrary.R;
import fast.glibrary.tools.L;
import fast.glibrary.tools.ScreenTools;
import fast.glibrary.views.refresh.utils.ScrollUtils;
import fast.glibrary.weight.uiKit.ScrollState;

/**
 * Created by lcodecore on 16/3/2.
 */
public class GRefresher extends RelativeLayout {
    //正在展开，正在回弹都不可以刷新
    Handler mHandler;
    FrameLayout mRefreshHeader;
    View mChildView;
    ScrollState mState = ScrollState.Normal;
    float mDownX;
    float mDownY;
    //往上回弹任务
    UpwardSlide mUpwardSlideTask;
    //刷新头的高度
    int mRefreshHeaderHeight = ScreenTools.px2dp(120);
    //回弹速度 1秒内回弹
    int mSpeed = 1;
    
   /* //波浪的高度,最大扩展高度
    protected float mWaveHeight;

    //头部的高度
    protected float mHeadHeight;

    //允许的越界回弹的高度
    protected float mOverScrollHeight;

    //子控件
    private View mChildView;

    //头部layout
    protected FrameLayout mHeadLayout;

    //整个头部
    private FrameLayout mExtraHeadLayout;
    //附加顶部高度
    private int mExHeadHeight = 0;

    private IHeaderView mHeadView;
    private IBottomView mBottomView;

    //底部高度
    private float mBottomHeight;

    //底部layout
    private FrameLayout mBottomLayout;


    //是否刷新视图可见
    protected boolean isRefreshVisible = false;

    //是否加载更多视图可见
    protected boolean isLoadingVisible = false;

    //是否需要加载更多,默认需要
    protected boolean enableLoadmore = true;
    //是否需要下拉刷新,默认需要
    protected boolean enableRefresh = true;

    //是否在越界回弹的时候显示下拉图标
    protected boolean isOverScrollTopShow = true;
    //是否在越界回弹的时候显示上拉图标
    protected boolean isOverScrollBottomShow = true;

    //是否隐藏刷新控件,开启越界回弹模式(开启之后刷新控件将隐藏)
    protected boolean isPureScrollModeOn = false;

    //是否自动加载更多
    protected boolean autoLoadMore = false;

    //是否开启悬浮刷新模式
    protected boolean floatRefresh = false;

    //是否允许进入越界回弹模式
    protected boolean enableOverScroll = true;

    private CoProcessor cp;*/

    public GRefresher(Context context) {
        this(context, null, 0);
    }

    public GRefresher(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GRefresher(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GRefresher, defStyleAttr, 0);
        /*mWaveHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_wave_height, (int) DensityUtil.dp2px(context, 120));
        mHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_head_height, (int) DensityUtil.dp2px(context, 80));
        mBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_bottom_height, (int) DensityUtil.dp2px(context, 60));
        mOverScrollHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_overscroll_height, (int) mHeadHeight);
        enableLoadmore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_loadmore, true);
        isPureScrollModeOn = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_pureScrollMode_on, false);
        isOverScrollTopShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_top_show, true);
        isOverScrollBottomShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_bottom_show, true);
        enableOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_overscroll, true);*/
        mHandler = new Handler(Looper.getMainLooper());
        a.recycle();
    }

    /**
     * View和Window绑定时就会调用这个函数
     */
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mRefreshHeader == null) {
            mRefreshHeader = new FrameLayout(getContext());
            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 80);
            layoutParams.addRule(ALIGN_PARENT_TOP);
            layoutParams.addRule(CENTER_VERTICAL);
            mRefreshHeader.setLayoutParams(layoutParams);
            this.addView(mRefreshHeader);
            mChildView = getChildAt(0);
        }
    }

    /**
     * 返回true,事件不再下发，交由本层处理
     *
     * @param ev
     * @return
     */
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mDownX = ev.getX();
                mDownY = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                float dx = ev.getX() - mDownX;
                float dy = ev.getY() - mDownY;
                //如果dy大于dx，说明在y轴上移动速度比在x轴上快，可认为用户上拉或下拉
                if (Math.abs(dx) <= Math.abs(dy)) {//滑动允许最大角度为45度
                    //如果mChildView不能向下拉了，说明子控件滑到到顶了,(并且同时可以上拉，为了与列表不足一屏幕时的情况区分)
                    if (!ScrollUtils.canChildScrollUp(mChildView) && ScrollUtils.canChildScrollDown(mChildView)) {
                        //当前正在刷新中
                        if (mState == ScrollState.Refreshing) {
                            //大于零往上滑
                            if (dy < 0) {
                                mState = ScrollState.UpwardResilience;
                            }
                            return true;
                        }<commit_msg>。。。。。<commit_after>package fast.glibrary.weight;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import fast.glibrary.R;
import fast.glibrary.tools.L;
import fast.glibrary.tools.ScreenTools;
import fast.glibrary.views.refresh.utils.ScrollUtils;
import fast.glibrary.weight.uiKit.ScrollState;

/**
 * Created by lcodecore on 16/3/2.
 */
public class GRefresher extends RelativeLayout {
    //正在展开，正在回弹都不可以刷新
    Handler mHandler;
    FrameLayout mRefreshHeader;
    View mChildView;
    ScrollState mState = ScrollState.Normal;
    float mDownX;
    float mDownY;
    //往上回弹任务
    UpwardSlide mUpwardSlideTask;
    //刷新头的高度
    int mRefreshHeaderHeight = ScreenTools.px2dp(120);
    //回弹速度 1秒内回弹
    int mSpeed = 1;
    
   /* //波浪的高度,最大扩展高度
    protected float mWaveHeight;

    //头部的高度
    protected float mHeadHeight;

    //允许的越界回弹的高度
    protected float mOverScrollHeight;

    //子控件
    private View mChildView;

    //头部layout
    protected FrameLayout mHeadLayout;

    //整个头部
    private FrameLayout mExtraHeadLayout;
    //附加顶部高度
    private int mExHeadHeight = 0;

    private IHeaderView mHeadView;
    private IBottomView mBottomView;

    //底部高度
    private float mBottomHeight;

    //底部layout
    private FrameLayout mBottomLayout;


    //是否刷新视图可见
    protected boolean isRefreshVisible = false;

    //是否加载更多视图可见
    protected boolean isLoadingVisible = false;

    //是否需要加载更多,默认需要
    protected boolean enableLoadmore = true;
    //是否需要下拉刷新,默认需要
    protected boolean enableRefresh = true;

    //是否在越界回弹的时候显示下拉图标
    protected boolean isOverScrollTopShow = true;
    //是否在越界回弹的时候显示上拉图标
    protected boolean isOverScrollBottomShow = true;

    //是否隐藏刷新控件,开启越界回弹模式(开启之后刷新控件将隐藏)
    protected boolean isPureScrollModeOn = false;

    //是否自动加载更多
    protected boolean autoLoadMore = false;

    //是否开启悬浮刷新模式
    protected boolean floatRefresh = false;

    //是否允许进入越界回弹模式
    protected boolean enableOverScroll = true;

    private CoProcessor cp;*/

    public GRefresher(Context context) {
        this(context, null, 0);
    }

    public GRefresher(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GRefresher(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GRefresher, defStyleAttr, 0);
        /*mWaveHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_wave_height, (int) DensityUtil.dp2px(context, 120));
        mHeadHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_head_height, (int) DensityUtil.dp2px(context, 80));
        mBottomHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_bottom_height, (int) DensityUtil.dp2px(context, 60));
        mOverScrollHeight = a.getDimensionPixelSize(R.styleable.TwinklingRefreshLayout_tr_overscroll_height, (int) mHeadHeight);
        enableLoadmore = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_loadmore, true);
        isPureScrollModeOn = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_pureScrollMode_on, false);
        isOverScrollTopShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_top_show, true);
        isOverScrollBottomShow = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_overscroll_bottom_show, true);
        enableOverScroll = a.getBoolean(R.styleable.TwinklingRefreshLayout_tr_enable_overscroll, true);*/
        mHandler = new Handler(Looper.getMainLooper());
        a.recycle();
    }

    /**
     * View和Window绑定时就会调用这个函数
     */
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mRefreshHeader == null) {
            mRefreshHeader = new FrameLayout(getContext());
            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 80);
            layoutParams.addRule(ALIGN_PARENT_TOP);
            layoutParams.addRule(CENTER_VERTICAL);
            mRefreshHeader.setLayoutParams(layoutParams);
            this.addView(mRefreshHeader);
            mChildView = getChildAt(0);
        }
    }

    /**
     * 返回true,事件不再下发，交由本层处理
     *
     * @param ev
     * @return
     */
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mDownX = ev.getX();
                mDownY = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                float dx = ev.getX() - mDownX;
                float dy = ev.getY() - mDownY;
                //如果abs（dy）大于abs（dx），说明在y轴上移动速度比在x轴上快，可认为用户上拉或下拉
                if (Math.abs(dx) <= Math.abs(dy)) {//滑动允许最大角度为45度
                    //如果mChildView不能向下拉了，说明子控件滑到到顶了,(并且同时可以上拉，为了与列表不足一屏幕时的情况区分)
                    if (!ScrollUtils.canChildScrollUp(mChildView) && ScrollUtils.canChildScrollDown(mChildView)) {
                        //当前正在刷新中
                        if (mState == ScrollState.Refreshing) {
                            //大于零往上滑
                            if (dy < 0) {
                                mState = ScrollState.UpwardResilience;
                            }
                            return true;
                        }
{'fraction_non_alphanumeric': 0.08766702780787287, 'fraction_numerical': 0.005417118093174431, 'mean_word_length': 2.681289464938518, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5710330', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3869, 'n_words': 608}