-
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
Showing
75 changed files
with
4,505 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
recyclerview_helper/.idea/inspectionProfiles/Project_Default.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
recyclerview_helper/.idea/inspectionProfiles/profiles_settings.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
159 changes: 159 additions & 0 deletions
159
recyclerview_helper/app/src/main/java/com/lvr/recyclerview_helper/sample/AllActivity.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,159 @@ | ||
package com.lvr.recyclerview_helper.sample; | ||
|
||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.os.SystemClock; | ||
import android.support.v7.app.AlertDialog; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
import com.lvr.library.adapter.CommonAdapter; | ||
import com.lvr.library.anims.adapters.ScaleInAnimationAdapter; | ||
import com.lvr.library.anims.animators.LandingAnimator; | ||
import com.lvr.library.holder.BaseViewHolder; | ||
import com.lvr.library.recyclerview.HRecyclerView; | ||
import com.lvr.library.recyclerview.OnLoadMoreListener; | ||
import com.lvr.library.recyclerview.OnRefreshListener; | ||
import com.lvr.recyclerview_helper.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* Created by lvr on 2017/5/25. | ||
*/ | ||
public class AllActivity extends AppCompatActivity implements OnLoadMoreListener, OnRefreshListener { | ||
private String[] mStrings = { | ||
"Apple", "Ball", "Camera", "Day", "Egg", "Foo", "Google", "Hello", "Iron", "Japan", "Coke", | ||
"Dog", "Cat", "Yahoo", "Sony", "Canon", "Fujitsu", "USA", "Nexus", "LINE", "Haskell", "C++", | ||
"Go" | ||
}; | ||
private int[] mImageRes = {R.drawable.image1, R.drawable.image2}; | ||
private HRecyclerView mRecyclerView; | ||
private LoadMoreFooterView mLoadMoreFooterView; | ||
private Handler mHandler = new Handler(){ | ||
@Override | ||
public void handleMessage(Message msg) { | ||
super.handleMessage(msg); | ||
if(msg.what==0){ | ||
//刷新完毕 | ||
mRecyclerView.setRefreshing(false); | ||
}else if(count==4){ | ||
//没有更多数据 | ||
mLoadMoreFooterView.setStatus(LoadMoreFooterView.Status.THE_END); | ||
}else{ | ||
//加载更多完毕 | ||
mDatas.add("Alibaba"); | ||
mDatas.add("Java"); | ||
mDatas.add("Kotlin"); | ||
mDatas.add("Swift"); | ||
mAdapter.notifyItemInserted(mDatas.size()+1); | ||
mLoadMoreFooterView.setStatus(LoadMoreFooterView.Status.GONE); | ||
} | ||
} | ||
}; | ||
private List<String> mDatas; | ||
private CommonAdapter<String> mAdapter; | ||
private int count =1; | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_all); | ||
mRecyclerView = (HRecyclerView) findViewById(R.id.list); | ||
mDatas = new ArrayList<>(); | ||
for(int i=0;i<mStrings.length;i++){ | ||
mDatas.add(mStrings[0]); | ||
} | ||
mAdapter = new CommonAdapter<String>(this, R.layout.item_common, mDatas) { | ||
@Override | ||
public void convert(BaseViewHolder holder, int position) { | ||
holder.setText(R.id.tv_content,mDatas.get(position)); | ||
int number = new Random().nextInt(2); | ||
holder.setImageResource(R.id.iv_content,mImageRes[number]); | ||
} | ||
}; | ||
|
||
mRecyclerView.setItemAnimator(new LandingAnimator()); | ||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(mAdapter); | ||
scaleAdapter.setFirstOnly(false); | ||
scaleAdapter.setDuration(500); | ||
mRecyclerView.setAdapter(scaleAdapter); | ||
mAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) { | ||
System.out.println("点击"); | ||
showMyDialog("响应点击事件"); | ||
} | ||
}); | ||
mAdapter.setOnItemLongClickListener(new CommonAdapter.OnItemLongClickListener() { | ||
@Override | ||
public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) { | ||
showMyDialog("响应长按事件"); | ||
return false; | ||
} | ||
}); | ||
mRecyclerView.setOnRefreshListener(this); | ||
mRecyclerView.setOnLoadMoreListener(this); | ||
mLoadMoreFooterView = (LoadMoreFooterView) mRecyclerView.getLoadMoreFooterView(); | ||
mRecyclerView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
mRecyclerView.setRefreshing(true); | ||
} | ||
}); | ||
} | ||
|
||
public void showMyDialog(String message){ | ||
AlertDialog.Builder builder = new AlertDialog.Builder(AllActivity.this); | ||
builder.setTitle("事件类型"); | ||
builder.setMessage(message); | ||
AlertDialog dialog = builder.create(); | ||
builder.setNegativeButton("知道", new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
dialog.dismiss(); | ||
} | ||
}); | ||
dialog.show(); | ||
} | ||
|
||
@Override | ||
public void onLoadMore() { | ||
if(mLoadMoreFooterView.canLoadMore()){ | ||
mLoadMoreFooterView.setStatus(LoadMoreFooterView.Status.LOADING); | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
//假装加载耗时数据 | ||
SystemClock.sleep(1000); | ||
Message message = Message.obtain(); | ||
message.what =count; | ||
count++; | ||
mHandler.sendMessage(message); | ||
} | ||
}).start(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onRefresh() { | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
//假装加载耗时数据 | ||
SystemClock.sleep(1000); | ||
Message msg = Message.obtain(); | ||
msg.what=0; | ||
mHandler.sendMessage(msg); | ||
} | ||
}).start(); | ||
|
||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...helper/app/src/main/java/com/lvr/recyclerview_helper/sample/ClassicRefreshHeaderView.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,121 @@ | ||
package com.lvr.recyclerview_helper.sample; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
import android.widget.ImageView; | ||
import android.widget.ProgressBar; | ||
import android.widget.RelativeLayout; | ||
import android.widget.TextView; | ||
|
||
import com.lvr.library.recyclerview.RefreshTrigger; | ||
import com.lvr.recyclerview_helper.R; | ||
|
||
|
||
public class ClassicRefreshHeaderView extends RelativeLayout implements RefreshTrigger { | ||
private ImageView ivArrow; | ||
|
||
private ImageView ivSuccess; | ||
|
||
private TextView tvRefresh; | ||
|
||
private ProgressBar progressBar; | ||
|
||
private Animation rotateUp; | ||
|
||
private Animation rotateDown; | ||
|
||
private boolean rotated = false; | ||
|
||
private int mHeight; | ||
|
||
public ClassicRefreshHeaderView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public ClassicRefreshHeaderView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public ClassicRefreshHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
|
||
inflate(context, R.layout.layout_hrecyclerview_classic_refresh_header_view, this); | ||
|
||
tvRefresh = (TextView) findViewById(R.id.tvRefresh); | ||
|
||
ivArrow = (ImageView) findViewById(R.id.ivArrow); | ||
|
||
ivSuccess = (ImageView) findViewById(R.id.ivSuccess); | ||
|
||
progressBar = (ProgressBar) findViewById(R.id.progressbar); | ||
|
||
rotateUp = AnimationUtils.loadAnimation(context, R.anim.rotate_up); | ||
|
||
rotateDown = AnimationUtils.loadAnimation(context, R.anim.rotate_down); | ||
} | ||
|
||
@Override | ||
public void onStart(boolean automatic, int headerHeight, int finalHeight) { | ||
this.mHeight = headerHeight; | ||
progressBar.setIndeterminate(false); | ||
} | ||
|
||
@Override | ||
public void onMove(boolean isComplete, boolean automatic, int moved) { | ||
if (!isComplete) { | ||
ivArrow.setVisibility(VISIBLE); | ||
progressBar.setVisibility(GONE); | ||
ivSuccess.setVisibility(GONE); | ||
if (moved <= mHeight) { | ||
if (rotated) { | ||
ivArrow.clearAnimation(); | ||
ivArrow.startAnimation(rotateDown); | ||
rotated = false; | ||
} | ||
tvRefresh.setText("下拉刷新"); | ||
} else { | ||
tvRefresh.setText("释放刷新"); | ||
if (!rotated) { | ||
ivArrow.clearAnimation(); | ||
ivArrow.startAnimation(rotateUp); | ||
rotated = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onRefresh() { | ||
ivSuccess.setVisibility(GONE); | ||
ivArrow.clearAnimation(); | ||
ivArrow.setVisibility(GONE); | ||
progressBar.setVisibility(VISIBLE); | ||
tvRefresh.setText("正在刷新"); | ||
} | ||
|
||
@Override | ||
public void onRelease() { | ||
|
||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
rotated = false; | ||
ivSuccess.setVisibility(VISIBLE); | ||
ivArrow.clearAnimation(); | ||
ivArrow.setVisibility(GONE); | ||
progressBar.setVisibility(GONE); | ||
tvRefresh.setText("完成"); | ||
} | ||
|
||
@Override | ||
public void onReset() { | ||
rotated = false; | ||
ivSuccess.setVisibility(GONE); | ||
ivArrow.clearAnimation(); | ||
ivArrow.setVisibility(GONE); | ||
progressBar.setVisibility(GONE); | ||
} | ||
} |
Oops, something went wrong.