├── .gitignore
├── .idea
├── inspectionProfiles
│ └── Project_Default.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── build.gradle
├── demo-app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── yan
│ │ └── androidhippo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── yan
│ │ │ └── androidhippo
│ │ │ ├── DemoActivity.java
│ │ │ ├── activity
│ │ │ ├── BaseActivity.java
│ │ │ ├── HippoActivity.java
│ │ │ └── HippoKotlinActivity.kt
│ │ │ └── broadcast
│ │ │ ├── BaseBroadcastReceiver.java
│ │ │ ├── SyncBroadcastReceiver.java
│ │ │ └── SyncKotlinBroadcastReceiver.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_demo.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── cn
│ └── yan
│ └── androidhippo
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
├── maven-publish.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── hippo-annotations
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── cn
│ └── yan
│ └── hippo
│ └── annotations
│ ├── OnActivityResult.java
│ ├── OnKeyDown.java
│ ├── OnKeyLongPress.java
│ ├── OnKeyMultiple.java
│ ├── OnKeyShortcut.java
│ ├── OnKeyUp.java
│ ├── OnReceive.java
│ ├── OnRequestPermissionsResult.java
│ └── OnTrimMemory.java
├── hippo-compiler
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── yan
│ │ └── hippo
│ │ └── compiler
│ │ ├── JavaHippoProcessor.java
│ │ ├── KspHippoProcessor.kt
│ │ ├── common
│ │ ├── HippoProcessingStep.kt
│ │ └── HippoScope.kt
│ │ └── process
│ │ ├── ActivityFragmentAnnotationClass.java
│ │ ├── AnnotationClass.java
│ │ ├── AnnotationMethod.java
│ │ └── BroadcastReceiverAnnotationClass.java
│ └── resources
│ └── META-INF
│ ├── gradle
│ └── incremental.annotation.processors
│ └── services
│ ├── com.google.devtools.ksp.processing.SymbolProcessorProvider
│ └── javax.annotation.processing.Processor
├── hippo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── yan
│ │ └── hippo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── yan
│ │ │ └── hippo
│ │ │ ├── Hippo.java
│ │ │ └── inner
│ │ │ ├── IHippoActivityFragment.java
│ │ │ └── IHippoBroadcastReceiver.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── cn
│ └── yan
│ └── hippo
│ └── ExampleUnitTest.java
├── jitpack.yml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 yanbo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-hippo
2 |
3 | [](https://jitpack.io/#yanbober/android-hippo)
4 |
5 | 河马是一个基于依赖注解的 Android 核心 case 方法优雅写法库,避免了多 case 的 switch 或者 if 条件判断,规避了条件判断中 equals 方法潜在空指针问题。
6 |
7 | 使用 google 的 X Processing 作为中间抽象层,通过一套逻辑代码实现 annotationProcessor/kapt 与 ksp 的兼容。
8 |
9 | 特性支持情况:
10 | - 支持纯 java 项目的 annotationProcessor 模式。
11 | - 支持纯 kotlin 项目的 kapt 或 ksp 模式。
12 | - 支持 java 与 kotlin 混编项目的 kapt 或 ksp 模式。
13 |
14 | 平时写广播接收的处理是如下写法:
15 | ```java
16 | public class BaseBroadcastReceiver extends BroadcastReceiver {
17 | @Override
18 | public void onReceive(Context context, Intent intent) {
19 | String action = intent.getAction();
20 | if (Intent.ACTION_CALL.equals(action)) {
21 | Toast.makeText(context, "bcCall", Toast.LENGTH_SHORT).show();
22 | } else if (Intent.ACTION_CHOOSER.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action)) {
23 | Toast.makeText(context, "bcChooseOrBatteryLow", Toast.LENGTH_SHORT).show();
24 | } else ......
25 | }
26 | }
27 | ```
28 |
29 | 使用 android-hippo 河马后的优雅写法如下:
30 | ```java
31 | public class BaseBroadcastReceiver extends BroadcastReceiver {
32 | @OnReceive(action = {Intent.ACTION_CHOOSER, Intent.ACTION_BATTERY_LOW})
33 | public void bcChooseOrBatteryLow(Context context, Intent intent) {
34 | Toast.makeText(context, "bcChooseOrBatteryLow", Toast.LENGTH_SHORT).show();
35 | }
36 |
37 | @OnReceive(action = Intent.ACTION_CALL)
38 | public void bcCall(Context context, Intent intent) {
39 | Toast.makeText(context, "bcCall", Toast.LENGTH_SHORT).show();
40 | }
41 |
42 | @Override
43 | public void onReceive(Context context, Intent intent) {
44 | Hippo.onReceive(this, context, intent);
45 | }
46 | }
47 | ```
48 | 其他更多 case 支持参见 API 列表。
49 |
50 | ## 配置
51 |
52 | 在你的 root build.gradle 中添加如下脚本片段:
53 | ```gradle
54 | allprojects {
55 | repositories {
56 | ...
57 | maven { url 'https://jitpack.io' }
58 | }
59 | }
60 | ```
61 |
62 | 在你需要用 andrond-hippo 的模块添加如下依赖片段:
63 | ```gradle
64 | dependencies {
65 | compile 'com.github.yanbober.android-hippo:hippo:[VERSION]'
66 | annotationProcessor 'com.github.yanbober.android-hippo:hippo-compiler:[VERSION]' //java
67 | kapt 'com.github.yanbober.android-hippo:hippo-compiler:[VERSION]' //kotlin & java
68 | ksp 'com.github.yanbober.android-hippo:hippo-compiler:[VERSION]' //kotlin & java
69 | }
70 | ```
71 |
72 | ## 使用
73 |
74 | 具体所有 API 样例可参见 demo-app 中详细示范。
75 |
76 | ## API 列表
77 |
78 | |case 注解名|Android 库方法名|
79 | |----|----|
80 | |@OnActivityResult|onActivityResult(int requestCode, int resultCode, Intent data)|
81 | |@OnRequestPermissionsResult|onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)|
82 | |@OnTrimMemory|onTrimMemory(int level)|
83 | |@OnKeyDown|onKeyDown(int keyCode, KeyEvent event)|
84 | |@OnKeyUp|onKeyUp(int keyCode, KeyEvent event)|
85 | |@OnKeyLongPress|onKeyLongPress(int keyCode, KeyEvent event)|
86 | |@OnKeyMultiple|onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)|
87 | |@OnKeyShortcut|onKeyShortcut(int keyCode, KeyEvent event)|
88 | |@OnReceive|onReceive(Context context, Intent intent)|
89 |
90 |
91 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | mavenCentral()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:7.1.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20"
13 | classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.6.21-1.0.5"
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | maven { url 'https://jitpack.io' }
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/demo-app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo-app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | apply plugin: 'com.google.devtools.ksp'
5 |
6 | android {
7 | compileSdkVersion 30
8 | defaultConfig {
9 | applicationId "cn.yan.androidhippo"
10 | minSdkVersion 14
11 | targetSdkVersion 30
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.20"
27 | implementation 'com.android.support:appcompat-v7:26.1.0'
28 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
32 |
33 | implementation project(':hippo')
34 | implementation project(':hippo-annotations')
35 | // annotationProcessor project(':hippo-compiler')
36 | // kapt project(':hippo-compiler')
37 | ksp project(':hippo-compiler')
38 | }
39 |
--------------------------------------------------------------------------------
/demo-app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/demo-app/src/androidTest/java/cn/yan/androidhippo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.yan.androidhippo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/demo-app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import cn.yan.androidhippo.activity.HippoActivity;
8 | import cn.yan.androidhippo.activity.HippoKotlinActivity;
9 | import cn.yan.androidhippo.broadcast.SyncBroadcastReceiver;
10 | import cn.yan.androidhippo.broadcast.SyncKotlinBroadcastReceiver;
11 |
12 | /**
13 | * Demo for Hippo use.
14 | */
15 | public class DemoActivity extends AppCompatActivity implements View.OnClickListener {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_demo);
21 |
22 | findViewById(R.id.activty_state_test).setOnClickListener(this);
23 | findViewById(R.id.sync_bc_test).setOnClickListener(this);
24 |
25 | findViewById(R.id.activty_state_test_kotlin).setOnClickListener(this);
26 | findViewById(R.id.sync_bc_test_kotlin).setOnClickListener(this);
27 | }
28 |
29 | @Override
30 | public void onClick(View v) {
31 | switch (v.getId()) {
32 | case R.id.activty_state_test:
33 | startActivity(new Intent(this, HippoActivity.class));
34 | break;
35 | case R.id.sync_bc_test:
36 | sendBroadcast(new Intent(SyncBroadcastReceiver.ACTION_TEST));
37 | break;
38 | case R.id.activty_state_test_kotlin:
39 | startActivity(new Intent(this, HippoKotlinActivity.class));
40 | break;
41 | case R.id.sync_bc_test_kotlin:
42 | sendBroadcast(new Intent(SyncKotlinBroadcastReceiver.ACTION_TEST));
43 | break;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.support.annotation.NonNull;
6 | import android.view.KeyEvent;
7 | import cn.yan.hippo.Hippo;
8 |
9 | /**
10 | * Demo for activity base Hippo.
11 | */
12 |
13 | public class BaseActivity extends Activity {
14 | @Override
15 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
16 | Hippo.onActivityResult(this, requestCode, resultCode, data);
17 | }
18 |
19 | @Override
20 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
21 | Hippo.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
22 | }
23 |
24 | @Override
25 | public void onTrimMemory(int level) {
26 | Hippo.onTrimMemory(this, level);
27 | }
28 |
29 | @Override
30 | public boolean onKeyDown(int keyCode, KeyEvent event) {
31 | return Hippo.onKeyDown(this, keyCode, event);
32 | }
33 |
34 | @Override
35 | public boolean onKeyUp(int keyCode, KeyEvent event) {
36 | return Hippo.onKeyUp(this, keyCode, event);
37 | }
38 |
39 | @Override
40 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
41 | return Hippo.onKeyLongPress(this, keyCode, event);
42 | }
43 |
44 | @Override
45 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
46 | return Hippo.onKeyMultiple(this, keyCode, repeatCount, event);
47 | }
48 |
49 | @Override
50 | public boolean onKeyShortcut(int keyCode, KeyEvent event) {
51 | return Hippo.onKeyShortcut(this, keyCode, event);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/activity/HippoActivity.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.util.Log;
6 | import android.view.KeyEvent;
7 | import cn.yan.hippo.annotations.OnActivityResult;
8 | import cn.yan.hippo.annotations.OnKeyDown;
9 | import cn.yan.hippo.annotations.OnKeyLongPress;
10 | import cn.yan.hippo.annotations.OnKeyMultiple;
11 | import cn.yan.hippo.annotations.OnKeyShortcut;
12 | import cn.yan.hippo.annotations.OnKeyUp;
13 | import cn.yan.hippo.annotations.OnRequestPermissionsResult;
14 | import cn.yan.hippo.annotations.OnTrimMemory;
15 |
16 | /**
17 | * Demo for activity simple.
18 | */
19 |
20 | public class HippoActivity extends BaseActivity {
21 | private static final String TAG = "HippoActivity";
22 |
23 | /*******************************************************
24 | * {@link OnActivityResult}
25 | ******************************************************/
26 |
27 | @OnActivityResult(requestCode = 23)
28 | public void resultHandle1(int resultCode, Intent data) {
29 | Log.i(TAG, "resultHandle1");
30 | }
31 |
32 | @OnActivityResult(requestCode = {24, 25})
33 | public void resultHandle2(int resultCode, Intent data) {
34 | Log.i(TAG, "resultHandle2");
35 | }
36 |
37 | /*******************************************************
38 | * {@link OnRequestPermissionsResult}
39 | ******************************************************/
40 |
41 | @OnRequestPermissionsResult(requestCode = 77777)
42 | public void permissionsResult1(String[] permissions, int[] grantResults) {
43 | Log.i(TAG, "permissionsResult1");
44 | }
45 |
46 | @OnRequestPermissionsResult(requestCode = {77778, 77779})
47 | public void permissionsResult2(String[] permissions, int[] grantResults) {
48 | Log.i(TAG, "permissionsResult2");
49 | }
50 |
51 | /*******************************************************
52 | * {@link OnKeyDown}
53 | ******************************************************/
54 |
55 | @OnKeyDown(keyCode = KeyEvent.ACTION_DOWN)
56 | public boolean onKeyDown1(int keyCode, KeyEvent event) {
57 | Log.i(TAG, "onKeyDown1");
58 | return true;
59 | }
60 |
61 | @OnKeyDown(keyCode = {KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK})
62 | public boolean onKeyDown2(int keyCode, KeyEvent event) {
63 | Log.i(TAG, "onKeyDown2");
64 | return true;
65 | }
66 |
67 | /*******************************************************
68 | * {@link OnKeyLongPress}
69 | ******************************************************/
70 | @OnKeyLongPress(keyCode = {KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK})
71 | public boolean onKeyLongPress1(int keyCode, KeyEvent event) {
72 | Log.i(TAG, "onKeyLongPress1");
73 | return true;
74 | }
75 |
76 | @OnKeyLongPress(keyCode = KeyEvent.ACTION_DOWN)
77 | public boolean onKeyLongPress2(int keyCode, KeyEvent event) {
78 | Log.i(TAG, "onKeyLongPress2");
79 | return true;
80 | }
81 |
82 | /*******************************************************
83 | * {@link OnKeyMultiple}
84 | ******************************************************/
85 |
86 | @OnKeyMultiple(keyCode = {KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK})
87 | public boolean OnKeyMultiple1(int keyCode, int repeatCount, KeyEvent event) {
88 | Log.i(TAG, "OnKeyMultiple1");
89 | return true;
90 | }
91 |
92 | @OnKeyMultiple(keyCode = KeyEvent.ACTION_DOWN)
93 | public boolean OnKeyMultiple2(int keyCode, int repeatCount, KeyEvent event) {
94 | Log.i(TAG, "OnKeyMultiple2");
95 | return true;
96 | }
97 |
98 | /*******************************************************
99 | * {@link OnKeyShortcut}
100 | ******************************************************/
101 |
102 | @OnKeyShortcut(keyCode = {KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK})
103 | public boolean OnKeyShortcut1(int keyCode, KeyEvent event) {
104 | Log.i(TAG, "OnKeyShortcut1");
105 | return true;
106 | }
107 |
108 | @OnKeyShortcut(keyCode = KeyEvent.ACTION_DOWN)
109 | public boolean OnKeyShortcut2(int keyCode, KeyEvent event) {
110 | Log.i(TAG, "OnKeyShortcut2");
111 | return true;
112 | }
113 |
114 | /*******************************************************
115 | * {@link OnKeyUp}
116 | ******************************************************/
117 |
118 | @OnKeyUp(keyCode = KeyEvent.KEYCODE_Y)
119 | public boolean onKeyUp1(int keyCode, KeyEvent event) {
120 | Log.i(TAG, "onKeyUp1");
121 | return true;
122 | }
123 |
124 | @OnKeyUp(keyCode = {KeyEvent.KEYCODE_X, KeyEvent.KEYCODE_Q})
125 | public boolean onKeyUp2(int keyCode, KeyEvent event) {
126 | Log.i(TAG, "onKeyUp2");
127 | return true;
128 | }
129 |
130 | /*******************************************************
131 | * {@link OnTrimMemory}
132 | ******************************************************/
133 |
134 | @OnTrimMemory(level = Activity.TRIM_MEMORY_RUNNING_MODERATE)
135 | public void onTrimMemory1(int level) {
136 | Log.i(TAG, "onTrimMemory1");
137 | }
138 |
139 | @OnTrimMemory(level = {
140 | Activity.TRIM_MEMORY_BACKGROUND,
141 | Activity.TRIM_MEMORY_RUNNING_LOW
142 | })
143 | public void onTrimMemory2(int level) {
144 | Log.i(TAG, "onTrimMemory2");
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/activity/HippoKotlinActivity.kt:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.activity
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.util.Log
6 | import android.view.KeyEvent
7 | import cn.yan.hippo.annotations.OnActivityResult
8 | import cn.yan.hippo.annotations.OnKeyDown
9 | import cn.yan.hippo.annotations.OnKeyLongPress
10 | import cn.yan.hippo.annotations.OnKeyMultiple
11 | import cn.yan.hippo.annotations.OnKeyShortcut
12 | import cn.yan.hippo.annotations.OnKeyUp
13 | import cn.yan.hippo.annotations.OnRequestPermissionsResult
14 | import cn.yan.hippo.annotations.OnTrimMemory
15 |
16 | /**
17 | * Demo for kotlin activity simple.
18 | */
19 |
20 | class HippoKotlinActivity: BaseActivity() {
21 | companion object {
22 | private const val TAG = "HippoKotlinActivity"
23 | }
24 |
25 | /*******************************************************
26 | * {@link OnActivityResult}
27 | ******************************************************/
28 |
29 | @OnActivityResult(requestCode = [23])
30 | fun resultHandle1(resultCode: Int, data: Intent) {
31 | Log.i(TAG, "resultHandle1 resultCode=${resultCode} data=${data}")
32 | }
33 |
34 | @OnActivityResult(requestCode = [24, 25])
35 | fun resultHandle2(resultCode: Int, data: Intent) {
36 | Log.i(TAG, "resultHandle2 resultCode=${resultCode} data=${data}")
37 | }
38 |
39 | /*******************************************************
40 | * {@link OnRequestPermissionsResult}
41 | ******************************************************/
42 |
43 | @OnRequestPermissionsResult(requestCode = [77777])
44 | fun permissionsResult1(permissions: Array, grantResults: IntArray) {
45 | Log.i(TAG, "permissionsResult1 permissions=${permissions} grantResults=${grantResults}")
46 | }
47 |
48 | @OnRequestPermissionsResult(requestCode = [77778, 77779])
49 | fun permissionsResult2(permissions: Array, grantResults: IntArray) {
50 | Log.i(TAG, "permissionsResult2 permissions=${permissions} grantResults=${grantResults}")
51 | }
52 |
53 | /*******************************************************
54 | * {@link OnKeyDown}
55 | ******************************************************/
56 |
57 | @OnKeyDown(keyCode = [KeyEvent.ACTION_DOWN])
58 | fun onKeyDown1(keyCode: Int, event: KeyEvent): Boolean {
59 | Log.i(TAG, "onKeyDown1 keyCode=${keyCode} event=${event}")
60 | return false
61 | }
62 |
63 | @OnKeyDown(keyCode = [KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK])
64 | fun onKeyDown2(keyCode: Int, event: KeyEvent): Boolean {
65 | Log.i(TAG, "onKeyDown2 keyCode=${keyCode} event=${event}")
66 | return true
67 | }
68 |
69 | /*******************************************************
70 | * {@link OnKeyLongPress}
71 | ******************************************************/
72 | @OnKeyLongPress(keyCode = [KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK])
73 | fun onKeyLongPress1(keyCode: Int, event: KeyEvent): Boolean {
74 | Log.i(TAG, "onKeyLongPress1 keyCode=${keyCode} event=${event}")
75 | return false
76 | }
77 |
78 | @OnKeyLongPress(keyCode = [KeyEvent.ACTION_DOWN])
79 | fun onKeyLongPress2(keyCode: Int, event: KeyEvent): Boolean {
80 | Log.i(TAG, "onKeyLongPress2 keyCode=${keyCode} event=${event}")
81 | return false
82 | }
83 |
84 | /*******************************************************
85 | * {@link OnKeyMultiple}
86 | ******************************************************/
87 |
88 | @OnKeyMultiple(keyCode = [KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK])
89 | fun OnKeyMultiple1(keyCode: Int, repeatCount: Int, event: KeyEvent): Boolean {
90 | Log.i(TAG, "OnKeyMultiple1 keyCode=${keyCode} repeatCount=${repeatCount} event=${event}")
91 | return false
92 | }
93 |
94 | @OnKeyMultiple(keyCode = [KeyEvent.ACTION_DOWN])
95 | fun OnKeyMultiple2(keyCode: Int, repeatCount: Int, event: KeyEvent): Boolean {
96 | Log.i(TAG, "OnKeyMultiple2 keyCode=${keyCode} repeatCount=${repeatCount} event=${event}")
97 | return false
98 | }
99 |
100 | /*******************************************************
101 | * {@link OnKeyShortcut}
102 | ******************************************************/
103 |
104 | @OnKeyShortcut(keyCode = [KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK])
105 | fun OnKeyShortcut1(keyCode: Int, event: KeyEvent): Boolean {
106 | Log.i(TAG, "OnKeyShortcut1 keyCode=${keyCode} event=${event}")
107 | return false
108 | }
109 |
110 | @OnKeyShortcut(keyCode = [KeyEvent.ACTION_DOWN])
111 | fun OnKeyShortcut2(keyCode: Int, event: KeyEvent): Boolean {
112 | Log.i(TAG, "OnKeyShortcut2 keyCode=${keyCode} event=${event}")
113 | return false
114 | }
115 |
116 | /*******************************************************
117 | * {@link OnKeyUp}
118 | ******************************************************/
119 |
120 | @OnKeyUp(keyCode = [KeyEvent.KEYCODE_Y])
121 | fun onKeyUp1(keyCode: Int, event: KeyEvent): Boolean {
122 | Log.i(TAG, "onKeyUp1 keyCode=${keyCode} event=${event}")
123 | return false
124 | }
125 |
126 | @OnKeyUp(keyCode = [KeyEvent.KEYCODE_X, KeyEvent.KEYCODE_Q])
127 | fun onKeyUp2(keyCode: Int, event: KeyEvent): Boolean {
128 | Log.i(TAG, "onKeyUp2 keyCode=${keyCode} event=${event}")
129 | return false
130 | }
131 |
132 | /*******************************************************
133 | * {@link OnTrimMemory}
134 | ******************************************************/
135 |
136 | @OnTrimMemory(level = [Activity.TRIM_MEMORY_RUNNING_MODERATE])
137 | fun onTrimMemory1(level: Int) {
138 | Log.i(TAG, "onTrimMemory1 level=${level}")
139 | }
140 |
141 | @OnTrimMemory(level = [
142 | Activity.TRIM_MEMORY_BACKGROUND,
143 | Activity.TRIM_MEMORY_RUNNING_LOW
144 | ])
145 | fun onTrimMemory2(level: Int) {
146 | Log.i(TAG, "onTrimMemory2 level=${level}")
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/broadcast/BaseBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.broadcast;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import cn.yan.hippo.Hippo;
7 |
8 | /**
9 | * Demo for BroadcastReceiver base Hippo.
10 | */
11 |
12 | public class BaseBroadcastReceiver extends BroadcastReceiver {
13 | @Override
14 | public void onReceive(Context context, Intent intent) {
15 | Hippo.onReceive(this, context, intent);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/broadcast/SyncBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.broadcast;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.widget.Toast;
6 | import cn.yan.hippo.annotations.OnReceive;
7 |
8 | /**
9 | * Demo for BroadcastReceiver simple.
10 | */
11 |
12 | public class SyncBroadcastReceiver extends BaseBroadcastReceiver {
13 | public static final String ACTION_TEST = "cn.yan.demo.test.actionTest";
14 |
15 | @OnReceive(action = ACTION_TEST)
16 | public void bcActionTest(Context context, Intent intent) {
17 | Toast.makeText(context, "bcActionTest", Toast.LENGTH_SHORT).show();
18 | }
19 |
20 | @OnReceive(action = {Intent.ACTION_CHOOSER, Intent.ACTION_BATTERY_LOW})
21 | public void bcChooseOrBatteryLow(Context context, Intent intent) {
22 | Toast.makeText(context, "bcChooseOrBatteryLow", Toast.LENGTH_SHORT).show();
23 | }
24 |
25 | @OnReceive(action = Intent.ACTION_CALL)
26 | public void bcCall(Context context, Intent intent) {
27 | Toast.makeText(context, "bcCall", Toast.LENGTH_SHORT).show();
28 | }
29 |
30 | @OnReceive(action = "cn.yan.demo.XXXXXX")
31 | public void bcXxxxxx(Context context, Intent intent) {
32 | Toast.makeText(context, "bcXxxxxx", Toast.LENGTH_SHORT).show();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/demo-app/src/main/java/cn/yan/androidhippo/broadcast/SyncKotlinBroadcastReceiver.kt:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo.broadcast
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.widget.Toast
6 | import cn.yan.hippo.annotations.OnReceive
7 |
8 | /**
9 | * Demo for kotlin BroadcastReceiver simple.
10 | */
11 |
12 | class SyncKotlinBroadcastReceiver: BaseBroadcastReceiver() {
13 | companion object {
14 | const val ACTION_TEST = "cn.yan.demo.test.actionKotlinTest"
15 | }
16 |
17 | @OnReceive(action = [ACTION_TEST])
18 | fun bcActionTest(context: Context, intent: Intent) {
19 | Toast.makeText(context, "bcActionTest intent=${intent}", Toast.LENGTH_SHORT).show()
20 | }
21 |
22 | @OnReceive(action = [Intent.ACTION_CHOOSER, Intent.ACTION_BATTERY_LOW])
23 | fun bcChooseOrBatteryLow(context: Context, intent: Intent) {
24 | Toast.makeText(context, "bcChooseOrBatteryLow intent=${intent}", Toast.LENGTH_SHORT).show()
25 | }
26 |
27 | @OnReceive(action = [Intent.ACTION_CALL])
28 | fun bcCall(context: Context, intent: Intent) {
29 | Toast.makeText(context, "bcCall intent=${intent}", Toast.LENGTH_SHORT).show()
30 | }
31 |
32 | @OnReceive(action = ["cn.yan.demo.XXXXXX"])
33 | fun bcXxxxxx(context: Context, intent: Intent) {
34 | Toast.makeText(context, "bcXxxxxx intent=${intent}", Toast.LENGTH_SHORT).show()
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
25 |
26 |
32 |
33 |
39 |
40 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/demo-app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidHippo
3 |
4 |
--------------------------------------------------------------------------------
/demo-app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/demo-app/src/test/java/cn/yan/androidhippo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.androidhippo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | android.injected.testOnly=false
19 | android.useAndroidX=true
20 | android.disableAutomaticComponentCreation=true
21 |
22 | # gradle.properties for debugging
23 | #kotlin.build.report.enable=true
24 | #kotlin.build.report.verbose=true
25 |
26 | # gradle property for metrics
27 | #kotlin.build.report.metrics=true
28 |
--------------------------------------------------------------------------------
/gradle/maven-publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 |
3 | afterEvaluate {
4 | publishing {
5 | publications {
6 | release(MavenPublication) {
7 | groupId = 'com.github.yanbober'
8 | artifactId = project.name
9 | version = project.version
10 | }
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/android-hippo/b5dcaa99f3336d5bd6f424a5c84732356a51ee62/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 13 09:57:57 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/hippo-annotations/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/hippo-annotations/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | }
6 |
7 | apply from: rootProject.file('gradle/maven-publish.gradle')
8 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnActivityResult.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnActivityResult {
34 | int[] requestCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnKeyDown.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnKeyDown {
34 | int[] keyCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnKeyLongPress.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnKeyLongPress {
34 | int[] keyCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnKeyMultiple.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnKeyMultiple {
34 | int[] keyCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnKeyShortcut.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnKeyShortcut {
34 | int[] keyCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnKeyUp.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnKeyUp {
34 | int[] keyCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnReceive.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnReceive {
34 | String[] action();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnRequestPermissionsResult.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnRequestPermissionsResult {
34 | int[] requestCode();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-annotations/src/main/java/cn/yan/hippo/annotations/OnTrimMemory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.annotations;
25 |
26 | import java.lang.annotation.ElementType;
27 | import java.lang.annotation.Retention;
28 | import java.lang.annotation.RetentionPolicy;
29 | import java.lang.annotation.Target;
30 |
31 | @Target(ElementType.METHOD)
32 | @Retention(RetentionPolicy.SOURCE)
33 | public @interface OnTrimMemory {
34 | int[] level();
35 | }
36 |
--------------------------------------------------------------------------------
/hippo-compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/hippo-compiler/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java-library'
3 | id 'org.jetbrains.kotlin.jvm'
4 | }
5 |
6 | dependencies {
7 | implementation fileTree(dir: 'libs', include: ['*.jar'])
8 | implementation("androidx.room:room-compiler-processing:2.4.2")
9 | implementation "com.google.devtools.ksp:symbol-processing:1.6.21-1.0.5"
10 | implementation 'com.google.devtools.ksp:symbol-processing-api:1.6.21-1.0.5'
11 | implementation 'com.squareup:javapoet:1.10.0'
12 | implementation project(':hippo-annotations')
13 | }
14 |
15 | apply from: rootProject.file('gradle/maven-publish.gradle')
16 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/JavaHippoProcessor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler;
25 |
26 | import androidx.room.compiler.processing.XMessager;
27 | import androidx.room.compiler.processing.XProcessingEnv;
28 | import androidx.room.compiler.processing.XProcessingStep;
29 | import androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor;
30 | import org.jetbrains.annotations.NotNull;
31 | import java.util.ArrayList;
32 | import java.util.List;
33 | import cn.yan.hippo.compiler.common.HippoProcessingStep;
34 |
35 | /**
36 | * Hippo compile process.
37 | */
38 | public final class JavaHippoProcessor extends JavacBasicAnnotationProcessor {
39 | private XMessager xMessager;
40 |
41 | @Override
42 | public void initialize(@NotNull XProcessingEnv env) {
43 | super.initialize(env);
44 | this.xMessager = env.getMessager();
45 | }
46 |
47 | @NotNull
48 | @Override
49 | public Iterable processingSteps() {
50 | List steps = new ArrayList<>();
51 | steps.add(new HippoProcessingStep(this.xMessager));
52 | return steps;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/KspHippoProcessor.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2022 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler
25 |
26 | import androidx.room.compiler.processing.ExperimentalProcessingApi
27 | import androidx.room.compiler.processing.XMessager
28 | import androidx.room.compiler.processing.XProcessingEnv
29 | import androidx.room.compiler.processing.XProcessingStep
30 | import androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor
31 | import cn.yan.hippo.compiler.common.HippoProcessingStep
32 | import com.google.devtools.ksp.processing.SymbolProcessor
33 | import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
34 | import com.google.devtools.ksp.processing.SymbolProcessorProvider
35 |
36 | /**
37 | * SymbolProcessorProvider for KSP entry point.
38 | */
39 | class HippoProcessorProvider: SymbolProcessorProvider {
40 | override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
41 | return KspHippoProcessor(environment)
42 | }
43 | }
44 |
45 | /**
46 | * a KSP SymbolProcessor for HippoProcessorProvider invoke.
47 | */
48 | class KspHippoProcessor(environment: SymbolProcessorEnvironment): KspBasicAnnotationProcessor(environment) {
49 | private lateinit var xMessager: XMessager
50 |
51 | @OptIn(ExperimentalProcessingApi::class)
52 | override fun initialize(env: XProcessingEnv) {
53 | super.initialize(env)
54 | this.xMessager = env.messager
55 | }
56 |
57 | override fun processingSteps(): Iterable {
58 | return listOf(HippoProcessingStep(this.xMessager))
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/common/HippoProcessingStep.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2022 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler.common
25 |
26 | import androidx.room.compiler.processing.*
27 | import cn.yan.hippo.annotations.*
28 | import cn.yan.hippo.compiler.process.ActivityFragmentAnnotationClass
29 | import cn.yan.hippo.compiler.process.AnnotationClass
30 | import cn.yan.hippo.compiler.process.BroadcastReceiverAnnotationClass
31 | import com.squareup.javapoet.ClassName
32 | import javax.tools.Diagnostic
33 | import kotlin.reflect.KClass
34 |
35 | /**
36 | * a XProcessingStep for X Processing.
37 | * @author yanbo1
38 | */
39 | class HippoProcessingStep(private val xMessager: XMessager): XProcessingStep {
40 | override fun annotations(): Set {
41 | return getSupportedAnnotations()
42 | }
43 |
44 | @ExperimentalProcessingApi
45 | override fun process(env: XProcessingEnv, elementsByAnnotation: Map>
46 | ): Set {
47 | printWaring("XProcessingStep start processing...")
48 | val targetClassMap: Map = createAssignedMethodAnnotations(elementsByAnnotation)
49 | for (annotationClass in targetClassMap.values) {
50 | try {
51 | env.filer.write(annotationClass.generateJavaFile())
52 | } catch (e: Exception) {
53 | printError(e.message)
54 | }
55 | }
56 | printWaring("XProcessingStep end processing...")
57 | return emptySet()
58 | }
59 |
60 | private fun createAssignedMethodAnnotations(elementsByAnnotation: Map>): Map {
61 | val targetClassMap: MutableMap = LinkedHashMap()
62 | parseActivityFragmentMethodAnnotations(targetClassMap, elementsByAnnotation)
63 | parseBroadcastMethodAnnotations(targetClassMap, elementsByAnnotation)
64 | return targetClassMap
65 | }
66 |
67 | private fun parseBroadcastMethodAnnotations(
68 | targetClassMap: MutableMap,
69 | elementsByAnnotation: Map>
70 | ) {
71 | val onReceiveElements = elementsByAnnotation[OnReceive::class.java.name] ?: return
72 | for (element in onReceiveElements) {
73 | if (!element.validate()) {
74 | continue
75 | }
76 | try {
77 | if (!element.isMethod()) {
78 | printError(element, "Hippo annotations can only be applied to method!")
79 | break
80 | }
81 | val enclosingElement = element.enclosingElement as XTypeElement
82 | var annotationClass = targetClassMap[enclosingElement]
83 | if (annotationClass == null) {
84 | val classPackage = enclosingElement.packageName
85 | val className = getClassName(enclosingElement, classPackage) + "_HippoProxy"
86 | val targetType = enclosingElement.qualifiedName
87 | annotationClass =
88 | BroadcastReceiverAnnotationClass(classPackage, className, targetType)
89 | targetClassMap[enclosingElement] = annotationClass
90 | }
91 | val methodName = element.name
92 | val annotation: XAnnotation = element.getAnnotation(ClassName.get(OnReceive::class.java))!!
93 | annotationClass.create(methodName, annotation)
94 | } catch (e: Exception) {
95 | printError(element, e.message)
96 | }
97 | }
98 | }
99 |
100 | private fun parseActivityFragmentMethodAnnotations(
101 | targetClassMap: MutableMap,
102 | elementsByAnnotation: Map>
103 | ) {
104 | val annotations: MutableSet> = LinkedHashSet()
105 | annotations.add(OnTrimMemory::class)
106 | annotations.add(OnKeyDown::class)
107 | annotations.add(OnKeyUp::class)
108 | annotations.add(OnKeyLongPress::class)
109 | annotations.add(OnKeyMultiple::class)
110 | annotations.add(OnKeyShortcut::class)
111 | annotations.add(OnActivityResult::class)
112 | annotations.add(OnRequestPermissionsResult::class)
113 | for (supported in annotations) {
114 | val supportedElements = elementsByAnnotation[supported.java.name] ?: continue
115 | for (element in supportedElements) {
116 | if (!element.validate()) {
117 | continue
118 | }
119 | try {
120 | if (!element.isMethod()) {
121 | printError(element, "Hippo annotations can only be applied to method!")
122 | break
123 | }
124 | val enclosingElement = element.enclosingElement as XTypeElement
125 | var annotationClass = targetClassMap[enclosingElement]
126 | if (annotationClass == null) {
127 | val classPackage = enclosingElement.packageName
128 | val className = getClassName(enclosingElement, classPackage) + "_HippoProxy"
129 | val targetType = enclosingElement.qualifiedName
130 | annotationClass =
131 | ActivityFragmentAnnotationClass(classPackage, className, targetType)
132 | targetClassMap[enclosingElement] = annotationClass
133 | }
134 | val methodName = element.name
135 | val annotation: XAnnotation = element.getAnnotation(ClassName.get(supported.java))!!
136 | annotationClass.create(methodName, annotation)
137 | } catch (e: Exception) {
138 | printError(element, e.message)
139 | }
140 | }
141 | }
142 | }
143 |
144 | private fun printError(element: XElement, msg: String?, vararg args: Any) {
145 | xMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg!!, *args), element)
146 | }
147 |
148 | private fun printError(msg: String?, vararg args: Any) {
149 | xMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg!!, *args))
150 | }
151 |
152 | private fun printWaring(msg: String?, vararg args: Any) {
153 | xMessager.printMessage(Diagnostic.Kind.WARNING, String.format(msg!!, *args))
154 | }
155 |
156 | private fun getClassName(typeElement: XTypeElement, packageName: String): String {
157 | val packageLength = packageName.length + 1
158 | return typeElement.qualifiedName.substring(packageLength).replace(".", "$")
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/common/HippoScope.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2022 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler.common
25 |
26 | import cn.yan.hippo.annotations.*
27 |
28 | /**
29 | *
30 | * @author yanbo1
31 | */
32 |
33 | internal fun getSupportedAnnotations(): Set {
34 | return setOf(
35 | OnTrimMemory::class.java.name,
36 | OnKeyDown::class.java.name,
37 | OnKeyUp::class.java.name,
38 | OnKeyLongPress::class.java.name,
39 | OnKeyMultiple::class.java.name,
40 | OnKeyShortcut::class.java.name,
41 | OnActivityResult::class.java.name,
42 | OnRequestPermissionsResult::class.java.name,
43 | OnReceive::class.java.name,
44 | )
45 | }
46 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/process/ActivityFragmentAnnotationClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler.process;
25 |
26 | import androidx.room.compiler.processing.XAnnotation;
27 | import com.squareup.javapoet.ClassName;
28 | import com.squareup.javapoet.MethodSpec;
29 | import com.squareup.javapoet.ParameterizedTypeName;
30 | import com.squareup.javapoet.TypeName;
31 | import com.squareup.javapoet.TypeVariableName;
32 | import java.util.ArrayList;
33 | import java.util.List;
34 | import javax.lang.model.element.Modifier;
35 | import cn.yan.hippo.annotations.OnActivityResult;
36 | import cn.yan.hippo.annotations.OnKeyDown;
37 | import cn.yan.hippo.annotations.OnKeyLongPress;
38 | import cn.yan.hippo.annotations.OnKeyMultiple;
39 | import cn.yan.hippo.annotations.OnKeyShortcut;
40 | import cn.yan.hippo.annotations.OnKeyUp;
41 | import cn.yan.hippo.annotations.OnRequestPermissionsResult;
42 | import cn.yan.hippo.annotations.OnTrimMemory;
43 |
44 | /**
45 | * create Activity or Fragment or other proxy java file.
46 | */
47 |
48 | public final class ActivityFragmentAnnotationClass extends AnnotationClass {
49 | public ActivityFragmentAnnotationClass(String classPackage, String className, String targetType) {
50 | super(classPackage, className, targetType);
51 | }
52 |
53 | @Override
54 | protected List generateSuperInterface() {
55 | List typeNameList = new ArrayList<>();
56 |
57 | ClassName iHippoActivityFragment = ClassName.get("cn.yan.hippo.inner", "IHippoActivityFragment");
58 | TypeName typeName = ParameterizedTypeName.get(iHippoActivityFragment, TypeVariableName.get("T"));
59 |
60 | typeNameList.add(typeName);
61 | return typeNameList;
62 | }
63 |
64 | @Override
65 | protected List generateMethods() {
66 | List methodSpecList = new ArrayList<>();
67 |
68 | methodSpecList.add(generateOnActivityResultMethod());
69 | methodSpecList.add(generateOnRequestPermissionResultMethod());
70 | methodSpecList.add(generateOnKeyDownMethod());
71 | methodSpecList.add(generateOnKeyLongPressMethod());
72 | methodSpecList.add(generateOnKeyMultipleMethod());
73 | methodSpecList.add(generateOnKeyShortcutMethod());
74 | methodSpecList.add(generateOnKeyUpMethod());
75 | methodSpecList.add(generateOnTrimMemoryMethod());
76 |
77 | return methodSpecList;
78 | }
79 |
80 | private MethodSpec generateOnActivityResultMethod() {
81 | MethodSpec.Builder builder = MethodSpec.methodBuilder("onActivityResult")
82 | .addAnnotation(Override.class)
83 | .addModifiers(Modifier.PUBLIC)
84 | .returns(void.class)
85 | .addParameter(TypeVariableName.get("T"), "target", Modifier.FINAL)
86 | .addParameter(int.class, "requestCode", Modifier.FINAL)
87 | .addParameter(int.class, "resultCode", Modifier.FINAL)
88 | .addParameter(ClassName.get("android.content", "Intent"), "data", Modifier.FINAL);
89 |
90 | final List annotationMethods = getAnnotationMethodMap().get(OnActivityResult.class.getSimpleName());
91 | if (annotationMethods == null || annotationMethods.isEmpty()) {
92 | return builder.build();
93 | }
94 |
95 | boolean firstCondition = true;
96 | for (AnnotationMethod method : annotationMethods) {
97 | XAnnotation onActivityResult = method.getMethodAnnotation();
98 | List requestCodes = onActivityResult.getAsIntList("requestCode");
99 | Object[] objectRequestCodes = new Object[requestCodes.size()];
100 | StringBuilder conditionBuilder = new StringBuilder("");
101 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnRequestPermissionsResult.class.getSimpleName());
131 | if (annotationMethods == null || annotationMethods.isEmpty()) {
132 | return builder.build();
133 | }
134 |
135 | boolean firstCondition = true;
136 | for (AnnotationMethod binding : annotationMethods) {
137 | XAnnotation onRequestPermissionsResult = binding.getMethodAnnotation();
138 | List requestCodes = onRequestPermissionsResult.getAsIntList("requestCode");
139 | Object[] objectRequestCodes = new Object[requestCodes.size()];
140 | StringBuilder conditionBuilder = new StringBuilder("");
141 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnTrimMemory.class.getSimpleName());
169 | if (annotationMethods == null || annotationMethods.isEmpty()) {
170 | return builder.build();
171 | }
172 |
173 | boolean firstCondition = true;
174 | for (AnnotationMethod method : annotationMethods) {
175 | XAnnotation onTrimMemory = method.getMethodAnnotation();
176 | List requestCodes = onTrimMemory.getAsIntList("level");
177 | Object[] objectRequestCodes = new Object[requestCodes.size()];
178 | StringBuilder conditionBuilder = new StringBuilder("");
179 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnKeyDown.class.getSimpleName());
208 | if (annotationMethods == null || annotationMethods.isEmpty()) {
209 | builder.addStatement("return false");
210 | return builder.build();
211 | }
212 |
213 | boolean firstCondition = true;
214 | for (AnnotationMethod method : annotationMethods) {
215 | XAnnotation onKeyDown = method.getMethodAnnotation();
216 | List keyCodes = onKeyDown.getAsIntList("keyCode");
217 | Object[] objectRequestCodes = new Object[keyCodes.size()];
218 | StringBuilder conditionBuilder = new StringBuilder("");
219 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnKeyUp.class.getSimpleName());
249 | if (annotationMethods == null || annotationMethods.isEmpty()) {
250 | builder.addStatement("return false");
251 | return builder.build();
252 | }
253 |
254 | boolean firstCondition = true;
255 | for (AnnotationMethod method : annotationMethods) {
256 | XAnnotation onKeyUp = method.getMethodAnnotation();
257 | List keyCodes = onKeyUp.getAsIntList("keyCode");
258 | Object[] objectRequestCodes = new Object[keyCodes.size()];
259 | StringBuilder conditionBuilder = new StringBuilder("");
260 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnKeyLongPress.class.getSimpleName());
290 | if (annotationMethods == null || annotationMethods.isEmpty()) {
291 | builder.addStatement("return false");
292 | return builder.build();
293 | }
294 |
295 | boolean firstCondition = true;
296 | for (AnnotationMethod method : annotationMethods) {
297 | XAnnotation onKeyLongPress = method.getMethodAnnotation();
298 | List keyCodes = onKeyLongPress.getAsIntList("keyCode");
299 | Object[] objectRequestCodes = new Object[keyCodes.size()];
300 | StringBuilder conditionBuilder = new StringBuilder("");
301 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnKeyMultiple.class.getSimpleName());
332 | if (annotationMethods == null || annotationMethods.isEmpty()) {
333 | builder.addStatement("return false");
334 | return builder.build();
335 | }
336 |
337 | boolean firstCondition = true;
338 | for (AnnotationMethod method : annotationMethods) {
339 | XAnnotation onKeyMultiple = method.getMethodAnnotation();
340 | List keyCodes = onKeyMultiple.getAsIntList("keyCode");
341 | Object[] objectRequestCodes = new Object[keyCodes.size()];
342 | StringBuilder conditionBuilder = new StringBuilder("");
343 | for (int index=0; index annotationMethods = getAnnotationMethodMap().get(OnKeyShortcut.class.getSimpleName());
373 | if (annotationMethods == null || annotationMethods.isEmpty()) {
374 | builder.addStatement("return false");
375 | return builder.build();
376 | }
377 |
378 | boolean firstCondition = true;
379 | for (AnnotationMethod method : annotationMethods) {
380 | XAnnotation onKeyShortcut = method.getMethodAnnotation();
381 | List keyCodes = onKeyShortcut.getAsIntList("keyCode");
382 | Object[] objectRequestCodes = new Object[keyCodes.size()];
383 | StringBuilder conditionBuilder = new StringBuilder("");
384 | for (int index=0; index> mAnnotationMethodMap;
51 |
52 | public String getPackage() {
53 | return mPackage;
54 | }
55 |
56 | public String getName() {
57 | return mName;
58 | }
59 |
60 | public String getTarget() {
61 | return mTarget;
62 | }
63 |
64 | public Map> getAnnotationMethodMap() {
65 | return mAnnotationMethodMap;
66 | }
67 |
68 | public AnnotationClass(String classPackage, String className, String targetType) {
69 | this.mPackage = classPackage;
70 | this.mName = className;
71 | this.mTarget = targetType;
72 | this.mAnnotationMethodMap = new HashMap<>();
73 | }
74 |
75 | public void create(String methodName, XAnnotation methodAnnotation) {
76 | AnnotationMethod method = new AnnotationMethod(methodName, methodAnnotation);
77 | String simpleName = methodAnnotation.getName();
78 | List annotationTypedMethods = mAnnotationMethodMap.get(simpleName);
79 | if (annotationTypedMethods == null) {
80 | annotationTypedMethods = new ArrayList<>();
81 | mAnnotationMethodMap.put(simpleName, annotationTypedMethods);
82 | }
83 |
84 | //TODO check repeat values?
85 | annotationTypedMethods.add(method);
86 | }
87 |
88 | public void writeTo(Filer filer) throws IOException {
89 | generateJavaFile().writeTo(filer);
90 | }
91 |
92 | public JavaFile generateJavaFile() {
93 | ClassName targetClassName = ClassName.get(mPackage, mTarget);
94 | TypeSpec.Builder typeSpec = TypeSpec.classBuilder(mName)
95 | .addModifiers(Modifier.PUBLIC)
96 | .addTypeVariable(TypeVariableName.get("T", targetClassName));
97 |
98 | List methodSpecList = generateMethods();
99 | typeSpec.addMethods(methodSpecList);
100 |
101 | List typeNameList = generateSuperInterface();
102 | typeSpec.addSuperinterfaces(typeNameList);
103 |
104 | return JavaFile.builder(mPackage, typeSpec.build()).build();
105 | }
106 |
107 | protected abstract List generateSuperInterface();
108 |
109 | protected abstract List generateMethods();
110 | }
111 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/process/AnnotationMethod.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler.process;
25 |
26 | import androidx.room.compiler.processing.XAnnotation;
27 | /**
28 | * Annotation method bean.
29 | */
30 |
31 | public final class AnnotationMethod {
32 | private final String mMethodName;
33 | private final XAnnotation mMethodAnnotation;
34 |
35 | public AnnotationMethod(String methodName, XAnnotation methodAnnotation) {
36 | this.mMethodName = methodName;
37 | this.mMethodAnnotation = methodAnnotation;
38 | }
39 |
40 | public XAnnotation getMethodAnnotation() {
41 | return mMethodAnnotation;
42 | }
43 |
44 | public String getMethodName() {
45 | return mMethodName;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/java/cn/yan/hippo/compiler/process/BroadcastReceiverAnnotationClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.compiler.process;
25 |
26 | import androidx.room.compiler.processing.XAnnotation;
27 | import com.squareup.javapoet.ClassName;
28 | import com.squareup.javapoet.MethodSpec;
29 | import com.squareup.javapoet.ParameterizedTypeName;
30 | import com.squareup.javapoet.TypeName;
31 | import com.squareup.javapoet.TypeVariableName;
32 | import java.util.ArrayList;
33 | import java.util.List;
34 | import javax.lang.model.element.Modifier;
35 | import cn.yan.hippo.annotations.OnReceive;
36 |
37 | /**
38 | * create BroadcastReceiver proxy java file.
39 | */
40 |
41 | public final class BroadcastReceiverAnnotationClass extends AnnotationClass {
42 | public BroadcastReceiverAnnotationClass(String classPackage, String className, String targetType) {
43 | super(classPackage, className, targetType);
44 | }
45 |
46 | @Override
47 | protected List generateSuperInterface() {
48 | List typeNameList = new ArrayList<>();
49 |
50 | ClassName iHippoBroadcastReceiver = ClassName.get("cn.yan.hippo.inner", "IHippoBroadcastReceiver");
51 | TypeName typeName = ParameterizedTypeName.get(iHippoBroadcastReceiver, TypeVariableName.get("T"));
52 |
53 | typeNameList.add(typeName);
54 | return typeNameList;
55 | }
56 |
57 | @Override
58 | protected List generateMethods() {
59 | List methodSpecList = new ArrayList<>();
60 |
61 | methodSpecList.add(generateOnReceiveMethod());
62 |
63 | return methodSpecList;
64 | }
65 |
66 | private MethodSpec generateOnReceiveMethod() {
67 | MethodSpec.Builder builder = MethodSpec.methodBuilder("onReceive")
68 | .addAnnotation(Override.class)
69 | .addModifiers(Modifier.PUBLIC)
70 | .returns(void.class)
71 | .addParameter(TypeVariableName.get("T"), "target", Modifier.FINAL)
72 | .addParameter(ClassName.get("android.content", "Context"), "context", Modifier.FINAL)
73 | .addParameter(ClassName.get("android.content", "Intent"), "intent", Modifier.FINAL);
74 |
75 | final List annotationMethods = getAnnotationMethodMap().get(OnReceive.class.getSimpleName());
76 | if (annotationMethods == null || annotationMethods.isEmpty()) {
77 | builder.addStatement("target.onReceive(context, intent)");
78 | return builder.build();
79 | }
80 |
81 | boolean firstCondition = true;
82 | for (AnnotationMethod method : annotationMethods) {
83 | XAnnotation onReceive = method.getMethodAnnotation();
84 | List actions = onReceive.getAsStringList("action");
85 | StringBuilder conditionBuilder = new StringBuilder("");
86 | for (String action : actions) {
87 | conditionBuilder.append("\"$L\".equals(intent.getAction())");
88 | conditionBuilder.append(" || ");
89 | }
90 | String condition = conditionBuilder.substring(0, conditionBuilder.length() - " || ".length());
91 |
92 | if (firstCondition) {
93 | builder.beginControlFlow("if (" + condition + ")", actions.toArray());
94 | firstCondition = false;
95 | } else {
96 | builder.nextControlFlow("else if (" + condition + ")", actions.toArray());
97 | }
98 | builder.addStatement("target.$L(context, intent)", method.getMethodName());
99 | }
100 | builder.endControlFlow();
101 | return builder.build();
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/resources/META-INF/gradle/incremental.annotation.processors:
--------------------------------------------------------------------------------
1 | cn.yan.hippo.compiler.JavaHippoProcessor,isolating
2 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider:
--------------------------------------------------------------------------------
1 | cn.yan.hippo.compiler.HippoProcessorProvider
2 |
--------------------------------------------------------------------------------
/hippo-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | cn.yan.hippo.compiler.JavaHippoProcessor
--------------------------------------------------------------------------------
/hippo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/hippo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 30
5 |
6 | defaultConfig {
7 | minSdkVersion 14
8 | targetSdkVersion 30
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 |
28 | implementation 'com.android.support:appcompat-v7:26.1.0'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
32 | implementation project(':hippo-annotations')
33 | }
34 |
35 | apply from: rootProject.file('gradle/maven-publish.gradle')
--------------------------------------------------------------------------------
/hippo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/hippo/src/androidTest/java/cn/yan/hippo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.hippo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.yan.hippo.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/hippo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/hippo/src/main/java/cn/yan/hippo/Hippo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo;
25 |
26 | import android.content.BroadcastReceiver;
27 | import android.content.Context;
28 | import android.content.Intent;
29 | import android.view.KeyEvent;
30 | import java.util.LinkedHashMap;
31 | import java.util.Map;
32 | import cn.yan.hippo.inner.IHippoActivityFragment;
33 | import cn.yan.hippo.inner.IHippoBroadcastReceiver;
34 |
35 | /**
36 | * Hippo for user method.
37 | */
38 |
39 | public final class Hippo {
40 | private static final String SUFFIX = "_HippoProxy";
41 | private static final String PREFIX_ANDROID = "android.";
42 | private static final String PREFIX_JAVA = "java.";
43 |
44 | private static final Map, IHippoActivityFragment>> S_HIPPO_AFS = new LinkedHashMap<>();
45 | private static final Map, IHippoBroadcastReceiver>> S_HIPPO_BC = new LinkedHashMap<>();
46 |
47 | private Hippo() {
48 | throw new AssertionError("Hippo can't be instance!");
49 | }
50 |
51 | public static void onReceive(BroadcastReceiver target, Context context, Intent intent) {
52 | Class> targetClass = target.getClass();
53 | IHippoBroadcastReceiver hippoBroadcastReceiver = findHippoBroadcastReceiverClass(targetClass);
54 | if (hippoBroadcastReceiver != null) {
55 | hippoBroadcastReceiver.onReceive(target, context, intent);
56 | }
57 | }
58 |
59 | public static void onActivityResult(Object target, int requestCode, int resultCode, Intent data) {
60 | Class> targetClass = target.getClass();
61 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
62 | if (hippoActivityFragment != null) {
63 | hippoActivityFragment.onActivityResult(target, requestCode, resultCode, data);
64 | }
65 | }
66 |
67 | public static void onRequestPermissionsResult(final Object target, final int requestCode, final String[] permissions, final int[] grantResults) {
68 | Class> targetClass = target.getClass();
69 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
70 | if (hippoActivityFragment != null) {
71 | hippoActivityFragment.onRequestPermissionsResult(target, requestCode, permissions, grantResults);
72 | }
73 | }
74 |
75 | public static void onTrimMemory(final Object target, final int level) {
76 | Class> targetClass = target.getClass();
77 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
78 | if (hippoActivityFragment != null) {
79 | hippoActivityFragment.onTrimMemory(target, level);
80 | }
81 | }
82 |
83 | public static boolean onKeyDown(final Object target, int keyCode, KeyEvent event) {
84 | Class> targetClass = target.getClass();
85 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
86 | if (hippoActivityFragment != null) {
87 | return hippoActivityFragment.onKeyDown(target, keyCode, event);
88 | }
89 | return false;
90 | }
91 |
92 | public static boolean onKeyUp(final Object target, int keyCode, KeyEvent event) {
93 | Class> targetClass = target.getClass();
94 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
95 | if (hippoActivityFragment != null) {
96 | return hippoActivityFragment.onKeyUp(target, keyCode, event);
97 | }
98 | return false;
99 | }
100 |
101 | public static boolean onKeyLongPress(final Object target, int keyCode, KeyEvent event) {
102 | Class> targetClass = target.getClass();
103 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
104 | if (hippoActivityFragment != null) {
105 | return hippoActivityFragment.onKeyLongPress(target, keyCode, event);
106 | }
107 | return false;
108 | }
109 |
110 | public static boolean onKeyMultiple(final Object target, int keyCode, int repeatCount, KeyEvent event) {
111 | Class> targetClass = target.getClass();
112 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
113 | if (hippoActivityFragment != null) {
114 | return hippoActivityFragment.onKeyMultiple(target, keyCode, repeatCount, event);
115 | }
116 | return false;
117 | }
118 |
119 | public static boolean onKeyShortcut(final Object target, int keyCode, KeyEvent event) {
120 | Class> targetClass = target.getClass();
121 | IHippoActivityFragment hippoActivityFragment = findHippoActivityFragmentClass(targetClass);
122 | if (hippoActivityFragment != null) {
123 | hippoActivityFragment.onKeyShortcut(target, keyCode, event);
124 | }
125 | return false;
126 | }
127 |
128 | private static IHippoActivityFragment findHippoActivityFragmentClass(Class> targetClass) {
129 | IHippoActivityFragment hippoActivityFragment = S_HIPPO_AFS.get(targetClass);
130 | if (hippoActivityFragment != null) {
131 | return hippoActivityFragment;
132 | }
133 |
134 | String className = targetClass.getName();
135 | if (className.startsWith(PREFIX_ANDROID) || className.startsWith(PREFIX_JAVA)) {
136 | return null;
137 | }
138 |
139 | try {
140 | Class> attachClass = Class.forName(className + SUFFIX);
141 | hippoActivityFragment = (IHippoActivityFragment) attachClass.newInstance();
142 | } catch (ClassNotFoundException e) {
143 | e.printStackTrace();
144 | hippoActivityFragment = findHippoActivityFragmentClass(targetClass.getSuperclass());
145 | } catch (IllegalAccessException e) {
146 | e.printStackTrace();
147 | } catch (InstantiationException e) {
148 | e.printStackTrace();
149 | }
150 | S_HIPPO_AFS.put(targetClass, hippoActivityFragment);
151 | return hippoActivityFragment;
152 | }
153 |
154 | private static IHippoBroadcastReceiver findHippoBroadcastReceiverClass(Class> targetClass) {
155 | IHippoBroadcastReceiver hippoBroadcastReceiver = S_HIPPO_BC.get(targetClass);
156 | if (hippoBroadcastReceiver != null) {
157 | return hippoBroadcastReceiver;
158 | }
159 |
160 | String className = targetClass.getName();
161 | if (className.startsWith(PREFIX_ANDROID) || className.startsWith(PREFIX_JAVA)) {
162 | return null;
163 | }
164 |
165 | try {
166 | Class> attachClass = Class.forName(className + SUFFIX);
167 | hippoBroadcastReceiver = (IHippoBroadcastReceiver) attachClass.newInstance();
168 | } catch (ClassNotFoundException e) {
169 | e.printStackTrace();
170 | hippoBroadcastReceiver = findHippoBroadcastReceiverClass(targetClass.getSuperclass());
171 | } catch (IllegalAccessException e) {
172 | e.printStackTrace();
173 | } catch (InstantiationException e) {
174 | e.printStackTrace();
175 | }
176 | S_HIPPO_BC.put(targetClass, hippoBroadcastReceiver);
177 | return hippoBroadcastReceiver;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/hippo/src/main/java/cn/yan/hippo/inner/IHippoActivityFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.inner;
25 |
26 | import android.content.Intent;
27 | import android.view.KeyEvent;
28 |
29 | /**
30 | * Proxy interface for Activity or Fragment some state method.
31 | */
32 |
33 | public interface IHippoActivityFragment {
34 | void onActivityResult(final T target, final int requestCode, final int resultCode, final Intent data);
35 |
36 | void onRequestPermissionsResult(final T target, final int requestCode, final String[] permissions, final int[] grantResults);
37 |
38 | void onTrimMemory(final T target, final int level);
39 |
40 | boolean onKeyDown(final T target, final int keyCode, final KeyEvent event);
41 |
42 | boolean onKeyUp(final T target, final int keyCode, final KeyEvent event);
43 |
44 | boolean onKeyLongPress(final T target, final int keyCode, final KeyEvent event);
45 |
46 | boolean onKeyMultiple(final T target, final int keyCode, final int repeatCount, final KeyEvent event);
47 |
48 | boolean onKeyShortcut(final T target, final int keyCode, final KeyEvent event);
49 | }
50 |
--------------------------------------------------------------------------------
/hippo/src/main/java/cn/yan/hippo/inner/IHippoBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.hippo.inner;
25 |
26 | import android.content.Context;
27 | import android.content.Intent;
28 |
29 | /**
30 | * Proxy interface for BroadcastReceiver onReceive state method.
31 | */
32 |
33 | public interface IHippoBroadcastReceiver {
34 | void onReceive(final T target, final Context context, final Intent intent);
35 | }
36 |
--------------------------------------------------------------------------------
/hippo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | hippo
3 |
4 |
--------------------------------------------------------------------------------
/hippo/src/test/java/cn/yan/hippo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.hippo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo-app', ':hippo-compiler', ':hippo-annotations', ':hippo'
2 |
--------------------------------------------------------------------------------