├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── component
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── component
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xhdpi
│ │ ├── ic_home_first_normal.png
│ │ ├── ic_home_first_selected.png
│ │ ├── ic_home_second_normal.png
│ │ ├── ic_home_second_selected.png
│ │ ├── ic_home_third_normal.png
│ │ └── ic_home_third_selected.png
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ ├── selector_tab_first.xml
│ │ ├── selector_tab_second.xml
│ │ ├── selector_tab_third.xml
│ │ └── selector_text_home_navigation.xml
│ │ ├── layout
│ │ └── activity_main.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
│ │ └── styles_home.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── component
│ └── ExampleUnitTest.java
├── baselib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── baselib
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── baselib
│ │ │ ├── base
│ │ │ └── BaseFragment.java
│ │ │ ├── interfaces
│ │ │ ├── SimpleCallback.java
│ │ │ └── SimpleReturnCallback.java
│ │ │ └── utils
│ │ │ ├── AppContext.java
│ │ │ ├── ToolUtil.java
│ │ │ └── VersionUtil.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── baselib
│ └── ExampleUnitTest.java
├── build.gradle
├── common
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── common
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── common
│ │ │ ├── manager
│ │ │ └── TabManager.java
│ │ │ └── modules
│ │ │ └── BaseModulesProvider.java
│ └── res
│ │ ├── anim
│ │ ├── slide_left_in.xml
│ │ ├── slide_left_out.xml
│ │ ├── slide_right_in.xml
│ │ └── slide_right_out.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles_app.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── common
│ └── ExampleUnitTest.java
├── config.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib_annotation
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── razerdp
│ └── annotations
│ ├── AnnotationConfig.java
│ └── modules
│ └── ServiceImpl.java
├── lib_processor
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── razerdp
│ │ ├── BaseProcessor.java
│ │ ├── processor
│ │ └── modules
│ │ │ └── ModuleServicesProcessor.java
│ │ └── utils
│ │ ├── Logger.java
│ │ └── Utils.java
│ └── resources
│ └── META-INF
│ └── services
│ └── javax.annotation.processing.Processor
├── module_first
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── module_first
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── module
│ │ │ └── first
│ │ │ ├── ModuleFirstProvider.java
│ │ │ ├── services
│ │ │ └── ModuleFirstServiceImpl.java
│ │ │ └── ui
│ │ │ └── ModuleFirstFragment.java
│ └── res
│ │ ├── layout
│ │ └── fragment_first.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── module_first
│ └── ExampleUnitTest.java
├── module_second
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── module_second
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── module
│ │ │ └── second
│ │ │ ├── ModuleSecondProvider.java
│ │ │ ├── services
│ │ │ └── ModuleSecondServiceImpl.java
│ │ │ └── ui
│ │ │ └── ModuleSecondFragment.java
│ └── res
│ │ ├── layout
│ │ └── fragment_second.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── module_second
│ └── ExampleUnitTest.java
├── module_third
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── module_third
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── module
│ │ │ └── third
│ │ │ ├── ModuleThirdProvider.java
│ │ │ ├── services
│ │ │ └── ModuleThirdServiceImpl.java
│ │ │ └── ui
│ │ │ └── ModuleThirdFragment.java
│ └── res
│ │ ├── layout
│ │ └── fragment_third.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── module_third
│ └── ExampleUnitTest.java
├── modules_private
├── module_first_private
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── razerdp
│ │ │ └── module_first_private
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── razerdp
│ │ │ │ └── module
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── first
│ │ │ │ └── ModuleFirstApplication.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ └── activity_main.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
│ │ └── com
│ │ └── razerdp
│ │ └── module_first_private
│ │ └── ExampleUnitTest.java
├── module_second_private
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── razerdp
│ │ │ └── module_second_private
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── razerdp
│ │ │ │ └── module
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── second
│ │ │ │ └── ModuleSecondApplication.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ └── activity_main.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
│ │ └── com
│ │ └── razerdp
│ │ └── module_second_private
│ │ └── ExampleUnitTest.java
└── module_third_private
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── module_third_private
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── module
│ │ │ ├── MainActivity.java
│ │ │ └── third
│ │ │ └── ModuleThirdApplication.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.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
│ └── com
│ └── razerdp
│ └── module_third_private
│ └── ExampleUnitTest.java
├── router
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── razerdp
│ │ └── router
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── razerdp
│ │ │ └── router
│ │ │ ├── core
│ │ │ ├── IModuleServiceProvider.java
│ │ │ ├── InitProvider.java
│ │ │ ├── ModuleManager.java
│ │ │ ├── define
│ │ │ │ └── ModuleDefine.java
│ │ │ └── utils
│ │ │ │ ├── ClassUtils.java
│ │ │ │ ├── DefaultThreadFactory.java
│ │ │ │ ├── ModuleUtils.java
│ │ │ │ ├── PoolExecutor.java
│ │ │ │ └── SPUtils.java
│ │ │ └── modules
│ │ │ ├── ModuleFirstService.java
│ │ │ ├── ModuleSecondService.java
│ │ │ └── ModuleThirdService.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── razerdp
│ └── router
│ └── ExampleUnitTest.java
└── 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
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | # External native build folder generated in Android Studio 2.2 and later
43 | .externalNativeBuild
44 |
45 | # Google Services (e.g. APIs or Firebase)
46 | google-services.json
47 |
48 | # Freeline
49 | freeline.py
50 | freeline/
51 | freeline_project_description.json
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Component
2 | // 组件化实践
3 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | defaultConfig {
5 | applicationId "com.razerdp.component"
6 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
7 | }
8 | }
9 |
10 | dependencies {
11 | implementation fileTree(dir: 'libs', include: ['*.jar'])
12 | testImplementation 'junit:junit:4.12'
13 | androidTestImplementation 'androidx.test:runner:1.2.0'
14 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
15 |
16 |
17 | //modules
18 | implementation project(':module_first')
19 | implementation project(':module_second')
20 | implementation project(':module_third')
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/razerdp/component/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.component;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.component", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/razerdp/component/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.component;
2 |
3 | import android.os.Bundle;
4 | import android.widget.TextView;
5 |
6 | import androidx.annotation.StringDef;
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.fragment.app.FragmentManager;
9 |
10 | import com.razerdp.common.manager.TabManager;
11 | import com.razerdp.router.core.ModuleManager;
12 | import com.razerdp.router.modules.ModuleFirstService;
13 | import com.razerdp.router.modules.ModuleSecondService;
14 | import com.razerdp.router.modules.ModuleThirdService;
15 |
16 | import java.lang.annotation.Retention;
17 | import java.lang.annotation.RetentionPolicy;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | @Retention(RetentionPolicy.SOURCE)
22 | @StringDef({TAB_FIRST, TAB_SECOND, TAB_THIRD})
23 | public @interface TabIndex {
24 | }
25 |
26 | public static final String TAB_FIRST = "TAB_FIRST";
27 | public static final String TAB_SECOND = "TAB_SECOND";
28 | public static final String TAB_THIRD = "TAB_THIRD";
29 |
30 | private TabManager manager;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_main);
36 | initView();
37 | }
38 |
39 | private void initView() {
40 | manager = TabManager.create(this, getSupportFragmentManager(), R.id.container).setFragmentManagerProvider(new TabManager.FragmentManagerProvider() {
41 | @Override
42 | public FragmentManager onGetFragmentManager() {
43 | return getSupportFragmentManager();
44 | }
45 | });
46 |
47 | TextView tvHomeFirst = findViewById(R.id.tv_home_first);
48 | TextView tvHomeSecond = findViewById(R.id.tv_home_second);
49 | TextView tvHomeThird = findViewById(R.id.tv_home_third);
50 |
51 | manager.append(TAB_FIRST, ModuleManager.INSTANCE.getService(ModuleFirstService.class).getFragmentClass(), null, tvHomeFirst, null)
52 | .append(TAB_SECOND, ModuleManager.INSTANCE.getService(ModuleSecondService.class).getFragmentClass(), null, tvHomeSecond, null)
53 | .append(TAB_THIRD, ModuleManager.INSTANCE.getService(ModuleThirdService.class).getFragmentClass(), null, tvHomeThird, null)
54 | .enableTabAnimation();
55 | manager.switchTab(TAB_FIRST);
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_first_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_first_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_first_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_first_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_second_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_second_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_second_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_second_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_third_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_third_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_home_third_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/drawable-xhdpi/ic_home_third_selected.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_tab_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_tab_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_tab_third.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_text_home_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
30 |
31 |
39 |
40 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Component
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/test/java/com/razerdp/component/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.component;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/baselib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/baselib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api 'com.android.support:appcompat-v7:28.0.0'
6 | api 'com.android.support.constraint:constraint-layout:1.1.3'
7 |
8 | api project(':lib_annotation')
9 | }
10 |
--------------------------------------------------------------------------------
/baselib/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 |
--------------------------------------------------------------------------------
/baselib/src/androidTest/java/com/razerdp/baselib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.baselib.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/baselib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.base;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.SystemClock;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import androidx.annotation.LayoutRes;
12 | import androidx.annotation.NonNull;
13 | import androidx.annotation.Nullable;
14 | import androidx.fragment.app.Fragment;
15 |
16 | /**
17 | * Created by 大灯泡 on 2019/4/9
18 | *
19 | * Description:
20 | */
21 | public abstract class BaseFragment extends Fragment {
22 | protected final String TAG = getClass().getSimpleName();
23 |
24 | private Context mContext;
25 | protected View mRootView;
26 | protected final State mState = new State();
27 |
28 |
29 | @Override
30 | public void onAttach(Context context) {
31 | super.onAttach(context);
32 | this.mContext = context;
33 | onHandledArguments(getArguments());
34 | }
35 |
36 | private void onHandledArguments(@Nullable Bundle arguments) {
37 |
38 | }
39 |
40 | @Override
41 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
42 | super.onViewCreated(view, savedInstanceState);
43 | if (mContext == null) {
44 | mContext = requireContext();
45 | }
46 | }
47 |
48 | @Nullable
49 | @Override
50 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
51 | if (mRootView == null) {
52 | Log.d("openFragment", "当前打开fragment: " + this.getClass().getSimpleName());
53 | mRootView = inflater.inflate(contentViewLayoutId(), container, false);
54 | onInitViews(mRootView);
55 | onAfterInitViews();
56 | }
57 | mState.handleShow();
58 | mState.state |= State.FLAG_INIT;
59 | return mRootView;
60 |
61 | }
62 |
63 |
64 | //region abstract
65 | @LayoutRes
66 | public abstract int contentViewLayoutId();
67 |
68 | protected abstract void onInitViews(View mRootView);
69 |
70 |
71 | //endregion
72 | protected void onAfterInitViews() {
73 |
74 | }
75 |
76 |
77 | protected void onBackPressed() {
78 | try {
79 | if (getFragmentManager() != null && getFragmentManager().getBackStackEntryCount() > 0) {
80 | getFragmentManager().popBackStack();
81 | } else {
82 | getActivity().finish();
83 | }
84 | } catch (Exception e) {
85 |
86 | }
87 | }
88 |
89 | protected void finishActivity() {
90 | try {
91 | getActivity().finish();
92 | } catch (Exception e) {
93 | e.printStackTrace();
94 | }
95 | }
96 |
97 | @Nullable
98 | @Override
99 | public Context getContext() {
100 | if (mContext != null) {
101 | return mContext;
102 | }
103 | return super.getContext();
104 | }
105 |
106 | //region life
107 |
108 |
109 | @Override
110 | public void setUserVisibleHint(boolean isVisibleToUser) {
111 | super.setUserVisibleHint(isVisibleToUser);
112 | //for viewpager,因为创建的时候就回调这货,可能ui还没开始创建,需要判断
113 | if (mState.hasFlag(State.FLAG_INIT)) {
114 | if (isVisibleToUser) {
115 | mState.handleShow();
116 | } else {
117 | mState.handleHided();
118 | }
119 | }
120 |
121 | }
122 |
123 | @Override
124 | public void onHiddenChanged(boolean hidden) {
125 | super.onHiddenChanged(hidden);
126 | //for show / hide
127 | if (mState.hasFlag(State.FLAG_INIT)) {
128 | if (hidden) {
129 | mState.handleHided();
130 | } else {
131 | mState.handleShow();
132 | }
133 | }
134 | }
135 |
136 |
137 | @Override
138 | public void onResume() {
139 | super.onResume();
140 | //当activity回调resume的时候,其所有fragment都会回调,因此需要判断具体的
141 | //getUserVisibleHint不在vp的时候默认就是true
142 | if (getUserVisibleHint() && !isHidden()) {
143 | mState.handleShow();
144 | }
145 | }
146 |
147 |
148 | @Override
149 | public void onStop() {
150 | super.onStop();
151 | if (getUserVisibleHint()) {
152 | mState.handleHided();
153 | }
154 | }
155 |
156 | @Override
157 | public void onDestroy() {
158 | super.onDestroy();
159 | mRootView = null;
160 | }
161 |
162 | //endregion
163 |
164 | //region callback
165 |
166 | public void onShow() {
167 | }
168 |
169 | public void onHided() {
170 | }
171 |
172 | //endregion
173 |
174 |
175 | private class State {
176 | private long lastShowingTime = 0;
177 | static final int FLAG_IDLE = 0x00000000;
178 | static final int FLAG_INIT = 0x00000001;
179 |
180 | static final int FLAG_SHOWING = 0x00010000;
181 | static final int FLAG_HIDED = FLAG_SHOWING << 1;
182 |
183 | int state = FLAG_IDLE;
184 |
185 |
186 | void handleShow() {
187 | if ((state & FLAG_SHOWING) != 0) return;
188 | state |= FLAG_SHOWING;
189 | onShow();
190 | state &= ~FLAG_HIDED;
191 | }
192 |
193 |
194 | void handleHided() {
195 | if ((state & FLAG_HIDED) != 0) return;
196 | state |= FLAG_HIDED;
197 | onHided();
198 | lastShowingTime = SystemClock.uptimeMillis();
199 | state &= ~FLAG_SHOWING;
200 | }
201 |
202 | void computeFlag(int mFlag) {
203 | state |= mFlag;
204 | }
205 |
206 | void removeFlag(int mFlag) {
207 | state &= ~mFlag;
208 | }
209 |
210 | void resetFlag() {
211 | state = FLAG_IDLE;
212 | }
213 |
214 | boolean hasFlag(int mFlag) {
215 | return (state & mFlag) != 0;
216 | }
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/interfaces/SimpleCallback.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.interfaces;
2 |
3 |
4 | import androidx.annotation.Keep;
5 |
6 | /**
7 | * Created by 大灯泡 on 2019/7/18.
8 | */
9 | @Keep
10 | public interface SimpleCallback {
11 | void onCall(T data);
12 | }
13 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/interfaces/SimpleReturnCallback.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.interfaces;
2 |
3 | /**
4 | * Created by 大灯泡 on 2019/7/18.
5 | */
6 | public interface SimpleReturnCallback {
7 | boolean onCall(T data);
8 | }
9 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/utils/AppContext.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.content.res.Resources;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 |
10 | import java.lang.ref.WeakReference;
11 |
12 | public class AppContext {
13 | private static final String TAG = "AppContext";
14 | public static Application sApplication;
15 | private static final InnerLifecycleHandler INNER_LIFECYCLE_HANDLER;
16 |
17 | static {
18 | Application app = null;
19 | try {
20 | app = (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null);
21 | if (app == null)
22 | throw new IllegalStateException("Static initialization of Applications must be on main thread.");
23 | } catch (final Exception e) {
24 | Log.e(TAG, "Failed to get current application from AppGlobals." + e.getMessage());
25 | try {
26 | app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
27 | } catch (final Exception ex) {
28 | Log.e(TAG, "Failed to get current application from ActivityThread." + e.getMessage());
29 | }
30 | } finally {
31 | sApplication = app;
32 | }
33 | INNER_LIFECYCLE_HANDLER = new InnerLifecycleHandler();
34 | if (sApplication != null) {
35 | sApplication.registerActivityLifecycleCallbacks(INNER_LIFECYCLE_HANDLER);
36 | }
37 | }
38 |
39 | public static boolean isAppVisable() {
40 | return INNER_LIFECYCLE_HANDLER != null && INNER_LIFECYCLE_HANDLER.started > INNER_LIFECYCLE_HANDLER.stopped;
41 | }
42 |
43 | public static boolean isAppBackground() {
44 | return INNER_LIFECYCLE_HANDLER != null && INNER_LIFECYCLE_HANDLER.resumed <= INNER_LIFECYCLE_HANDLER.stopped;
45 | }
46 |
47 | private static void checkAppContext() {
48 | if (sApplication == null) {
49 | reflectAppContext();
50 | }
51 | if (sApplication == null) {
52 | throw new IllegalStateException("app reference is null");
53 | }
54 | }
55 |
56 | private static void reflectAppContext() {
57 | Application app = null;
58 | try {
59 | app = (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null);
60 | if (app == null)
61 | throw new IllegalStateException("Static initialization of Applications must be on main thread.");
62 | } catch (final Exception e) {
63 | Log.e(TAG, "Failed to get current application from AppGlobals." + e.getMessage());
64 | try {
65 | app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
66 | } catch (final Exception ex) {
67 | Log.e(TAG, "Failed to get current application from ActivityThread." + e.getMessage());
68 | }
69 | } finally {
70 | sApplication = app;
71 | }
72 | if (sApplication != null && INNER_LIFECYCLE_HANDLER != null) {
73 | sApplication.registerActivityLifecycleCallbacks(INNER_LIFECYCLE_HANDLER);
74 | }
75 | }
76 |
77 | public static Application getAppInstance() {
78 | checkAppContext();
79 | return sApplication;
80 | }
81 |
82 | public static Context getAppContext() {
83 | checkAppContext();
84 | return sApplication.getApplicationContext();
85 | }
86 |
87 | public static Resources getResources() {
88 | checkAppContext();
89 | return sApplication.getResources();
90 | }
91 |
92 | public static Activity getTopActivity() {
93 | return INNER_LIFECYCLE_HANDLER.mTopActivity == null ? null : INNER_LIFECYCLE_HANDLER.mTopActivity.get();
94 | }
95 |
96 | private static class InnerLifecycleHandler implements Application.ActivityLifecycleCallbacks {
97 | private int created;
98 | private int resumed;
99 | private int paused;
100 | private int started;
101 | private int stopped;
102 | private WeakReference mTopActivity;
103 |
104 |
105 | @Override
106 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
107 | ++created;
108 |
109 | }
110 |
111 | @Override
112 | public void onActivityStarted(Activity activity) {
113 | ++started;
114 |
115 | }
116 |
117 | @Override
118 | public void onActivityResumed(Activity activity) {
119 | ++resumed;
120 | mTopActivity = new WeakReference<>(activity);
121 | }
122 |
123 | @Override
124 | public void onActivityPaused(Activity activity) {
125 | ++paused;
126 |
127 | }
128 |
129 | @Override
130 | public void onActivityStopped(Activity activity) {
131 | ++stopped;
132 |
133 | }
134 |
135 | @Override
136 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
137 |
138 | }
139 |
140 | @Override
141 | public void onActivityDestroyed(Activity activity) {
142 |
143 | }
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/utils/ToolUtil.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.ActivityManager;
5 | import android.content.ClipData;
6 | import android.content.ClipboardManager;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.pm.PackageManager;
10 | import android.content.pm.ResolveInfo;
11 | import android.net.Uri;
12 | import android.os.Looper;
13 |
14 | import java.io.UnsupportedEncodingException;
15 | import java.util.List;
16 | import java.util.Random;
17 |
18 | public class ToolUtil {
19 | public static boolean isListEmpty(List> datas) {
20 | return datas == null || datas.size() <= 0;
21 | }
22 |
23 | public static boolean isListEmptyOrEmptyElements(List> datas) {
24 | if (isListEmpty(datas)) return true;
25 | for (Object data : datas) {
26 | if (data != null) {
27 | return false;
28 | }
29 | }
30 | return true;
31 |
32 | }
33 |
34 | /**
35 | * 复制到剪切板
36 | *
37 | * @param szContent
38 | */
39 | @SuppressLint({"NewApi", "ServiceCast"})
40 | public static void copyToClipboard(String szContent) {
41 | android.content.ClipboardManager clipboard = (android.content.ClipboardManager) AppContext.getAppContext().getSystemService(Context.CLIPBOARD_SERVICE);
42 | ClipData clip = ClipData.newPlainText("Copied Text", szContent);
43 | if (clipboard != null) {
44 | clipboard.setPrimaryClip(clip);
45 | }
46 | }
47 |
48 | /**
49 | * 获取剪贴板中的第一条数据
50 | */
51 | public static String getDataFromClipboard() {
52 | ClipboardManager clipboard = (ClipboardManager) AppContext.getAppContext().getSystemService(Context.CLIPBOARD_SERVICE);
53 | if (clipboard == null) {
54 | return "";
55 | }
56 |
57 | ClipData clipData = clipboard.getPrimaryClip();
58 | if (clipData != null && clipData.getItemCount() > 0) {
59 | return clipData.getItemAt(0).getText().toString();
60 | } else {
61 | return "";
62 | }
63 | }
64 |
65 | /**
66 | * 清空剪贴板
67 | */
68 | public static void clearClipboard() {
69 | ClipboardManager clipboard = (ClipboardManager) AppContext.getAppContext().getSystemService(Context.CLIPBOARD_SERVICE);
70 | if (clipboard == null) {
71 | return;
72 | }
73 | clipboard.setPrimaryClip(ClipData.newPlainText(null, ""));
74 | }
75 |
76 | public static boolean isMainThread() {
77 | return Looper.getMainLooper().getThread() == Thread.currentThread();
78 | }
79 |
80 | public static boolean indexInList(List> target, int index) {
81 | if (target == null) return false;
82 | return index >= 0 && index < target.size();
83 | }
84 |
85 | public static boolean openInSystemBroswer(Context context, String url) {
86 | try {
87 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
88 | context.startActivity(intent);
89 | if (!hasPreferredApplication(context, intent)) {
90 | intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
91 | }
92 | return true;
93 | } catch (Exception e) {
94 | e.printStackTrace();
95 | return false;
96 | }
97 | }
98 |
99 | private static boolean hasPreferredApplication(Context context, Intent intent) {
100 | PackageManager pm = context.getPackageManager();
101 | ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
102 | return !"android".equals(info.activityInfo.packageName);
103 | }
104 |
105 | public static String getProcessName(Context context, int pid) {
106 | ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
107 | List processInfoList = am.getRunningAppProcesses();
108 | if (processInfoList == null) {
109 | return null;
110 | }
111 | for (ActivityManager.RunningAppProcessInfo processInfo : processInfoList) {
112 | if (processInfo.pid == pid) {
113 | return processInfo.processName;
114 | }
115 | }
116 | return null;
117 | }
118 |
119 | public static O cast(I input, Class outClass, O... defaultValue) {
120 | if (input != null && outClass.isAssignableFrom(input.getClass())) {
121 | return outClass.cast(input);
122 | } else {
123 | if (defaultValue != null && defaultValue.length > 0) {
124 | return defaultValue[0];
125 | }
126 | return null;
127 | }
128 | }
129 |
130 | public static String getChinese(int len) {
131 | String randomName = "";
132 | for (int i = 0; i < len; i++) {
133 | String str = null;
134 | int hightPos, lowPos;
135 | Random random = new Random();
136 | hightPos = (176 + Math.abs(random.nextInt(39)));
137 | lowPos = (161 + Math.abs(random.nextInt(93)));
138 | byte[] b = new byte[2];
139 | b[0] = Integer.valueOf(hightPos).byteValue();
140 | b[1] = Integer.valueOf(lowPos).byteValue();
141 | try {
142 | str = new String(b, "GBK");
143 | } catch (UnsupportedEncodingException ex) {
144 | ex.printStackTrace();
145 | }
146 | randomName += str;
147 | }
148 | return randomName;
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/razerdp/baselib/utils/VersionUtil.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib.utils;
2 |
3 | import android.content.pm.PackageInfo;
4 | import android.content.pm.PackageManager;
5 | import android.os.Build;
6 | import android.text.TextUtils;
7 |
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/4/19.
11 | */
12 | public class VersionUtil {
13 |
14 | private static String versionName;
15 | private static long versionCode = -1;
16 |
17 | public static String getVersionName() {
18 | if (TextUtils.isEmpty(versionName)) {
19 | PackageManager packageManager = AppContext.getAppContext().getPackageManager();
20 | PackageInfo packInfo = null;
21 | try {
22 | packInfo = packageManager.getPackageInfo(AppContext.getAppContext().getPackageName(), 0);
23 | versionName = packInfo.versionName;
24 | } catch (PackageManager.NameNotFoundException e) {
25 | e.printStackTrace();
26 | versionName = "";
27 | }
28 | }
29 | return versionName;
30 | }
31 |
32 |
33 | /**
34 | * 获取当前应用的版本号
35 | */
36 | public static long getVersionCode() {
37 | if (versionCode == -1) {
38 | PackageManager packageManager = AppContext.getAppContext().getPackageManager();
39 | PackageInfo packInfo;
40 | try {
41 | packInfo = packageManager.getPackageInfo(
42 | AppContext.getAppContext().getPackageName(), 0);
43 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
44 | versionCode = packInfo.getLongVersionCode();
45 | }else {
46 | versionCode = packInfo.versionCode;
47 | }
48 | } catch (PackageManager.NameNotFoundException e) {
49 | e.printStackTrace();
50 | versionCode = -1;
51 | }
52 | }
53 | return versionCode;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/baselib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | baselib
3 |
4 |
--------------------------------------------------------------------------------
/baselib/src/test/java/com/razerdp/baselib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.baselib;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: 'config.gradle'
3 |
4 | buildscript {
5 | repositories {
6 | mavenCentral()
7 | google()
8 | jcenter { url 'https://maven.aliyun.com/repository/jcenter' }
9 | jcenter()
10 | maven { url "https://jitpack.io" }
11 |
12 | }
13 | dependencies {
14 | classpath 'com.android.tools.build:gradle:3.4.2'
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | mavenCentral()
21 | google()
22 | jcenter { url 'https://maven.aliyun.com/repository/jcenter' }
23 | jcenter()
24 | maven { url "https://jitpack.io" }
25 | }
26 |
27 |
28 | gradle.taskGraph.whenReady {
29 | tasks.each { task ->
30 | if (task.name.contains("Test")
31 | || task.name.contains("mockableAndroidJar")
32 | || task.name.contains("UnitTest")
33 | || task.name.contains("AndroidTest")) {
34 | task.enabled = false
35 | }
36 | }
37 | }
38 | }
39 |
40 | task clean(type: Delete) {
41 | delete rootProject.buildDir
42 | }
43 |
44 | //子项目配置
45 | subprojects { project ->
46 | afterEvaluate {
47 | if (project.hasProperty("android")) {
48 | android {
49 | compileSdkVersion rootProject.ext.compileSdkVersion
50 |
51 | defaultConfig {
52 | minSdkVersion rootProject.ext.minSdkVersion
53 | targetSdkVersion rootProject.ext.targetSdkVersion
54 | versionCode rootProject.ext.versionCode
55 | versionName rootProject.ext.versionName
56 | }
57 |
58 | lintOptions {
59 | abortOnError true
60 | disable 'GradleDependency'
61 | disable 'InvalidPackage'
62 | disable 'TypographyDashes'
63 | disable 'TypographyFractions'
64 | disable 'LabelFor'
65 | disable 'IconLauncherShape'
66 | disable 'IconMissingDensityFolder'
67 | }
68 |
69 |
70 | compileOptions {
71 | sourceCompatibility JavaVersion.VERSION_1_8
72 | targetCompatibility JavaVersion.VERSION_1_8
73 | }
74 |
75 | packagingOptions {
76 | exclude 'META-INF/DEPENDENCIES.txt'
77 | exclude 'META-INF/LICENSE.txt'
78 | exclude 'META-INF/NOTICE.txt'
79 | exclude 'META-INF/NOTICE'
80 | exclude 'META-INF/LICENSE'
81 | exclude 'META-INF/DEPENDENCIES'
82 | exclude 'META-INF/notice.txt'
83 | exclude 'META-INF/license.txt'
84 | exclude 'META-INF/dependencies.txt'
85 | exclude 'META-INF/LGPL2.1'
86 | }
87 | }
88 | } else {
89 | println "==== with no android property: ${project.name} ===="
90 | }
91 |
92 | if (project.plugins.hasPlugin('com.android.library')) {
93 | android {
94 | buildTypes {
95 | release {
96 | minifyEnabled true
97 | consumerProguardFiles 'proguard-rules.pro'
98 | }
99 | debug {
100 | minifyEnabled false
101 | consumerProguardFiles 'proguard-rules.pro'
102 | }
103 | }
104 |
105 | }
106 | if (project.name.contains('module')) {
107 | println "==== add arguments: ${project.name} ===="
108 | android {
109 | defaultConfig {
110 | javaCompileOptions {
111 | annotationProcessorOptions {
112 | arguments = ['MODULE_NAME': project.getName()]
113 | }
114 | }
115 | }
116 | }
117 | }
118 | } else if (project.plugins.hasPlugin('com.android.application')) {
119 | android {
120 | buildTypes {
121 | debug {
122 | shrinkResources false
123 | minifyEnabled false
124 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
125 | }
126 |
127 | release {
128 | zipAlignEnabled true
129 | shrinkResources true
130 | minifyEnabled true
131 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
132 | }
133 | }
134 |
135 | dexOptions {
136 | javaMaxHeapSize "4g"
137 | jumboMode = true
138 | }
139 | }
140 | }
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/common/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/common/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api project(':baselib')
6 |
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/common/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 |
--------------------------------------------------------------------------------
/common/src/androidTest/java/com/razerdp/common/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.common;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.common.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/common/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/common/src/main/java/com/razerdp/common/manager/TabManager.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.common.manager;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.text.TextUtils;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.animation.OvershootInterpolator;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 | import androidx.fragment.app.FragmentManager;
14 | import androidx.fragment.app.FragmentTransaction;
15 |
16 | import com.razerdp.baselib.interfaces.SimpleReturnCallback;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 |
22 | /**
23 | * Created by 大灯泡 on 2019/4/9
24 | *
25 | * Description:多Fragment导航切换管理类
26 | */
27 | public class TabManager {
28 | private final Context mContext;
29 | private FragmentManager mManager;
30 | private FragmentManagerProvider managerProvider;
31 | private final int mContainerId;
32 | private List mTabInfos;
33 | private TabInfo mCurTabInfo;
34 | private TabInfo mLastTabInfo;
35 | private boolean tabAnimateEnable = false;
36 | private static final long ANIMATION_DURATION = 350;
37 | private static final String SAVE_TAG = "TabManager_CurTab";
38 |
39 |
40 | private TabManager(Context context, FragmentManager manager, int containerId) {
41 | this.mContext = context;
42 | this.mManager = manager;
43 | this.mContainerId = containerId;
44 | mTabInfos = new ArrayList<>();
45 | }
46 |
47 |
48 | public static TabManager create(Context context, FragmentManager mManager, int mContainerId) {
49 | return new TabManager(context, mManager, mContainerId);
50 | }
51 |
52 | public TabManager setFragmentManagerProvider(FragmentManagerProvider managerProvider) {
53 | this.managerProvider = managerProvider;
54 | return this;
55 | }
56 |
57 | private FragmentManager getManager() {
58 | if (mManager == null || mManager.isDestroyed()) {
59 | if (managerProvider != null) {
60 | mManager = managerProvider.onGetFragmentManager();
61 | }
62 | }
63 | return mManager;
64 | }
65 |
66 | public TabManager append(@NonNull String tag,
67 | @NonNull Class extends Fragment> clas,
68 | @Nullable Bundle arguments,
69 | @Nullable View mTabView,
70 | @Nullable SimpleReturnCallback mClickCallback) {
71 | if (clas == null) return this;
72 | if (TextUtils.isEmpty(tag)) {
73 | tag = clas.getSimpleName();
74 | }
75 | TabInfo tabInfo = new TabInfo(tag, clas);
76 | tabInfo.mArguments = arguments;
77 | tabInfo.mTabView = mTabView;
78 | tabInfo.mClickCallback = mClickCallback;
79 | addToList(tabInfo);
80 | return this;
81 | }
82 |
83 | public TabManager append(@NonNull String tag,
84 | @NonNull Fragment fragment,
85 | @Nullable View mTabView,
86 | @Nullable SimpleReturnCallback mClickCallback) {
87 | if (fragment == null) return this;
88 | if (TextUtils.isEmpty(tag)) {
89 | tag = fragment.getClass().getSimpleName();
90 | }
91 | TabInfo tabInfo = new TabInfo(tag, fragment.getClass());
92 | tabInfo.mFragment = fragment;
93 | tabInfo.mTabView = mTabView;
94 | tabInfo.mClickCallback = mClickCallback;
95 | addToList(tabInfo);
96 | return this;
97 | }
98 |
99 |
100 | private void addToList(final TabInfo info) {
101 | if (info == null) return;
102 | int index = -1;
103 | int cursor = 0;
104 | for (TabInfo tabInfo : mTabInfos) {
105 | if (TextUtils.equals(tabInfo.tag, info.tag)) {
106 | index = cursor;
107 | break;
108 | }
109 | cursor++;
110 | }
111 | if (index != -1) {
112 | mTabInfos.set(index, info);
113 | } else {
114 | mTabInfos.add(info);
115 | }
116 | if (info.mTabView != null) {
117 | info.mTabView.setOnClickListener(new View.OnClickListener() {
118 | @Override
119 | public void onClick(View v) {
120 | if (info.mClickCallback != null && info.mClickCallback.onCall(info.tag)) {
121 | return;
122 | }
123 | switchTab(info);
124 | }
125 | });
126 | }
127 | }
128 |
129 | public TabManager enableTabAnimation() {
130 | this.tabAnimateEnable = true;
131 | return this;
132 | }
133 |
134 | public TabManager disableTabAnimation() {
135 | this.tabAnimateEnable = false;
136 | return this;
137 | }
138 |
139 | public void switchTab(String tag) {
140 | for (TabInfo mTabInfo : mTabInfos) {
141 | if (TextUtils.equals(mTabInfo.tag, tag)) {
142 | switchTab(mTabInfo);
143 | break;
144 | }
145 | }
146 | }
147 |
148 | private void switchTab(TabInfo info) {
149 | if (mCurTabInfo == null) {
150 | mCurTabInfo = info;
151 | } else {
152 | if (mCurTabInfo.compareTo(info)) {
153 | return;
154 | }
155 | mLastTabInfo = mCurTabInfo;
156 | mCurTabInfo = info;
157 | }
158 |
159 | FragmentTransaction ft = onTabChange(info);
160 | if (ft != null) {
161 | ft.commitAllowingStateLoss();
162 | }
163 |
164 | }
165 |
166 | private FragmentTransaction onTabChange(TabInfo info) {
167 | if (info == null) return null;
168 |
169 | FragmentTransaction ft = getManager().beginTransaction();
170 |
171 | Fragment target = info.getFragment();
172 | Fragment last = mLastTabInfo != null ? mLastTabInfo.getFragment() : null;
173 | if (target == null) {
174 | Log.e("", "Can not find tab for " + info.tag);
175 | return null;
176 | }
177 |
178 | if (target.isAdded()) {
179 | ft.show(target);
180 | } else {
181 | ft.add(mContainerId, target, info.tag);
182 | }
183 | if (last != null) {
184 | if (last.isAdded()) {
185 | ft.hide(last);
186 | }
187 | }
188 |
189 | for (TabInfo mTabInfo : mTabInfos) {
190 | if (mTabInfo.compareTo(info)) {
191 | selecteTab(mTabInfo);
192 | } else {
193 | unselectTab(mTabInfo);
194 | }
195 | }
196 | return ft;
197 | }
198 |
199 | private void selecteTab(TabInfo mTabInfo) {
200 | if (mTabInfo == null) return;
201 | if (mTabInfo.mTabView != null) {
202 | mTabInfo.mTabView.setSelected(true);
203 | if (tabAnimateEnable) {
204 | mTabInfo.mTabView.animate()
205 | .setDuration(ANIMATION_DURATION)
206 | .setInterpolator(new OvershootInterpolator(6))
207 | .scaleX(1)
208 | .scaleY(1).start();
209 | }
210 | }
211 | }
212 |
213 | private void unselectTab(TabInfo mTabInfo) {
214 | if (mTabInfo == null) return;
215 | if (mTabInfo.mTabView != null) {
216 | mTabInfo.mTabView.setSelected(false);
217 | if (tabAnimateEnable) {
218 | mTabInfo.mTabView.animate()
219 | .setDuration(ANIMATION_DURATION)
220 | .setInterpolator(new OvershootInterpolator(6))
221 | .scaleX(.9f)
222 | .scaleY(.9f).start();
223 | }
224 | }
225 | }
226 |
227 |
228 | public void destroy() {
229 | for (TabInfo mTabInfo : mTabInfos) {
230 | mTabInfo.destroy();
231 | }
232 | mTabInfos.clear();
233 | }
234 |
235 |
236 | public void onRestoreInstanceState(Bundle savedInstanceState) {
237 | if (savedInstanceState == null || getManager() == null || getManager().isDestroyed())
238 | return;
239 |
240 | String tag = savedInstanceState.getString(SAVE_TAG, null);
241 | if (TextUtils.isEmpty(tag)) {
242 | tag = mTabInfos.get(0).tag;
243 | }
244 |
245 | TabInfo tabInfo = null;
246 | List hidedTabs = new ArrayList<>();
247 |
248 | for (TabInfo mTabInfo : mTabInfos) {
249 | String tabTag = mTabInfo.tag;
250 | Fragment fragment = getManager().findFragmentByTag(tabTag);
251 | if (fragment != null) {
252 | mTabInfo.mFragment = fragment;
253 | if (fragment.isHidden() || !fragment.isAdded()) {
254 | if (TextUtils.equals(tag, tabTag)) {
255 | tabInfo = mTabInfo;
256 | } else {
257 | hidedTabs.add(mTabInfo);
258 | }
259 | }
260 | }
261 | }
262 | FragmentTransaction ft = onTabChange(tabInfo);
263 | if (ft != null) {
264 | for (TabInfo hidedTab : hidedTabs) {
265 | if (hidedTab.mFragment != null) {
266 | ft.hide(hidedTab.mFragment);
267 | }
268 | }
269 | ft.commitAllowingStateLoss();
270 | }
271 |
272 |
273 | }
274 |
275 | public void onSaveInstanceState(Bundle outState) {
276 | if (outState == null) return;
277 | if (mCurTabInfo != null) {
278 | outState.putString(SAVE_TAG, mCurTabInfo.tag);
279 | }
280 | }
281 |
282 | final class TabInfo {
283 | private final String tag;
284 | private final Class extends Fragment> clas;
285 | private Bundle mArguments;
286 | private Fragment mFragment;
287 | private View mTabView;
288 | private SimpleReturnCallback mClickCallback;
289 |
290 | public TabInfo(String tag, Class extends Fragment> clss) {
291 | this.tag = tag;
292 | this.clas = clss;
293 | }
294 |
295 | boolean compareTo(TabInfo mOther) {
296 | if (mOther == null) return false;
297 | if (this == mOther) return true;
298 | return TextUtils.equals(tag, mOther.tag);
299 | }
300 |
301 |
302 | void destroy() {
303 | mArguments = null;
304 | mFragment = null;
305 | mTabView.setOnClickListener(null);
306 | mTabView = null;
307 | mClickCallback = null;
308 | }
309 |
310 |
311 | Fragment getFragment() {
312 | if (mFragment != null) return mFragment;
313 | if (clas == null) return null;
314 | mFragment = Fragment.instantiate(mContext, clas.getName(), mArguments);
315 | return mFragment;
316 | }
317 |
318 |
319 | }
320 |
321 | public interface FragmentManagerProvider {
322 | FragmentManager onGetFragmentManager();
323 | }
324 |
325 | }
326 |
--------------------------------------------------------------------------------
/common/src/main/java/com/razerdp/common/modules/BaseModulesProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.common.modules;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentValues;
5 | import android.content.Context;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 |
9 | import androidx.annotation.NonNull;
10 |
11 |
12 | /**
13 | * Created by 大灯泡 on 2019/7/18
14 | *
15 | * Description:
16 | */
17 | public abstract class BaseModulesProvider extends ContentProvider {
18 | @Override
19 | public boolean onCreate() {
20 | onInit(getContext());
21 | return false;
22 | }
23 |
24 | public abstract void onInit(@NonNull Context context);
25 |
26 | @Override
27 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
28 | return null;
29 | }
30 |
31 |
32 | @Override
33 | public String getType(Uri uri) {
34 | return null;
35 | }
36 |
37 |
38 | @Override
39 | public Uri insert(Uri uri, ContentValues values) {
40 | return null;
41 | }
42 |
43 | @Override
44 | public int delete(Uri uri, String selection, String[] selectionArgs) {
45 | return 0;
46 | }
47 |
48 | @Override
49 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
50 | return 0;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/common/src/main/res/anim/slide_left_in.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/common/src/main/res/anim/slide_left_out.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/common/src/main/res/anim/slide_right_in.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/common/src/main/res/anim/slide_right_out.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/common/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #23242e
4 | #1A1B22
5 | #6B7887
6 |
7 | #e0e0e0
8 | #826655
9 | #826655
10 | #826655
11 | #999999
12 | #F2F5FC
13 |
14 | #d2d5dd
15 | #fee4b7
16 |
17 |
18 |
--------------------------------------------------------------------------------
/common/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | common
3 |
4 |
--------------------------------------------------------------------------------
/common/src/main/res/values/styles_app.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
20 |
21 |
24 |
25 |
31 |
32 |
--------------------------------------------------------------------------------
/common/src/test/java/com/razerdp/common/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.common;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | //Android
3 | compileSdkVersion = 28
4 | minSdkVersion = 19
5 | targetSdkVersion = 28
6 | versionCode = 1
7 | versionName = "1.0.0"
8 | }
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 18 09:46:59 CST 2019
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-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/lib_annotation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib_annotation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | }
6 |
7 | sourceCompatibility = JavaVersion.VERSION_1_8
8 | targetCompatibility = JavaVersion.VERSION_1_8
9 |
--------------------------------------------------------------------------------
/lib_annotation/src/main/java/com/razerdp/annotations/AnnotationConfig.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.annotations;
2 |
3 | /**
4 | * Created by razerdp on 2019/7/18
5 | *
6 | * Description router code gen
7 | */
8 | public class AnnotationConfig {
9 |
10 | public static class ModuleServiceConfig {
11 | public static final String LOG_PRE_FIX = "ModuleServicesCompiler:: ";
12 | public static final String TARGET_PACKAGE = "com.razerdp.router.core";
13 | public static final String GEN_PACKAGE = TARGET_PACKAGE + ".gen";
14 | public static final String GENERATE_FILE_NAME = "ServicesImplGen";
15 | public static final String FIELD_MAP = "SERVICES_IMPL_MAP";
16 | public static final String SERVICES_BASE_PACKAGE = "com.razerdp.router";
17 | public static final String INTERFACE_PROCESSOR = ".IModuleServiceProvider";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/lib_annotation/src/main/java/com/razerdp/annotations/modules/ServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.annotations.modules;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by razerdp on 2019/7/18
10 | *
11 | * Description annotation for module service
12 | */
13 | @Retention(RetentionPolicy.CLASS)
14 | @Target(ElementType.TYPE)
15 | public @interface ServiceImpl {
16 |
17 | //service tag
18 | int value() default 0;
19 | }
--------------------------------------------------------------------------------
/lib_processor/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib_processor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | implementation project(':lib_annotation')
6 | implementation 'com.squareup:javapoet:1.10.0'
7 | implementation 'com.google.auto.service:auto-service:1.0-rc5'
8 | }
9 |
10 | sourceCompatibility = JavaVersion.VERSION_1_8
11 | targetCompatibility = JavaVersion.VERSION_1_8
12 |
--------------------------------------------------------------------------------
/lib_processor/src/main/java/com/razerdp/BaseProcessor.java:
--------------------------------------------------------------------------------
1 | package com.razerdp;
2 |
3 |
4 | import com.razerdp.utils.Logger;
5 |
6 | import java.lang.annotation.Annotation;
7 | import java.util.LinkedHashSet;
8 | import java.util.Set;
9 |
10 | import javax.annotation.processing.AbstractProcessor;
11 | import javax.annotation.processing.Filer;
12 | import javax.annotation.processing.ProcessingEnvironment;
13 | import javax.lang.model.SourceVersion;
14 | import javax.lang.model.element.TypeElement;
15 | import javax.lang.model.util.Elements;
16 | import javax.lang.model.util.Types;
17 |
18 | /**
19 | * Created by razerdp on 2019/5/30
20 | *
21 | * Description base processor
22 | */
23 | public abstract class BaseProcessor extends AbstractProcessor {
24 | protected Filer mFiler;
25 | protected Logger logger;
26 | protected Types types;
27 | protected Elements elementUtils;
28 |
29 | @Override
30 | public synchronized void init(ProcessingEnvironment processingEnv) {
31 | super.init(processingEnv);
32 |
33 | mFiler = processingEnv.getFiler();
34 | types = processingEnv.getTypeUtils();
35 | elementUtils = processingEnv.getElementUtils();
36 | logger = new Logger(processingEnv.getMessager());
37 | }
38 |
39 | @Override
40 | public SourceVersion getSupportedSourceVersion() {
41 | return SourceVersion.latestSupported();
42 | }
43 |
44 | @Override
45 | public Set getSupportedAnnotationTypes() {
46 | Set types = new LinkedHashSet<>();
47 | Set> annotations = new LinkedHashSet<>();
48 | onAppendAnnotation(annotations);
49 | for (Class extends Annotation> annotation : annotations) {
50 | types.add(annotation.getCanonicalName());
51 | }
52 | return types;
53 | }
54 |
55 | protected abstract void onAppendAnnotation(Set> set);
56 |
57 | public void logi(CharSequence info) {
58 | logger.i(info);
59 | }
60 |
61 | public void loge(CharSequence error) {
62 | logger.e(error);
63 | }
64 |
65 | public void loge(Throwable error) {
66 | logger.e(error);
67 | }
68 |
69 | public void logw(CharSequence warning) {
70 | logger.w(warning);
71 | }
72 |
73 |
74 | public TypeElement getTypeElement(String str) {
75 | return elementUtils.getTypeElement(str);
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/lib_processor/src/main/java/com/razerdp/processor/modules/ModuleServicesProcessor.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.processor.modules;
2 |
3 | import com.google.auto.service.AutoService;
4 | import com.razerdp.BaseProcessor;
5 | import com.razerdp.annotations.modules.ServiceImpl;
6 | import com.squareup.javapoet.ClassName;
7 | import com.squareup.javapoet.CodeBlock;
8 | import com.squareup.javapoet.FieldSpec;
9 | import com.squareup.javapoet.JavaFile;
10 | import com.squareup.javapoet.MethodSpec;
11 | import com.squareup.javapoet.ParameterizedTypeName;
12 | import com.squareup.javapoet.TypeName;
13 | import com.squareup.javapoet.TypeSpec;
14 |
15 | import java.io.IOException;
16 | import java.lang.annotation.Annotation;
17 | import java.util.ArrayList;
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 | import java.util.Set;
22 |
23 | import javax.annotation.processing.ProcessingEnvironment;
24 | import javax.annotation.processing.Processor;
25 | import javax.annotation.processing.RoundEnvironment;
26 | import javax.lang.model.element.Element;
27 | import javax.lang.model.element.ElementKind;
28 | import javax.lang.model.element.TypeElement;
29 | import javax.lang.model.type.TypeKind;
30 | import javax.lang.model.type.TypeMirror;
31 |
32 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.FIELD_MAP;
33 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.GENERATE_FILE_NAME;
34 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.GEN_PACKAGE;
35 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.INTERFACE_PROCESSOR;
36 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.LOG_PRE_FIX;
37 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.SERVICES_BASE_PACKAGE;
38 | import static com.razerdp.annotations.AnnotationConfig.ModuleServiceConfig.TARGET_PACKAGE;
39 | import static javax.lang.model.element.Modifier.FINAL;
40 | import static javax.lang.model.element.Modifier.PRIVATE;
41 | import static javax.lang.model.element.Modifier.PUBLIC;
42 | import static javax.lang.model.element.Modifier.STATIC;
43 |
44 | /**
45 | * Created by razerdp on 2019/7/18
46 | *
47 | * Description:compiler for {@link com.razerdp.annotations.modules.ServiceImpl}
48 | */
49 | @AutoService(Processor.class)
50 | public class ModuleServicesProcessor extends BaseProcessor {
51 |
52 | private static final String KEY_MODULE_NAME = "MODULE_NAME";
53 | private String moduleName = null;
54 | private static final HashMap> mServiceImplMap = new HashMap<>();
55 |
56 | @Override
57 | public synchronized void init(ProcessingEnvironment processingEnv) {
58 | super.init(processingEnv);
59 | Map options = processingEnv.getOptions();
60 | if (options != null && !options.isEmpty()) {
61 | moduleName = options.get(KEY_MODULE_NAME);
62 | }
63 | }
64 |
65 | private static class InnerInfo {
66 | final TypeElement mirror;
67 | final String fullClassName;
68 | final int tag;
69 |
70 | InnerInfo(TypeElement mirror, String fullClassName, int tag) {
71 | this.mirror = mirror;
72 | this.fullClassName = fullClassName;
73 | this.tag = tag;
74 | }
75 | }
76 |
77 | @Override
78 | protected void onAppendAnnotation(Set> set) {
79 | set.add(ServiceImpl.class);
80 | }
81 |
82 | @Override
83 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnvironment) {
84 | if (roundEnvironment.processingOver()) {
85 | if (!set.isEmpty()) {
86 | loge(LOG_PRE_FIX + "Unexpected processing state: annotations still available after processing over");
87 | return false;
88 | }
89 | }
90 | if (set.isEmpty()) {
91 | return false;
92 | }
93 | logi(LOG_PRE_FIX + "Processing");
94 | mServiceImplMap.clear();
95 | try {
96 | collectionImpls(set, roundEnvironment);
97 | if (!mServiceImplMap.isEmpty()) {
98 | printMethod();
99 | createFile();
100 | } else {
101 | logi(LOG_PRE_FIX + "find nothings");
102 | }
103 | logi(LOG_PRE_FIX + "finish\n\n");
104 | } catch (Exception e) {
105 | loge(e);
106 | }
107 | return false;
108 | }
109 |
110 | private void collectionImpls(Set extends TypeElement> set, RoundEnvironment env) {
111 | Set extends Element> elements = env.getElementsAnnotatedWith(ServiceImpl.class);
112 | for (Element element : elements) {
113 |
114 | //if this element is non of class,don't work for that
115 | if (!(element instanceof TypeElement)) continue;
116 |
117 | TypeElement typeElement = (TypeElement) element;
118 |
119 | TypeMirror mirror = typeElement.asType();
120 | if (!(mirror.getKind() == TypeKind.DECLARED)) {
121 | continue;
122 | }
123 |
124 | List extends TypeMirror> superClassElement = types.directSupertypes(mirror);
125 |
126 | if (superClassElement == null || superClassElement.size() <= 0) continue;
127 |
128 | TypeMirror serviceSuperClassElement = null;
129 | for (TypeMirror typeMirror : superClassElement) {
130 | logi(LOG_PRE_FIX + typeMirror.toString());
131 |
132 | //check service path
133 | if (typeMirror.toString().startsWith(SERVICES_BASE_PACKAGE)) {
134 | serviceSuperClassElement = typeMirror;
135 | break;
136 | }
137 | }
138 |
139 | if (serviceSuperClassElement == null) continue;
140 |
141 |
142 | TypeName classType = ClassName.get(serviceSuperClassElement);
143 |
144 |
145 | if (element.getKind() != ElementKind.CLASS) {
146 | loge(LOG_PRE_FIX + elements.toString() + " :: @ServiceImpl is only valid for class");
147 | continue;
148 | }
149 | if (!element.getModifiers().contains(PUBLIC)) {
150 | loge(LOG_PRE_FIX + elements.toString() + " :: @ServiceImpl is only valid for public class");
151 | continue;
152 | }
153 |
154 |
155 | List innerInfos = null;
156 | if (mServiceImplMap.containsKey(classType)) {
157 | innerInfos = mServiceImplMap.get(classType);
158 | }
159 |
160 | if (innerInfos == null) {
161 | innerInfos = new ArrayList<>();
162 | mServiceImplMap.put(classType, innerInfos);
163 | }
164 |
165 | int tag = element.getAnnotation(ServiceImpl.class).value();
166 |
167 | InnerInfo info = new InnerInfo(typeElement, typeElement.getQualifiedName().toString(), tag);
168 | innerInfos.add(info);
169 | }
170 | }
171 |
172 | private void createFile() {
173 | try {
174 | logi(LOG_PRE_FIX + "generate code");
175 | JavaFile javaFile = JavaFile.builder(GEN_PACKAGE, createType())
176 | .addFileComment("$S", "Generated code from " + GEN_PACKAGE + "." + GENERATE_FILE_NAME + " Do not modify!")
177 | .build();
178 | javaFile.writeTo(mFiler);
179 | } catch (IOException e) {
180 | loge(e);
181 | }
182 | }
183 |
184 |
185 | private TypeSpec createType() {
186 | TypeSpec.Builder result = TypeSpec.classBuilder(GENERATE_FILE_NAME + "$$" + moduleName)
187 | .addModifiers(PUBLIC, FINAL);
188 | result.addSuperinterface(ClassName.get(getTypeElement(TARGET_PACKAGE + INTERFACE_PROCESSOR)));
189 | result.addField(createMapField());
190 | result.addMethod(createMethod());
191 | result.addStaticBlock(fillStaticBlock());
192 | return result.build();
193 | }
194 |
195 | private FieldSpec createMapField() {
196 | ParameterizedTypeName typeMap = ParameterizedTypeName.get(ClassName.get(HashMap.class),
197 | ClassName.get(Class.class),
198 | ParameterizedTypeName.get(ClassName.get("android.util", "SparseArray"),
199 | ClassName.get(Object.class)));
200 |
201 | FieldSpec.Builder result = FieldSpec.builder(typeMap, FIELD_MAP)
202 | .addModifiers(PRIVATE, STATIC, FINAL)
203 | .initializer("new $T()", typeMap);
204 | return result.build();
205 | }
206 |
207 | private MethodSpec createMethod() {
208 | ParameterizedTypeName typeMap = ParameterizedTypeName.get(ClassName.get(HashMap.class),
209 | ClassName.get(Class.class),
210 | ParameterizedTypeName.get(ClassName.get("android.util", "SparseArray"),
211 | ClassName.get(Object.class)));
212 |
213 | MethodSpec.Builder result = MethodSpec.methodBuilder("getMap")
214 | .addAnnotation(Override.class)
215 | .addModifiers(PUBLIC)
216 | .addStatement("return " + FIELD_MAP)
217 | .returns(typeMap);
218 |
219 | return result.build();
220 | }
221 |
222 | private CodeBlock fillStaticBlock() {
223 | CodeBlock.Builder result = CodeBlock.builder();
224 | final String serviceInfosName = "servicesImplList";
225 | TypeName sparseArrayType = ClassName.get("android.util", "SparseArray");
226 |
227 | result.addStatement("\t$T<$T> " + serviceInfosName,
228 | sparseArrayType,
229 | ClassName.get(Object.class));
230 |
231 | for (HashMap.Entry> entry : mServiceImplMap.entrySet()) {
232 |
233 | result.addStatement("\t" + serviceInfosName + " = new $T()",
234 | sparseArrayType);
235 |
236 | for (InnerInfo innerInfo : entry.getValue()) {
237 | result.addStatement("\t" + serviceInfosName + ".put($L, new $T())",
238 | innerInfo.tag,
239 | ClassName.get(innerInfo.mirror));
240 | }
241 |
242 | result.addStatement("\t" + FIELD_MAP + ".put($T.class, " + serviceInfosName + ")",
243 | entry.getKey());
244 |
245 | }
246 | return result.build();
247 | }
248 |
249 | private void printMethod() {
250 | for (HashMap.Entry> entry : mServiceImplMap.entrySet()) {
251 | String key = entry.getKey().toString();
252 | StringBuilder builder = new StringBuilder();
253 | builder.append(" find services impl for : ").append(key).append(" [\n");
254 | List list = entry.getValue();
255 | if (list != null && list.size() > 0) {
256 | for (InnerInfo innerInfo : list) {
257 | builder.append("tag = ")
258 | .append(String.valueOf(innerInfo.tag))
259 | .append('\n')
260 | .append("class name = ")
261 | .append(innerInfo.fullClassName)
262 | .append('\n');
263 |
264 | }
265 | builder.append("]");
266 | }
267 | logi(LOG_PRE_FIX + builder);
268 | }
269 | }
270 | }
271 |
--------------------------------------------------------------------------------
/lib_processor/src/main/java/com/razerdp/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.utils;
2 |
3 | import javax.annotation.processing.Messager;
4 | import javax.tools.Diagnostic;
5 |
6 | /**
7 | * Created by razerdp on 2019/5/30
8 | */
9 | public class Logger {
10 | private Messager msg;
11 |
12 | public Logger(Messager messager) {
13 | msg = messager;
14 | }
15 |
16 | public void i(CharSequence info) {
17 | if (Utils.noEmpty(info)) {
18 | msg.printMessage(Diagnostic.Kind.NOTE, info);
19 | }
20 | }
21 |
22 | public void e(CharSequence error) {
23 | if (Utils.noEmpty(error)) {
24 | msg.printMessage(Diagnostic.Kind.ERROR, "An exception is encountered, [" + error + "]");
25 | }
26 | }
27 |
28 | public void e(Throwable error) {
29 | if (null != error) {
30 | msg.printMessage(Diagnostic.Kind.ERROR, "An exception is encountered, [" + error.getMessage() + "]" + "\n" + formatStackTrace(error.getStackTrace()));
31 | }
32 | }
33 |
34 | public void w(CharSequence warning) {
35 | if (Utils.noEmpty(warning)) {
36 | msg.printMessage(Diagnostic.Kind.WARNING, warning);
37 | }
38 | }
39 |
40 |
41 | private String formatStackTrace(StackTraceElement[] stackTrace) {
42 | StringBuilder sb = new StringBuilder();
43 | for (StackTraceElement element : stackTrace) {
44 | sb.append(" at ").append(element.toString());
45 | sb.append("\n");
46 | }
47 | return sb.toString();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/lib_processor/src/main/java/com/razerdp/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.utils;
2 |
3 | /**
4 | * Created by razerdp on 2019/5/30
5 | */
6 | public class Utils {
7 |
8 | public static boolean isEmpty(CharSequence str) {
9 | return str == null || str.length() == 0;
10 | }
11 |
12 | public static boolean noEmpty(CharSequence str) {
13 | return !isEmpty(str);
14 | }
15 |
16 | public static boolean equals(CharSequence a, CharSequence b) {
17 | if (a == b) return true;
18 | int length;
19 | if (a != null && b != null && (length = a.length()) == b.length()) {
20 | if (a instanceof String && b instanceof String) {
21 | return a.equals(b);
22 | } else {
23 | for (int i = 0; i < length; i++) {
24 | if (a.charAt(i) != b.charAt(i)) return false;
25 | }
26 | return true;
27 | }
28 | }
29 | return false;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib_processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | com.razerdp.processor.modules.ModuleServicesProcessor
--------------------------------------------------------------------------------
/module_first/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module_first/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api project(':router')
6 |
7 | annotationProcessor project(':lib_processor')
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/module_first/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 |
--------------------------------------------------------------------------------
/module_first/src/androidTest/java/com/razerdp/module_first/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_first;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_first.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/module_first/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/module_first/src/main/java/com/razerdp/module/first/ModuleFirstProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.first;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import com.razerdp.common.modules.BaseModulesProvider;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | public class ModuleFirstProvider extends BaseModulesProvider {
15 | @Override
16 | public void onInit(@NonNull Context context) {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/module_first/src/main/java/com/razerdp/module/first/services/ModuleFirstServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.first.services;
2 |
3 | import androidx.fragment.app.Fragment;
4 |
5 | import com.razerdp.annotations.modules.ServiceImpl;
6 | import com.razerdp.module.first.ui.ModuleFirstFragment;
7 | import com.razerdp.router.modules.ModuleFirstService;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | @ServiceImpl
15 | public class ModuleFirstServiceImpl implements ModuleFirstService {
16 | @Override
17 | public Class extends Fragment> getFragmentClass() {
18 | return ModuleFirstFragment.class;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/module_first/src/main/java/com/razerdp/module/first/ui/ModuleFirstFragment.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.first.ui;
2 |
3 | import android.view.View;
4 |
5 | import com.razerdp.baselib.base.BaseFragment;
6 | import com.razerdp.module.first.R;
7 |
8 | /**
9 | * Created by 大灯泡 on 2019/7/18
10 | *
11 | * Description:
12 | */
13 | public class ModuleFirstFragment extends BaseFragment {
14 | @Override
15 | public int contentViewLayoutId() {
16 | return R.layout.fragment_first;
17 | }
18 |
19 | @Override
20 | protected void onInitViews(View mRootView) {
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/module_first/src/main/res/layout/fragment_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/module_first/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_first
3 |
4 |
--------------------------------------------------------------------------------
/module_first/src/test/java/com/razerdp/module_first/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_first;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/module_second/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module_second/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api project(':router')
6 |
7 | annotationProcessor project(':lib_processor')
8 |
9 | }
--------------------------------------------------------------------------------
/module_second/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 |
--------------------------------------------------------------------------------
/module_second/src/androidTest/java/com/razerdp/module_second/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_second;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_second.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/module_second/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/module_second/src/main/java/com/razerdp/module/second/ModuleSecondProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.second;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import com.razerdp.common.modules.BaseModulesProvider;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | public class ModuleSecondProvider extends BaseModulesProvider {
15 | @Override
16 | public void onInit(@NonNull Context context) {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/module_second/src/main/java/com/razerdp/module/second/services/ModuleSecondServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.second.services;
2 |
3 | import androidx.fragment.app.Fragment;
4 |
5 | import com.razerdp.annotations.modules.ServiceImpl;
6 | import com.razerdp.module.second.ui.ModuleSecondFragment;
7 | import com.razerdp.router.modules.ModuleSecondService;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | @ServiceImpl
15 | public class ModuleSecondServiceImpl implements ModuleSecondService {
16 | @Override
17 | public Class extends Fragment> getFragmentClass() {
18 | return ModuleSecondFragment.class;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/module_second/src/main/java/com/razerdp/module/second/ui/ModuleSecondFragment.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.second.ui;
2 |
3 | import android.view.View;
4 |
5 | import androidx.fragment.app.Fragment;
6 |
7 | import com.razerdp.baselib.base.BaseFragment;
8 | import com.razerdp.module.second.R;
9 |
10 | /**
11 | * Created by 大灯泡 on 2019/7/18
12 | *
13 | * Description:
14 | */
15 | public class ModuleSecondFragment extends BaseFragment {
16 | @Override
17 | public int contentViewLayoutId() {
18 | return R.layout.fragment_second;
19 | }
20 |
21 | @Override
22 | protected void onInitViews(View mRootView) {
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/module_second/src/main/res/layout/fragment_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/module_second/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_second
3 |
4 |
--------------------------------------------------------------------------------
/module_second/src/test/java/com/razerdp/module_second/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_second;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/module_third/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module_third/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api project(':router')
6 |
7 | annotationProcessor project(':lib_processor')
8 |
9 | }
--------------------------------------------------------------------------------
/module_third/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 |
--------------------------------------------------------------------------------
/module_third/src/androidTest/java/com/razerdp/module_third/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_third;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_third.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/module_third/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/module_third/src/main/java/com/razerdp/module/third/ModuleThirdProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.third;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import com.razerdp.common.modules.BaseModulesProvider;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | public class ModuleThirdProvider extends BaseModulesProvider {
15 | @Override
16 | public void onInit(@NonNull Context context) {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/module_third/src/main/java/com/razerdp/module/third/services/ModuleThirdServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.third.services;
2 |
3 | import androidx.fragment.app.Fragment;
4 |
5 | import com.razerdp.annotations.modules.ServiceImpl;
6 | import com.razerdp.module.third.ui.ModuleThirdFragment;
7 | import com.razerdp.router.modules.ModuleThirdService;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | @ServiceImpl
15 | public class ModuleThirdServiceImpl implements ModuleThirdService {
16 | @Override
17 | public Class extends Fragment> getFragmentClass() {
18 | return ModuleThirdFragment.class;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/module_third/src/main/java/com/razerdp/module/third/ui/ModuleThirdFragment.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.third.ui;
2 |
3 | import android.view.View;
4 |
5 | import com.razerdp.baselib.base.BaseFragment;
6 | import com.razerdp.module.third.R;
7 |
8 | /**
9 | * Created by 大灯泡 on 2019/7/18
10 | *
11 | * Description:
12 | */
13 | public class ModuleThirdFragment extends BaseFragment {
14 | @Override
15 | public int contentViewLayoutId() {
16 | return R.layout.fragment_third;
17 | }
18 |
19 | @Override
20 | protected void onInitViews(View mRootView) {
21 |
22 | }
23 | }
--------------------------------------------------------------------------------
/module_third/src/main/res/layout/fragment_third.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/module_third/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_third
3 |
4 |
--------------------------------------------------------------------------------
/module_third/src/test/java/com/razerdp/module_third/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_third;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/modules_private/module_first_private/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | defaultConfig {
6 | applicationId "com.razerdp.module_first_private"
7 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
8 | }
9 |
10 | }
11 |
12 | dependencies {
13 | implementation fileTree(dir: 'libs', include: ['*.jar'])
14 | implementation project(':module_first')
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/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 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/androidTest/java/com/razerdp/module_first_private/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_first_private;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_first_private.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/java/com/razerdp/module/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.annotation.Nullable;
6 | import androidx.appcompat.app.AppCompatActivity;
7 |
8 | import com.razerdp.module.first.ui.ModuleFirstFragment;
9 | import com.razerdp.module_first_private.R;
10 |
11 | /**
12 | * Created by 大灯泡 on 2019/7/18
13 | *
14 | * Description:
15 | */
16 | public class MainActivity extends AppCompatActivity {
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | getSupportFragmentManager()
23 | .beginTransaction()
24 | .add(R.id.container, new ModuleFirstFragment(), "ModuleFirstFragment")
25 | .commitAllowingStateLoss();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/java/com/razerdp/module/first/ModuleFirstApplication.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.first;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by 大灯泡 on 2019/7/18
7 | *
8 | * Description:
9 | */
10 | public class ModuleFirstApplication extends Application {
11 | }
12 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_first_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_first_private
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/modules_private/module_first_private/src/test/java/com/razerdp/module_first_private/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_first_private;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/modules_private/module_second_private/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | defaultConfig {
6 | applicationId "com.razerdp.module_second_private"
7 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
8 | }
9 |
10 | }
11 |
12 | dependencies {
13 | implementation fileTree(dir: 'libs', include: ['*.jar'])
14 | implementation project(':module_second')
15 |
16 | }
--------------------------------------------------------------------------------
/modules_private/module_second_private/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 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/androidTest/java/com/razerdp/module_second_private/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_second_private;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_second_private.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/java/com/razerdp/module/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.annotation.Nullable;
6 | import androidx.appcompat.app.AppCompatActivity;
7 |
8 | import com.razerdp.module.second.ui.ModuleSecondFragment;
9 | import com.razerdp.module_second_private.R;
10 |
11 |
12 | /**
13 | * Created by 大灯泡 on 2019/7/18
14 | *
15 | * Description:
16 | */
17 | public class MainActivity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | getSupportFragmentManager()
24 | .beginTransaction()
25 | .add(R.id.container, new ModuleSecondFragment(), "ModuleSecondFragment")
26 | .commitAllowingStateLoss();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/java/com/razerdp/module/second/ModuleSecondApplication.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.second;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by 大灯泡 on 2019/7/18
7 | *
8 | * Description:
9 | */
10 | public class ModuleSecondApplication extends Application {
11 | }
12 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_second_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_second_private
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/modules_private/module_second_private/src/test/java/com/razerdp/module_second_private/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_second_private;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/modules_private/module_third_private/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | defaultConfig {
6 | applicationId "com.razerdp.module_third_private"
7 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
8 | }
9 |
10 | }
11 |
12 | dependencies {
13 | implementation fileTree(dir: 'libs', include: ['*.jar'])
14 | implementation project(':module_third')
15 |
16 | }
--------------------------------------------------------------------------------
/modules_private/module_third_private/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 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/androidTest/java/com/razerdp/module_third_private/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_third_private;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.module_third_private.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/java/com/razerdp/module/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.annotation.Nullable;
6 | import androidx.appcompat.app.AppCompatActivity;
7 |
8 | import com.razerdp.module.third.ui.ModuleThirdFragment;
9 | import com.razerdp.module_third_private.R;
10 |
11 |
12 | /**
13 | * Created by 大灯泡 on 2019/7/18
14 | *
15 | * Description:
16 | */
17 | public class MainActivity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | getSupportFragmentManager()
24 | .beginTransaction()
25 | .add(R.id.container, new ModuleThirdFragment(), "ModuleThirdFragment")
26 | .commitAllowingStateLoss();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/java/com/razerdp/module/third/ModuleThirdApplication.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module.third;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by 大灯泡 on 2019/7/18
7 | *
8 | * Description:
9 | */
10 | public class ModuleThirdApplication extends Application {
11 | }
12 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/Component/fcb1679e81fa5ede83e8f5bf16b8fe2e571657e5/modules_private/module_third_private/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_third_private
3 |
4 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/modules_private/module_third_private/src/test/java/com/razerdp/module_third_private/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.module_third_private;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/router/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/router/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | dependencies {
4 | api fileTree(dir: 'libs', include: ['*.jar'])
5 | api project(':common')
6 | }
7 |
--------------------------------------------------------------------------------
/router/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 |
--------------------------------------------------------------------------------
/router/src/androidTest/java/com/razerdp/router/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.router;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.razerdp.router.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/router/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/router/src/main/java/com/razerdp/router/core/IModuleServiceProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.router.core;
2 |
3 | import android.util.SparseArray;
4 |
5 | import java.util.HashMap;
6 |
7 | /**
8 | * Created by 大灯泡 on 2019/7/18
9 | *
10 | * Description:module生成文件提供
11 | */
12 | public interface IModuleServiceProvider {
13 | HashMap> getMap();
14 | }
15 |
--------------------------------------------------------------------------------
/router/src/main/java/com/razerdp/router/core/InitProvider.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.router.core;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import com.razerdp.common.modules.BaseModulesProvider;
8 |
9 | /**
10 | * Created by 大灯泡 on 2019/7/18
11 | *
12 | * Description:
13 | */
14 | public class InitProvider extends BaseModulesProvider {
15 | @Override
16 | public void onInit(@NonNull Context context) {
17 | ModuleManager.INSTANCE.init(context);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/router/src/main/java/com/razerdp/router/core/ModuleManager.java:
--------------------------------------------------------------------------------
1 | package com.razerdp.router.core;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.util.SparseArray;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 |
10 | import com.razerdp.baselib.interfaces.SimpleCallback;
11 | import com.razerdp.baselib.utils.ToolUtil;
12 | import com.razerdp.router.core.define.ModuleDefine;
13 | import com.razerdp.router.core.utils.ClassUtils;
14 | import com.razerdp.router.core.utils.ModuleUtils;
15 | import com.razerdp.router.core.utils.SPUtils;
16 |
17 | import java.util.HashMap;
18 | import java.util.Map;
19 | import java.util.Set;
20 |
21 | /**
22 | * Created by 大灯泡 on 2019/7/18
23 | *
24 | * Description:module services单例,用于获取各个modules暴露的服务
25 | */
26 | public enum ModuleManager {
27 | INSTANCE;
28 | private static final String TAG = "ModuleManager";
29 | //services的实例缓存
30 | private Map> routerImplCacheMap = new HashMap<>();
31 |
32 | protected void init(Context context) {
33 | routerImplCacheMap.clear();
34 | boolean needUpdate = ModuleUtils.isNewVersion(context);
35 | if (needUpdate) {
36 | scan(context);
37 | ModuleUtils.updateVersion(context);
38 | } else {
39 | long startInit = System.currentTimeMillis();
40 | Set mapping = SPUtils.getPreference().getStringSet(ModuleDefine.KEY_SERVICE_IMPL_CACHE, null);
41 | if (mapping != null) {
42 | attach(mapping);
43 | } else {
44 | scan(context);
45 | }
46 | Log.i(TAG, "init duration >> " + (System.currentTimeMillis() - startInit) + " ms");
47 | }
48 |
49 | }
50 |
51 | private void scan(Context context) {
52 | try {
53 | long startInit = System.currentTimeMillis();
54 | Set mapping = ClassUtils.getFileNameByPackageName(context, ModuleDefine.ROOT_PAKCAGE);
55 |
56 | if (!mapping.isEmpty()) {
57 | SPUtils.getEditor().putStringSet(ModuleDefine.KEY_SERVICE_IMPL_CACHE, mapping).apply();
58 | }
59 | attach(mapping);
60 | Log.i(TAG, "init duration >> " + (System.currentTimeMillis() - startInit) + " ms");
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | throw new IllegalArgumentException("组件初始化失败");
64 | }
65 | }
66 |
67 | private void attach(Set from) {
68 | for (String s : from) {
69 | Object object = create(s);
70 | if (object instanceof IModuleServiceProvider) {
71 | HashMap> map = ((IModuleServiceProvider) object).getMap();
72 | if (map != null && !map.isEmpty()) {
73 | routerImplCacheMap.putAll(map);
74 | }
75 | }
76 | }
77 | }
78 |
79 | public T getService(@NonNull Class clazz) {
80 | return getService(clazz, 0);
81 | }
82 |
83 | @Nullable
84 | public T getService(@NonNull Class clazz, int tag) {
85 | T result = null;
86 | SparseArray