compare(@Part("api_key") RequestBody apiKey,
21 | @Part("api_secret") RequestBody apiSecret,
22 | @Part MultipartBody.Part... files);
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/classic/demo/HttpDemo.java:
--------------------------------------------------------------------------------
1 | package com.classic.demo;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.classic.android.BasicProject;
7 | import com.classic.android.base.RxActivity;
8 | import com.classic.android.consts.MIME;
9 | import com.classic.android.event.ActivityEvent;
10 | import com.classic.android.rx.RxTransformer;
11 | import com.classic.android.utils.SDCardUtil;
12 | import com.elvishew.xlog.LogLevel;
13 | import com.elvishew.xlog.XLog;
14 | import com.google.gson.FieldNamingPolicy;
15 | import com.google.gson.Gson;
16 | import com.google.gson.GsonBuilder;
17 | import com.google.gson.reflect.TypeToken;
18 |
19 | import java.io.File;
20 | import java.util.concurrent.TimeUnit;
21 |
22 | import io.reactivex.functions.Function;
23 | import io.reactivex.observers.DisposableObserver;
24 | import okhttp3.MediaType;
25 | import okhttp3.MultipartBody;
26 | import okhttp3.OkHttpClient;
27 | import okhttp3.RequestBody;
28 | import okhttp3.logging.HttpLoggingInterceptor;
29 | import retrofit2.Retrofit;
30 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
31 | import retrofit2.converter.gson.GsonConverterFactory;
32 |
33 | @SuppressWarnings({"Convert2Lambda", "RedundantTypeArguments"})
34 | public class HttpDemo extends RxActivity {
35 |
36 | private static final int CONNECT_TIMEOUT_TIME = 15;
37 |
38 | private FaceApi mFaceApi;
39 |
40 | @Override
41 | public int getLayoutResId() {
42 | return R.layout.activity_main;
43 | }
44 |
45 | @Override
46 | public void initView(Bundle savedInstanceState) {
47 | super.initView(savedInstanceState);
48 | BasicProject.config(new BasicProject.Builder().setLog(BuildConfig.DEBUG ?
49 | LogLevel.ALL : LogLevel.NONE));
50 | initApi();
51 |
52 | //身份证内置的照片
53 | final String img1 = SDCardUtil.getImageDirPath() + "/IDCardPhoto.jpg";
54 | //摄像头拍摄的照片
55 | final String img2 = SDCardUtil.getImageDirPath() + "/CurrentPhoto.jpg";
56 |
57 | testFaceApi(img1, img2);
58 | }
59 |
60 | /**
61 | * 测试人脸识别API
62 | *
63 | * 实际项目中:步骤1和3会在合适的地方进行统一处理,不需要每个接口都进行设置
64 | *
65 | * @param imagePath1 需要比对的照片1
66 | * @param imagePath2 需要比对的照片2
67 | */
68 | private void testFaceApi(@NonNull String imagePath1, @NonNull String imagePath2) {
69 | //PrivateConstant里面声明的私有api_id,需要自己到官网申请
70 | mFaceApi.compare(convert(PrivateConstant.FACE_API_ID),
71 | convert(PrivateConstant.FACE_API_SECRET),
72 | convert("image_file1", new File(imagePath1)),
73 | convert("image_file2", new File(imagePath2)))
74 | //1.线程切换的封装
75 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO_ON_UI))
76 | //2.当前Activity onStop时自动取消请求
77 | .compose(this.bindEvent(ActivityEvent.STOP))
78 | //3.原始数据转换为对象
79 | .map(DATA_PARSE_FUNCTION)
80 | .subscribeWith(new DisposableObserver() {
81 | @Override
82 | public void onNext(IdentifyResult identifyResult) {
83 | XLog.d("FaceApi --> " + identifyResult.toString());
84 | }
85 |
86 | @Override
87 | public void onError(Throwable e) {
88 | XLog.e("FaceApi --> " + e.getMessage());
89 | }
90 |
91 | @Override
92 | public void onComplete() {
93 | XLog.d("FaceApi --> onComplete");
94 | }
95 | });
96 | }
97 |
98 | private static final Function DATA_PARSE_FUNCTION =
99 | new Function() {
100 | @Override
101 | public IdentifyResult apply(String s) throws Exception {
102 | if (null != s) {
103 | return new Gson().fromJson(s, new TypeToken(){}.getType());
104 | }
105 | return null;
106 | }
107 | };
108 |
109 | private MultipartBody.Part convert(@NonNull String key, @NonNull File file) {
110 | return MultipartBody.Part.createFormData(key, key,
111 | RequestBody.create(MultipartBody.FORM, file));
112 | }
113 |
114 | private RequestBody convert(@NonNull String param) {
115 | return RequestBody.create(MediaType.parse(MIME.TEXT), param);
116 | }
117 |
118 |
119 | private void initApi() {
120 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
121 | .addNetworkInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
122 | .retryOnConnectionFailure(true)
123 | .connectTimeout(CONNECT_TIMEOUT_TIME, TimeUnit.SECONDS)
124 | .writeTimeout(CONNECT_TIMEOUT_TIME, TimeUnit.SECONDS)
125 | .readTimeout(CONNECT_TIMEOUT_TIME, TimeUnit.SECONDS)
126 | .build();
127 | Gson gson = new GsonBuilder()
128 | .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
129 | .create();
130 | mFaceApi = new Retrofit.Builder().baseUrl(PrivateConstant.FACE_URL_PREFIX)
131 | .client(okHttpClient)
132 | .addConverterFactory(GsonConverterFactory.create(gson))
133 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
134 | .build()
135 | .create(FaceApi.class);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/com/classic/demo/IdentifyResult.java:
--------------------------------------------------------------------------------
1 | package com.classic.demo;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 应用名称: RxJava2Demo
7 | * 包 名 称: com.classic.demo
8 | *
9 | * 文件描述: 人脸识别结果 {https://www.faceplusplus.com.cn/face/index.html}
10 | * 创 建 人: 续写经典
11 | * 创建时间: 2016/12/19 16:06
12 | */
13 | @SuppressWarnings("unused") class IdentifyResult {
14 | /**
15 | * faces1 : [{"face_rectangle":{"width":54,"top":37,"left":25,"height":54},"face_token":"a5c10fad04c6a4aa173bd"}]
16 | * faces2 : [{"face_rectangle":{"width":211,"top":260,"left":431,"height":211},"face_token":"a1a43744ab4a71e542a1a0"}]
17 | * time_used : 1017
18 | * thresholds : {"1e-3":65.3,"1e-5":76.5,"1e-4":71.8}
19 | * confidence : 87.538
20 | * image_id2 : H3Jigcmksj2y==
21 | * image_id1 : qdl1Uhn1UScej2==
22 | * request_id : 148180,f9803-ad0-484-ba1-f35ab77
23 | */
24 |
25 | private int time_used;
26 | //private String thresholds;
27 | private double confidence;
28 | private String image_id2;
29 | private String image_id1;
30 | private String request_id;
31 | private List faces1;
32 | private List faces2;
33 |
34 | static class FaceBean {
35 |
36 | /**
37 | * face_rectangle : {"width":211,"top":260,"left":431,"height":211}
38 | * face_token : a1a0437aaaaaaa45b842ae014a0
39 | */
40 |
41 | private FaceRectangleBean face_rectangle;
42 | private String face_token;
43 |
44 | public FaceRectangleBean getFace_rectangle() { return face_rectangle;}
45 |
46 | public void setFace_rectangle(FaceRectangleBean face_rectangle) {
47 | this.face_rectangle = face_rectangle;
48 | }
49 |
50 | public String getFace_token() { return face_token;}
51 |
52 | public void setFace_token(String face_token) { this.face_token = face_token;}
53 |
54 | static class FaceRectangleBean {
55 | /**
56 | * width : 211
57 | * top : 260
58 | * left : 431
59 | * height : 211
60 | */
61 |
62 | private int width;
63 | private int top;
64 | private int left;
65 | private int height;
66 |
67 | public int getWidth() { return width;}
68 |
69 | public void setWidth(int width) { this.width = width;}
70 |
71 | public int getTop() { return top;}
72 |
73 | public void setTop(int top) { this.top = top;}
74 |
75 | public int getLeft() { return left;}
76 |
77 | public void setLeft(int left) { this.left = left;}
78 |
79 | public int getHeight() { return height;}
80 |
81 | public void setHeight(int height) { this.height = height;}
82 | }
83 | }
84 |
85 | public int getTime_used() {
86 | return time_used;
87 | }
88 |
89 | public void setTime_used(int time_used) {
90 | this.time_used = time_used;
91 | }
92 |
93 | public double getConfidence() {
94 | return confidence;
95 | }
96 |
97 | public void setConfidence(double confidence) {
98 | this.confidence = confidence;
99 | }
100 |
101 | public String getImage_id2() {
102 | return image_id2;
103 | }
104 |
105 | public void setImage_id2(String image_id2) {
106 | this.image_id2 = image_id2;
107 | }
108 |
109 | public String getImage_id1() {
110 | return image_id1;
111 | }
112 |
113 | public void setImage_id1(String image_id1) {
114 | this.image_id1 = image_id1;
115 | }
116 |
117 | public String getRequest_id() {
118 | return request_id;
119 | }
120 |
121 | public void setRequest_id(String request_id) {
122 | this.request_id = request_id;
123 | }
124 |
125 | public List getFaces1() {
126 | return faces1;
127 | }
128 |
129 | public void setFaces1(List faces1) {
130 | this.faces1 = faces1;
131 | }
132 |
133 | public List getFaces2() {
134 | return faces2;
135 | }
136 |
137 | public void setFaces2(List faces2) {
138 | this.faces2 = faces2;
139 | }
140 |
141 | @Override public String toString() {
142 | return "IdentifyResult{" +
143 | "time_used=" + time_used +
144 | ", confidence=" + confidence +
145 | ", image_id2='" + image_id2 + '\'' +
146 | ", image_id1='" + image_id1 + '\'' +
147 | ", request_id='" + request_id +
148 | '}';
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/app/src/main/java/com/classic/demo/OperatorDemo.java:
--------------------------------------------------------------------------------
1 | package com.classic.demo;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.classic.android.BasicProject;
6 | import com.classic.android.base.RxActivity;
7 | import com.classic.android.rx.RxTransformer;
8 | import com.elvishew.xlog.LogLevel;
9 | import com.elvishew.xlog.XLog;
10 |
11 | import org.reactivestreams.Publisher;
12 | import org.reactivestreams.Subscriber;
13 |
14 | import java.util.ArrayList;
15 | import java.util.concurrent.Callable;
16 | import java.util.concurrent.TimeUnit;
17 |
18 | import io.reactivex.Observable;
19 | import io.reactivex.ObservableEmitter;
20 | import io.reactivex.ObservableOnSubscribe;
21 | import io.reactivex.Observer;
22 | import io.reactivex.android.schedulers.AndroidSchedulers;
23 | import io.reactivex.disposables.Disposable;
24 | import io.reactivex.functions.Action;
25 | import io.reactivex.functions.Consumer;
26 | import io.reactivex.observers.DisposableObserver;
27 | import io.reactivex.schedulers.Schedulers;
28 |
29 | /**
30 | * 文件描述: RxJava2.X 使用示例
31 | * 创 建 人: 续写经典
32 | * 创建时间: 2016/12/6 16:18
33 | */
34 | @SuppressWarnings("All")
35 | public class OperatorDemo extends RxActivity {
36 |
37 | @Override public int getLayoutResId() {
38 | return R.layout.activity_main;
39 | }
40 |
41 | @Override public void initView(Bundle savedInstanceState) {
42 | super.initView(savedInstanceState);
43 | BasicProject.config(new BasicProject.Builder().setLog(BuildConfig.DEBUG ?
44 | LogLevel.ALL : LogLevel.NONE));
45 | create();
46 |
47 | // recycle()方法用于回收Disposable, 释放资源
48 | recycle(fromArray());
49 | recycle(fromCallable());
50 | recycle(time());
51 | recycle(interval());
52 | // recycle(...);
53 | }
54 |
55 | /**
56 | * create 示例
57 | */
58 | private void create() {
59 | Observable.create(new ObservableOnSubscribe() {
60 | @Override public void subscribe(ObservableEmitter emitter)
61 | throws Exception {
62 | if (!emitter.isDisposed()) {
63 | for (int i = 0; i < 10; i++) {
64 | emitter.onNext(i);
65 | }
66 | emitter.onComplete();
67 | }
68 | }
69 | })
70 | .subscribeOn(Schedulers.io())
71 | .unsubscribeOn(Schedulers.io())
72 | .observeOn(AndroidSchedulers.mainThread())
73 | //这里只列举三种常见的使用方式
74 | .subscribe(OBSERVER); //方式1
75 | //.subscribeWith(DISPOSABLE_OBSERVER); //方式2
76 | //.subscribe(NEXT_CONSUMER, ERROR_CONSUMER, COMPLETE); //方式3
77 | }
78 |
79 | /**
80 | * fromArray 示例
81 | */
82 | private Disposable fromArray() {
83 | return Observable.fromArray(1, 2, 3, 4, 5)
84 | //使用变换将线程控制的代码封装起来,使代码更简洁,也便于管理
85 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
86 | .subscribeWith(DISPOSABLE_OBSERVER);
87 | }
88 |
89 | /**
90 | * fromCallable 示例
91 | */
92 | private Disposable fromCallable() {
93 | return Observable.fromCallable(new Callable() {
94 | @Override public Integer call() throws Exception {
95 | return 123;
96 | }
97 | })
98 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
99 | .subscribeWith(DISPOSABLE_OBSERVER);
100 | }
101 |
102 | /**
103 | * fromIterable 示例
104 | */
105 | private Disposable fromIterable() {
106 | ArrayList list = new ArrayList<>();
107 | list.add(123);
108 | list.add(456);
109 | list.add(789);
110 | return Observable.fromIterable(list)
111 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
112 | .subscribeWith(DISPOSABLE_OBSERVER);
113 | }
114 |
115 | /**
116 | * fromPublisher 示例
117 | */
118 | private Disposable fromPublisher() {
119 | return Observable.fromPublisher(new Publisher() {
120 | @Override public void subscribe(Subscriber super Integer> s) {
121 | s.onNext(6);
122 | s.onNext(7);
123 | s.onNext(8);
124 | s.onNext(9);
125 | s.onComplete();
126 | }
127 | })
128 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
129 | .subscribeWith(DISPOSABLE_OBSERVER);
130 | }
131 |
132 | /**
133 | * just 示例
134 | */
135 | private Disposable just() {
136 | return Observable.just(1, 2, 3, 4, 5, 6)
137 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
138 | .subscribeWith(DISPOSABLE_OBSERVER);
139 | }
140 |
141 | /**
142 | * range 示例
143 | */
144 | private Disposable range() {
145 | return Observable.range(100, 60)
146 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.IO))
147 | .subscribeWith(DISPOSABLE_OBSERVER);
148 | }
149 |
150 | /**
151 | * time 示例
152 | */
153 | private Disposable time() {
154 | return Observable.timer(10, TimeUnit.MILLISECONDS)
155 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.COMPUTATION))
156 | .subscribe(new Consumer() {
157 | @Override
158 | public void accept(Long aLong) throws Exception {
159 | XLog.d("延迟10毫秒的任务启动");
160 | }
161 | });
162 | }
163 |
164 | /**
165 | * interval 示例
166 | */
167 | private Disposable interval() {
168 | return Observable.interval(1, TimeUnit.SECONDS)
169 | .compose(RxTransformer.applySchedulers(RxTransformer.Observable.COMPUTATION))
170 | .subscribe(new Consumer() {
171 | @Override
172 | public void accept(Long aLong) throws Exception {
173 | XLog.d("每隔1秒的定时任务启动");
174 | }
175 | });
176 | }
177 |
178 | private static final Observer OBSERVER = new Observer() {
179 | @Override public void onSubscribe(Disposable d) {
180 | XLog.d("onSubscribe");
181 | }
182 |
183 | @Override public void onNext(Integer value) {
184 | XLog.d("onNext:" + value);
185 | }
186 |
187 | @Override public void onError(Throwable e) {
188 | XLog.e("onError:" + e.getMessage());
189 | }
190 |
191 | @Override public void onComplete() {
192 | XLog.d("onComplete");
193 | }
194 | };
195 |
196 | private static final Consumer NEXT_CONSUMER = new Consumer() {
197 | @Override public void accept(Integer integer) throws Exception {
198 | XLog.d("onNext:" + integer);
199 | }
200 | };
201 |
202 | private static final Consumer ERROR_CONSUMER = new Consumer() {
203 | @Override public void accept(Throwable throwable) throws Exception {
204 | XLog.e("onError:" + throwable.getMessage());
205 | }
206 | };
207 |
208 | private static final Action COMPLETE = new Action() {
209 | @Override public void run() throws Exception {
210 | XLog.d("onComplete");
211 | }
212 | };
213 |
214 | private static final DisposableObserver DISPOSABLE_OBSERVER
215 | = new DisposableObserver() {
216 | @Override public void onNext(Integer value) {
217 | XLog.d("onNext:" + value);
218 | }
219 |
220 | @Override public void onError(Throwable e) {
221 | XLog.e("onError:" + e.getMessage());
222 | }
223 |
224 | @Override public void onComplete() {
225 | XLog.d("onComplete");
226 | }
227 | };
228 |
229 |
230 | }
231 |
--------------------------------------------------------------------------------
/app/src/main/java/com/classic/demo/PrivateConstant.java:
--------------------------------------------------------------------------------
1 | package com.classic.demo;
2 |
3 | /**
4 | * TODO
5 | *
6 | * @author classic
7 | * @version v2.0, 2017/11/21 下午12:20
8 | */
9 | interface PrivateConstant {
10 |
11 | String FACE_API_ID = "You face api id";
12 | String FACE_API_SECRET = "You face api secret";
13 | String FACE_URL_PREFIX = "You face url prefix";
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxJava2Demo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.0.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qyxxjd/RxJava2Demo/a510d12e1da4ecdcb4164b76dfabb3d7e6228fbe/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-4.3.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------