├── .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 | 36 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 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 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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/v/yanbober/android-hippo.svg)](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 |