package cn.bvin.android.apps.gesturerefresh;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import cn.bvin.android.lib.widget.refresh.GestureRefreshLayout;

public class MainActivity extends AppCompatActivity implements GestureRefreshLayout.OnRefreshListener {

    private GestureRefreshLayout mGestureRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mGestureRefreshLayout = (GestureRefreshLayout) findViewById(R.id.gesture_refresh_layout);
        final TextView refreshText = (TextView) findViewById(R.id.refresh_text);
        mGestureRefreshLayout.setTranslateContent(true);//是否移动ContentView
        mGestureRefreshLayout.setOnGestureChangeListener(new GestureRefreshLayout.OnGestureStateChangeListener() {
            @Override
            public void onStartDrag(float startY) {
                refreshText.setText("下拉刷新");
            }

            @Override
            public void onDragging(float draggedDistance, float releaseDistance) {
                refreshText.setText("下拉刷新...");
            }

            @Override
            public void onFinishDrag(float endY) {
                refreshText.setText("释放更新");
            }
        });
        mGestureRefreshLayout.setOnRefreshListener(this);
    }

    @Override
    public void onRefresh() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mGestureRefreshLayout.setRefreshing(false);
                    }
                });
            }
        }).start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.refresh) {
            mGestureRefreshLayout.setRefreshing(true);
            onRefresh();
        }
        return super.onOptionsItemSelected(item);
    }
}

@@ -1220,39 +1220,229 @@
     
-refreshText.setText(%22%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0...%22);
+if (draggedDistance%3EreleaseDistance)%7B%0A                    refreshText.setText(%22%E9%87%8A%E6%94%BE%E6%9B%B4%E6%96%B0%22);%0A                %7Delse %7B%0A                    refreshText.setText(%22%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0...%22);%0A                %7D%0A                // %E8%B6%85%E8%BF%87%E5%AE%9A%E4%B9%89%E7%9A%84%E5%90%8C%E6%AD%A5%E8%B7%9D%E7%A6%BB%E5%B0%B1%E6%84%8F%E5%91%B3%E7%9D%80%E5%8F%AF%E4%BB%A5%E9%87%8A%E6%94%BE%E5%88%B7%E6%96%B0%E4%BA%86%0A
 %0A   
@@ -1555,36 +1555,39 @@
 shText.setText(%22
-%E9%87%8A%E6%94%BE%E6%9B%B4%E6%96%B0
+%E6%AD%A3%E5%9C%A8%E6%9B%B4%E6%96%B0...
 %22);%0A            

update correct refresh text