├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── jiangzn.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jzn │ │ └── rxjavatest │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jzn │ │ │ └── rxjavatest │ │ │ ├── MainActivity.java │ │ │ ├── concat.java │ │ │ ├── foreach.java │ │ │ ├── interval.java │ │ │ ├── lifecycle.java │ │ │ ├── map_flatmap.java │ │ │ ├── merge.java │ │ │ ├── schedulePeriodically.java │ │ │ ├── simplestAty.java │ │ │ ├── timer.java │ │ │ ├── twoexample.java │ │ │ └── utils │ │ │ └── MyLog.java │ └── res │ │ ├── drawable │ │ └── aa.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── test2.xml │ │ └── test3.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jzn │ └── rxjavatest │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | RxJavaTest -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/jiangzn.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Android 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 1.8 67 | 68 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RxJavaTest 2 |

11个RxJava的实例集合


3 | 类名一一对应内容,分别是:
4 | * MainActivity——RxJava基础用法
5 | * simplestAty——RxJava简单实例
6 | * timer——延时操作
7 | * interval——周期性操作
8 | * twoexample——两个RxJava初始化demo
9 | * schedulePeriodically——使用RxJava做轮询请求
10 | * merge——合并两个数据源
11 | * map_flatmap——RxJava实现变换
12 | * foreach——实现数组,List遍历
13 | * concat——实现比较一堆item,一旦满足后面的item不执行的功能
14 | * lifecycle——回收Observable以防止内存泄漏

15 | 16 | 以上合集涵盖了大部分RxJava语法与使用场景
17 | 每个实例都可单独运行,打印输出结果
18 | 希望给正在学习RxJava中的你一点启发
19 | 持续更新中,欢迎pull requests.

20 | 21 | 博客地址:RxJava使用场景总结

22 | 23 | 24 |

License

25 |
    Copyright 2017 Jiangzhengnan.
