Skip to content

Commit

Permalink
增加对TV
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanarcheannovice committed Apr 11, 2018
1 parent d99b668 commit 9b1ec8b
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 115 deletions.
343 changes: 241 additions & 102 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Xadapter/Xadapter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,26 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/typedefs.txt" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
4 changes: 2 additions & 2 deletions Xadapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
66 changes: 56 additions & 10 deletions Xadapter/src/main/java/com/xz/xadapter/XRvDataAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,39 @@
*/
public abstract class XRvDataAdapter<T> extends RecyclerView.Adapter<XRvViewHolder> {

protected List<T> mDatas;//一般数据
protected SparseArrayCompat<View> mHeaderViews = new SparseArrayCompat<>();//headerView数量
protected SparseArrayCompat<View> 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<T> mDatas;
/**
* headerView数量
*/
protected SparseArrayCompat<View> mHeaderViews = new SparseArrayCompat<>();
/**
* footerView数量
*/
protected SparseArrayCompat<View> 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<T> getDatas() {
if (mDatas == null) {
Expand Down Expand Up @@ -83,7 +108,7 @@ public void addDatas(List<T> data, boolean isRefresh) {
}
} else {
this.mDatas.addAll(data);
if(isRefresh) {
if (isRefresh) {
notifyItemRangeInserted(mDatas.size() - data.size(), data.size());
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}

/**
* 点击事件
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion Xadapter/src/main/java/com/xz/xadapter/XRvPureAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public abstract class XRvPureAdapter extends RecyclerView.Adapter<XRvViewHolder>
*/
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));
Expand All @@ -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;
}

Expand All @@ -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);
}

/**
* 点击事件
*/
Expand All @@ -86,5 +115,10 @@ public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickLi
this.mOnItemLongClickListener = onItemLongClickListener;
}


/**
* 焦点选中时间
*/
public void setOnItemFocusableListener(OnItemFocusableListener onItemFocusableListener) {
this.mOnItemFocusableListener = onItemFocusableListener;
}
}

0 comments on commit 9b1ec8b

Please sign in to comment.