All Projects → codezjx → Andlinker

codezjx / Andlinker

Licence: apache-2.0
AndLinker is a IPC library for Android, which combines the features of AIDL and Retrofit. Allows IPC call seamlessly compose with RxJava and RxJava2 call adapters.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Andlinker

AndroidTutorials
Ejemplos Android [Dagger2,RxJava,MVP,Retrofit2,SQLite]
Stars: ✭ 22 (-95%)
Mutual labels:  rxjava, retrofit2
catchflicks
🎬 Kitchen sink project for learning android concepts 🎬
Stars: ✭ 12 (-97.27%)
Mutual labels:  rxjava, retrofit2
BookReader
📕 "任阅" 网络小说阅读器,3D翻页效果、txt/pdf/epub书籍阅读、Wifi传书~
Stars: ✭ 6,113 (+1289.32%)
Mutual labels:  rxjava, retrofit2
NewsReader
Android News Reader app. Kotlin Coroutines, Retrofit and Realm
Stars: ✭ 21 (-95.23%)
Mutual labels:  rxjava, retrofit2
Rxeasyhttp
本库是一款基于RxJava2+Retrofit2实现简单易用的网络请求框架,结合android平台特性的网络封装库,采用api链式调用一点到底,集成cookie管理,多种缓存模式,极简https配置,上传下载进度显示,请求错误自动重试,请求携带token、时间戳、签名sign动态配置,自动登录成功后请求重发功能,3种层次的参数设置默认全局局部,默认标准ApiResult同时可以支持自定义的数据结构,已经能满足现在的大部分网络请求。
Stars: ✭ 3,021 (+586.59%)
Mutual labels:  rxjava, retrofit2
UseCases
This a library that offers a generic implementation of the data layers from the clean architecture by Uncle bob.
Stars: ✭ 23 (-94.77%)
Mutual labels:  rxjava, retrofit2
AndroidMVPArchitecture
Android MVP architecture sample project with or without RxJava and Dagger2 and Kotlin
Stars: ✭ 78 (-82.27%)
Mutual labels:  rxjava, retrofit2
iMoney
iMoney 金融项目
Stars: ✭ 55 (-87.5%)
Mutual labels:  rxjava, retrofit2
Friendbook
📕 "友书" 小说阅读app
Stars: ✭ 275 (-37.5%)
Mutual labels:  rxjava, retrofit2
Gank
gank.io unofficial client - RxJava2、Retrofit2 & MVP技术干货
Stars: ✭ 256 (-41.82%)
Mutual labels:  rxjava, retrofit2
Animewallpaper
[Android] Konachan wallpaper downloader
Stars: ✭ 402 (-8.64%)
Mutual labels:  rxjava, retrofit2
Kotlinmvp
🔥 基于Kotlin+MVP+Retrofit+RxJava+Glide 等架构实现短视频类小项目,简约风格及详细注释,欢迎 star or fork!
Stars: ✭ 3,488 (+692.73%)
Mutual labels:  rxjava, retrofit2
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-94.32%)
Mutual labels:  rxjava, retrofit2
jshodan
Powerful Shodan API client using RxJava and Retrofit
Stars: ✭ 56 (-87.27%)
Mutual labels:  rxjava, retrofit2
BaseDevelop
an android project for now fashion open source framework
Stars: ✭ 24 (-94.55%)
Mutual labels:  rxjava, retrofit2
Fineract-CN-mobile
DEPRECATED project - Check the Apache fineract-cn-mobile project instead
Stars: ✭ 17 (-96.14%)
Mutual labels:  rxjava, retrofit2
photon
Fast and light image loading library based on kotlin
Stars: ✭ 20 (-95.45%)
Mutual labels:  rxjava, retrofit2
MusicUU
一款让你解决下歌烦恼的APP
Stars: ✭ 15 (-96.59%)
Mutual labels:  rxjava, retrofit2
RxRetroAPICall
API call example using Retrofit and RxJava2
Stars: ✭ 16 (-96.36%)
Mutual labels:  rxjava, retrofit2
Apollo
🚀 Awesome EventBus by RxJava.
Stars: ✭ 329 (-25.23%)
Mutual labels:  rxjava, ipc

Build Status JCenter License

AndLinker

中文文档

Introduction

AndLinker is a IPC(Inter-Process Communication) library for Android, which combines the features of AIDL and Retrofit. Allows IPC call seamlessly compose with RxJava and RxJava2 call adapters. Project design and partial code refer to the great project Retrofit.

Setup

Add the jcenter() repository in your root build.gradle.

allprojects {
    repositories {
        jcenter()
    }
}

