Skip to content

Commit fb1e1ad

Browse files
committed
Add sample project.
1 parent 3b08a34 commit fb1e1ad

29 files changed

+583
-2
lines changed

dependencies.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ ext.versions = [
66
'rxjava': '1.3.6',
77
'rxandroid': '1.2.1',
88
'rxjava2': '2.1.10',
9-
'rxandroid2': '2.0.2'
9+
'rxandroid2': '2.0.2',
10+
'butterKnife': '8.8.1'
1011
]
1112

1213
ext.deps = [
@@ -15,5 +16,9 @@ ext.deps = [
1516
'android': "io.reactivex:rxandroid:${versions.rxandroid}",
1617
'java2': "io.reactivex.rxjava2:rxjava:${versions.rxjava2}",
1718
'android2': "io.reactivex.rxjava2:rxandroid:${versions.rxandroid2}"
19+
],
20+
'butterKnife': [
21+
'runtime': "com.jakewharton:butterknife:${versions.butterKnife}",
22+
'compiler': "com.jakewharton:butterknife-compiler:${versions.butterKnife}",
1823
]
1924
]

sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample/build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
6+
defaultConfig {
7+
applicationId "com.example.andlinker"
8+
minSdkVersion 17
9+
targetSdkVersion 26
10+
versionCode 1
11+
versionName "1.0"
12+
13+
}
14+
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
22+
compileOptions {
23+
sourceCompatibility JavaVersion.VERSION_1_8
24+
targetCompatibility JavaVersion.VERSION_1_8
25+
}
26+
27+
}
28+
29+
dependencies {
30+
implementation fileTree(dir: 'libs', include: ['*.jar'])
31+
implementation project(':andlinker')
32+
33+
// support
34+
implementation 'com.android.support:appcompat-v7:26.1.0'
35+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
36+
37+
// butterknife
38+
implementation deps.butterKnife.runtime
39+
annotationProcessor deps.butterKnife.compiler
40+
41+
// rxjava
42+
implementation deps.rx.java2
43+
implementation deps.rx.android2
44+
}

