-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
li-xiaojun
committed
May 8, 2017
1 parent
aeedede
commit 14c0676
Showing
16 changed files
with
429 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
sample/src/main/java/com/xrefreshlayout/sample/CustomRefreshAnimActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.xrefreshlayout.sample; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.Toast; | ||
|
||
import com.lxj.xrefreshlayout.XRefreshLayout; | ||
import com.lxj.xrefreshlayout.loadinglayout.DefaultLoadingLayout; | ||
import com.lxj.xrefreshlayout.loadinglayout.CircleLoadingLayout; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
/** | ||
* Created by dance on 2017/5/8. | ||
*/ | ||
|
||
public class CustomRefreshAnimActivity extends AppCompatActivity { | ||
@BindView(R.id.xrefreshLayout) | ||
XRefreshLayout xrefreshLayout; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_custom_refresh_anim); | ||
ButterKnife.bind(this); | ||
|
||
|
||
|
||
xrefreshLayout.setOnRefreshListener(new XRefreshLayout.OnRefreshListener() { | ||
@Override | ||
public void onRefresh() { | ||
doNothing(); | ||
} | ||
|
||
@Override | ||
public void onLoadMore() { | ||
doNothing(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private void doNothing() { | ||
new Handler().postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
Toast.makeText(CustomRefreshAnimActivity.this, "Refresh Successfully!", Toast.LENGTH_SHORT).show(); | ||
xrefreshLayout.completeRefresh(); | ||
} | ||
},2500); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()){ | ||
case R.id.dafulat: | ||
xrefreshLayout.setLoadingLayout(new DefaultLoadingLayout()); | ||
break; | ||
case R.id.circle: | ||
CircleLoadingLayout circleLoadingLayout = new CircleLoadingLayout(); | ||
// circleLoadingLayout.setCircleColor(Color.GREEN); | ||
xrefreshLayout.setLoadingLayout(circleLoadingLayout); | ||
break; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.custom_refresh,menu); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sample/src/main/res/layout/activity_custom_refresh_anim.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.lxj.xrefreshlayout.XRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:id="@+id/xrefreshLayout" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.v4.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:fontFamily="monospace" | ||
android:id="@+id/textView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="30dp" | ||
android:layout_gravity="center" | ||
android:text="Refresh Animation:\n | ||
1. DefaultLoadingLayout\n | ||
2. CircleLoadingLayout\n | ||
3. Custom your anim!" | ||
android:textSize="22sp" /> | ||
|
||
|
||
</android.support.v4.widget.NestedScrollView> | ||
|
||
|
||
</com.lxj.xrefreshlayout.XRefreshLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
app:showAsAction="never" | ||
android:title="DefaultLoadingLayout" | ||
android:id="@+id/dafulat" | ||
/> | ||
<item | ||
app:showAsAction="never" | ||
android:title="CircleLoadingLayout" | ||
android:id="@+id/circle" | ||
/> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
app:showAsAction="never" | ||
android:title="LinearLayoutManager" | ||
android:id="@+id/linear_manager" | ||
/> | ||
<item | ||
app:showAsAction="never" | ||
android:title="GridLayoutManager" | ||
android:id="@+id/grid_manager" | ||
/> | ||
<item | ||
app:showAsAction="never" | ||
android:title="StaggeredLayoutManager" | ||
android:id="@+id/staggered_manager" | ||
/> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
xrefreshlayout/src/main/java/com/lxj/xrefreshlayout/loadinglayout/CircleLoadingLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.lxj.xrefreshlayout.loadinglayout; | ||
|
||
import android.animation.FloatEvaluator; | ||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.v4.view.ViewCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.animation.DecelerateInterpolator; | ||
|
||
import com.lxj.xrefreshlayout.R; | ||
|
||
/** | ||
* Created by dance on 2017/5/8. | ||
*/ | ||
|
||
public class CircleLoadingLayout implements ILoadingLayout { | ||
|
||
private CircleLoadingView headerProgressView; | ||
private CircleLoadingView footerProgressView; | ||
|
||
private FloatEvaluator floatEval = new FloatEvaluator(); | ||
private View header; | ||
private float startVal = 0f; | ||
|
||
private final int MSG_HEADER = 1; | ||
private final int MSG_FOOTER = 2; | ||
Handler handler = new Handler() { | ||
@Override | ||
public void handleMessage(Message msg) { | ||
super.handleMessage(msg); | ||
switch (msg.what){ | ||
case MSG_HEADER: | ||
rotateView(headerProgressView); | ||
break; | ||
case MSG_FOOTER: | ||
rotateView(footerProgressView); | ||
break; | ||
} | ||
|
||
handler.sendEmptyMessageDelayed(msg.what, 1200); | ||
} | ||
}; | ||
|
||
private int circleColor = Color.BLUE; | ||
|
||
/** | ||
* set the circle color! | ||
* @param color | ||
*/ | ||
public void setCircleColor(int color){ | ||
this.circleColor = color; | ||
} | ||
|
||
@Override | ||
public View createLoadingHeader(Context context, ViewGroup parent) { | ||
header = (View) LayoutInflater.from(context).inflate(R.layout.xrl_progress_header, parent, false); | ||
headerProgressView = (CircleLoadingView) header.findViewById(R.id.progressView); | ||
headerProgressView.setProgressColor(circleColor); | ||
return header; | ||
} | ||
|
||
@Override | ||
public View createLoadingFooter(Context context, ViewGroup parent) { | ||
View footer = (View) LayoutInflater.from(context).inflate(R.layout.xrl_progress_footer, parent, false); | ||
footerProgressView = (CircleLoadingView) footer.findViewById(R.id.progressView); | ||
footerProgressView.setProgressColor(circleColor); | ||
return footer; | ||
} | ||
|
||
@Override | ||
public void initAndResetHeader() { | ||
handler.removeCallbacksAndMessages(null); | ||
headerProgressView.setProgress(0); | ||
headerProgressView.setRotation(0); | ||
if(startVal==0f){ | ||
header.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
//计算当headerProgressView开始完全可见的百分比 | ||
startVal = headerProgressView.getHeight()*1f/header.getHeight(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@Override | ||
public void initAndResetFooter() { | ||
handler.removeCallbacksAndMessages(null); | ||
footerProgressView.setStart(-270); | ||
footerProgressView.setProgress(0); | ||
footerProgressView.setRotation(0); | ||
|
||
} | ||
|
||
@Override | ||
public void onPullHeader(float percent) { | ||
if(percent>=startVal){ | ||
float p = (percent-startVal)/(1-startVal); | ||
headerProgressView.setProgress(p); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPullFooter(float percent) { | ||
if(percent>=startVal){ | ||
float p = (percent-startVal)/(1-startVal); | ||
footerProgressView.setProgress(p); | ||
} | ||
} | ||
|
||
@Override | ||
public void onHeaderRefreshing() { | ||
handler.sendEmptyMessage(MSG_HEADER); | ||
} | ||
|
||
@Override | ||
public void onFooterRefreshing() { | ||
handler.sendEmptyMessage(MSG_FOOTER); | ||
} | ||
|
||
private void rotateView(View view){ | ||
ViewCompat.animate(view).rotationXBy(360).setDuration(1000) | ||
.setInterpolator(new DecelerateInterpolator()) | ||
.start(); | ||
} | ||
|
||
} |
Oops, something went wrong.