apt 实现
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.simple.base.adapter;
|
||||
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/12/3.
|
||||
* 通用Holder
|
||||
*/
|
||||
public class AbsHolder extends RecyclerView.ViewHolder {
|
||||
View mView;
|
||||
private SparseArray<View> mViews = new SparseArray<>();
|
||||
|
||||
public AbsHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends View> T getView(@IdRes int id) {
|
||||
View view = mViews.get(id);
|
||||
if (view == null) {
|
||||
view = mView.findViewById(id);
|
||||
mViews.put(id, view);
|
||||
}
|
||||
return (T) view;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.simple.base.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/12/3.
|
||||
* RecyclerView 通用Adapter
|
||||
*/
|
||||
public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
|
||||
extends RecyclerView.Adapter<Holder> {
|
||||
protected String TAG;
|
||||
protected List<T> mData = new ArrayList<>();
|
||||
protected Context mContext;
|
||||
Holder holder;
|
||||
|
||||
public AbsRVAdapter(Context context, List<T> data) {
|
||||
mData = data;
|
||||
mContext = context;
|
||||
String arrays[] = getClass().getName().split("\\.");
|
||||
TAG = arrays[arrays.length - 1];
|
||||
}
|
||||
|
||||
@Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view =
|
||||
LayoutInflater.from(parent.getContext()).inflate(setLayoutId(viewType), parent, false);
|
||||
holder = getViewHolder(view, viewType);
|
||||
return holder;
|
||||
}
|
||||
|
||||
protected abstract Holder getViewHolder(View convertView, int viewType);
|
||||
|
||||
@Override public void onBindViewHolder(Holder holder, int position) {
|
||||
bindData(holder, position, mData.get(position));
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@Override public int getItemCount() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* item 的type
|
||||
*/
|
||||
protected abstract int setLayoutId(int type);
|
||||
|
||||
protected abstract void bindData(Holder holder, int position, T item);
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.simple.base.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
/*
|
||||
* RecyclerView item 事件监听帮助类
|
||||
* RvItemClickSupport.addTo(recyclerView).setOnItemClickListener(new RvItemClickSupport.OnItemClickListener() {
|
||||
*
|
||||
* @Override
|
||||
* public void onItemClicked(RecyclerView recyclerView, int position, View v) {
|
||||
* //处理你的事件
|
||||
* });
|
||||
*/
|
||||
public class RvItemClickSupport {
|
||||
private final RecyclerView mRecyclerView;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private OnItemLongClickListener mOnItemLongClickListener;
|
||||
private OnItemTouchListener mOnItemTouchListener;
|
||||
private OnItemFocusChangeListener mOnItemFocusChangeListener;
|
||||
private OnItemKeyListener mOnItemKeyListener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClicked(RecyclerView recyclerView, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemLongClickListener {
|
||||
boolean onItemLongClicked(RecyclerView recyclerView, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemTouchListener {
|
||||
public void onTouchEvent(RecyclerView rv, MotionEvent e, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemFocusChangeListener {
|
||||
public void onFocusChange(View v, int position, boolean hasFocus);
|
||||
}
|
||||
|
||||
public interface OnItemKeyListener {
|
||||
public boolean onKey(View v, int keyCode, int position, KeyEvent event);
|
||||
}
|
||||
|
||||
private View.OnFocusChangeListener mOnFocusChangeListener = new View.OnFocusChangeListener() {
|
||||
|
||||
@Override public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (mOnItemFocusChangeListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemFocusChangeListener.onFocusChange(v, holder.getAdapterPosition(),
|
||||
holder.itemView.hasFocus());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemClickListener.onItemClicked(mRecyclerView, holder.getAdapterPosition(), v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnLongClickListener mOnLongClickListener = new View.OnLongClickListener() {
|
||||
@Override public boolean onLongClick(View v) {
|
||||
if (mOnItemLongClickListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
return mOnItemLongClickListener.onItemLongClicked(mRecyclerView,
|
||||
holder.getAdapterPosition(), v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnTouchListener mOnTouchListener = new View.OnTouchListener() {
|
||||
@Override public boolean onTouch(View v, MotionEvent event) {
|
||||
if (mOnItemTouchListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemTouchListener.onTouchEvent(mRecyclerView, event, holder.getAdapterPosition(), v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnKeyListener mOnKeyListener = new View.OnKeyListener() {
|
||||
@Override public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (mOnItemKeyListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
return mOnItemKeyListener.onKey(v, keyCode, holder.getAdapterPosition(), event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private RecyclerView.OnChildAttachStateChangeListener mAttachListener =
|
||||
new RecyclerView.OnChildAttachStateChangeListener() {
|
||||
@Override public void onChildViewAttachedToWindow(View view) {
|
||||
if (mOnItemClickListener != null) {
|
||||
view.setOnClickListener(mOnClickListener);
|
||||
}
|
||||
if (mOnItemLongClickListener != null) {
|
||||
view.setOnLongClickListener(mOnLongClickListener);
|
||||
}
|
||||
if (mOnItemTouchListener != null) {
|
||||
view.setOnTouchListener(mOnTouchListener);
|
||||
}
|
||||
if (mOnItemFocusChangeListener != null) {
|
||||
view.setOnFocusChangeListener(mOnFocusChangeListener);
|
||||
}
|
||||
if (mOnItemKeyListener != null) {
|
||||
view.setOnKeyListener(mOnKeyListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onChildViewDetachedFromWindow(View view) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private RvItemClickSupport(RecyclerView recyclerView) {
|
||||
mRecyclerView = recyclerView;
|
||||
mRecyclerView.setTag(R.id.item_click_support, this);
|
||||
mRecyclerView.addOnChildAttachStateChangeListener(mAttachListener);
|
||||
}
|
||||
|
||||
public static RvItemClickSupport addTo(RecyclerView view) {
|
||||
RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support);
|
||||
if (support == null) {
|
||||
support = new RvItemClickSupport(view);
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
public static RvItemClickSupport removeFrom(RecyclerView view) {
|
||||
RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support);
|
||||
if (support != null) {
|
||||
support.detach(view);
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置按键监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemKeyListenr(OnItemKeyListener onItemKeyListener) {
|
||||
mOnItemKeyListener = onItemKeyListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置焦点监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemFocusChangeListener(
|
||||
OnItemFocusChangeListener onItemFocusChangeListener) {
|
||||
mOnItemFocusChangeListener = onItemFocusChangeListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触摸监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemTouchListener(OnItemTouchListener onItemTouchListener) {
|
||||
mOnItemTouchListener = onItemTouchListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemClickListener(OnItemClickListener listener) {
|
||||
mOnItemClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置长按监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemLongClickListener(OnItemLongClickListener listener) {
|
||||
mOnItemLongClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void detach(RecyclerView view) {
|
||||
view.removeOnChildAttachStateChangeListener(mAttachListener);
|
||||
view.setTag(R.id.item_click_support, null);
|
||||
}
|
||||
}
|
@ -34,7 +34,6 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.Test;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@ -134,12 +133,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
};
|
||||
|
||||
@Download.onPre private void hehe(String str, DownloadTask task) {
|
||||
@Download.onPre void onPre(DownloadTask task) {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gg(){
|
||||
@Download.onTaskStart
|
||||
void onStart(DownloadTask task){
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,12 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.adapter.AbsHolder;
|
||||
import com.arialyy.simple.base.adapter.AbsRVAdapter;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -22,10 +22,10 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.adapter.AbsHolder;
|
||||
import com.arialyy.simple.base.adapter.AbsRVAdapter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
19
app/src/main/res/values/ids.xml
Normal file
19
app/src/main/res/values/ids.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright (C) 2014 Lucas Rocha
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<item name="item_click_support" type="id" />
|
||||
</resources>
|
Reference in New Issue
Block a user