Android Open Source - Easy-PullToRefresh-Android Pull To Refresh Header View






From Project

Back to project page Easy-PullToRefresh-Android.

License

The source code is released under:

Copyright (c) 2013 neevek <i@neevek.net> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in ...

If you think the Android project Easy-PullToRefresh-Android 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.neevek.android.demo.ptr;
// w  w w .  j a  v a 2s  .c o m
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.neevek.android.lib.ptr.OverScrollListView;

/**
 * @author neevek <i@neevek.net>
 *
 * The default implementation of a pull-to-load-more header view for OverScrollListView.
 * this can be taken as an implementation reference.
 */
public class PullToRefreshHeaderView extends LinearLayout implements OverScrollListView.PullToRefreshCallback {
    private final static int ROTATE_ANIMATION_DURATION = 300;

    private View mArrowView;
    private TextView mTvRefresh;
    private ProgressBar mProgressBar;

    private Animation mAnimRotateUp;
    private Animation mAnimRotateDown;

    private String mPullText = "Pull to refresh";
    private String mReleaseText = "Release to refresh";
    private String mRefreshText = "Refreshing...";

    public PullToRefreshHeaderView(Context context) {
        super(context);
        init();
    }

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

    public void init() {
        mAnimRotateUp = new RotateAnimation(0, -180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        mAnimRotateUp.setDuration(ROTATE_ANIMATION_DURATION);
        mAnimRotateUp.setFillAfter(true);
        mAnimRotateDown = new RotateAnimation(-180f, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        mAnimRotateDown.setDuration(ROTATE_ANIMATION_DURATION);
        mAnimRotateDown.setFillAfter(true);
    }

    @Override
    protected void onFinishInflate() {
        mArrowView = findViewById(R.id.iv_down_arrow);
        mTvRefresh = (TextView)findViewById(R.id.tv_refresh);
        mProgressBar = (ProgressBar)findViewById(R.id.pb_refreshing);
    }

    @Override
    public void onStartPulling() {
        mProgressBar.setVisibility(GONE);
        mArrowView.setVisibility(VISIBLE);
        mTvRefresh.setVisibility(VISIBLE);
        mTvRefresh.setText(mPullText);
    }

    /**
     * @param scrollY [screenHeight, 0]
     */
    @Override
    public void onPull(int scrollY) {
    }

    @Override
    public void onReachAboveHeaderViewHeight() {
        mProgressBar.setVisibility(GONE);
        mTvRefresh.setText(mReleaseText);
        mArrowView.startAnimation(mAnimRotateUp);
    }

    @Override
    public void onReachBelowHeaderViewHeight() {
        mProgressBar.setVisibility(GONE);
        mTvRefresh.setText(mPullText);
        mArrowView.startAnimation(mAnimRotateDown);
    }

    @Override
    public void onStartRefreshing() {
        mArrowView.clearAnimation();
        mArrowView.setVisibility(GONE);
        mProgressBar.setVisibility(VISIBLE);
        mTvRefresh.setText(mRefreshText);
    }

    @Override
    public void onEndRefreshing() {
        mProgressBar.setVisibility(GONE);
        mTvRefresh.setVisibility(GONE);
    }

    public void setPullText(String pullText) {
        mPullText = pullText;
    }

    public void setReleaseText(String releaseText) {
        mReleaseText = releaseText;
    }

    public void setRefreshText(String refreshText) {
        mRefreshText = refreshText;
    }
}




Java Source Code List

net.neevek.android.demo.ptr.MainActivity.java
net.neevek.android.demo.ptr.PullToLoadMoreFooterView.java
net.neevek.android.demo.ptr.PullToRefreshHeaderView.java
net.neevek.android.lib.ptr.OverScrollListView.java