26 | 
27 |     Licensed under the Apache License, Version 2.0 (the "License");
28 |     you may not use this file except in compliance with the License.
29 |     You may obtain a copy of the License at
30 | 
31 |        http://www.apache.org/licenses/LICENSE-2.0
32 | 
33 |     Unless required by applicable law or agreed to in writing, software
34 |     distributed under the License is distributed on an "AS IS" BASIS,
35 |     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 |     See the License for the specific language governing permissions and
37 |     limitations under the License.
38 | 
39 | 40 | 41 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.jzn.rxjavatest" 9 | minSdkVersion 14 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.0' 26 | compile 'io.reactivex:rxjava:1.0.14' 27 | compile 'io.reactivex:rxandroid:1.2.1' 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jiangzn/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jzn/rxjavatest/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import rx.Observable; 7 | import rx.Observer; 8 | import rx.Subscriber; 9 | 10 | /** 11 | * 基本的观察者,被观察者创建方式以及实现订阅。 12 | */ 13 | public class MainActivity extends AppCompatActivity { 14 | String tag = "MainActivity"; 15 | 16 | //定义观察者 17 | Observer observer = new Observer() { 18 | @Override 19 | public void onCompleted() { 20 | Log.d(tag,"Completed!"); 21 | } 22 | 23 | @Override 24 | public void onError(Throwable e) { 25 | Log.d(tag,"Error!"); 26 | } 27 | 28 | @Override 29 | public void onNext(String s) { 30 | Log.d(tag,"Item: " + s); 31 | } 32 | }; 33 | 34 | //实现了Observer的抽象类,对其进行了一些扩展,基本使用方式完全一样。 35 | Subscriber subscriber = new Subscriber() { 36 | 37 | @Override 38 | public void onCompleted() { 39 | Log.d(tag,"Completed!"); 40 | } 41 | 42 | @Override 43 | public void onError(Throwable e) { 44 | Log.d(tag,"Error!"); 45 | } 46 | 47 | @Override 48 | public void onNext(String s) { 49 | Log.d(tag,"Item: " + s); 50 | } 51 | }; 52 | 53 | //被观察者 使用onCreate创建 54 | Observable observable = Observable.create(new Observable.OnSubscribe(){ 55 | @Override 56 | public void call(Subscriber subscriber) { 57 | subscriber.onNext("Hello"); 58 | subscriber.onNext("whale"); 59 | subscriber.onNext("nangua"); 60 | subscriber.onCompleted(); 61 | } 62 | }); 63 | 64 | //被观察者 使用just创建 65 | Observable observable1 = Observable.just("Hello","Hi","Aloha"); 66 | 67 | //被观察者 使用数组传入创建 68 | String[] words = {"Hello","Hi","Aloha"}; 69 | Observable observable2 = Observable.from(words); 70 | 71 | @Override 72 | protected void onCreate(Bundle savedInstanceState) { 73 | super.onCreate(savedInstanceState); 74 | setContentView(R.layout.activity_main); 75 | //订阅 76 | observable.subscribe(subscriber); 77 | //observable.subscribe(observer); 78 | } 79 | 80 | @Override 81 | protected void onDestroy() { 82 | super.onDestroy(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/concat.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import rx.Observable; 9 | import rx.Subscriber; 10 | import rx.functions.Action1; 11 | import rx.schedulers.Schedulers; 12 | 13 | /** 14 | * concat与operator 15 | * 使用模拟三级缓存实现来举例 16 | * 首先检查内存是否有缓存 17 | * 然后检查文件缓存 18 | * 最后才从网络中取 19 | * 只要满足前面任何一个条件,就不会再执行后面的操作 20 | * Created by jiangzn on 16/9/9. 21 | */ 22 | public class concat extends Activity { 23 | String memoryChache = null; //假装是内存缓存 24 | String diskChache = "read to diskChache"; //假装是磁盘缓存 25 | 26 | Observable memory = Observable.create(new Observable.OnSubscribe() { 27 | @Override 28 | public void call(Subscriber subscriber) { 29 | if (memoryChache != null) { 30 | subscriber.onNext(memoryChache); 31 | } else { 32 | subscriber.onCompleted(); 33 | } 34 | } 35 | }); 36 | 37 | Observable disk = Observable.create(new Observable.OnSubscribe() { 38 | @Override 39 | public void call(Subscriber subscriber) { 40 | if (diskChache != null) { 41 | subscriber.onNext(diskChache); 42 | } else { 43 | subscriber.onCompleted(); 44 | } 45 | } 46 | }); 47 | 48 | Observable network = Observable.just("network"); 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | 54 | //主要靠concat operator来实现 55 | Observable.concat(memory,disk,network) 56 | .first() //first过滤器:只执行满足条件的第一个观察者 57 | .subscribeOn(Schedulers.newThread()) 58 | .subscribe(new Action1() { 59 | @Override 60 | public void call(String s) { 61 | MyLog.d("----subsribe:" + s); 62 | } 63 | }); 64 | 65 | } 66 | 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/foreach.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import rx.Observable; 9 | import rx.functions.Action1; 10 | 11 | /** 12 | * 数组,list遍历 13 | * Created by jiangzn on 16/9/9. 14 | */ 15 | public class foreach extends Activity { 16 | String[] names = {"Tom","Lily","Fucker","Bill"}; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | Observable.from(names) 22 | .subscribe(new Action1() { 23 | @Override 24 | public void call(String s) { 25 | MyLog.d(s); 26 | } 27 | }); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/interval.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import rx.Observable; 11 | import rx.Subscriber; 12 | 13 | /** 14 | * interval 15 | * 做周期性操作 16 | * 每两秒输出"啪啪啪" 17 | * Created by jiangzn on 16/9/9. 18 | */ 19 | public class interval extends Activity { 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | Observable.interval(2, TimeUnit.SECONDS) 25 | .subscribe(new Subscriber() { 26 | @Override 27 | public void onCompleted() { 28 | MyLog.d("completed"); 29 | } 30 | 31 | @Override 32 | public void onError(Throwable e) { 33 | MyLog.d("error"); 34 | } 35 | 36 | @Override 37 | public void onNext(Long aLong) { 38 | MyLog.d("啪啪啪"); 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/lifecycle.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import rx.Observable; 9 | import rx.functions.Action1; 10 | import rx.subscriptions.CompositeSubscription; 11 | 12 | /** 13 | * 生命周期 14 | * 防止Observable持有Context导致的内存泄露 15 | * 解决方案就是在生命周期的某个时刻取消订阅。 16 | * 一个很常见的模式就是使用CompositeSubscription来持有所有的Subscriptions, 17 | * 然后在onDestroy()或者onDestroyView()里取消所有的订阅。 18 | * 19 | * Created by jiangzn on 16/9/11. 20 | */ 21 | public class lifecycle extends Activity{ 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | } 28 | 29 | private CompositeSubscription mCompositeSubscription 30 | = new CompositeSubscription(); 31 | 32 | private void doSomething() { 33 | mCompositeSubscription.add( Observable.just("Hello, World!") 34 | .subscribe(new Action1(){ 35 | @Override 36 | public void call(String s) { 37 | MyLog.d(s); 38 | } 39 | })); 40 | } 41 | 42 | @Override 43 | protected void onDestroy() { 44 | super.onDestroy(); 45 | mCompositeSubscription.unsubscribe(); 46 | //注意! 一旦你调用了 CompositeSubscription.unsubscribe(), 47 | // 这个CompositeSubscription对象就不可用了, 如果你还想使用CompositeSubscription, 48 | // 就必须在创建一个新的对象了。 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/map_flatmap.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.os.Bundle; 6 | 7 | import com.jzn.rxjavatest.utils.MyLog; 8 | 9 | import rx.Observable; 10 | import rx.Subscriber; 11 | import rx.functions.Action1; 12 | import rx.functions.Func1; 13 | 14 | /** 15 | * 变换 16 | * 就是将事件序列中的对象或整个序列进行加工处理,转换成不同的事件或事件序列 17 | * 简而言之就是参数类型和返回类型不同 18 | * 有两种,一种是map(),一种是flatMap() 19 | * 下面分别用两个小栗子举例说明之 20 | * Created by jiangzn on 16/9/9. 21 | */ 22 | public class map_flatmap extends Activity { 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | //mapExample(); 29 | flatMapExample(); 30 | } 31 | 32 | 33 | class Student{ 34 | String name; 35 | 36 | public Student(String name) { 37 | this.name = name; 38 | } 39 | 40 | Course[] courses; 41 | 42 | public Course[] getCourses() { 43 | return courses; 44 | } 45 | 46 | public void setCourses(Course[] course) { 47 | this.courses = course; 48 | } 49 | } 50 | class Course 51 | { 52 | public Course(String name) { 53 | this.name = name; 54 | } 55 | 56 | String name; 57 | public String getName() { 58 | return name; 59 | } 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | } 64 | //使用flatMap()的实例 65 | // 打印出每个学生所需要修的所有课程的名称 66 | //(每个学生只有一个名字,但却有多个课程。) 67 | private void flatMapExample() { 68 | Student student1 = new Student("小明"); 69 | Student student2 = new Student("小红"); 70 | Course[] courses1 = {new Course("语文"),new Course("数学"),new Course("英语")}; 71 | Course[] courses2 = {new Course("物理"),new Course("化学"),new Course("生物")}; 72 | student1.setCourses(courses1); 73 | student2.setCourses(courses2); 74 | Student[] students = {student1,student2}; 75 | Subscriber subscriber = new Subscriber() { 76 | @Override 77 | public void onCompleted() { 78 | } 79 | 80 | @Override 81 | public void onError(Throwable e) { 82 | } 83 | 84 | @Override 85 | public void onNext(Course course) { 86 | MyLog.d(course.getName()); 87 | } 88 | }; 89 | 90 | Observable.from(students) 91 | .flatMap(new Func1>() { 92 | @Override 93 | public Observable call(Student student) { 94 | MyLog.d(student.name); 95 | return Observable.from(student.getCourses()); 96 | //flatMap() 和 map() 有一个相同点:它也是把传入的参数转化之后返回另一个对象。 97 | // 但需要注意,和 map() 不同的是, flatMap() 中返回的是个 Observable 对象, 98 | // 并且这个 Observable 对象并不是被直接发送到了 Subscriber 的回调方法中。 99 | // flatMap() 的原理是这样的:1. 使用传入的事件对象创建一个 Observable 对象; 100 | // 2. 并不发送这个 Observable, 而是将它激活,于是它开始发送事件; 101 | // 3. 每一个创建出来的 Observable 发送的事件,都被汇入同一个 Observable , 102 | // 而这个 Observable 负责将这些事件统一交给 Subscriber 的回调方法。这三个步骤, 103 | // 把事件拆成了两级,通过一组新创建的 Observable 将初始的对象『铺平』 104 | // 之后通过统一路径分发了下去。而这个『铺平』就是 flatMap() 所谓的 flat。 105 | } 106 | }).subscribe(subscriber); 107 | } 108 | 109 | 110 | 111 | //使用map()的实例 112 | private void mapExample() { 113 | Observable.just("images/logo.png") //输入类型 114 | .map(new Func1() { 115 | @Override 116 | public Bitmap call(String filepath) { 117 | return getBitmapFromPath(filepath); 118 | } 119 | }) 120 | .subscribe(new Action1() { 121 | @Override 122 | public void call(Bitmap bitmap) { 123 | showBitmap(bitmap); 124 | } 125 | }); 126 | 127 | //这里出现了一个叫做 Func1 的类。它和 Action1 非常相似, 128 | //也是 RxJava 的一个接口,用于包装含有一个参数的方法。 129 | // Func1 和 Action 的区别在于, Func1 包装的是有返回值的方法。 130 | // 另外,和 ActionX 一样, FuncX 也有多个,用于不同参数个数的方法。 131 | // FuncX 和 ActionX 的区别在 FuncX 包装的是有返回值的方法。 132 | } 133 | //模拟方法显示图片 134 | private void showBitmap(Bitmap bitmap) { 135 | MyLog.d("显示图片辣"); 136 | } 137 | //模拟方法得到图片地址 138 | private Bitmap getBitmapFromPath(String filepath) { 139 | MyLog.d("从地址得到图片辣"); 140 | return null; 141 | } 142 | 143 | 144 | 145 | } 146 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/merge.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.widget.EditText; 7 | import android.widget.Toast; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import rx.Observable; 13 | import rx.Subscriber; 14 | import rx.android.schedulers.AndroidSchedulers; 15 | 16 | /** 17 | * Merge 18 | * 使用merge合并两个数据源 19 | * 例如一组数据来自网络,一组数据来自文件,需要合并数据并一起显示的情况 20 | * 21 | * 可以理解为拼接两个Observable的输出,不保证顺序,按照事件产生的顺序发送给订阅者 22 | * Created by jiangzn on 16/9/8. 23 | */ 24 | public class merge extends Activity { 25 | String tag = "xiaojingyu"; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.test3); 31 | Observable.merge(getDataFromFile() ,getDataFromNet()) 32 | .observeOn(AndroidSchedulers.mainThread()) 33 | .subscribe(new Subscriber() { 34 | @Override 35 | public void onCompleted() { 36 | Log.d(tag,"done loading all data"); 37 | } 38 | 39 | @Override 40 | public void onError(Throwable e) { 41 | Log.d(tag,"error"); 42 | } 43 | 44 | @Override 45 | public void onNext(String s) { 46 | Log.d(tag,"merge:" + s); 47 | } 48 | }); 49 | } 50 | 51 | 52 | private Observable getDataFromFile() { 53 | String[] strs = {"filedata1","filedata2","filedata3","filedata4"}; 54 | Observable temp = Observable.from(strs); 55 | return temp; 56 | } 57 | 58 | private Observable getDataFromNet() { 59 | String[] strs = {"netdata1","netdata2","netdata3","netdata4"}; 60 | Observable temp = Observable.from(strs); 61 | return temp; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/schedulePeriodically.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import rx.Observable; 11 | import rx.Subscriber; 12 | import rx.functions.Action0; 13 | import rx.functions.Action1; 14 | import rx.schedulers.Schedulers; 15 | 16 | /** 17 | * schedulePeriodically 18 | * 轮询请求 19 | * Created by jiangzn on 16/9/9. 20 | */ 21 | public class schedulePeriodically extends Activity { 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | Observable.create(new Observable.OnSubscribe( 27 | ) { 28 | @Override 29 | public void call(final Subscriber subscriber) { 30 | Schedulers.io().createWorker() //指定在io线程执行 31 | .schedulePeriodically(new Action0() { 32 | @Override 33 | public void call() { 34 | subscriber.onNext("doNetworkCallAndGetStringResult"); 35 | } 36 | }, 2000, 1000, TimeUnit.MILLISECONDS);//初始延迟,polling延迟 37 | } 38 | 39 | }) 40 | .subscribe(new Action1() { 41 | @Override 42 | public void call(String s) { 43 | MyLog.d("polling..." + s); 44 | } 45 | }); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/simplestAty.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.os.PersistableBundle; 6 | import android.util.Log; 7 | import android.view.ViewTreeObserver; 8 | 9 | import rx.Observable; 10 | import rx.functions.Action0; 11 | import rx.functions.Action1; 12 | import rx.subscriptions.CompositeSubscription; 13 | 14 | /** 15 | * subscribe()支持的不完整回调 16 | * Created by jiangzn on 16/9/8. 17 | */ 18 | public class simplestAty extends Activity { 19 | String tag = "xiaojingyu"; 20 | 21 | Action1 onNextAction = new Action1() { 22 | @Override 23 | public void call(String s) { 24 | Log.d(tag,s); 25 | } 26 | }; 27 | 28 | Action1 onErrorAction = new Action1() { 29 | @Override 30 | public void call(Throwable throwable) { 31 | //错误处理 32 | } 33 | }; 34 | 35 | Action0 onCompleteAction = new Action0() { 36 | @Override 37 | public void call() { 38 | Log.d(tag,"completed"); 39 | } 40 | }; 41 | 42 | @Override 43 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 44 | super.onCreate(savedInstanceState, persistentState); 45 | Observable observable = Observable.just("hello"); 46 | observable.subscribe(onNextAction,onErrorAction,onCompleteAction); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/timer.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.jzn.rxjavatest.utils.MyLog; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import rx.Observable; 11 | import rx.Observer; 12 | 13 | /** 14 | * Timer 15 | * 做一些延时操作 16 | * 比如两秒后输入”啪啪啪“ 17 | * Created by jiangzn on 16/9/9. 18 | */ 19 | public class timer extends Activity{ 20 | String tag="xiaojingyu"; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | Observable.timer(2, TimeUnit.SECONDS) 25 | .subscribe(new Observer() { 26 | @Override 27 | public void onCompleted() { 28 | MyLog.d("completed"); 29 | } 30 | 31 | @Override 32 | public void onError(Throwable e) { 33 | MyLog.d("error"); 34 | } 35 | 36 | @Override 37 | public void onNext(Long aLong) { 38 | MyLog.d("啪啪啪!"); 39 | } 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/twoexample.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import android.app.Activity; 4 | import android.graphics.drawable.Drawable; 5 | import android.os.Bundle; 6 | import android.os.PersistableBundle; 7 | import android.util.Log; 8 | import android.widget.ImageView; 9 | import android.widget.Toast; 10 | import rx.Observable; 11 | import rx.Subscriber; 12 | import rx.android.schedulers.AndroidSchedulers; 13 | import rx.functions.Action1; 14 | import rx.schedulers.Schedulers; 15 | 16 | /** 17 | * 两个小栗子 18 | * a打印字符串数组 19 | * b由id取得突破并显示 设置执行的线程 20 | * Created by jiangzn on 16/9/8. 21 | */ 22 | public class twoexample extends Activity { 23 | String tag = "xiaojingyu"; 24 | String[] names = {"a","b","c"}; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.test2); 30 | Log.d(tag,"MainActivity"); 31 | // a(); 32 | b(); 33 | } 34 | 35 | private void b() { 36 | final int drawableRes = R.drawable.aa; 37 | final ImageView imageView = (ImageView) findViewById(R.id.iv_test2); 38 | Observable.create(new Observable.OnSubscribe() { 39 | @Override 40 | public void call(Subscriber subscriber) { 41 | Log.d(tag,"call:" + Thread.currentThread().getName()); 42 | //打印结果:call:RxCachedThreadScheduler-1... 43 | Drawable drawable = getResources().getDrawable(drawableRes); 44 | subscriber.onNext(drawable); 45 | subscriber.onCompleted(); 46 | } 47 | }).subscribeOn(Schedulers.io()) //指定OnSubscribe被激活时处在的线程,事件产生线程 48 | .observeOn(AndroidSchedulers.mainThread()) //Subscriber所运行的线程,事件消费的线程 49 | .subscribe(new Subscriber() { 50 | @Override 51 | public void onCompleted() { 52 | Log.d(tag,"Completed!"); 53 | } 54 | 55 | @Override 56 | public void onError(Throwable e) { 57 | Log.d(tag,e.getMessage()); 58 | } 59 | 60 | @Override 61 | public void onNext(Drawable drawable) { 62 | imageView.setImageDrawable(drawable); 63 | Log.d(tag,"加载线程:" + Thread.currentThread().getName()); 64 | //打印结果:加载线程:main 65 | } 66 | }); 67 | } 68 | 69 | private void a() { 70 | Observable.from(names) 71 | .subscribe(new Action1() { 72 | @Override 73 | public void call(String s) { 74 | Log.d(tag,s); 75 | } 76 | }); 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/jzn/rxjavatest/utils/MyLog.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by jiangzn on 16/9/9. 7 | */ 8 | public class MyLog { 9 | private static String tag = "xiaojingyu"; 10 | public static void d(String txt) { 11 | Log.d(tag,txt); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/aa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/app/src/main/res/drawable/aa.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/test2.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/test3.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/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 | RxJavaTest 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/jzn/rxjavatest/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jzn.rxjavatest; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /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 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiangzhengnan/RxJavaModel/d0efeea3c05b76d94c553c346a0df5cdca7fd3fc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 07 18:07:34 CST 2016 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-2.14.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 | --------------------------------------------------------------------------------