├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── copyright │ ├── profiles_settings.xml │ └── xuexiang.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml └── runConfigurations.xml ├── JitPackUpload.gradle ├── README.md ├── apk ├── remote_demo_1.0.apk └── xipc_demo_1.0.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xuexiang │ │ └── xipcdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── aidl │ │ └── com │ │ │ └── xuexiang │ │ │ └── aidl │ │ │ └── ICompute.aidl │ ├── java │ │ └── com │ │ │ └── xuexiang │ │ │ ├── aidl │ │ │ └── AIDLService.java │ │ │ └── xipcdemo │ │ │ ├── App.java │ │ │ ├── activity │ │ │ ├── MainActivity.java │ │ │ └── SecondProcessActivity.java │ │ │ ├── fragment │ │ │ ├── AIDLProcessFragment.java │ │ │ ├── DifferentProcessFragment.java │ │ │ ├── MainFragment.java │ │ │ └── SameProcessFragment.java │ │ │ └── service │ │ │ ├── IComputeService.java │ │ │ ├── IFileUtils.java │ │ │ ├── ILoadingTask.java │ │ │ ├── IUserManager.java │ │ │ ├── LoadingCallback.java │ │ │ └── impl │ │ │ ├── ComputeService.java │ │ │ ├── FileUtils.java │ │ │ ├── LoadingTask.java │ │ │ └── UserManager.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── layout_aidl_test.xml │ │ └── layout_ipc_test.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xuexiang │ └── xipcdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── 1.png └── demo.gif ├── principle.md ├── remote_demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xuexiang │ │ └── remotedemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── aidl │ │ └── com │ │ │ └── xuexiang │ │ │ └── aidl │ │ │ └── ICompute.aidl │ ├── java │ │ └── com │ │ │ └── xuexiang │ │ │ └── remotedemo │ │ │ ├── App.java │ │ │ ├── activity │ │ │ └── MainActivity.java │ │ │ ├── fragment │ │ │ ├── AIDLProcessFragment.java │ │ │ ├── CrossApplicationProcessFragment.java │ │ │ └── MainFragment.java │ │ │ └── service │ │ │ ├── IComputeService.java │ │ │ ├── IFileUtils.java │ │ │ ├── ILoadingTask.java │ │ │ ├── IUserManager.java │ │ │ └── LoadingCallback.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── layout_aidl_test.xml │ │ └── layout_ipc_test.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xuexiang │ └── remotedemo │ └── ExampleUnitTest.java ├── settings.gradle ├── versions.gradle └── xipc-runtime ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml └── java └── com └── xuexiang └── xipc ├── XIPC.java ├── annotation ├── Background.java ├── ClassName.java ├── MethodName.java ├── Singleton.java ├── WeakRef.java └── WithinProcess.java ├── core ├── channel │ ├── Channel.java │ ├── IIPCService.java │ ├── IIPCServiceCallback.java │ ├── IPCCallbackInvocationHandler.java │ ├── IPCInvocationHandler.java │ ├── IPCListener.java │ └── IPCService.java ├── entity │ ├── CallbackMail.java │ ├── Mail.java │ └── Reply.java ├── receiver │ ├── IReceiver.java │ ├── Receiver.java │ ├── ReceiverDesignator.java │ └── impl │ │ ├── InstanceCreatingReceiver.java │ │ ├── InstanceGettingReceiver.java │ │ ├── ObjectReceiver.java │ │ ├── UtilityGettingReceiver.java │ │ └── UtilityReceiver.java ├── sender │ ├── ISender.java │ ├── Sender.java │ └── impl │ │ ├── InstanceCreatingSender.java │ │ ├── InstanceGettingSender.java │ │ ├── ObjectSender.java │ │ ├── SenderDesignator.java │ │ └── UtilityGettingSender.java └── wrapper │ ├── BaseWrapper.java │ ├── MethodWrapper.java │ ├── ObjectWrapper.java │ ├── ParameterWrapper.java │ └── TypeWrapper.java ├── exception ├── ErrorCodes.java └── IPCException.java ├── logs ├── ILogger.java ├── IPCLog.java └── LogcatLogger.java └── util ├── CallbackManager.java ├── ClassUtils.java ├── IPCCallbackGc.java ├── IPCGc.java ├── IPCPoolExecutor.java ├── ObjectCenter.java ├── SerializeUtils.java ├── TimeStampGenerator.java ├── Triple.java ├── TypeCenter.java └── TypeUtils.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /keystores 4 | /local.properties 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuexiangjys/XIPC/1113736f9298b4acb6d4743b6c42a2ec4d90399c/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/copyright/xuexiang.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /JitPackUpload.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | // 指定group,com.github.<用户名>,这里我默认填写的是我的github账号,请换成你自己的。 4 | group='com.github.xuexiangjys' 5 | 6 | //--------------------------------------------- 7 | 8 | 9 | // 指定编码 10 | tasks.withType(JavaCompile) { 11 | options.encoding = "UTF-8" 12 | } 13 | 14 | tasks.withType(Javadoc) { 15 | options.encoding = 'UTF-8' 16 | } 17 | 18 | if (project.hasProperty("android")) { // Android libraries 19 | task sourcesJar(type: Jar) { 20 | classifier = 'sources' 21 | from android.sourceSets.main.java.srcDirs 22 | } 23 | 24 | task javadoc(type: Javadoc) { 25 | failOnError false 26 | source = android.sourceSets.main.java.srcDirs 27 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 28 | } 29 | } else { // Java libraries 30 | task sourcesJar(type: Jar, dependsOn: classes) { 31 | classifier = 'sources' 32 | from sourceSets.main.allSource 33 | } 34 | } 35 | 36 | javadoc { 37 | options { 38 | encoding "UTF-8" 39 | charSet 'UTF-8' 40 | author true 41 | version true 42 | links "http://docs.oracle.com/javase/7/docs/api" 43 | } 44 | } 45 | 46 | // 制作文档(Javadoc) 47 | task javadocJar(type: Jar, dependsOn: javadoc) { 48 | classifier = 'javadoc' 49 | from javadoc.destinationDir 50 | } 51 | 52 | artifacts { 53 | archives javadocJar 54 | archives sourcesJar 55 | } -------------------------------------------------------------------------------- /apk/remote_demo_1.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuexiangjys/XIPC/1113736f9298b4acb6d4743b6c42a2ec4d90399c/apk/remote_demo_1.0.apk -------------------------------------------------------------------------------- /apk/xipc_demo_1.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuexiangjys/XIPC/1113736f9298b4acb6d4743b6c42a2ec4d90399c/apk/xipc_demo_1.0.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.xuexiang.xaop' //引用xaop插件 3 | 4 | android { 5 | compileSdkVersion build_versions.target_sdk 6 | buildToolsVersion build_versions.build_tools 7 | 8 | defaultConfig { 9 | applicationId "com.xuexiang.xipcdemo" 10 | minSdkVersion 19 11 | targetSdkVersion build_versions.target_sdk 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | 17 | if (isNeedPackage.toBoolean()) { 18 | signingConfigs { 19 | release { 20 | storeFile file(app_release.storeFile) 21 | storePassword app_release.storePassword 22 | keyAlias app_release.keyAlias 23 | keyPassword app_release.keyPassword 24 | } 25 | } 26 | } 27 | 28 | buildTypes { 29 | release { 30 | minifyEnabled true 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | if (isNeedPackage.toBoolean()) { 33 | signingConfig signingConfigs.release 34 | } 35 | } 36 | } 37 | 38 | if (isNeedPackage.toBoolean()) { 39 | applicationVariants.all { variant -> 40 | variant.outputs.all { 41 | if (variant.buildType.name.equals('release')) { 42 | outputFileName = "xipc_demo_${defaultConfig.versionName}.apk" 43 | } 44 | } 45 | } 46 | } 47 | 48 | lintOptions { 49 | abortOnError false 50 | } 51 | } 52 | 53 | dependencies { 54 | implementation fileTree(include: ['*.jar'], dir: 'libs') 55 | implementation deps.support.app_compat 56 | testImplementation deps.junit 57 | androidTestImplementation deps.runner 58 | androidTestImplementation deps.espresso.core 59 | implementation deps.support.recyclerview 60 | implementation 'com.github.xuexiangjys.XUtil:xutil-core:1.1.4' 61 | implementation 'com.github.xuexiangjys.XAOP:xaop-runtime:1.0.1' 62 | //添加依赖 63 | //XPage 64 | implementation 'com.github.xuexiangjys.XPage:xpage-lib:2.2.2' 65 | annotationProcessor 'com.github.xuexiangjys.XPage:xpage-compiler:2.2.2' 66 | //butterKnife的sdk 67 | implementation 'com.jakewharton:butterknife:8.8.1' 68 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 69 | //如果开启了内存泄漏监测leak,就需要加上这个依赖 70 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' 71 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 72 | testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 73 | 74 | 75 | implementation 'com.github.xuexiangjys:XIPC:1.0.0' 76 | // implementation project(':xipc-runtime') 77 | } 78 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/xuexiang/xipcdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xuexiang.xipcdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xuexiang.xipcdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/aidl/com/xuexiang/aidl/ICompute.aidl: -------------------------------------------------------------------------------- 1 | // ICompute.aidl 2 | package com.xuexiang.aidl; 3 | 4 | // Declare any non-default types here with import statements 5 | 6 | interface ICompute { 7 | /** 8 | * Demonstrates some basic types that you can use as parameters 9 | * and return values in AIDL. 10 | */ 11 | float calculate(float value1, String symbol, float value2); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/aidl/AIDLService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.aidl; 18 | 19 | import android.app.Service; 20 | import android.content.Intent; 21 | import android.os.IBinder; 22 | import android.os.RemoteException; 23 | import android.support.annotation.Nullable; 24 | 25 | import com.xuexiang.xipcdemo.service.impl.ComputeService; 26 | 27 | /** 28 | * aidl服务 29 | * 30 | * @author xuexiang 31 | * @since 2018/9/24 下午1:49 32 | */ 33 | public class AIDLService extends Service { 34 | 35 | @Nullable 36 | @Override 37 | public IBinder onBind(Intent intent) { 38 | return new RemoteBinder(); 39 | } 40 | 41 | @Override 42 | public boolean onUnbind(Intent intent) { 43 | return super.onUnbind(intent); 44 | } 45 | 46 | 47 | /** 48 | * 远程绑定服务 49 | */ 50 | public class RemoteBinder extends ICompute.Stub { 51 | 52 | private ComputeService mComputeService; 53 | 54 | public RemoteBinder() { 55 | mComputeService = new ComputeService(); 56 | } 57 | 58 | @Override 59 | public float calculate(float value1, String symbol, float value2) throws RemoteException { 60 | return mComputeService.calculate(value1, symbol, value2); 61 | } 62 | 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/App.java: -------------------------------------------------------------------------------- 1 | package com.xuexiang.xipcdemo; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | 7 | import com.xuexiang.xipc.XIPC; 8 | import com.xuexiang.xipcdemo.service.LoadingCallback; 9 | import com.xuexiang.xipcdemo.service.impl.ComputeService; 10 | import com.xuexiang.xipcdemo.service.impl.FileUtils; 11 | import com.xuexiang.xipcdemo.service.impl.LoadingTask; 12 | import com.xuexiang.xipcdemo.service.impl.UserManager; 13 | import com.xuexiang.xpage.AppPageConfig; 14 | import com.xuexiang.xpage.PageConfig; 15 | import com.xuexiang.xpage.PageConfiguration; 16 | import com.xuexiang.xpage.model.PageInfo; 17 | import com.xuexiang.xutil.XUtil; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * @author xuexiang 23 | * @since 2018/9/14 下午2:47 24 | */ 25 | public class App extends Application { 26 | 27 | @Override 28 | public void onCreate() { 29 | super.onCreate(); 30 | 31 | XUtil.init(this); 32 | XUtil.debug(true); 33 | 34 | initXIPC(); 35 | 36 | PageConfig.getInstance().setPageConfiguration(new PageConfiguration() { //页面注册 37 | @Override 38 | public List registerPages(Context context) { 39 | return AppPageConfig.getInstance().getPages(); //自动注册页面 40 | } 41 | }).debug("PageLog").enableWatcher(true).init(this); 42 | } 43 | 44 | private void initXIPC() { 45 | XIPC.init(this); 46 | XIPC.debug(BuildConfig.DEBUG); 47 | 48 | XIPC.register(UserManager.class); 49 | XIPC.register(LoadingTask.class); 50 | XIPC.register(FileUtils.class); 51 | XIPC.register(LoadingCallback.class); 52 | XIPC.register(ComputeService.class); 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xuexiang.xipcdemo.activity; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.xuexiang.xipcdemo.fragment.MainFragment; 6 | import com.xuexiang.xpage.base.XPageActivity; 7 | 8 | public class MainActivity extends XPageActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | openPage(MainFragment.class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/activity/SecondProcessActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.activity; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.xuexiang.xipcdemo.fragment.DifferentProcessFragment; 22 | import com.xuexiang.xpage.base.XPageActivity; 23 | 24 | /** 25 | * @author xuexiang 26 | * @since 2018/9/18 下午12:05 27 | */ 28 | public class SecondProcessActivity extends XPageActivity { 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | 34 | openPage(DifferentProcessFragment.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/fragment/AIDLProcessFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.fragment; 18 | 19 | import android.content.ComponentName; 20 | import android.content.Context; 21 | import android.content.Intent; 22 | import android.content.ServiceConnection; 23 | import android.os.IBinder; 24 | import android.os.RemoteException; 25 | 26 | import com.xuexiang.aidl.AIDLService; 27 | import com.xuexiang.aidl.ICompute; 28 | import com.xuexiang.xipcdemo.R; 29 | import com.xuexiang.xpage.annotation.Page; 30 | import com.xuexiang.xpage.base.XPageFragment; 31 | import com.xuexiang.xutil.tip.ToastUtils; 32 | 33 | import butterknife.OnClick; 34 | 35 | /** 36 | * @author xuexiang 37 | * @since 2018/9/24 下午1:39 38 | */ 39 | @Page(name = "原生AIDL进程间通信") 40 | public class AIDLProcessFragment extends XPageFragment { 41 | 42 | private ICompute mICompute; 43 | 44 | @Override 45 | protected int getLayoutId() { 46 | return R.layout.layout_aidl_test; 47 | } 48 | 49 | @Override 50 | protected void initArgs() { 51 | super.initArgs(); 52 | getContext().bindService(new Intent(getContext(), AIDLService.class), mServiceConnection, Context.BIND_AUTO_CREATE); 53 | } 54 | 55 | @Override 56 | protected void initViews() { 57 | 58 | } 59 | 60 | @Override 61 | protected void initListeners() { 62 | 63 | } 64 | 65 | @OnClick(R.id.btn_compute) 66 | public void onViewClicked() { 67 | try { 68 | ToastUtils.toast("3+4=" + mICompute.calculate(3 , "+", 4)); 69 | } catch (RemoteException e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | @Override 75 | public void onDestroyView() { 76 | if (mServiceConnection != null) { 77 | getContext().unbindService(mServiceConnection); 78 | } 79 | super.onDestroyView(); 80 | } 81 | 82 | private ServiceConnection mServiceConnection = new ServiceConnection() { 83 | 84 | @Override 85 | public void onServiceDisconnected(ComponentName name) { 86 | mICompute = null; 87 | } 88 | @Override 89 | public void onServiceConnected(ComponentName name, IBinder service) { 90 | mICompute = ICompute.Stub.asInterface(service); 91 | } 92 | }; 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/fragment/DifferentProcessFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.fragment; 18 | 19 | import android.view.View; 20 | import android.widget.ProgressBar; 21 | 22 | import com.xuexiang.xaop.annotation.SingleClick; 23 | import com.xuexiang.xipc.XIPC; 24 | import com.xuexiang.xipcdemo.R; 25 | import com.xuexiang.xipcdemo.service.IComputeService; 26 | import com.xuexiang.xipcdemo.service.IFileUtils; 27 | import com.xuexiang.xipcdemo.service.ILoadingTask; 28 | import com.xuexiang.xipcdemo.service.IUserManager; 29 | import com.xuexiang.xipcdemo.service.LoadingCallback; 30 | import com.xuexiang.xipcdemo.service.impl.UserManager; 31 | import com.xuexiang.xpage.annotation.Page; 32 | import com.xuexiang.xpage.base.XPageFragment; 33 | import com.xuexiang.xutil.tip.ToastUtils; 34 | 35 | import butterknife.BindView; 36 | import butterknife.OnClick; 37 | 38 | /** 39 | * @author xuexiang 40 | * @since 2018/9/18 上午10:11 41 | */ 42 | @Page(name = "不同进程间的通信") 43 | public class DifferentProcessFragment extends XPageFragment { 44 | 45 | @BindView(R.id.progress_bar) 46 | ProgressBar progressBar; 47 | 48 | @Override 49 | protected void initArgs() { 50 | super.initArgs(); 51 | XIPC.connect(getContext()); 52 | } 53 | 54 | @Override 55 | protected int getLayoutId() { 56 | return R.layout.layout_ipc_test; 57 | } 58 | 59 | @Override 60 | protected void initViews() { 61 | 62 | } 63 | 64 | @Override 65 | protected void initListeners() { 66 | 67 | } 68 | 69 | @SingleClick 70 | @OnClick({R.id.btn_compute, R.id.btn_download, R.id.btn_get_user, R.id.btn_util_test}) 71 | public void onViewClicked(View view) { 72 | switch (view.getId()) { 73 | case R.id.btn_compute: 74 | IComputeService computeService = XIPC.getService(IComputeService.class); 75 | ToastUtils.toast("3*4=" + computeService.calculate(3 , "*", 4)); 76 | break; 77 | case R.id.btn_download: 78 | ILoadingTask loadingTask = XIPC.getService(ILoadingTask.class, "pic.png"); 79 | loadingTask.start(new LoadingCallback() { 80 | @Override 81 | public void callback(int progress) { 82 | progressBar.setProgress(progress); 83 | } 84 | }); 85 | break; 86 | case R.id.btn_get_user: 87 | IUserManager userManager = XIPC.getInstance(IUserManager.class); 88 | ToastUtils.toast("不使用XIPC获取单例的内容:" + UserManager.getInstance().getUser() + "\r\n" + 89 | "使用XIPC获取单例的内容:" + userManager.getUser()); 90 | break; 91 | case R.id.btn_util_test: 92 | IFileUtils fileUtils = XIPC.getUtilityClass(IFileUtils.class); 93 | ToastUtils.toast("应用目录:" + fileUtils.getExternalCacheDir(getContext())); 94 | break; 95 | } 96 | } 97 | 98 | @Override 99 | public void onDestroyView() { 100 | XIPC.disconnect(getContext()); 101 | super.onDestroyView(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/fragment/MainFragment.java: -------------------------------------------------------------------------------- 1 | package com.xuexiang.xipcdemo.fragment; 2 | 3 | import android.view.KeyEvent; 4 | import android.view.View; 5 | 6 | import com.xuexiang.xipcdemo.activity.SecondProcessActivity; 7 | import com.xuexiang.xipcdemo.service.impl.UserManager; 8 | import com.xuexiang.xpage.annotation.Page; 9 | import com.xuexiang.xpage.base.XPageContainerListFragment; 10 | import com.xuexiang.xpage.base.XPageSimpleListFragment; 11 | import com.xuexiang.xpage.utils.TitleBar; 12 | import com.xuexiang.xutil.app.ActivityUtils; 13 | import com.xuexiang.xutil.common.ClickUtils; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @author xuexiang 19 | * @since 2018/9/14 下午2:50 20 | */ 21 | @Page(name = "XIPC 进程间通信框架") 22 | public class MainFragment extends XPageSimpleListFragment { 23 | 24 | @Override 25 | protected List initSimpleData(List lists) { 26 | lists.add("同进程通信"); 27 | lists.add("不同进程间的通信"); 28 | lists.add("原生AIDL进程间通信"); 29 | return lists; 30 | } 31 | 32 | @Override 33 | protected void initArgs() { 34 | super.initArgs(); 35 | UserManager.getInstance().setUser("我的名字改了!");//修改一下单例的内容 36 | } 37 | 38 | @Override 39 | protected void onItemClick(int position) { 40 | switch(position) { 41 | case 0: 42 | openPage(SameProcessFragment.class); 43 | break; 44 | case 1: 45 | ActivityUtils.startActivity(SecondProcessActivity.class); 46 | break; 47 | case 2: 48 | openPage(AIDLProcessFragment.class); 49 | break; 50 | default: 51 | break; 52 | } 53 | } 54 | 55 | @Override 56 | protected TitleBar initTitleBar() { 57 | return super.initTitleBar().setLeftClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View view) { 60 | ClickUtils.exitBy2Click(); 61 | } 62 | }); 63 | } 64 | 65 | 66 | /** 67 | * 菜单、返回键响应 68 | */ 69 | @Override 70 | public boolean onKeyDown(int keyCode, KeyEvent event) { 71 | if (keyCode == KeyEvent.KEYCODE_BACK) { 72 | ClickUtils.exitBy2Click(); 73 | } 74 | return true; 75 | } 76 | 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/fragment/SameProcessFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.fragment; 18 | 19 | import android.view.View; 20 | import android.widget.ProgressBar; 21 | 22 | import com.xuexiang.xaop.annotation.SingleClick; 23 | import com.xuexiang.xipc.XIPC; 24 | import com.xuexiang.xipcdemo.R; 25 | import com.xuexiang.xipcdemo.service.IComputeService; 26 | import com.xuexiang.xipcdemo.service.IFileUtils; 27 | import com.xuexiang.xipcdemo.service.ILoadingTask; 28 | import com.xuexiang.xipcdemo.service.IUserManager; 29 | import com.xuexiang.xipcdemo.service.LoadingCallback; 30 | import com.xuexiang.xpage.annotation.Page; 31 | import com.xuexiang.xpage.base.XPageFragment; 32 | import com.xuexiang.xutil.tip.ToastUtils; 33 | 34 | import butterknife.BindView; 35 | import butterknife.OnClick; 36 | 37 | /** 38 | * @author xuexiang 39 | * @since 2018/9/18 上午10:03 40 | */ 41 | @Page(name = "同进程通信") 42 | public class SameProcessFragment extends XPageFragment { 43 | 44 | @BindView(R.id.progress_bar) 45 | ProgressBar progressBar; 46 | 47 | @Override 48 | protected void initArgs() { 49 | super.initArgs(); 50 | XIPC.connect(getContext()); 51 | } 52 | 53 | @Override 54 | protected int getLayoutId() { 55 | return R.layout.layout_ipc_test; 56 | } 57 | 58 | @Override 59 | protected void initViews() { 60 | 61 | } 62 | 63 | @Override 64 | protected void initListeners() { 65 | 66 | } 67 | 68 | @SingleClick 69 | @OnClick({R.id.btn_compute, R.id.btn_download, R.id.btn_get_user, R.id.btn_util_test}) 70 | public void onViewClicked(View view) { 71 | switch (view.getId()) { 72 | case R.id.btn_compute: 73 | IComputeService computeService = XIPC.getService(IComputeService.class); 74 | ToastUtils.toast("3*4=" + computeService.calculate(3 , "*", 4)); 75 | break; 76 | case R.id.btn_download: 77 | ILoadingTask loadingTask = XIPC.getService(ILoadingTask.class, "pic.png"); 78 | loadingTask.start(new LoadingCallback() { 79 | @Override 80 | public void callback(int progress) { 81 | progressBar.setProgress(progress); 82 | } 83 | }); 84 | break; 85 | case R.id.btn_get_user: 86 | IUserManager userManager = XIPC.getInstance(IUserManager.class); 87 | ToastUtils.toast(userManager.getUser()); 88 | break; 89 | case R.id.btn_util_test: 90 | IFileUtils fileUtils = XIPC.getUtilityClass(IFileUtils.class); 91 | ToastUtils.toast("应用目录:" + fileUtils.getExternalCacheDir(getContext())); 92 | break; 93 | } 94 | } 95 | 96 | @Override 97 | public void onDestroyView() { 98 | XIPC.disconnect(getContext()); 99 | super.onDestroyView(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/IComputeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | 22 | /** 23 | * 服务接口测试 24 | * 25 | * @author xuexiang 26 | * @since 2018/9/18 上午10:26 27 | */ 28 | @ClassName("ComputeService") 29 | public interface IComputeService { 30 | 31 | /** 32 | * 计算 33 | * 34 | * @param value1 值1 35 | * @param symbol 算数符号 36 | * @param value2 值2 37 | * @return 38 | */ 39 | @MethodName("calculate") 40 | float calculate(float value1, String symbol, float value2); 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/IFileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service; 18 | 19 | import android.content.Context; 20 | 21 | import com.xuexiang.xipc.annotation.ClassName; 22 | 23 | /** 24 | * 工具类测试 25 | * 26 | * @author xuexiang 27 | * @since 2018/9/18 上午9:59 28 | */ 29 | @ClassName("FileUtils") 30 | public interface IFileUtils { 31 | 32 | String getExternalCacheDir(Context context); 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/ILoadingTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | import com.xuexiang.xipc.annotation.WeakRef; 22 | 23 | /** 24 | * 服务接口测试 25 | * 26 | * @author xuexiang 27 | * @since 2018/9/18 上午9:58 28 | */ 29 | @ClassName("LoadingTask") 30 | public interface ILoadingTask { 31 | 32 | @MethodName("start") 33 | void start(@WeakRef LoadingCallback loadingCallback); 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/IUserManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | 22 | /** 23 | * 测试单例的获取 24 | * 25 | * @author xuexiang 26 | * @since 2018/9/18 上午9:56 27 | */ 28 | @ClassName("UserManager") 29 | public interface IUserManager { 30 | 31 | @MethodName("getUser") 32 | String getUser(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/LoadingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | 21 | /** 22 | * 定义的回调接口 23 | * 24 | * @author xuexiang 25 | * @since 2018/9/18 上午9:51 26 | */ 27 | @ClassName("LoadingCallback") 28 | public interface LoadingCallback { 29 | 30 | void callback(int progress); 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/impl/ComputeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service.impl; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | import com.xuexiang.xipcdemo.service.IComputeService; 22 | 23 | /** 24 | * 服务接口测试 25 | * @author xuexiang 26 | * @since 2018/9/18 上午10:33 27 | */ 28 | @ClassName("ComputeService") 29 | public class ComputeService implements IComputeService { 30 | 31 | @Override 32 | @MethodName("calculate") 33 | public float calculate(float value1, String symbol, float value2) { 34 | float result; 35 | switch(symbol) { 36 | case "+": 37 | result = value1 + value2; 38 | break; 39 | case "-": 40 | result = value1 - value2; 41 | break; 42 | case "*": 43 | result = value1 * value2; 44 | break; 45 | case "/": 46 | result = value1 / value2; 47 | break; 48 | default: 49 | result = value1 + value2; 50 | break; 51 | } 52 | return result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/impl/FileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service.impl; 18 | 19 | import android.content.Context; 20 | 21 | import com.xuexiang.xipc.annotation.ClassName; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * 工具类测试 27 | * 28 | * @author xuexiang 29 | * @since 2018/9/18 上午10:00 30 | */ 31 | @ClassName("FileUtils") 32 | public class FileUtils { 33 | 34 | public static String getExternalCacheDir(Context context) { 35 | try { 36 | return context.getExternalCacheDir().getCanonicalPath(); 37 | } catch (IOException e) { 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/impl/LoadingTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service.impl; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | import com.xuexiang.xipcdemo.service.ILoadingTask; 22 | import com.xuexiang.xipcdemo.service.LoadingCallback; 23 | 24 | import java.util.Timer; 25 | import java.util.TimerTask; 26 | 27 | /** 28 | * 测试接口回调、服务接口 29 | * 30 | * @author xuexiang 31 | * @since 2018/9/18 上午9:50 32 | */ 33 | @ClassName("LoadingTask") 34 | public class LoadingTask implements ILoadingTask { 35 | 36 | public LoadingTask(String url) { 37 | 38 | } 39 | 40 | @MethodName("start") 41 | @Override 42 | public void start(final LoadingCallback loadingCallback) { 43 | final Timer timer = new Timer(); 44 | timer.schedule(new TimerTask() { 45 | int time = 0; 46 | @Override 47 | public void run() { 48 | time += 10; 49 | if (time > 100) { 50 | time = 100; 51 | } 52 | loadingCallback.callback(time); 53 | if (time == 100) { 54 | timer.cancel(); 55 | } 56 | } 57 | }, 0, 100); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/xuexiang/xipcdemo/service/impl/UserManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xuexiang.xipcdemo.service.impl; 18 | 19 | import com.xuexiang.xipc.annotation.ClassName; 20 | import com.xuexiang.xipc.annotation.MethodName; 21 | import com.xuexiang.xipc.annotation.Singleton; 22 | import com.xuexiang.xipcdemo.service.IUserManager; 23 | 24 | /** 25 | * 测试单例的获取 26 | * 27 | * @author xuexiang 28 | * @since 2018/9/18 上午9:56 29 | */ 30 | @ClassName("UserManager") 31 | public class UserManager implements IUserManager { 32 | 33 | private static volatile UserManager sInstance = null; 34 | 35 | private String mUser; 36 | 37 | private UserManager() { 38 | mUser = "我的名字叫:XIPC"; 39 | } 40 | 41 | @Singleton 42 | public static UserManager getInstance() { 43 | if (sInstance == null) { 44 | synchronized (UserManager.class) { 45 | if (sInstance == null) { 46 | sInstance = new UserManager(); 47 | } 48 | } 49 | } 50 | return sInstance; 51 | } 52 | 53 | @MethodName("getUser") 54 | @Override 55 | public String getUser() { 56 | return mUser; 57 | } 58 | 59 | public UserManager setUser(String user) { 60 | mUser = user; 61 | return this; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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/layout/layout_aidl_test.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 27 | 28 | 33 | 34 |