Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6a65ab6
Showing
56 changed files
with
14,294 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
.idea | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
编译时注解框架 | ||
|
||
TODO | ||
|
||
- [x] findViewById | ||
- [ ] 替换为javapoet https://github.com/square/javapoet | ||
- [ ] 点击事件、长按事件 | ||
- [ ] 广播 | ||
- [ ] 路由 | ||
- [ ] 动态权限 | ||
|
||
|
||
持续时间,预计到明年6月完成 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
apply plugin: 'com.android.application' | ||
android { | ||
compileSdkVersion 28 | ||
buildToolsVersion '28.0.3' | ||
defaultConfig { | ||
applicationId "com.example.huangyuan.testandroid" | ||
minSdkVersion 19 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
debug { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
|
||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
|
||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
implementation "org.permissionsdispatcher:permissionsdispatcher:4.5.0" | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
annotationProcessor "org.permissionsdispatcher:permissionsdispatcher-processor:4.5.0" | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
|
||
implementation project(':view-inject-api') | ||
implementation project(':view-inject-annotation') | ||
annotationProcessor project(':view-inject-compiler') | ||
} | ||
repositories { | ||
mavenCentral() | ||
google() | ||
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.example.huangyuan.testandroid"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<application | ||
android:name=".MyApplication" | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:resizeableActivity="true" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<activity android:name=".view.TestViewInjectActivity"></activity> | ||
<activity android:name=".view.TestPermissionsDispatcherActivity" /> | ||
<activity | ||
android:name=".view.MainActivity" | ||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" | ||
android:screenOrientation="portrait"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<action android:name="android.intent.action.VIEW" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/example/huangyuan/testandroid/MyApplication.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.huangyuan.testandroid; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
/** | ||
* Description: | ||
* Author: huangyuan | ||
* Create on: 2018/7/30. | ||
* Job number: 1800829 | ||
* Phone: 13120112517 | ||
* Email: huangyuan@chunyu.me | ||
*/ | ||
public class MyApplication extends Application { | ||
|
||
|
||
private static Context applicationContext; | ||
|
||
|
||
public static Context getContext() { | ||
return applicationContext; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
applicationContext = this; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/example/huangyuan/testandroid/annotation/BindView.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.huangyuan.testandroid.annotation; | ||
|
||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface BindView { | ||
int value() ; | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/example/huangyuan/testandroid/annotation/OnClick.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.huangyuan.testandroid.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface OnClick { | ||
|
||
int id(); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/example/huangyuan/testandroid/annotation/OnLongClick.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.huangyuan.testandroid.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
||
public @interface OnLongClick { | ||
int id(); | ||
boolean result() default true; | ||
} |
116 changes: 116 additions & 0 deletions
116
app/src/main/java/com/example/huangyuan/testandroid/view/MainActivity.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.example.huangyuan.testandroid.view; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.Toast; | ||
|
||
import com.example.huangyuan.testandroid.R; | ||
import com.example.huangyuan.testandroid.annotation.BindView; | ||
import com.example.huangyuan.testandroid.annotation.OnClick; | ||
import com.example.huangyuan.testandroid.annotation.OnLongClick; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
|
||
public class MainActivity extends Activity { | ||
@BindView(value = R.id.test_runtime_annotation) | ||
Button testRuntimeAnnotation; | ||
|
||
|
||
Toast toast; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
initAnnotation(); | ||
} | ||
|
||
@OnLongClick(id = R.id.test_runtime_annotation) | ||
void testRuntimeAnnotationOnLongClick(View v) { | ||
Toast.makeText(this, "测试运行时注解", Toast.LENGTH_LONG).show(); | ||
} | ||
|
||
@OnClick(id = R.id.test_runtime_annotation) | ||
void setTestRuntimeAnnotationOnClick(View v) { | ||
if (toast == null) { | ||
toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); | ||
} | ||
|
||
toast.setText(String.valueOf(System.currentTimeMillis())); | ||
toast.setGravity(Gravity.CENTER, 0, 0); | ||
toast.show(); | ||
} | ||
|
||
|
||
@OnClick(id = R.id.test_runtime_permission) | ||
void testRuntimePermission(View v) { | ||
startActivity(new Intent(this, TestPermissionsDispatcherActivity.class)); | ||
} | ||
|
||
@OnClick(id = R.id.test_view_inject) | ||
void testViewInject(View v) { | ||
startActivity(new Intent(this, TestViewInjectActivity.class)); | ||
} | ||
|
||
|
||
private void initAnnotation() { | ||
Field fields[] = this.getClass().getDeclaredFields(); | ||
|
||
for (Field field : fields) { | ||
field.setAccessible(true); | ||
BindView bindView = field.getAnnotation(BindView.class); | ||
if (bindView != null) { | ||
try { | ||
field.set(this, findViewById(bindView.value())); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
|
||
Method methods[] = this.getClass().getDeclaredMethods(); | ||
for (Method method : methods) { | ||
method.setAccessible(true); | ||
OnLongClick onLongClick = method.getAnnotation(OnLongClick.class); | ||
if (onLongClick != null) { | ||
findViewById(onLongClick.id()).setOnLongClickListener(new View.OnLongClickListener() { | ||
@Override | ||
public boolean onLongClick(View v) { | ||
try { | ||
method.invoke(v.getContext(), v); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return onLongClick.result(); | ||
|
||
} | ||
}); | ||
} | ||
OnClick onClick = method.getAnnotation(OnClick.class); | ||
if (onClick != null) { | ||
findViewById(onClick.id()).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
try { | ||
method.invoke(v.getContext(), v); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
Oops, something went wrong.