sample/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.andlinker">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".BindingActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
20+
<service
21+
android:name=".RemoteService"
22+
android:enabled="true"
23+
android:exported="true"
24+
android:process=":remote">
25+
<intent-filter>
26+
<action android:name="com.example.andlinker.REMOTE_SERVICE_ACTION" />
27+
</intent-filter>
28+
</service>
29+
</application>
30+
31+
</manifest>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.example.andlinker;
2+
3+
import android.graphics.Rect;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Toast;
8+
9+
import com.codezjx.andlinker.AndLinker;
10+
11+
import butterknife.ButterKnife;
12+
import butterknife.OnClick;
13+
14+
public class BindingActivity extends AppCompatActivity {
15+
16+
private static final String REMOTE_SERVICE_PKG = "com.example.andlinker";
17+
public static final String REMOTE_SERVICE_ACTION = "com.example.andlinker.REMOTE_SERVICE_ACTION";
18+
19+
private AndLinker mLinker;
20+
private IRemoteService mRemoteService;
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_binding);
26+
ButterKnife.bind(this);
27+
28+
mLinker = new AndLinker.Builder(this)
29+
.packageName(REMOTE_SERVICE_PKG)
30+
.action(REMOTE_SERVICE_ACTION)
31+
.build();
32+
mLinker.bind();
33+
mLinker.registerObject(mRemoteCallback);
34+
35+
mRemoteService = mLinker.create(IRemoteService.class);
36+
}
37+
38+
@OnClick({R.id.btn_pid, R.id.btn_basic_types, R.id.btn_callback, R.id.btn_directional, R.id.btn_oneway})
39+
public void onClick(View view) {
40+
switch (view.getId()) {
41+
case R.id.btn_pid:
42+
Toast.makeText(this, "Server pid: " + mRemoteService.getPid(), Toast.LENGTH_SHORT).show();
43+
mRemoteService.getPid();
44+
break;
45+
case R.id.btn_basic_types:
46+
mRemoteService.basicTypes(1, 2L, true, 3.0f, 4.0d, "str");
47+
break;
48+
case R.id.btn_callback:
49+
mRemoteService.registerCallback(mRemoteCallback);
50+
break;
51+
case R.id.btn_directional:
52+
int[] arr = {1, 2, 3};
53+
ParcelableObj parcelableObj = new ParcelableObj();
54+
Rect rect = new Rect(10, 20, 30, 40);
55+
mRemoteService.directionalParamMethod(arr, parcelableObj, rect);
56+
Toast.makeText(this, "After directionalParamMethod parcelableObj: " + parcelableObj
57+
+ " rect: " + rect, Toast.LENGTH_LONG).show();
58+
break;
59+
case R.id.btn_oneway:
60+
mRemoteService.onewayMethod("oneway");
61+
Toast.makeText(this, "After oneway method client.", Toast.LENGTH_SHORT).show();
62+
break;
63+
default:
64+
break;
65+
}
66+
}
67+
68+
@Override
69+
protected void onDestroy() {
70+
super.onDestroy();
71+
mLinker.unbind();
72+
}
73+
74+
private final IRemoteCallback mRemoteCallback = new IRemoteCallback() {
75+
@Override
76+
public void onValueChange(int value) {
77+
// Invoke when server side callback
78+
Toast.makeText(BindingActivity.this, "Server callback value: " + value, Toast.LENGTH_SHORT).show();
79+
}
80+
};
81+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.andlinker;
2+
3+
import com.codezjx.andlinker.annotation.ClassName;
4+
import com.codezjx.andlinker.annotation.MethodName;
5+
6+
/**
7+
* Created by codezjx on 2018/3/13.<br/>
8+
*/
9+
@ClassName("com.example.andlinker.IRemoteCallback")
10+
public interface IRemoteCallback {
11+
12+
@MethodName("onValueChange")
13+
void onValueChange(int value);
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.example.andlinker;
2+
3+
import android.graphics.Rect;
4+
5+
import com.codezjx.andlinker.annotation.Callback;
6+
import com.codezjx.andlinker.annotation.ClassName;
7+
import com.codezjx.andlinker.annotation.In;
8+
import com.codezjx.andlinker.annotation.Inout;
9+
import com.codezjx.andlinker.annotation.MethodName;
10+
import com.codezjx.andlinker.annotation.OneWay;
11+
import com.codezjx.andlinker.annotation.Out;
12+
13+
/**
14+
* Created by codezjx on 2018/3/12.<br/>
15+
*/
16+
@ClassName("com.example.andlinker.IRemoteService")
17+
public interface IRemoteService {
18+
19+
@MethodName("getPid")
20+
int getPid();
21+
22+
@MethodName("basicTypes")
23+
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
24+
double aDouble, String aString);
25+
26+
@MethodName("registerCallback")
27+
void registerCallback(@Callback IRemoteCallback callback);
28+
29+
@MethodName("directionalParamMethod")
30+
void directionalParamMethod(@In int[] arr, @Out ParcelableObj obj, @Inout Rect rect);
31+
32+
@MethodName("onewayMethod")
33+
@OneWay
34+
void onewayMethod(String msg);
35+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.example.andlinker;
2+
3+
import android.os.Parcel;
4+
5+
import com.codezjx.andlinker.SuperParcelable;
6+
7+
/**
8+
* Created by codezjx on 2018/3/14.<br/>
9+
*/
10+
public class ParcelableObj implements SuperParcelable {
11+
12+
private int mType;
13+
private float mValue;
14+
private String mMsg;
15+
16+
17+
@Override
18+
public int describeContents() {
19+
return 0;
20+
}
21+
22+
@Override
23+
public void writeToParcel(Parcel dest, int flags) {
24+
dest.writeInt(this.mType);
25+
dest.writeFloat(this.mValue);
26+
dest.writeString(this.mMsg);
27+
}
28+
29+
public ParcelableObj() {
30+
}
31+
32+
protected ParcelableObj(Parcel in) {
33+
readFromParcel(in);
34+
}
35+
36+
public static final Creator<ParcelableObj> CREATOR = new Creator<ParcelableObj>() {
37+
@Override
38+
public ParcelableObj createFromParcel(Parcel source) {
39+
return new ParcelableObj(source);
40+
}
41+
42+
@Override
43+
public ParcelableObj[] newArray(int size) {
44+
return new ParcelableObj[size];
45+
}
46+
};
47+
48+
@Override
49+
public void readFromParcel(Parcel in) {
50+
mType = in.readInt();
51+
mValue = in.readFloat();
52+
mMsg = in.readString();
53+
}
54+
55+
public int getType() {
56+
return mType;
57+
}
58+
59+
public void setType(int type) {
60+
mType = type;
61+
}
62+
63+
public float getValue() {
64+
return mValue;
65+
}
66+
67+
public void setValue(float value) {
68+
mValue = value;
69+
}
70+
71+
public String getMsg() {
72+
return mMsg;
73+
}
74+
75+
public void setMsg(String msg) {
76+
mMsg = msg;
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return "ParcelableObj{" +
82+
"mType=" + mType +
83+
", mValue=" + mValue +
84+
", mMsg='" + mMsg + '\'' +
85+
'}';
86+
}
87+
}

0 commit comments

Comments
 (0)