├── .gitignore
├── README.md
├── app-join-launcher.psd
├── app-lite-launcher.psd
├── library
├── AndroidManifest.xml
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
├── resources
│ └── META-INF
│ │ └── services
│ │ └── javax.annotation.processing.Processor
└── src
│ └── com
│ └── litesuits
│ └── auto
│ ├── AutoLiteProcessor.java
│ ├── AutoLiter.java
│ ├── AutoMan.java
│ ├── SourceFile.java
│ └── anno
│ ├── AutoLite.java
│ ├── Bind.java
│ └── UnBind.java
└── sample
├── AndroidManifest.xml
├── res
├── drawable-xhdpi
│ └── ic_launcher.png
├── layout
│ └── main_ioc.xml
└── values
│ └── strings.xml
├── resources
└── META-INF
│ └── services
│ └── javax.annotation.processing.Processor
└── src
└── com
└── litesuits
└── tidy
├── $.java
├── AutoFind.java
├── LiteTidy.java
├── LiteTidyProcessor.java
├── sample
├── Application.java
├── BaseActivity.java
├── MainActivity.java
└── MyActivity.java
└── test
└── Test.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # root files
2 |
3 | # built application files
4 | *.apk
5 | *.ap_
6 |
7 | # files for the dex VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Local configuration file (sdk path, etc)
19 | *.properties
20 | proguard-project.txt
21 |
22 | # Eclipse project files
23 | .classpath
24 | .project
25 | .settings
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Intellij project files
31 | *.iml
32 | *.ipr
33 | *.iws
34 | .idea/
35 |
36 | .DS_Store
37 |
38 |
39 | gen/com/litesuits/common/BuildConfig.java
40 |
41 | lint.xml
42 |
43 | project.properties
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-lite-tidy
2 | Android IOC Framework.
3 |
4 | QQgroup : [42960650][1] , [47357508][2]
5 |
6 |
7 | [1]: http://shang.qq.com/wpa/qunwpa?idkey=19bf15b9c85ec15c62141dd00618f725e2983803cd2b48566fa0e94964ae8370
8 | [2]: http://shang.qq.com/wpa/qunwpa?idkey=492d63aaffb04b23d8dc4df21f6b594008cbe1a819978659cddab2dbc397684e
9 |
--------------------------------------------------------------------------------
/app-join-launcher.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/app-join-launcher.psd
--------------------------------------------------------------------------------
/app-lite-launcher.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/app-lite-launcher.psd
--------------------------------------------------------------------------------
/library/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/library/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/library/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/library/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/library/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/library/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/library/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ACTIVITY_ENTRY_NAME
4 |
5 |
--------------------------------------------------------------------------------
/library/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | com.litesuits.auto.AutoLiteProcessor
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/AutoLiteProcessor.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto;
2 |
3 |
4 | import com.litesuits.auto.anno.AutoLite;
5 | import com.litesuits.auto.anno.Bind;
6 | import com.litesuits.auto.anno.UnBind;
7 |
8 | import javax.annotation.processing.*;
9 | import javax.lang.model.SourceVersion;
10 | import javax.lang.model.element.*;
11 | import javax.lang.model.type.*;
12 | import javax.lang.model.util.Elements;
13 | import javax.lang.model.util.Types;
14 | import javax.tools.Diagnostic;
15 | import javax.tools.JavaFileObject;
16 | import java.io.Writer;
17 | import java.util.*;
18 |
19 | /**
20 | * 注解处理器:凹凸曼.
21 | * 圣诞快乐
22 | * 愿你享受动手的快感
23 | *
24 | * @author MaTianyu @http://litesuits.com
25 | * @date 2015-12-08 15:44,
26 | */
27 | public class AutoLiteProcessor extends AbstractProcessor {
28 |
29 | /**
30 | * 传递给注解处理工具的处理器选项。
31 | */
32 | Map options;
33 |
34 | /**
35 | * 用来报告错误、警告和其他通知的消息管理器。
36 | */
37 | Messager messager;
38 |
39 | /**
40 | * 用来新建源文件、类文件或辅助文件的文件处理器。
41 | */
42 | Filer filer;
43 |
44 | /**
45 | * 在元素上进行操作的一些工具方法的实现。
46 | */
47 | Elements elementUtils;
48 |
49 | /**
50 | * 在类型上进行操作的一些工具方法的实现。
51 | */
52 | Types types;
53 |
54 | /**
55 | * 任何生成的源和类文件应该符合的源版本。
56 | */
57 | SourceVersion sourceVersion;
58 |
59 | /**
60 | * 当前语言环境,没有特定语言环境此对象为null,语言环境可以用来提供本地化的消息。
61 | */
62 | Locale locale;
63 |
64 | public synchronized void init(ProcessingEnvironment processingEnv) {
65 | super.init(processingEnv);
66 | options = processingEnv.getOptions();
67 | messager = processingEnv.getMessager();
68 | filer = processingEnv.getFiler();
69 | elementUtils = processingEnv.getElementUtils();
70 | types = processingEnv.getTypeUtils();
71 | sourceVersion = processingEnv.getSourceVersion();
72 | locale = processingEnv.getLocale();
73 | }
74 |
75 | @Override
76 | public SourceVersion getSupportedSourceVersion() {
77 | return SourceVersion.latestSupported();
78 | }
79 |
80 | @Override
81 | public Set getSupportedAnnotationTypes() {
82 | Set set = new LinkedHashSet();
83 | set.add(AutoLite.class.getCanonicalName());
84 | set.add(Bind.class.getCanonicalName());
85 | set.add(UnBind.class.getCanonicalName());
86 | return set;
87 | }
88 |
89 | @Override
90 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
91 | //processEnv(annotations, roundEnv);
92 | //try {
93 | //
94 | // Class claxx = Class.forName("com.litesuits.join.BaseActivity");
95 | // messager.printMessage(Diagnostic.Kind.NOTE, "R : " + claxx);
96 | //} catch (ClassNotFoundException e) {
97 | // e.printStackTrace();
98 | //}
99 | processAutoElement(roundEnv);
100 | return true;
101 | }
102 |
103 | public void processAutoElement(RoundEnvironment roundEnv) {
104 | Set extends Element> eleSet = roundEnv.getElementsAnnotatedWith(AutoLite.class);
105 | if (eleSet != null) {
106 | for (Element element : eleSet) {
107 | printElement(element);
108 | if (element.getKind() == ElementKind.CLASS) {
109 | TypeElement typeElement = (TypeElement) element;
110 | messager.printMessage(Diagnostic.Kind.NOTE, "_________________ CLASS " + typeElement.getSimpleName() + " _________________");
111 | messager.printMessage(Diagnostic.Kind.NOTE, "getInterfaces : " + typeElement.getInterfaces());
112 | messager.printMessage(Diagnostic.Kind.NOTE, "getNestingKind : " + typeElement.getNestingKind());
113 | messager.printMessage(Diagnostic.Kind.NOTE, "getQualifiedName : " + typeElement.getQualifiedName());
114 | messager.printMessage(Diagnostic.Kind.NOTE, "getSuperclass : " + typeElement.getSuperclass());
115 | messager.printMessage(Diagnostic.Kind.NOTE, "getTypeParameters : " + typeElement.getTypeParameters());
116 | handleClassElement(element);
117 | writeSourceFile(typeElement);
118 | }
119 | }
120 | }
121 | }
122 |
123 | private void writeSourceFile(TypeElement typeElement) {
124 | try {
125 | //Writer writer = new FileWriter(new File("/Users/Matianyu/app-debug/AutoLiter.java"));
126 | SourceFile sourceFile = createSourceFile(typeElement);
127 | JavaFileObject jfo = filer.createSourceFile(sourceFile.getSourceFileName(), typeElement);
128 | Writer writer = jfo.openWriter();
129 | writer.write(sourceFile.generateJava());
130 | writer.flush();
131 | writer.close();
132 | } catch (Exception e) {
133 | e.printStackTrace();
134 | }
135 | }
136 |
137 | /**
138 | * 构建代码生成类,找出一个类元素中的所有关键对象:View、ClickMethod等。
139 | */
140 | private SourceFile createSourceFile(TypeElement typeElement) {
141 | // init class info
142 | SourceFile sourceFile = new SourceFile()
143 | .setPackageName(elementUtils.getPackageOf(typeElement).getQualifiedName().toString())
144 | .setClassName(typeElement.getSimpleName().toString() + SourceFile.CLASSNAME_SUFFIX)
145 | .setAutoClass(typeElement.getSimpleName().toString());
146 | List extends Element> elementList = typeElement.getEnclosedElements();
147 | // find views
148 | HashMap viewMap = findViewsMap(elementList);
149 | sourceFile.setViewElementMap(viewMap);
150 | // find methods
151 | HashMap methodMap = findMappingMehtods(viewMap.keySet(), elementList);
152 | sourceFile.setMethodElementMap(methodMap);
153 | return sourceFile;
154 |
155 | }
156 |
157 | /**
158 | * 找到所有元素中,属于视图(View)类的元素
159 | */
160 | private HashMap findViewsMap(List extends Element> elementList) {
161 | HashMap viewMap = new HashMap();
162 | if (elementList != null) {
163 | for (Element e : elementList) {
164 | if (isViewElement(e)) {
165 | viewMap.put(e.getSimpleName().toString(), e);
166 | }
167 | }
168 | }
169 | return viewMap;
170 | }
171 |
172 | /**
173 | * 找到所有元素中,属于方法(Method)类的元素
174 | */
175 | private HashMap findMappingMehtods(Set viewSet, List extends Element> elementList) {
176 | HashMap methodMap = new HashMap();
177 | if (elementList != null) {
178 | for (Element e : elementList) {
179 | if (e instanceof ExecutableElement) {
180 | String methodName = e.getSimpleName().toString();
181 | if (methodName.startsWith("click")) {
182 | String viewName = methodName.substring("click".length(), methodName.length());
183 | for (String view : viewSet) {
184 | if (viewName.equalsIgnoreCase(view)) {
185 | methodMap.put(view, (ExecutableElement) e);
186 | }
187 | }
188 | }
189 | }
190 | }
191 | }
192 | return methodMap;
193 | }
194 |
195 | /**
196 | * 判断该元素(变量or类型)是否为View类
197 | */
198 | private boolean isViewElement(Element element) {
199 | if (element instanceof VariableElement) {
200 | // 将成员变量转换为类型
201 | return isViewTypeMirror(element.asType());
202 | } else if (element instanceof TypeElement) {
203 | // 判断类型是否继承自 android view 类
204 | TypeElement typeElement = (TypeElement) element;
205 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement TypeElement : " + typeElement.getQualifiedName());
206 | if (typeElement.getQualifiedName().contentEquals("android.view.View")) {
207 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement TypeElement: " + true);
208 | return true;
209 | }
210 | return isViewTypeMirror(typeElement.getSuperclass());
211 | }
212 | return false;
213 | }
214 |
215 | /**
216 | * 判断该类型是否为View类
217 | */
218 | private boolean isViewTypeMirror(TypeMirror typeMirror) {
219 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement typeMirror : " + typeMirror);
220 | if (typeMirror != null) {
221 | if (typeMirror.toString().equals("android.view.View")) {
222 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement TypeMirror : " + true);
223 | return true;
224 | } else if (typeMirror instanceof DeclaredType) {
225 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement getEnclosingType : " + ((DeclaredType) typeMirror).getEnclosingType());
226 | messager.printMessage(Diagnostic.Kind.NOTE, "------------ isViewElement getTypeArguments : " + ((DeclaredType) typeMirror).getTypeArguments());
227 | return isViewElement(((DeclaredType) typeMirror).asElement());
228 | }
229 | }
230 | return false;
231 | }
232 |
233 | public void processEnv(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
234 | for (TypeElement typeElement : annotations) {
235 | messager.printMessage(Diagnostic.Kind.NOTE, "_________________ " + typeElement.getSimpleName() + " _________________");
236 | messager.printMessage(Diagnostic.Kind.NOTE, "class : " + typeElement.getClass());
237 | messager.printMessage(Diagnostic.Kind.NOTE, "enclosing ele : " + typeElement.getEnclosingElement());
238 | messager.printMessage(Diagnostic.Kind.NOTE, "kind : " + typeElement.getKind());
239 | messager.printMessage(Diagnostic.Kind.NOTE, "modifier : " + typeElement.getModifiers());
240 | messager.printMessage(Diagnostic.Kind.NOTE, "nesting kind : " + typeElement.getNestingKind());
241 | messager.printMessage(Diagnostic.Kind.NOTE, "qualified name : " + typeElement.getQualifiedName());
242 | messager.printMessage(Diagnostic.Kind.NOTE, "type parameters : " + typeElement.getTypeParameters());
243 | messager.printMessage(Diagnostic.Kind.NOTE, "super class : " + typeElement.getSuperclass());
244 | messager.printMessage(Diagnostic.Kind.NOTE, "enclosed ele : " + typeElement.getEnclosedElements());
245 | messager.printMessage(Diagnostic.Kind.NOTE, "anno mirrors : " + typeElement.getAnnotationMirrors());
246 | }
247 | messager.printMessage(Diagnostic.Kind.NOTE, "_________________ " + roundEnv.toString());
248 |
249 | Set extends Element> eleSet = roundEnv.getElementsAnnotatedWith(AutoLite.class);
250 | if (eleSet != null) {
251 | for (Element element : eleSet) {
252 |
253 | printElement(element);
254 |
255 | if (element.getKind() == ElementKind.CLASS) {
256 | TypeElement typeElement = (TypeElement) element;
257 | messager.printMessage(Diagnostic.Kind.NOTE, "_________________ CLASS " + typeElement.getSimpleName() + " _________________");
258 | messager.printMessage(Diagnostic.Kind.NOTE, "getInterfaces : " + typeElement.getInterfaces());
259 | messager.printMessage(Diagnostic.Kind.NOTE, "getNestingKind : " + typeElement.getNestingKind());
260 | messager.printMessage(Diagnostic.Kind.NOTE, "getQualifiedName : " + typeElement.getQualifiedName());
261 | messager.printMessage(Diagnostic.Kind.NOTE, "getSuperclass : " + typeElement.getSuperclass());
262 | messager.printMessage(Diagnostic.Kind.NOTE, "getTypeParameters : " + typeElement.getTypeParameters());
263 | handleClassElement(element);
264 | writeSourceFile(typeElement);
265 | //messager.printMessage(Diagnostic.Kind.NOTE, "getSourceFileName : " + getSourceFileName(typeElement));
266 |
267 | }
268 | }
269 | }
270 | }
271 |
272 | private void handleClassElement(Element element) {
273 | List extends Element> elementList = element.getEnclosedElements();
274 | if (elementList != null) {
275 | for (Element varEle : elementList) {
276 | printElement(varEle);
277 | TypeMirror mirror = varEle.asType();
278 | messager.printMessage(Diagnostic.Kind.NOTE, "------TypeMirror : " + mirror.toString());
279 | if (mirror instanceof ReferenceType) {
280 | ReferenceType rt = (ReferenceType) mirror;
281 | messager.printMessage(Diagnostic.Kind.NOTE, "------ReferenceType : " + rt);
282 | if (mirror instanceof TypeVariable) {
283 | TypeVariable tv = (TypeVariable) mirror;
284 | messager.printMessage(Diagnostic.Kind.NOTE, "------TypeVariable getLowerBound : " + tv.getLowerBound());
285 | messager.printMessage(Diagnostic.Kind.NOTE, "------TypeVariable getUpperBound : " + tv.getUpperBound());
286 | }
287 | } else if (mirror instanceof ExecutableType) {
288 | ExecutableType et = (ExecutableType) mirror;
289 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableType : " + et.getParameterTypes());
290 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableType : " + et.getReturnType());
291 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableType : " + et.getThrownTypes());
292 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableType : " + et.getTypeVariables());
293 | }
294 | if (varEle.getKind() == ElementKind.FIELD) {
295 | VariableElement ve = (VariableElement) varEle;
296 | } else if (varEle.getKind() == ElementKind.METHOD) {
297 | ExecutableElement ee = (ExecutableElement) varEle;
298 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableElement getDefaultValue : " + ee.getDefaultValue());
299 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableElement getParameters : " + ee.getParameters());
300 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableElement getReturnType : " + ee.getReturnType());
301 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableElement getThrownTypes : " + ee.getThrownTypes());
302 | messager.printMessage(Diagnostic.Kind.NOTE, "------ExecutableElement getTypeParameters : " + ee.getTypeParameters());
303 | }
304 | }
305 | }
306 | }
307 |
308 | private void printElement(Element element) {
309 | messager.printMessage(Diagnostic.Kind.NOTE, "_________________ " + element.getSimpleName() + " _________________");
310 | messager.printMessage(Diagnostic.Kind.NOTE, "class : " + element.getClass());
311 | messager.printMessage(Diagnostic.Kind.NOTE, "enclosing ele : " + element.getEnclosingElement());
312 | messager.printMessage(Diagnostic.Kind.NOTE, "kind : " + element.getKind());
313 | messager.printMessage(Diagnostic.Kind.NOTE, "modifier : " + element.getModifiers());
314 | messager.printMessage(Diagnostic.Kind.NOTE, "enclosed ele : " + element.getEnclosedElements());
315 | messager.printMessage(Diagnostic.Kind.NOTE, "anno mirrors : " + element.getAnnotationMirrors());
316 | }
317 |
318 | // String packageName = "com.litesuits.join";
319 | // String className = "WelcomeActivity$AutoLiter";
320 | // String classT = "WelcomeActivity";
321 |
322 |
323 | }
324 |
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/AutoLiter.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto;
2 |
3 | /**
4 | * 自动化代码产生接口
5 | *
6 | * @author MaTianyu @http://litesuits.com
7 | * @date 2015-12-17 16:05
8 | */
9 | public interface AutoLiter {
10 | void onCreate(T target);
11 |
12 | void onDestroy(T target);
13 | }
14 |
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/AutoMan.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto;
2 |
3 | /**
4 | * @author MaTianyu @http://litesuits.com
5 | * @date 2015-12-17 18:08
6 | */
7 | public class AutoMan {
8 |
9 | protected static String appPackageName = "com.litesuits.join";
10 |
11 | /**
12 | * Activate and execute the code that auto-generated by lite-auto.
13 | */
14 | @SuppressWarnings("unchecked")
15 | public static void activateThis(T autoTarget) {
16 | try {
17 | Class claxx = Class.forName(autoTarget.getClass().getName() + "$AutoLiter");
18 | AutoLiter autoLiter = (AutoLiter) claxx.newInstance();
19 | autoLiter.onCreate(autoTarget);
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 | }
24 |
25 | /**
26 | * Cast Object To T
27 | */
28 | public static T cast(Object object) {
29 | return (T) object;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/SourceFile.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto;
2 |
3 | import java.util.Map;
4 |
5 | import javax.lang.model.element.Element;
6 | import javax.lang.model.element.ExecutableElement;
7 |
8 | /**
9 | * @author MaTianyu on 2015-12-17 15:41, http://litesuits.com
10 | */
11 | public class SourceFile {
12 | public static final Object CLASSNAME_SUFFIX = "$AutoLiter";
13 | public static final String AUTO_WEB = " http://litesuits.com";
14 | public static final String AUTO_GENERATE = "AUTO-GENERATED FILE BY LITE-AUTO. DO NOT MODIFY.";
15 |
16 | protected String packageName;
17 | protected String className;
18 | protected String autoClass;
19 | protected Map viewElementMap;
20 | protected Map methodElementMap;
21 |
22 |
23 | public String getSourceFileName() {
24 | return packageName + "." + className;
25 | }
26 |
27 | public String getPackageName() {
28 | return packageName;
29 | }
30 |
31 | public SourceFile setPackageName(String packageName) {
32 | this.packageName = packageName;
33 | return this;
34 | }
35 |
36 | public String getClassName() {
37 | return className;
38 | }
39 |
40 | public SourceFile setClassName(String className) {
41 | this.className = className;
42 | return this;
43 | }
44 |
45 | public String getAutoClass() {
46 | return autoClass;
47 | }
48 |
49 | public SourceFile setAutoClass(String autoClass) {
50 | this.autoClass = autoClass;
51 | return this;
52 | }
53 |
54 | public Map getViewElementMap() {
55 | return viewElementMap;
56 | }
57 |
58 | public SourceFile setViewElementMap(Map viewElementMap) {
59 | this.viewElementMap = viewElementMap;
60 | return this;
61 | }
62 |
63 | public Map getMethodElementMap() {
64 | return methodElementMap;
65 | }
66 |
67 | public SourceFile setMethodElementMap(Map methodElementMap) {
68 | this.methodElementMap = methodElementMap;
69 | return this;
70 | }
71 |
72 | public String generateJava() {
73 | StringBuilder builder = new StringBuilder();
74 |
75 | // 1. build note
76 | builder.append("/* ").append(AUTO_WEB)
77 | .append("\n * ").append(AUTO_GENERATE)
78 | .append("\n */\n");
79 |
80 | // 2. build package
81 | builder.append("package ").append(packageName).append(";\n\n");
82 |
83 | // 3. build import
84 | builder.append("import android.view.View;\n")
85 | .append("import com.litesuits.auto.AutoMan;\n")
86 | .append("import com.litesuits.auto.AutoLiter;\n\n");
87 |
88 | // 4. build class starting
89 | builder.append("/** ").append(AUTO_GENERATE).append(" */\n");
90 | builder.append("public class ").append(className).append(" implements AutoLiter<")
91 | .append(autoClass).append("> {\n\n");
92 |
93 | // 5. build onCreate method
94 | builder.append(" @Override public void onCreate(final ").append(autoClass).append(" target) {\n");
95 | if (viewElementMap != null) {
96 | builder.append(" View view;\n");
97 | // build as view = target.findViewById(R.id.tvLabel);
98 | // build as target.tvLabel = AutoMan.cast(view);
99 | for (String fieldName : viewElementMap.keySet()) {
100 | builder.append(" try {\n");
101 | builder.append(" view = target.findViewById(com.litesuits.join.R.id.").append(fieldName).append(");\n");
102 | builder.append(" target.").append(fieldName).append(" = AutoMan.cast(view);\n");
103 | builder.append(" } catch (Exception e) { android.util.Log.w(\"").append(autoClass).append("\", \"")
104 | .append(fieldName).append(" Can Not Find R.id.").append(fieldName).append("\" );}\n");
105 | }
106 | builder.append("\n");
107 | }
108 | if (methodElementMap != null) {
109 | boolean isFirst = true;
110 | String setListenerString = "";
111 | builder.append(" View.OnClickListener clickListener = new View.OnClickListener() {\n")
112 | .append(" @Override public void onClick(View v) {\n");
113 | // build as if (v == target.tvLabel) {
114 | // target.clickTvLabel(v);
115 | // }
116 | // build as target.tvLabel.setOnClickListener(clickListener);
117 | for (Map.Entry en : methodElementMap.entrySet()) {
118 | String viewName = en.getKey();
119 | String methodName = en.getValue().getSimpleName().toString();
120 | if (isFirst) {
121 | builder.append(" if (v == target.").append(viewName).append(") {\n");
122 | isFirst = false;
123 | } else {
124 | builder.append(" } else if (v == target.").append(viewName).append(") {\n");
125 | }
126 | builder.append(" target.").append(methodName).append("(v);\n");
127 |
128 | setListenerString += " target." + viewName + ".setOnClickListener(clickListener);\n";
129 | }
130 | if (!isFirst) {
131 | builder.append(" }\n");
132 | }
133 | builder.append(" }\n")
134 | .append(" };\n");
135 | if (setListenerString.length() > 0) {
136 | builder.append(setListenerString);
137 | }
138 | }
139 | builder.append(" }\n\n");
140 |
141 |
142 | // 6. build onDestroy method
143 | builder.append(" @Override public void onDestroy( ").append(autoClass).append(" target) {\n");
144 | if (viewElementMap != null) {
145 | // build as target.tvLabel = null;
146 | for (String fieldName : viewElementMap.keySet()) {
147 | builder.append(" target.").append(fieldName).append(" = null;\n");
148 | }
149 | }
150 | builder.append(" }\n\n");
151 |
152 | // 7. build class ending
153 | builder.append("}");
154 | return builder.toString();
155 | }
156 |
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/anno/AutoLite.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by MaTianyu on 15/12/7.
10 | */
11 | @Retention(RetentionPolicy.CLASS)
12 | @Target(ElementType.TYPE)
13 | public @interface AutoLite {
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/anno/Bind.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author MaTianyu on 2015-12-10 14:08, http://litesuits.com
10 | */
11 | @Retention(RetentionPolicy.CLASS)
12 | @Target(ElementType.FIELD)
13 | public @interface Bind {
14 | int value();
15 | }
--------------------------------------------------------------------------------
/library/src/com/litesuits/auto/anno/UnBind.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.auto.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author MaTianyu on 2015-12-10 14:05, http://litesuits.com
10 | */
11 | @Retention(RetentionPolicy.CLASS)
12 | @Target({ElementType.FIELD, ElementType.METHOD})
13 | public @interface UnBind {
14 | }
15 |
--------------------------------------------------------------------------------
/sample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/litesuits/android-lite-tidy/24b2adbbe5c9fedad2dd3c040f33c1f01a53e9f4/sample/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/layout/main_ioc.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
23 |
24 |
31 |
32 |
39 |
40 |
44 |
45 |
52 |
53 |
60 |
61 |
68 |
69 |
76 |
77 |
81 |
82 |
89 |
90 |
97 |
98 |
105 |
106 |
113 |
114 |
118 |
119 |
120 |
127 |
128 |
135 |
136 |
143 |
144 |
145 |
152 |
153 |
157 |
158 |
165 |
166 |
173 |
174 |
181 |
182 |
189 |
190 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
--------------------------------------------------------------------------------
/sample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | sample-tidy
4 |
5 |
--------------------------------------------------------------------------------
/sample/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | com.litesuits.tidy.LiteTidyProcessor
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/$.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author MaTianyu @http://litesuits.com
10 | * @date 2015-11-26
11 | */
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Target({ElementType.FIELD, ElementType.METHOD})
14 | public @interface $ {
15 | }
16 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/AutoFind.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author MaTianyu @http://litesuits.com
10 | * @date 2015-12-01
11 | */
12 | @Retention(RetentionPolicy.CLASS)
13 | @Target(ElementType.FIELD)
14 | public @interface AutoFind {
15 | }
16 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/LiteTidy.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy;
2 |
3 | import android.app.Activity;
4 |
5 | /**
6 | * @author MaTianyu @http://litesuits.com
7 | * @date 2015-11-23
8 | */
9 | public class LiteTidy {
10 | private static final LiteTidy instance = new LiteTidy();
11 |
12 | private LiteTidy() {}
13 |
14 | public static LiteTidy getInstance() {return instance;}
15 |
16 | //public synchronized void init() {}
17 |
18 | public static LiteTidy inject(Activity activity) {
19 | instance.inject();
20 | return instance;
21 | }
22 |
23 | public LiteTidy inject() {
24 | System.out.println("inject");
25 | return instance;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/LiteTidyProcessor.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy;
2 |
3 | import android.util.Log;
4 |
5 | import javax.annotation.processing.AbstractProcessor;
6 | import javax.annotation.processing.ProcessingEnvironment;
7 | import javax.annotation.processing.RoundEnvironment;
8 | import javax.lang.model.element.TypeElement;
9 | import java.util.Set;
10 |
11 | /**
12 | * @author MaTianyu @http://litesuits.com
13 | * @date 2015-11-24
14 | */
15 | public class LiteTidyProcessor extends AbstractProcessor {
16 | private static final String TAG = LiteTidyProcessor.class.getSimpleName();
17 |
18 | @Override
19 | public synchronized void init(ProcessingEnvironment processingEnvironment) {
20 | super.init(processingEnvironment);
21 | Log.i(TAG, "init ---------------->");
22 | }
23 |
24 | @Override
25 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnvironment) {
26 | System.out.println("process ---------------->");
27 | return false;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/sample/Application.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy.sample;
2 |
3 | import com.litesuits.tidy.LiteTidy;
4 |
5 | /**
6 | * @author MaTianyu @http://litesuits.com
7 | * @date 2015-11-23
8 | */
9 | public class Application extends android.app.Application {
10 |
11 | @Override
12 | public void onCreate() {
13 | super.onCreate();
14 | //LiteTidy.inject();
15 | LiteTidy.getInstance().inject();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/sample/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import com.litesuits.tidy.$;
7 | import com.litesuits.tidy.R;
8 |
9 | import java.lang.reflect.Field;
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * @author MaTianyu @http://litesuits.com
14 | * @date 2015-11-30
15 | */
16 | public class BaseActivity extends Activity {
17 | //private String c;
18 | //protected int c1;
19 | //float c2;
20 | //public View c3;
21 | //ActivityManager c4;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 |
27 | }
28 |
29 | @Override
30 | public void setContentView(int layoutResID) {
31 | long start = System.currentTimeMillis();
32 | super.setContentView(layoutResID);
33 | long cost = System.currentTimeMillis() - start;
34 | System.out.println("setContentView cost : " + cost);
35 | start = System.currentTimeMillis();
36 | //XmlResourceParser parser = getResources().getLayout(layoutResID);
37 | System.out.println("-----------------");
38 | //Field[] fields1 = R.id.class.getDeclaredFields();
39 | //for (Field f : fields1) {
40 | // System.out.println(f.getName());
41 | //}
42 | ArrayList fields2 = getFieldsRecursive(this.getClass(), BaseActivity.class);
43 | int id = getResources().getIdentifier("tvLabel", "id", getPackageName());
44 | System.out.println("id: " + id);
45 | for (Field f : fields2) {
46 | System.out.println(f.getName());
47 | try {
48 | int resID = R.id.class.getDeclaredField(f.getName()).getInt(R.class);
49 | System.out.println("resID: " + resID);
50 | f.setAccessible(true);
51 | f.set(this, findViewById(resID));
52 | } catch (Exception e) {
53 | e.printStackTrace();
54 | }
55 | }
56 | cost = System.currentTimeMillis() - start;
57 | System.out.println("reflect time: " + cost);
58 | }
59 |
60 | /**
61 | * Populates {@code result} with fields defined by this class, its
62 | * superclasses.
63 | */
64 | private ArrayList getFieldsRecursive(Class> fromClasss, Class> toClass) {
65 | ArrayList result = new ArrayList();
66 | boolean go = true;
67 | for (Class> c = fromClasss; go && c != null; c = c.getSuperclass()) {
68 | for (Field field : c.getDeclaredFields()) {
69 | $ anno = field.getAnnotation($.class);
70 | if (anno != null && View.class.isAssignableFrom(field.getType())) {
71 | result.add(field);
72 | }
73 | }
74 | go = c != toClass;
75 | }
76 | return result;
77 | }
78 |
79 | /**
80 | * Populates {@code result} with fields defined by this class, its
81 | * superclasses.
82 | */
83 | private ArrayList getFieldsRecursive(Class> claxx) {
84 | ArrayList result = new ArrayList();
85 | for (Class> c = claxx; c != null; c = c.getSuperclass()) {
86 | for (Field field : c.getDeclaredFields()) {
87 | result.add(field);
88 | }
89 | }
90 | return result;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.TextView;
6 | import com.litesuits.auto.AutoMan;
7 | import com.litesuits.auto.anno.AutoLite;
8 | import com.litesuits.tidy.$;
9 | import com.litesuits.tidy.R;
10 |
11 | @AutoLite
12 | public class MainActivity extends BaseActivity {
13 |
14 | @$ TextView tvLabel;
15 | @$ TextView tvLabel1;
16 | @$ TextView tvLabel2;
17 | @$ TextView tvLabel3;
18 | @$ TextView tvLabel4;
19 | @$ TextView tvLabel5;
20 | @$ TextView tvLabel6;
21 | @$ TextView tvLabel7;
22 | @$ TextView tvLabel8;
23 | @$ TextView tvLabel9;
24 | @$ TextView tvLabel10;
25 | @$ TextView tvLabel11;
26 | @$ TextView tvLabel12;
27 | @$ TextView tvLabel13;
28 | @$ TextView tvLabel14;
29 | @$ TextView tvLabel15;
30 | @$ TextView tvLabel16;
31 | @$ TextView tvLabel17;
32 | @$ TextView tvLabel18;
33 | @$ TextView tvLabel19;
34 | private String b;
35 | protected int b1;
36 | float b2;
37 | public View b3, b4, b5, b6, b7;
38 |
39 | @Override
40 | public void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.main_ioc);
43 | long start = System.currentTimeMillis();
44 | tvLabel = (TextView) findViewById(R.id.tvLabel);
45 | long cost = System.currentTimeMillis() - start;
46 | System.out.println("find cost : " + cost);
47 | tvLabel.setText("Hello Lite 1!");
48 | tvLabel3.setText("Hello Lite 3!");
49 | tvLabel7.setText("Hello Lite 7!");
50 | tvLabel11.setText("Hello Lite 11!");
51 | tvLabel16.setText("Hello Lite 16!");
52 | tvLabel19.setText("Hello Lite 19!");
53 |
54 | AutoMan.activateThis(this);
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/sample/MyActivity.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy.sample;
2 |
3 | import android.app.ActivityManager;
4 | import android.os.Bundle;
5 |
6 | /**
7 | * @author MaTianyu @http://litesuits.com
8 | * @date 2015-11-30
9 | */
10 | public class MyActivity extends BaseActivity {
11 | private String a;
12 | protected int a1;
13 | float a2;
14 | //View a3;
15 | ActivityManager a4;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/sample/src/com/litesuits/tidy/test/Test.java:
--------------------------------------------------------------------------------
1 | package com.litesuits.tidy.test;
2 |
3 | import com.litesuits.tidy.$;
4 |
5 | /**
6 | * @author MaTianyu(http://litesuits.com) on 2015-06-01
7 | */
8 | public class Test {
9 |
10 | @$
11 | public static void main(String[] args) {
12 | System.out.println("hehe");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------