diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 91c07ea..c4b0ad4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -43,30 +43,22 @@ - - - - - - - - - - - + + + - + - + @@ -76,68 +68,97 @@ - + - + - - + + - - + + - + - + + + + + + - - + + - - - + + + + + + + - - + + - - - + + + + + + + + + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + @@ -155,6 +176,7 @@ mOnItemClickListener + mOnItemFocusableListener @@ -2820,22 +2842,22 @@ @@ -2852,8 +2874,6 @@ - - @@ -2866,10 +2886,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + - + + + @@ -2981,7 +3045,7 @@ - + - + - + @@ -3505,32 +3615,24 @@ + + + - - - - - - - - - - - - - + + @@ -3541,33 +3643,15 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -3575,7 +3659,9 @@ - + + + @@ -3591,7 +3677,12 @@ - + + + + + + @@ -3599,7 +3690,11 @@ - + + + + + @@ -3607,30 +3702,74 @@ + + + + + + + + + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Xadapter/Xadapter.iml b/Xadapter/Xadapter.iml index 41d7dac..91f5628 100644 --- a/Xadapter/Xadapter.iml +++ b/Xadapter/Xadapter.iml @@ -85,18 +85,26 @@ + + + + + + + + diff --git a/Xadapter/build.gradle b/Xadapter/build.gradle index 3f5b329..595aed7 100644 --- a/Xadapter/build.gradle +++ b/Xadapter/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 3 - versionName "3.0" + versionCode 6 + versionName "1.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/Xadapter/src/main/java/com/xz/xadapter/XRvDataAdapter.java b/Xadapter/src/main/java/com/xz/xadapter/XRvDataAdapter.java index 69e2e32..7089419 100644 --- a/Xadapter/src/main/java/com/xz/xadapter/XRvDataAdapter.java +++ b/Xadapter/src/main/java/com/xz/xadapter/XRvDataAdapter.java @@ -16,14 +16,39 @@ */ public abstract class XRvDataAdapter extends RecyclerView.Adapter { - protected List mDatas;//一般数据 - protected SparseArrayCompat mHeaderViews = new SparseArrayCompat<>();//headerView数量 - protected SparseArrayCompat mFootViews = new SparseArrayCompat<>();//footerView数量 - protected static final int BASE_ITEM_TYPE_HEADER = 100000;//定义header的key的起始位置 - protected static final int BASE_ITEM_TYPE_FOOTER = 200000;//定义footer的Key的起始位置 - protected OnItemClickListener mOnItemClickListener;//点击事件 - protected OnItemLongClickListener mOnItemLongClickListener;//长按事件 - + /** + * 一般数据 + */ + protected List mDatas; + /** + * headerView数量 + */ + protected SparseArrayCompat mHeaderViews = new SparseArrayCompat<>(); + /** + * footerView数量 + */ + protected SparseArrayCompat mFootViews = new SparseArrayCompat<>(); + /** + * 定义header的key的起始位置 + */ + protected static final int BASE_ITEM_TYPE_HEADER = 100000; + /** + * 定义footer的Key的起始位置 + */ + protected static final int BASE_ITEM_TYPE_FOOTER = 200000; + /** + * 点击事件 + */ + protected OnItemClickListener mOnItemClickListener; + /** + * 长按事件 + */ + protected OnItemLongClickListener mOnItemLongClickListener; + /** + * Tv端或者键盘手机使用 + * item 焦点 被选中 + */ + protected XRvPureAdapter.OnItemFocusableListener mOnItemFocusableListener; public List getDatas() { if (mDatas == null) { @@ -83,7 +108,7 @@ public void addDatas(List data, boolean isRefresh) { } } else { this.mDatas.addAll(data); - if(isRefresh) { + if (isRefresh) { notifyItemRangeInserted(mDatas.size() - data.size(), data.size()); } } @@ -104,7 +129,7 @@ public void addData(T data, boolean isRefresh) { } } else { this.mDatas.add(data); - if(isRefresh) { + if (isRefresh) { notifyItemRangeInserted(mDatas.size() - 1, 1); } } @@ -215,6 +240,27 @@ public interface OnItemLongClickListener { boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position); } + /** + * Tv端或者键盘手机使用 + * 焦点选中接口 + */ + public interface OnItemFocusableListener { + /** + * @param view 被选中的view + * @param hasFocus 是否有焦点 + * @param holder holder + * @param position 下标 + */ + void onItemFocusable(View view, boolean hasFocus, RecyclerView.ViewHolder holder, int position); + } + + /** + * 焦点选中时间 + */ + public void setOnItemFocusableListener(XRvPureAdapter.OnItemFocusableListener onItemFocusableListener) { + this.mOnItemFocusableListener = onItemFocusableListener; + } + /** * 点击事件 */ diff --git a/Xadapter/src/main/java/com/xz/xadapter/XRvMultiItemTypeAdapter.java b/Xadapter/src/main/java/com/xz/xadapter/XRvMultiItemTypeAdapter.java index 89b9dfd..74007e1 100644 --- a/Xadapter/src/main/java/com/xz/xadapter/XRvMultiItemTypeAdapter.java +++ b/Xadapter/src/main/java/com/xz/xadapter/XRvMultiItemTypeAdapter.java @@ -138,6 +138,14 @@ public boolean onLongClick(View v) { } }); } + if (mOnItemFocusableListener != null) { + viewHolder.getConvertView().setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + mOnItemFocusableListener.onItemFocusable(v,hasFocus,viewHolder,viewHolder.getAdapterPosition()); + } + }); + } } @Override diff --git a/Xadapter/src/main/java/com/xz/xadapter/XRvPureAdapter.java b/Xadapter/src/main/java/com/xz/xadapter/XRvPureAdapter.java index f6906b6..226e393 100644 --- a/Xadapter/src/main/java/com/xz/xadapter/XRvPureAdapter.java +++ b/Xadapter/src/main/java/com/xz/xadapter/XRvPureAdapter.java @@ -27,6 +27,13 @@ public abstract class XRvPureAdapter extends RecyclerView.Adapter */ protected OnItemLongClickListener mOnItemLongClickListener; + + /** + * Tv端或者键盘手机使用 + * item 焦点 被选中 + */ + protected OnItemFocusableListener mOnItemFocusableListener; + @Override public XRvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final XRvViewHolder viewHolder = XRvViewHolder.createViewHolder(parent.getContext(), parent, getItemLayout(viewType)); @@ -48,6 +55,14 @@ public boolean onLongClick(View v) { } }); } + if (mOnItemFocusableListener != null) { + viewHolder.getConvertView().setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + mOnItemFocusableListener.onItemFocusable(v,hasFocus,viewHolder,viewHolder.getAdapterPosition()); + } + }); + } return viewHolder; } @@ -70,6 +85,20 @@ public interface OnItemLongClickListener { boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position); } + /** + * Tv端或者键盘手机使用 + * 焦点选中接口 + */ + public interface OnItemFocusableListener { + /** + * @param view 被选中的view + * @param hasFocus 是否有焦点 + * @param holder holder + * @param position 下标 + */ + void onItemFocusable(View view, boolean hasFocus, RecyclerView.ViewHolder holder, int position); + } + /** * 点击事件 */ @@ -86,5 +115,10 @@ public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickLi this.mOnItemLongClickListener = onItemLongClickListener; } - + /** + * 焦点选中时间 + */ + public void setOnItemFocusableListener(OnItemFocusableListener onItemFocusableListener) { + this.mOnItemFocusableListener = onItemFocusableListener; + } }