Add the dependencies in your app level build.gradle.

dependencies {
    implementation 'com.codezjx.library:andlinker:0.7.2'
}

Features

  • Define normal Java Interface instead of AIDL Interface
  • Generates the IPC implementation of the remote service interface like Retrofit
  • Support call adapter: Call, RxJava Observable, RxJava2 Observable & Flowable
  • Support remote service callback
  • Support all AIDL data types
  • Support all AIDL directional tag, either in, out, or inout
  • Support the AIDL oneway keyword

Getting Started

Define a normal java Interface with @RemoteInterface annotation, and implements the interface.

@RemoteInterface
public interface IRemoteService {

    int getPid();

    void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
            double aDouble, String aString);
}

private final IRemoteService mRemoteService = new IRemoteService() {
    
    @Override
    public int getPid() {
        return android.os.Process.myPid();
    }

    @Override
    public void basicTypes(int anInt, long aLong, boolean aBoolean,
        float aFloat, double aDouble, String aString) {
        // Does something
    }
};

In your server app, create the AndLinkerBinder object and register interface implementation above, then expose the linker binder to clients.

private AndLinkerBinder mLinkerBinder;

public class RemoteService extends Service {
    @Override
    public void onCreate() {
        super.onCreate();
        mLinkerBinder = AndLinkerBinder.Factory.newBinder();
        mLinkerBinder.registerObject(mRemoteService);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mLinkerBinder;
    }
}

In your client app, create the AndLinker object and generates an implementation of the IRemoteService interface.

public class BindingActivity extends Activity {

    private AndLinker mLinker;
    private IRemoteService mRemoteService;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLinker = new AndLinker.Builder(this)
                .packageName("com.example.andlinker")
                .action("com.example.andlinker.REMOTE_SERVICE_ACTION")
                .build();
        mLinker.bind();

        mRemoteService = mLinker.create(IRemoteService.class);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLinker.unbind();
    }
}

Now your client app is ready, all methods from the created IRemoteService are IPC methods, call it directly!

int pid = mRemoteService.getPid();
mRemoteService.basicTypes(1, 2L, true, 3.0f, 4.0d, "str");

Supported data types

AndLinker supports all AIDL data types:

  • All primitive types in the Java programming language (such as int, long, char, boolean, and so on)
  • String
  • CharSequence
  • Parcelable
  • List (All elements in the List must be one of the supported data types in this list)
  • Map (All elements in the Map must be one of the supported data types in this list)

Advanced

Call Adapters

You can modify the client side app's remote service interface, wrap the return type of the method.

@RemoteInterface
public interface IRemoteService {

    Observable<Integer> getPid();

    Call<Void> basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, 
        double aDouble, String aString);
}

Register the call adapter factory in AndLinker.Builder, the remaining steps are consistent with Retrofit.

new AndLinker.Builder(this)
        ...
        .addCallAdapterFactory(OriginalCallAdapterFactory.create()) // Basic
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())  // RxJava2
        .build();

Deal with callbacks

Define callback interface to receive callbacks from the remote service with @RemoteInterface annotation.

@RemoteInterface
public interface IRemoteCallback {

    void onValueChange(int value);
}

Use @Callback annotation for callback parameter.

void registerCallback(@Callback IRemoteCallback callback);

In your client app, implements the remote callback and register to AndLinker, and that's it!

private final IRemoteCallback mRemoteCallback = new IRemoteCallback() {
    @Override
    public void onValueChange(int value) {
        // Invoke when server side callback
    }
};
mLinker.registerObject(mRemoteCallback);

Specify directional tag

You can specify @In, @Out, or @Inout annotation for parameter, indicating which way the data goes, same as AIDL.

void directionalParamMethod(@In KeyEvent event, @Out int[] arr, @Inout Rect rect);

Caution:

  • All non-primitive parameters require a directional annotation indicating which way the data goes. Either @In, @Out, or @Inout. Primitives are @In by default, and cannot be otherwise.
  • Parcelable parameter with @Out or @Inout annotation must implements from SuperParcelable, or you must add method public void readFromParcel(Parcel in) by yourself.

Use @OneWay annotation

You can use @OneWay for a method which modifies the behavior of remote calls. When used, a remote call does not block, it simply sends the transaction data and immediately returns, same as AIDL.

@OneWay
void onewayMethod(String msg);

Proguard Configuration

Add following rules to proguard-rules.pro file, keep classes that will be serialized/deserialized over AndLinker.

-keep class com.example.andlinker.model.** {
    public void readFromParcel(android.os.Parcel);
}

Feedback

Any issues or PRs are welcome!

License

Copyright 2018 codezjx <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].