This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| adb shell dumpsys activity activities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Target(ElementType.TYPE_USE) | |
| public @interface Test {} | |
| public class A {} | |
| public class B extends @Test A { | |
| public @Test int add(@Test int a, @Test int b) { | |
| @Test int result = a + b; | |
| System.out.println(result); | |
| return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun groupingElementWithType(eleSet: Set<Element>): Map<TypeElement, ArrayList<Element>> { | |
| val groupedElement = HashMap<TypeElement, ArrayList<Element>>() | |
| for (item in eleSet) { | |
| checkAnnotationLegal(item) | |
| val enclosingElement = item.enclosingElement as TypeElement | |
| if (groupedElement.keys.contains(enclosingElement)) { | |
| groupedElement[enclosingElement]!!.add(item) | |
| } else { | |
| val list = ArrayList<Element>() | |
| list += item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun checkAnnotationLegal(ele: Element) { | |
| if (ele.kind != ElementKind.FIELD) { | |
| throw RuntimeException("@BindView must in filed! $ele kind is ${ele.kind}") | |
| } | |
| val modifier = ele.modifiers | |
| if (modifier.contains(Modifier.FINAL)) { | |
| throw RuntimeException("@BindView filed can not be final!") | |
| } | |
| if (modifier.contains(Modifier.PRIVATE)) { | |
| throw RuntimeException("@BindView filed can not be private") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun makeConstructor(typeElement: TypeElement): MethodSpec.Builder { | |
| val typeMirror = typeElement.asType() | |
| return MethodSpec.constructorBuilder() | |
| .addModifiers(Modifier.PUBLIC) | |
| .addParameter(TypeName.get(typeMirror), "target") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (itemView in elements) { | |
| bindMethodBuilder.addStatement("target.${itemView} = " + | |
| "target.findViewById(${itemView.getAnnotation(BindView::class.java).value})") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val typeBuilder = TypeSpec.classBuilder("${typeEle.simpleName}_Binding") | |
| .addModifiers(Modifier.PUBLIC) | |
| typeBuilder.addMethod(constructor) | |
| // Generate a Java class file | |
| val file = JavaFile.builder(getPackageName(classItem), typeBuilder.build()) | |
| .build() | |
| file.writeTo(this.processingEnv.filer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun bind(activity: Activity) { | |
| val targetClass = activity::class.java | |
| val constructor = findBindingConstructorForClass(targetClass) | |
| constructor?.newInstance(activity) | |
| } | |
| private fun findBindingConstructorForClass(cls: Class<*>?): Constructor<*>? { | |
| if (cls == null) return null | |
| var bindingConstructor: Constructor<*>? = null | |
| val clsName = cls.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client = new OkHttpClient(); | |
| Request request = new Request.Builder().url("your url").build(); | |
| // synchronously launch a request | |
| Response syncResponse = client.newCall(request).execute(); | |
| // Asynchronously launch a request | |
| client.newCall(request).enqueue(new Callback() { | |
| @Override | |
| public void onFailure(@NotNull Call call, @NotNull IOException e) { } | |
| @Override | |
| public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Interceptor { | |
| @Throws(IOException::class) | |
| fun intercept(chain: Chain): Response | |
| } |
OlderNewer