apt 实现
This commit is contained in:
@ -68,6 +68,22 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将当前类注册到Aria
|
||||||
|
*/
|
||||||
|
public DownloadReceiver register() {
|
||||||
|
DownloadSchedulers.getInstance().register(targetName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消注册
|
||||||
|
*/
|
||||||
|
public DownloadReceiver unRegister() {
|
||||||
|
DownloadSchedulers.getInstance().unRegister(targetName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除回调
|
* 移除回调
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.aria.core.scheduler;
|
||||||
|
|
||||||
|
import com.arialyy.aria.core.inf.ITask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Aria.Lao on 2017/6/7.
|
||||||
|
*/
|
||||||
|
public class AbsSchedulerListener<TASK extends ITask> implements ISchedulerListener<TASK> {
|
||||||
|
@Override public void onPre(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskPre(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskResume(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskStart(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskStop(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskCancel(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskFail(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskComplete(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onTaskRunning(TASK task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -26,27 +26,40 @@ import com.arialyy.aria.core.inf.IEntity;
|
|||||||
import com.arialyy.aria.core.inf.ITask;
|
import com.arialyy.aria.core.inf.ITask;
|
||||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||||
import com.arialyy.aria.core.upload.UploadTask;
|
import com.arialyy.aria.core.upload.UploadTask;
|
||||||
|
import com.arialyy.compiler.ProxyConstance;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by AriaL on 2017/6/4.
|
* Created by lyy on 2017/6/4.
|
||||||
*/
|
*/
|
||||||
public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity, TASK extends ITask<ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY, ENTITY>>
|
public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity, TASK extends ITask<ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY, ENTITY>>
|
||||||
implements ISchedulers<TASK> {
|
implements ISchedulers<TASK> {
|
||||||
private static final String TAG = "AbsSchedulers";
|
private static final String TAG = "AbsSchedulers";
|
||||||
|
|
||||||
protected QUEUE mQueue;
|
protected QUEUE mQueue;
|
||||||
|
protected boolean isDownload = true;
|
||||||
|
|
||||||
private Map<String, ISchedulerListener<TASK>> mSchedulerListeners = new ConcurrentHashMap<>();
|
private Map<String, ISchedulerListener<TASK>> mSchedulerListeners = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
private Map<String, AbsSchedulerListener<TASK>> mObservers = new ConcurrentHashMap<>();
|
||||||
public void addSchedulerListener(String targetName, ISchedulerListener<TASK> schedulerListener) {
|
|
||||||
|
/**
|
||||||
|
* @param targetName 观察者,创建该监听器的对象类名
|
||||||
|
* @param schedulerListener {@link ISchedulerListener}
|
||||||
|
* @see #register(String)
|
||||||
|
*/
|
||||||
|
@Deprecated @Override public void addSchedulerListener(String targetName,
|
||||||
|
ISchedulerListener<TASK> schedulerListener) {
|
||||||
mSchedulerListeners.put(targetName, schedulerListener);
|
mSchedulerListeners.put(targetName, schedulerListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param targetName 观察者,创建该监听器的对象类名
|
||||||
|
* @see #unRegister(String)
|
||||||
|
*/
|
||||||
@Override public void removeSchedulerListener(String targetName,
|
@Override public void removeSchedulerListener(String targetName,
|
||||||
ISchedulerListener<TASK> schedulerListener) {
|
ISchedulerListener<TASK> schedulerListener) {
|
||||||
//该内存泄露解决方案:http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element
|
//该内存泄露解决方案:http://stackoverflow.com/questions/14585829/how-safe-is-to-delete-already-removed-concurrenthashmap-element
|
||||||
@ -57,6 +70,46 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void register(String targetName) {
|
||||||
|
AbsSchedulerListener<TASK> listener = mObservers.get(targetName);
|
||||||
|
if (listener == null) {
|
||||||
|
mObservers.put(targetName, createListener(targetName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void unRegister(String targetName) {
|
||||||
|
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK>>> iter =
|
||||||
|
mObservers.entrySet().iterator(); iter.hasNext(); ) {
|
||||||
|
Map.Entry<String, AbsSchedulerListener<TASK>> entry = iter.next();
|
||||||
|
if (entry.getKey().equals(targetName)) iter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建代理类
|
||||||
|
*
|
||||||
|
* @param targetName 通过观察者创建对应的Aria事件代理
|
||||||
|
*/
|
||||||
|
private AbsSchedulerListener<TASK> createListener(String targetName) {
|
||||||
|
AbsSchedulerListener<TASK> listener = null;
|
||||||
|
try {
|
||||||
|
Class clazz = Class.forName(
|
||||||
|
targetName + (isDownload ? ProxyConstance.DOWNLOAD_PROXY_CLASS_SUFFIX
|
||||||
|
: ProxyConstance.UPLOAD_PROXY_CLASS_SUFFIX));
|
||||||
|
listener = (AbsSchedulerListener<TASK>) clazz.newInstance();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法");
|
||||||
|
//e.printStackTrace();
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
//e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean handleMessage(Message msg) {
|
@Override public boolean handleMessage(Message msg) {
|
||||||
TASK task = (TASK) msg.obj;
|
TASK task = (TASK) msg.obj;
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
@ -98,8 +151,13 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
|
|||||||
if (mSchedulerListeners.size() > 0) {
|
if (mSchedulerListeners.size() > 0) {
|
||||||
Set<String> keys = mSchedulerListeners.keySet();
|
Set<String> keys = mSchedulerListeners.keySet();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
|
if (mSchedulerListeners.size() > 0) {
|
||||||
callback(state, task, mSchedulerListeners.get(key));
|
callback(state, task, mSchedulerListeners.get(key));
|
||||||
}
|
}
|
||||||
|
if (mObservers.size() > 0) {
|
||||||
|
callback(state, task, mObservers.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ public class DownloadSchedulers
|
|||||||
|
|
||||||
private DownloadSchedulers() {
|
private DownloadSchedulers() {
|
||||||
mQueue = DownloadTaskQueue.getInstance();
|
mQueue = DownloadTaskQueue.getInstance();
|
||||||
|
isDownload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DownloadSchedulers getInstance() {
|
public static DownloadSchedulers getInstance() {
|
||||||
|
@ -80,4 +80,18 @@ public interface ISchedulers<Task extends ITask> extends Handler.Callback {
|
|||||||
*/
|
*/
|
||||||
public void removeSchedulerListener(String targetName,
|
public void removeSchedulerListener(String targetName,
|
||||||
ISchedulerListener<Task> schedulerListener);
|
ISchedulerListener<Task> schedulerListener);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将当前类注册到Aria
|
||||||
|
*
|
||||||
|
* @param targetName 类完整路径
|
||||||
|
*/
|
||||||
|
public void register(String targetName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除注册
|
||||||
|
*
|
||||||
|
* @param targetName 类完整路径
|
||||||
|
*/
|
||||||
|
public void unRegister(String targetName);
|
||||||
}
|
}
|
@ -32,6 +32,7 @@ public class UploadSchedulers
|
|||||||
|
|
||||||
private UploadSchedulers() {
|
private UploadSchedulers() {
|
||||||
mQueue = UploadTaskQueue.getInstance();
|
mQueue = UploadTaskQueue.getInstance();
|
||||||
|
isDownload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UploadSchedulers getInstance() {
|
public static UploadSchedulers getInstance() {
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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.annotations;
|
package com.arialyy.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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.annotations;
|
package com.arialyy.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
@ -15,8 +30,8 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre {
|
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
|
//@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
|
||||||
}
|
//}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
|
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ dependencies {
|
|||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
compile 'com.google.auto:auto-common:0.6'
|
compile 'com.google.auto:auto-common:0.6'
|
||||||
compile 'com.google.auto.service:auto-service:1.0-rc2'
|
compile 'com.google.auto.service:auto-service:1.0-rc2'
|
||||||
compile 'com.squareup:javapoet:1.7.0'
|
compile 'com.squareup:javapoet:1.9.0'
|
||||||
compile project(':AriaAnnotations')
|
compile project(':AriaAnnotations')
|
||||||
|
|
||||||
sourceCompatibility = "1.7"
|
sourceCompatibility = "1.7"
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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.compiler;
|
package com.arialyy.compiler;
|
||||||
|
|
||||||
import com.arialyy.annotations.Download;
|
import com.arialyy.annotations.Download;
|
||||||
@ -22,7 +37,7 @@ import javax.lang.model.element.TypeElement;
|
|||||||
@Override public synchronized void init(ProcessingEnvironment processingEnv) {
|
@Override public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||||
super.init(processingEnv);
|
super.init(processingEnv);
|
||||||
PrintLog.init(processingEnv.getMessager());
|
PrintLog.init(processingEnv.getMessager());
|
||||||
mHandler = new ElementHandle(processingEnv.getFiler());
|
mHandler = new ElementHandle(processingEnv.getFiler(), processingEnv.getElementUtils());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Set<String> getSupportedAnnotationTypes() {
|
@Override public Set<String> getSupportedAnnotationTypes() {
|
||||||
@ -43,7 +58,7 @@ import javax.lang.model.element.TypeElement;
|
|||||||
annotataions.add(Upload.onTaskComplete.class.getCanonicalName());
|
annotataions.add(Upload.onTaskComplete.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskFail.class.getCanonicalName());
|
annotataions.add(Upload.onTaskFail.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskPre.class.getCanonicalName());
|
annotataions.add(Upload.onTaskPre.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskResume.class.getCanonicalName());
|
//annotataions.add(Upload.onTaskResume.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskRunning.class.getCanonicalName());
|
annotataions.add(Upload.onTaskRunning.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskStart.class.getCanonicalName());
|
annotataions.add(Upload.onTaskStart.class.getCanonicalName());
|
||||||
annotataions.add(Upload.onTaskStop.class.getCanonicalName());
|
annotataions.add(Upload.onTaskStop.class.getCanonicalName());
|
||||||
@ -56,10 +71,10 @@ import javax.lang.model.element.TypeElement;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
PrintLog.getInstance().info("开始扫描");
|
|
||||||
mHandler.clean();
|
mHandler.clean();
|
||||||
mHandler.handleDownload(roundEnv);
|
mHandler.handleDownload(roundEnv);
|
||||||
mHandler.handleUpload(roundEnv);
|
mHandler.handleUpload(roundEnv);
|
||||||
|
mHandler.createProxyFile();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.compiler;
|
package com.arialyy.compiler;
|
||||||
|
|
||||||
import com.arialyy.annotations.Download;
|
import com.arialyy.annotations.Download;
|
||||||
import com.arialyy.annotations.Upload;
|
import com.arialyy.annotations.Upload;
|
||||||
|
import com.squareup.javapoet.ClassName;
|
||||||
|
import com.squareup.javapoet.FieldSpec;
|
||||||
|
import com.squareup.javapoet.JavaFile;
|
||||||
|
import com.squareup.javapoet.MethodSpec;
|
||||||
|
import com.squareup.javapoet.ParameterSpec;
|
||||||
|
import com.squareup.javapoet.TypeSpec;
|
||||||
|
import com.squareup.javapoet.ParameterizedTypeName;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -14,7 +36,10 @@ import javax.lang.model.element.Element;
|
|||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
|
import javax.lang.model.element.PackageElement;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.element.VariableElement;
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2017/6/6.
|
* Created by lyy on 2017/6/6.
|
||||||
@ -23,10 +48,12 @@ import javax.lang.model.element.VariableElement;
|
|||||||
class ElementHandle {
|
class ElementHandle {
|
||||||
|
|
||||||
private Filer mFiler;
|
private Filer mFiler;
|
||||||
private Map<String, Set<String>> mMethods = new HashMap<>();
|
private Elements mElementUtil;
|
||||||
|
private Map<String, ProxyEntity> mMethods = new HashMap<>();
|
||||||
|
|
||||||
ElementHandle(Filer filer) {
|
ElementHandle(Filer filer, Elements elements) {
|
||||||
mFiler = filer;
|
mFiler = filer;
|
||||||
|
mElementUtil = elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,12 +82,137 @@ class ElementHandle {
|
|||||||
saveMethod(false, roundEnv, Upload.onTaskComplete.class);
|
saveMethod(false, roundEnv, Upload.onTaskComplete.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskFail.class);
|
saveMethod(false, roundEnv, Upload.onTaskFail.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskPre.class);
|
saveMethod(false, roundEnv, Upload.onTaskPre.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskResume.class);
|
//saveMethod(false, roundEnv, Upload.onTaskResume.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskRunning.class);
|
saveMethod(false, roundEnv, Upload.onTaskRunning.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskStart.class);
|
saveMethod(false, roundEnv, Upload.onTaskStart.class);
|
||||||
saveMethod(false, roundEnv, Upload.onTaskStop.class);
|
saveMethod(false, roundEnv, Upload.onTaskStop.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printMethods() {
|
||||||
|
//Set<String> keys = mMethods.keySet();
|
||||||
|
//for (String key : keys) {
|
||||||
|
// ProxyEntity entity = mMethods.get(key);
|
||||||
|
// for (String method : entity.methods) {
|
||||||
|
// PrintLog.getInstance().info(method);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
PrintLog.getInstance().info("size ==> " + mMethods.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在build文件夹中生成如下代码的文件
|
||||||
|
* <pre>
|
||||||
|
* <code>
|
||||||
|
* package com.arialyy.simple.download;
|
||||||
|
*
|
||||||
|
* import com.arialyy.aria.core.download.DownloadTask;
|
||||||
|
* import com.arialyy.aria.core.scheduler.AbsSchedulerListener;
|
||||||
|
*
|
||||||
|
* public final class SingleTaskActivity$$DownloadListenerProxy extends
|
||||||
|
* AbsSchedulerListener<DownloadTask> {
|
||||||
|
* private SingleTaskActivity obj;
|
||||||
|
*
|
||||||
|
* public void onPre(final DownloadTask task) {
|
||||||
|
* obj.onPre((DownloadTask)task);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void onTaskStart(final DownloadTask task) {
|
||||||
|
* obj.onStart((DownloadTask)task);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void setListener(final SingleTaskActivity obj) {
|
||||||
|
* this.obj = obj;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void createProxyFile() {
|
||||||
|
Set<String> keys = mMethods.keySet();
|
||||||
|
try {
|
||||||
|
for (String key : keys) {
|
||||||
|
ProxyEntity entity = mMethods.get(key);
|
||||||
|
JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build();
|
||||||
|
|
||||||
|
jf.writeTo(mFiler);
|
||||||
|
// 如果需要在控制台打印生成的文件,则去掉下面的注释
|
||||||
|
//jf.writeTo(System.out);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建代理方法
|
||||||
|
*
|
||||||
|
* @param isDownload 是否是下载的注解
|
||||||
|
* @param annotation {@link Download}、{@link Upload}
|
||||||
|
* @param methodName 被代理类注解的方法名
|
||||||
|
*/
|
||||||
|
private MethodSpec createProxyMethod(boolean isDownload, Class<? extends Annotation> annotation,
|
||||||
|
String methodName) {
|
||||||
|
ClassName task = ClassName.get(
|
||||||
|
isDownload ? "com.arialyy.aria.core.download" : "com.arialyy.aria.core.upload",
|
||||||
|
isDownload ? "DownloadTask" : "UploadTask");
|
||||||
|
ParameterSpec parameterSpec =
|
||||||
|
ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build();
|
||||||
|
return MethodSpec.methodBuilder(annotation.getSimpleName())
|
||||||
|
.addModifiers(Modifier.PUBLIC)
|
||||||
|
.returns(void.class)
|
||||||
|
.addParameter(parameterSpec)
|
||||||
|
.addAnnotation(Override.class)
|
||||||
|
.addCode("obj."
|
||||||
|
+ methodName
|
||||||
|
+ "("
|
||||||
|
+ (isDownload ? "(DownloadTask)" : "(UploadTask)")
|
||||||
|
+ "task);\n")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建代理类
|
||||||
|
*/
|
||||||
|
private TypeSpec createProxyClass(ProxyEntity entity) {
|
||||||
|
TypeSpec.Builder builder = TypeSpec.classBuilder(
|
||||||
|
entity.className + (entity.isDownlaod ? ProxyConstance.DOWNLOAD_PROXY_CLASS_SUFFIX
|
||||||
|
: ProxyConstance.UPLOAD_PROXY_CLASS_SUFFIX))
|
||||||
|
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
|
|
||||||
|
//添加被代理的类的字段
|
||||||
|
ClassName obj = ClassName.get(entity.packageName, entity.className);
|
||||||
|
FieldSpec observerField = FieldSpec.builder(obj, "obj").addModifiers(Modifier.PRIVATE).build();
|
||||||
|
builder.addField(observerField);
|
||||||
|
|
||||||
|
//添加注解方法
|
||||||
|
for (Class<? extends Annotation> annotation : entity.methods.keySet()) {
|
||||||
|
MethodSpec method =
|
||||||
|
createProxyMethod(entity.isDownlaod, annotation, entity.methods.get(annotation));
|
||||||
|
builder.addMethod(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加设置代理的类
|
||||||
|
ParameterSpec parameterSpec =
|
||||||
|
ParameterSpec.builder(obj, "obj").addModifiers(Modifier.FINAL).build();
|
||||||
|
MethodSpec listener = MethodSpec.methodBuilder(ProxyConstance.SET_LISTENER)
|
||||||
|
.addModifiers(Modifier.PUBLIC)
|
||||||
|
.returns(void.class)
|
||||||
|
.addParameter(parameterSpec)
|
||||||
|
.addCode("this.obj = obj;\n")
|
||||||
|
.build();
|
||||||
|
builder.addJavadoc("该文件为Aria自动生成的代理文件,请不要修改该文件的任何代码!\n");
|
||||||
|
|
||||||
|
//创建父类参数
|
||||||
|
ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener");
|
||||||
|
//创建泛型
|
||||||
|
ClassName typeVariableName = ClassName.get(
|
||||||
|
entity.isDownlaod ? "com.arialyy.aria.core.download" : "com.arialyy.aria.core.upload",
|
||||||
|
entity.isDownlaod ? "DownloadTask" : "UploadTask");
|
||||||
|
builder.superclass(ParameterizedTypeName.get(superClass, typeVariableName));
|
||||||
|
builder.addMethod(listener);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
void clean() {
|
void clean() {
|
||||||
mMethods.clear();
|
mMethods.clear();
|
||||||
}
|
}
|
||||||
@ -74,15 +226,21 @@ class ElementHandle {
|
|||||||
ElementKind kind = element.getKind();
|
ElementKind kind = element.getKind();
|
||||||
if (kind == ElementKind.METHOD) {
|
if (kind == ElementKind.METHOD) {
|
||||||
ExecutableElement method = (ExecutableElement) element;
|
ExecutableElement method = (ExecutableElement) element;
|
||||||
|
TypeElement classElement = (TypeElement) method.getEnclosingElement();
|
||||||
|
PackageElement packageElement = mElementUtil.getPackageOf(classElement);
|
||||||
checkDownloadMethod(isDownload, method);
|
checkDownloadMethod(isDownload, method);
|
||||||
String methodName = method.getSimpleName().toString();
|
String methodName = method.getSimpleName().toString();
|
||||||
String className = method.getEnclosingElement().toString();
|
String className = method.getEnclosingElement().toString(); //全类名
|
||||||
Set<String> methods = mMethods.get(className);
|
ProxyEntity proxyEntity = mMethods.get(className);
|
||||||
if (methods == null) {
|
if (proxyEntity == null) {
|
||||||
methods = new HashSet<>();
|
proxyEntity = new ProxyEntity();
|
||||||
mMethods.put(className, methods);
|
proxyEntity.isDownlaod = isDownload;
|
||||||
|
//proxyEntity.packageName = classElement.getQualifiedName().toString();
|
||||||
|
proxyEntity.packageName = packageElement.getQualifiedName().toString();
|
||||||
|
proxyEntity.className = classElement.getSimpleName().toString();
|
||||||
|
mMethods.put(className, proxyEntity);
|
||||||
}
|
}
|
||||||
methods.add(methodName);
|
proxyEntity.methods.put(annotationClazz, methodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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.compiler;
|
package com.arialyy.compiler;
|
||||||
|
|
||||||
import javax.annotation.processing.Messager;
|
import javax.annotation.processing.Messager;
|
||||||
@ -8,7 +23,7 @@ import javax.tools.Diagnostic;
|
|||||||
* Created by Aria.Lao on 2017/6/6.
|
* Created by Aria.Lao on 2017/6/6.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PrintLog {
|
class PrintLog {
|
||||||
|
|
||||||
private volatile static PrintLog INSTANCE = null;
|
private volatile static PrintLog INSTANCE = null;
|
||||||
private Messager mMessager;
|
private Messager mMessager;
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.compiler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by lyy on 2017/6/7.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ProxyConstance {
|
||||||
|
/**
|
||||||
|
* 设置观察者的方法
|
||||||
|
*/
|
||||||
|
String SET_LISTENER = "setListener";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载的动态生成的代理类后缀
|
||||||
|
*/
|
||||||
|
String DOWNLOAD_PROXY_CLASS_SUFFIX = "$$DownloadListenerProxy";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传的动态生成的代理类后缀
|
||||||
|
*/
|
||||||
|
String UPLOAD_PROXY_CLASS_SUFFIX = "$$UploadListenerProxy";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.compiler;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Aria.Lao on 2017/6/7.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ProxyEntity {
|
||||||
|
public String packageName;
|
||||||
|
public String className;
|
||||||
|
public boolean isDownlaod = true;
|
||||||
|
|
||||||
|
public Map<Class<? extends Annotation>, String> methods = new HashMap<>();
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
//package com.arialyy.compiler;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Created by AriaL on 2017/6/6.
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
//public class test {
|
|
||||||
// Object obj;
|
|
||||||
//
|
|
||||||
// public void setObj(Object obj){
|
|
||||||
// this.obj = obj;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void onPre(DownloadTask task){
|
|
||||||
// obj.method(task);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//}
|
|
@ -24,6 +24,7 @@ android {
|
|||||||
|
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||||
|
exclude 'squareup.javapoet.*'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +37,6 @@ dependencies {
|
|||||||
compile 'com.google.code.gson:gson:2.7'
|
compile 'com.google.code.gson:gson:2.7'
|
||||||
compile 'com.squareup.okhttp3:okhttp:3.2.0'
|
compile 'com.squareup.okhttp3:okhttp:3.2.0'
|
||||||
compile 'com.arialyy.frame:MVVM2:2.2.0'
|
compile 'com.arialyy.frame:MVVM2:2.2.0'
|
||||||
compile 'com.arialyy.absadapter:AbsAdapter:1.1.2'
|
|
||||||
compile project(':Aria')
|
compile project(':Aria')
|
||||||
// compile 'com.arialyy.aria:Aria:3.0.0'
|
// compile 'com.arialyy.aria:Aria:3.0.0'
|
||||||
}
|
}
|
||||||
|
@ -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 android.widget.Toast;
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import com.arialyy.annotations.Download;
|
import com.arialyy.annotations.Download;
|
||||||
import com.arialyy.annotations.Test;
|
|
||||||
import com.arialyy.aria.core.download.DownloadTarget;
|
import com.arialyy.aria.core.download.DownloadTarget;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
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
|
@Download.onTaskStart
|
||||||
public void gg(){
|
void onStart(DownloadTask task){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import butterknife.Bind;
|
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.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.simple.R;
|
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 com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -22,10 +22,10 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import butterknife.Bind;
|
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.Aria;
|
||||||
import com.arialyy.simple.R;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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