├── .gitignore
├── LICENSE
├── README.md
├── Retrofit
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── lib
│ │ └── com
│ │ └── myapplication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── lib
│ │ │ └── com
│ │ │ └── myapplication
│ │ │ ├── MainActivity.java
│ │ │ ├── bean
│ │ │ └── User.java
│ │ │ └── netI
│ │ │ └── UserI.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.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
│ └── lib
│ └── com
│ └── myapplication
│ └── ExampleUnitTest.java
├── RxAndroid
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── lib
│ │ └── com
│ │ └── myapplication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── lib
│ │ │ └── com
│ │ │ └── myapplication
│ │ │ ├── MainActivity.java
│ │ │ ├── RxBus.java
│ │ │ └── RxBusActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity1.xml
│ │ └── activity_main.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
│ └── lib
│ └── com
│ └── myapplication
│ └── ExampleUnitTest.java
├── RxBinding
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── lib
│ │ └── com
│ │ └── myapplication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── lib
│ │ │ └── com
│ │ │ └── myapplication
│ │ │ ├── DebounceActivity.java
│ │ │ ├── ListActivity.java
│ │ │ ├── LoginActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── TextViewActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_debounce.xml
│ │ ├── activity_list.xml
│ │ ├── activity_login.xml
│ │ ├── activity_main.xml
│ │ └── activity_text_view.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
│ └── lib
│ └── com
│ └── myapplication
│ └── ExampleUnitTest.java
├── RxLifecycle
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── lib
│ │ └── com
│ │ └── myapplication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── lib
│ │ │ └── com
│ │ │ └── myapplication
│ │ │ ├── MainActivity.java
│ │ │ ├── MyFragment.java
│ │ │ ├── OtherActivity.java
│ │ │ └── StopActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_other.xml
│ │ ├── activity_stop.xml
│ │ └── fragment_my.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
│ └── lib
│ └── com
│ └── myapplication
│ └── ExampleUnitTest.java
├── RxPreferences
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── app
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── app
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.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
│ └── app
│ └── ExampleUnitTest.java
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── app
│ │ └── com
│ │ └── myapplication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── app
│ │ │ └── com
│ │ │ └── myapplication
│ │ │ ├── Activity1.java
│ │ │ ├── Activity10.java
│ │ │ ├── Activity2.java
│ │ │ ├── Activity3.java
│ │ │ ├── Activity4.java
│ │ │ ├── Activity5.java
│ │ │ ├── Activity6.java
│ │ │ ├── Activity7.java
│ │ │ ├── Activity8.java
│ │ │ ├── BufferActivity.java
│ │ │ ├── CombineLatestActivity.java
│ │ │ ├── DeferActivity.java
│ │ │ ├── DelayActivity.java
│ │ │ ├── DoOnNextActivity.java
│ │ │ ├── ElementAtActivity.java
│ │ │ ├── FilterActivity.java
│ │ │ ├── IntervalActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MergeActivity.java
│ │ │ ├── RangeActivity.java
│ │ │ ├── ScanActivity.java
│ │ │ ├── StartWithActivity.java
│ │ │ ├── TakeActivity.java
│ │ │ └── TimerActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_buffer.xml
│ │ ├── activity_combine_latest.xml
│ │ ├── activity_defer.xml
│ │ ├── activity_delay.xml
│ │ ├── activity_element_at.xml
│ │ ├── activity_filter.xml
│ │ ├── activity_finally_do.xml
│ │ ├── activity_interval.xml
│ │ ├── activity_main.xml
│ │ ├── activity_merge.xml
│ │ ├── activity_range.xml
│ │ ├── activity_scan.xml
│ │ ├── activity_start_with.xml
│ │ ├── activity_take.xml
│ │ ├── activity_timer.xml
│ │ └── content_main.xml
│ │ ├── menu
│ │ └── menu_main.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-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── app
│ └── com
│ └── myapplication
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Intellij project files
9 | .idea/
10 | .gradle/
11 | *.iml
12 |
13 | # Java class files
14 | *.class
15 |
16 | # Local configuration file (sdk path, etc)
17 | local.properties
18 | build
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "{}" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright 2016 君君小朋友
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 我的博客
2 | [RxJava 和 RxAndroid 一 (基础)](http://www.cnblogs.com/zhaoyanjun/p/5175502.html)
3 |
4 | [RxJava 和 RxAndroid 二(操作符的使用)](http://www.cnblogs.com/zhaoyanjun/p/5502804.html)
5 |
6 | [RxJava 和 RxAndroid 三(生命周期控制和内存优化)](http://www.cnblogs.com/zhaoyanjun/p/5523454.html)
7 |
8 | [RxJava 和 RxAndroid 四(RxBinding的使用)](http://www.cnblogs.com/zhaoyanjun/p/5535651.html)
9 |
10 | [RxJava 和 RxAndroid 五(线程调度)](http://www.cnblogs.com/zhaoyanjun/p/5624395.html)
11 |
12 | ---
13 | ### 相关的github地址
14 | [RxJava](https://github.com/ReactiveX/RxJava)
15 |
16 | [RxAndroid]( https://github.com/ReactiveX/RxAndroid)
17 |
18 | [RxLifecycle](https://github.com/trello/RxLifecycle)
19 |
20 | [RxBinding](https://github.com/JakeWharton/RxBinding)
21 |
22 | ---
23 |
24 | 个人微信号:`zhaoyanjun125 ` , 欢迎关注
25 |
26 | 
--------------------------------------------------------------------------------
/Retrofit/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Retrofit/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "lib.com.myapplication"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
27 | compile 'com.squareup.retrofit2:converter-gson:2.0.2'
28 | compile 'com.google.code.gson:gson:2.6.2'
29 | }
30 |
--------------------------------------------------------------------------------
/Retrofit/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 D:\soft\SDKandroidStudio/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 |
--------------------------------------------------------------------------------
/Retrofit/src/androidTest/java/lib/com/myapplication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/Retrofit/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Retrofit/src/main/java/lib/com/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.widget.TextView;
7 | import android.widget.Toast;
8 |
9 | import lib.com.myapplication.netI.UserI;
10 | import okhttp3.OkHttpClient;
11 | import retrofit2.Call;
12 | import retrofit2.Callback;
13 | import retrofit2.Response;
14 | import retrofit2.Retrofit;
15 | import retrofit2.converter.gson.GsonConverterFactory;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 |
19 | String Tag = "Retrofit" ;
20 |
21 | private TextView textView ;
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | // HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
28 | // httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
29 | // OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build();
30 |
31 | OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
32 |
33 | textView = (TextView) findViewById( R.id.tv );
34 |
35 | //http://www.app.zhaoaiqiao.com/web2/
36 | Retrofit retrofit = new Retrofit.Builder()
37 | .baseUrl( "http://www.app.zhaoaiqiao.com/web2" )
38 | .addConverterFactory( GsonConverterFactory.create())
39 | .build();
40 | UserI userBiz = retrofit.create(UserI.class);
41 | final Call call = userBiz.getUsers();
42 |
43 | call.enqueue(new Callback() {
44 | @Override
45 | public void onResponse(final Call call, final Response response) {
46 | Log.e(Tag, "normalGet:" + response.body().toString() + "" );
47 | runOnUiThread(new Runnable() {
48 | @Override
49 | public void run() {
50 | Toast.makeText(MainActivity.this, "success:" + response.body() , Toast.LENGTH_SHORT).show();
51 | Log.e(Tag, "normalGet:" + response.body().toString() + "" );
52 | textView.setText( response.body().toString() );
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | public void onFailure(Call call, Throwable t) {
59 | Toast.makeText(MainActivity.this, "failc" + t.toString() , Toast.LENGTH_SHORT).show();
60 | textView.setText( t.toString() );
61 | }
62 | });
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Retrofit/src/main/java/lib/com/myapplication/bean/User.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication.bean;
2 |
3 | /**
4 | * Created by ${zyj} on 2016/6/1.
5 | */
6 | public class User {
7 |
8 | String name ;
9 | String id ;
10 | String sex ;
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getSex() {
21 | return sex;
22 | }
23 |
24 | public void setSex(String sex) {
25 | this.sex = sex;
26 | }
27 |
28 | public String getId() {
29 | return id;
30 | }
31 |
32 | public void setId(String id) {
33 | this.id = id;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Retrofit/src/main/java/lib/com/myapplication/netI/UserI.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication.netI;
2 |
3 | import retrofit2.Call;
4 | import retrofit2.http.GET;
5 |
6 | /**
7 | * Created by ${zyj} on 2016/6/1.
8 | */
9 | public interface UserI {
10 | @GET("/PeopleServlet")
11 | Call getUsers();
12 | }
13 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/Retrofit/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/Retrofit/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/Retrofit/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/Retrofit/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/Retrofit/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/Retrofit/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Retrofit/src/test/java/lib/com/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxAndroid/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RxAndroid/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "lib.com.myapplication"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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:23.2.1'
26 | compile 'io.reactivex:rxandroid:1.2.0'
27 | }
28 |
--------------------------------------------------------------------------------
/RxAndroid/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 D:\soft\SDKandroidStudio/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 |
--------------------------------------------------------------------------------
/RxAndroid/src/androidTest/java/lib/com/myapplication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxAndroid/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/java/lib/com/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.os.HandlerThread;
5 | import android.os.Looper;
6 | import android.os.Process;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.view.View;
10 |
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import rx.Observable;
14 | import rx.Subscriber;
15 | import rx.android.schedulers.AndroidSchedulers;
16 | import rx.exceptions.OnErrorThrowable;
17 | import rx.functions.Func0;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | private static final String TAG = "RxAndroidSamples";
22 | private Looper backgroundLooper;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 | BackgroundThread backgroundThread = new BackgroundThread();
30 | backgroundThread.start();
31 | backgroundLooper = backgroundThread.getLooper();
32 |
33 | findViewById(R.id.button_run_scheduler).setOnClickListener(new View.OnClickListener() {
34 | @Override public void onClick(View v) {
35 | onRunSchedulerExampleButtonClicked();
36 | }
37 | });
38 |
39 | }
40 |
41 | void onRunSchedulerExampleButtonClicked() {
42 | sampleObservable()
43 | // Run on a background thread
44 | .subscribeOn( AndroidSchedulers.from(backgroundLooper))
45 | // Be notified on the main thread
46 | .observeOn(AndroidSchedulers.mainThread())
47 | .subscribe(new Subscriber() {
48 | @Override public void onCompleted() {
49 | Log.d(TAG, "onCompleted()");
50 | }
51 |
52 | @Override public void onError(Throwable e) {
53 | Log.e(TAG, "onError()", e);
54 | }
55 |
56 | @Override public void onNext(String string) {
57 | Log.d(TAG, "onNext(" + string + ")");
58 | }
59 | });
60 | }
61 |
62 | static rx.Observable sampleObservable() {
63 | return rx.Observable.defer(new Func0>() {
64 | @Override public rx.Observable call() {
65 | try {
66 | // Do some long running operation
67 | Thread.sleep(TimeUnit.SECONDS.toMillis(5));
68 | } catch (InterruptedException e) {
69 | throw OnErrorThrowable.from(e);
70 | }
71 | return Observable.just("one", "two", "three", "four", "five");
72 | }
73 | });
74 | }
75 |
76 | static class BackgroundThread extends HandlerThread {
77 | BackgroundThread() {
78 | super("SchedulerSample-BackgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
79 | }
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/java/lib/com/myapplication/RxBus.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 | import android.support.annotation.NonNull;
3 | import android.util.Log;
4 | import java.util.ArrayList;
5 | import java.util.Collection;
6 | import java.util.List;
7 | import java.util.concurrent.ConcurrentHashMap;
8 | import rx.Observable;
9 | import rx.subjects.PublishSubject;
10 | import rx.subjects.Subject;
11 |
12 | /**
13 | * Created by ${zyj} on 2016/5/6.
14 | */
15 | public class RxBus {
16 |
17 | private static final String TAG = RxBus.class.getSimpleName();
18 | private static RxBus instance;
19 | public static boolean DEBUG = false;
20 |
21 | public static RxBus get() {
22 | if (instance == null) {
23 | synchronized (RxBus.class) {
24 | if (instance == null) {
25 | instance = new RxBus();
26 | }
27 | }
28 | }
29 | return instance;
30 | }
31 |
32 | private RxBus() {
33 | }
34 |
35 | private ConcurrentHashMap> subjectMapper = new ConcurrentHashMap<>();
36 |
37 | @SuppressWarnings("unchecked")
38 | public Observable register(@NonNull Object tag, @NonNull Class clazz) {
39 | List subjectList = subjectMapper.get(tag);
40 | if (null == subjectList) {
41 | subjectList = new ArrayList<>();
42 | subjectMapper.put(tag, subjectList);
43 | }
44 |
45 | Subject subject;
46 | subjectList.add(subject = PublishSubject.create());
47 | if (DEBUG) Log.d(TAG, "[register]subjectMapper: " + subjectMapper);
48 | return subject;
49 | }
50 |
51 | public void unregister(@NonNull Object tag, @NonNull Observable observable) {
52 | List subjects = subjectMapper.get(tag);
53 | if (null != subjects) {
54 | if ( observable != null && subjects.contains( observable )){
55 | subjects.remove((Subject) observable);
56 | }
57 |
58 | if (isEmpty(subjects)) {
59 | subjectMapper.remove(tag);
60 | }
61 | }
62 |
63 | if (DEBUG) Log.d(TAG, "[unregister]subjectMapper: " + subjectMapper);
64 | }
65 |
66 | public void post(@NonNull Object content) {
67 | post( content.getClass().getName(), content);
68 | }
69 |
70 | @SuppressWarnings("unchecked")
71 | public void post(@NonNull Object tag, @NonNull Object content) {
72 | List subjectList = subjectMapper.get(tag);
73 |
74 | if (!isEmpty(subjectList)) {
75 | for (Subject subject : subjectList) {
76 | subject.onNext(content);
77 | }
78 | }
79 | if (DEBUG) Log.d(TAG, "[send]subjectMapper: " + subjectMapper);
80 | }
81 |
82 | private boolean isEmpty(Collection collection) {
83 | return null == collection || collection.isEmpty();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/java/lib/com/myapplication/RxBusActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 | import android.os.Bundle;
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.widget.TextView;
5 |
6 | import rx.Observable;
7 | import rx.android.schedulers.AndroidSchedulers;
8 | import rx.functions.Action1;
9 | import rx.schedulers.Schedulers;
10 |
11 | public class RxBusActivity extends AppCompatActivity {
12 |
13 | String tag = "tag" ;
14 | Observable ob ;
15 | private TextView tv ;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity1);
21 |
22 | tv = (TextView) findViewById( R.id.tv );
23 |
24 | //创建被观察者
25 | ob = RxBus.get().register( tag , String.class ) ;
26 | //订阅观察事件
27 | ob.subscribeOn( Schedulers.io())
28 | .observeOn(AndroidSchedulers.mainThread() )
29 | .subscribe(new Action1() {
30 | @Override
31 | public void call(String s) {
32 | tv.setText( s );
33 | }
34 | }) ;
35 |
36 | //发送内容
37 | RxBus.get().post( tag , "我是内容,万能的Rxjava" );
38 |
39 | }
40 |
41 | @Override
42 | protected void onDestroy() {
43 | super.onDestroy();
44 | //取消订阅
45 | RxBus.get().unregister( tag , ob );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/layout/activity1.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxAndroid/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxAndroid/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxAndroid/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxAndroid/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxAndroid/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/RxAndroid/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RxAndroid/src/test/java/lib/com/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxBinding/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RxBinding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "lib.com.myapplication"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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:23.4.0'
26 | compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
27 | }
28 |
--------------------------------------------------------------------------------
/RxBinding/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 D:\soft\SDKandroidStudio/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 |
--------------------------------------------------------------------------------
/RxBinding/src/androidTest/java/lib/com/myapplication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxBinding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/RxBinding/src/main/java/lib/com/myapplication/DebounceActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.text.TextUtils;
6 | import android.widget.ArrayAdapter;
7 | import android.widget.EditText;
8 | import android.widget.ListView;
9 |
10 | import com.jakewharton.rxbinding.widget.RxTextView;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.concurrent.TimeUnit;
15 |
16 | import rx.android.schedulers.AndroidSchedulers;
17 | import rx.functions.Action1;
18 | import rx.functions.Func1;
19 | import rx.schedulers.Schedulers;
20 |
21 | public class DebounceActivity extends AppCompatActivity {
22 |
23 | private EditText editText ;
24 | private ListView listView ;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_debounce);
30 |
31 | editText = (EditText) findViewById( R.id.editText );
32 | listView = (ListView) findViewById( R.id.listview );
33 |
34 | final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1 );
35 | listView.setAdapter( adapter );
36 |
37 | RxTextView.textChanges( editText )
38 | .debounce( 600 , TimeUnit.MILLISECONDS )
39 | .map(new Func1() {
40 | @Override
41 | public String call(CharSequence charSequence) {
42 | //get the keyword
43 | String key = charSequence.toString() ;
44 | return key ;
45 | }
46 | })
47 | .observeOn( Schedulers.io() )
48 | .map(new Func1>() {
49 | @Override
50 | public List call(String keyWord ) {
51 | //get list
52 | List dataList = new ArrayList() ;
53 | if ( ! TextUtils.isEmpty( keyWord )){
54 | for ( String s : getData() ) {
55 | if (s != null) {
56 | if (s.contains(keyWord)) {
57 | dataList.add(s);
58 | }
59 | }
60 | }
61 | }
62 | return dataList ;
63 | }
64 | })
65 | .observeOn( AndroidSchedulers.mainThread() )
66 | .subscribe(new Action1>() {
67 | @Override
68 | public void call(List strings) {
69 | adapter.clear();
70 | adapter.addAll( strings );
71 | adapter.notifyDataSetChanged();
72 | }
73 | }) ;
74 | }
75 |
76 | public List getData(){
77 | List list = new ArrayList<>() ;
78 | list.add( "a" ) ;
79 | list.add( "aab" ) ;
80 | list.add( "aaabc" ) ;
81 | list.add( "aaaaabcd" ) ;
82 | list.add( "aaaaaabcde" ) ;
83 | list.add( "aaaaaaac" ) ;
84 | list.add( "aaaaaaaacd" ) ;
85 | list.add( "aaaaaaaaacdef" ) ;
86 | list.add( "aaaaaaaaaabc" ) ;
87 | list.add( "bcd" ) ;
88 | list.add( "bcdef" ) ;
89 | list.add( "cd" ) ;
90 | list.add( "cde" ) ;
91 | list.add( "cdefg" ) ;
92 | list.add( "dddkkk5662" ) ;
93 | list.add( "bbs" ) ;
94 | list.add( "7b4s" ) ;
95 | list.add( "jjjsssd995556214613" ) ;
96 | list.add( "58350675" ) ;
97 |
98 | return list ;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/RxBinding/src/main/java/lib/com/myapplication/ListActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.ArrayAdapter;
6 | import android.widget.ListView;
7 | import android.widget.Toast;
8 |
9 | import com.jakewharton.rxbinding.widget.RxAdapterView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import rx.functions.Action1;
15 |
16 | public class ListActivity extends AppCompatActivity {
17 |
18 | ListView listView ;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_list);
24 |
25 | listView = (ListView) findViewById( R.id.listview );
26 |
27 | List list = new ArrayList<>() ;
28 | for ( int i = 0 ; i < 40 ; i++ ){
29 | list.add( "sss" + i ) ;
30 | }
31 |
32 | final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1 );
33 | adapter.addAll( list );
34 |
35 | listView.setAdapter( adapter );
36 |
37 | //item click event
38 | RxAdapterView.itemClicks( listView )
39 | .subscribe(new Action1() {
40 | @Override
41 | public void call(Integer integer) {
42 | Toast.makeText(ListActivity.this, "item click " + integer , Toast.LENGTH_SHORT).show();
43 | }
44 | }) ;
45 |
46 | //item long click
47 | RxAdapterView.itemLongClicks( listView)
48 | .subscribe(new Action1() {
49 | @Override
50 | public void call(Integer integer) {
51 | Toast.makeText(ListActivity.this, "item long click " + integer , Toast.LENGTH_SHORT).show();
52 | }
53 | }) ;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/RxBinding/src/main/java/lib/com/myapplication/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 | import android.support.v7.app.AppCompatActivity;
3 | import android.os.Bundle;
4 | import android.widget.Button;
5 | import android.widget.CheckBox;
6 | import com.jakewharton.rxbinding.widget.RxCompoundButton;
7 | import rx.functions.Action1;
8 |
9 | public class LoginActivity extends AppCompatActivity {
10 |
11 | private Button button ;
12 | private CheckBox checkBox ;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_login);
18 |
19 | button = (Button) findViewById( R.id.login_bt );
20 | checkBox = (CheckBox) findViewById( R.id.checkbox );
21 |
22 | RxCompoundButton.checkedChanges( checkBox )
23 | .subscribe(new Action1() {
24 | @Override
25 | public void call(Boolean aBoolean) {
26 | button.setEnabled( aBoolean );
27 | button.setBackgroundResource( aBoolean ? R.color.button_yes : R.color.button_no );
28 | }
29 | }) ;
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/RxBinding/src/main/java/lib/com/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.Button;
7 | import android.widget.Toast;
8 |
9 | import com.jakewharton.rxbinding.view.RxView;
10 |
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import rx.functions.Action1;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | private Button button ;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | button = (Button) findViewById( R.id.bt ) ;
25 |
26 | RxView.clicks( button )
27 | .throttleFirst( 2 , TimeUnit.SECONDS ) //两秒钟之内只取一个点击事件,防抖操作
28 | .subscribe(new Action1() {
29 | @Override
30 | public void call(Void aVoid) {
31 | Toast.makeText(MainActivity.this, "click!!", Toast.LENGTH_SHORT).show();
32 | }
33 | }) ;
34 |
35 | button = (Button) findViewById( R.id.bt ) ;
36 |
37 | //监听长按时间
38 | RxView.longClicks( button)
39 | .subscribe(new Action1() {
40 | @Override
41 | public void call(Void aVoid) {
42 | Toast.makeText(MainActivity.this, "long click !!", Toast.LENGTH_SHORT).show();
43 | }
44 | }) ;
45 |
46 | //跳转到listActivity
47 | RxView.clicks( findViewById( R.id.bt2 ))
48 | .subscribe(new Action1() {
49 | @Override
50 | public void call(Void aVoid) {
51 | startActivity( new Intent( MainActivity.this , ListActivity.class ));
52 | }
53 | }) ;
54 |
55 | //跳转到LoginActivity
56 | RxView.clicks( findViewById( R.id.bt3 ))
57 | .subscribe(new Action1() {
58 | @Override
59 | public void call(Void aVoid) {
60 | startActivity( new Intent( MainActivity.this , LoginActivity.class ));
61 | }
62 | }) ;
63 |
64 | //跳转到DebounceActivity
65 | RxView.clicks( findViewById( R.id.debounce ))
66 | .subscribe(new Action1() {
67 | @Override
68 | public void call(Void aVoid) {
69 | startActivity( new Intent( MainActivity.this , DebounceActivity.class ));
70 | }
71 | }) ;
72 |
73 | //跳转到TextViewActivity
74 | RxView.clicks( findViewById( R.id.textView ))
75 | .subscribe(new Action1() {
76 | @Override
77 | public void call(Void aVoid) {
78 | startActivity( new Intent( MainActivity.this , TextViewActivity.class ));
79 | }
80 | }) ;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/RxBinding/src/main/java/lib/com/myapplication/TextViewActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.TextView;
6 |
7 | public class TextViewActivity extends AppCompatActivity {
8 |
9 | private TextView textView ;
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_text_view);
15 |
16 | textView = (TextView) findViewById( R.id.tv );
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/layout/activity_debounce.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
24 |
25 |
31 |
32 |
38 |
39 |
40 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/layout/activity_text_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxBinding/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxBinding/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxBinding/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxBinding/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxBinding/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxBinding/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxBinding/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxBinding/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxBinding/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxBinding/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #dddddd
7 | #3f51b5
8 |
9 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/RxBinding/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RxBinding/src/test/java/lib/com/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxLifecycle/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RxLifecycle/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "lib.com.myapplication"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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:23.4.0'
26 | compile 'com.trello:rxlifecycle-components:0.6.1'
27 | }
28 |
--------------------------------------------------------------------------------
/RxLifecycle/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 D:\soft\SDKandroidStudio/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 |
--------------------------------------------------------------------------------
/RxLifecycle/src/androidTest/java/lib/com/myapplication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxLifecycle/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/java/lib/com/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 | import android.content.Intent;
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.TextView;
6 | import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
7 | import java.util.concurrent.TimeUnit;
8 | import rx.Observable;
9 | import rx.android.schedulers.AndroidSchedulers;
10 | import rx.functions.Action1;
11 | import rx.schedulers.Schedulers;
12 |
13 | public class MainActivity extends RxAppCompatActivity {
14 | TextView textView ;
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | textView = (TextView) findViewById(R.id.textView);
21 | textView.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | startActivity( new Intent( MainActivity.this , StopActivity.class));
25 | }
26 | });
27 |
28 | //循环发送数字
29 | Observable.interval(0, 1, TimeUnit.SECONDS)
30 | .subscribeOn( Schedulers.io())
31 | .compose(this.bindToLifecycle()) //这个订阅关系跟Activity绑定,Observable 和activity生命周期同步
32 | .observeOn( AndroidSchedulers.mainThread())
33 | .subscribe(new Action1() {
34 | @Override
35 | public void call(Long aLong) {
36 | System.out.println("lifecycle--" + aLong);
37 | textView.setText( "" + aLong );
38 | }
39 | });
40 | }
41 |
42 | @Override
43 | protected void onDestroy() {
44 | super.onDestroy();
45 | System.out.println("life-- Destory");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/java/lib/com/myapplication/MyFragment.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.trello.rxlifecycle.components.RxFragment;
10 |
11 | /**
12 | * Created by ${zyj} on 2016/5/23.
13 | */
14 | public class MyFragment extends RxFragment {
15 |
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
19 | return super.onCreateView(inflater, container, savedInstanceState);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/java/lib/com/myapplication/OtherActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class OtherActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_other);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/java/lib/com/myapplication/StopActivity.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.TextView;
7 |
8 | import com.trello.rxlifecycle.ActivityEvent;
9 | import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
10 |
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import rx.Observable;
14 | import rx.android.schedulers.AndroidSchedulers;
15 | import rx.functions.Action1;
16 | import rx.schedulers.Schedulers;
17 |
18 | public class StopActivity extends RxAppCompatActivity {
19 |
20 | TextView textView ;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_stop);
26 |
27 | textView = (TextView) findViewById(R.id.textview);
28 | textView.setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | startActivity( new Intent( StopActivity.this , OtherActivity.class));
32 | }
33 | });
34 |
35 | //循环发送数字
36 | Observable.interval(0, 1, TimeUnit.SECONDS)
37 | .subscribeOn( Schedulers.io())
38 | .compose(this.bindUntilEvent(ActivityEvent.STOP )) //当Activity执行Onstop()方法是解除订阅关系
39 | .observeOn( AndroidSchedulers.mainThread())
40 | .subscribe(new Action1() {
41 | @Override
42 | public void call(Long aLong) {
43 | System.out.println("lifecycle-stop-" + aLong);
44 | textView.setText( "" + aLong );
45 | }
46 | });
47 | }
48 |
49 | @Override
50 | protected void onPause() {
51 | super.onPause();
52 | System.out.println("lifecycle-stop-" + "onPause()方法调用了");
53 | }
54 |
55 | @Override
56 | protected void onStop() {
57 | super.onStop();
58 | System.out.println("lifecycle-stop-" + "onStop()方法调用了");
59 | }
60 |
61 | @Override
62 | protected void onDestroy() {
63 | super.onDestroy();
64 | System.out.println("lifecycle-stop-" + "onDestroy()方法调用了");
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/layout/activity_other.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/layout/activity_stop.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/layout/fragment_my.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxLifecycle/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxLifecycle/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxLifecycle/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxLifecycle/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxLifecycle/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/RxLifecycle/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RxLifecycle/src/test/java/lib/com/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lib.com.myapplication;
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 | }
--------------------------------------------------------------------------------
/RxPreferences/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RxPreferences/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.app"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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:23.4.0'
26 | compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1'
27 | }
28 |
--------------------------------------------------------------------------------
/RxPreferences/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 D:\soft\SDKandroidStudio/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 |
--------------------------------------------------------------------------------
/RxPreferences/src/androidTest/java/com/app/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.app;
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 | }
--------------------------------------------------------------------------------
/RxPreferences/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/java/com/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.app;
2 |
3 | import android.content.SharedPreferences;
4 | import android.os.Bundle;
5 | import android.preference.PreferenceManager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.EditText;
9 | import android.widget.Toast;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | private EditText editText ;
14 | private SharedPreferences.Editor editor ;
15 | private SharedPreferences preferences ;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | editText = (EditText) findViewById( R.id.et) ;
23 | preferences = PreferenceManager.getDefaultSharedPreferences( MainActivity.this ) ;
24 | editor = preferences.edit() ;
25 |
26 | preferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
27 | @Override
28 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
29 | Toast.makeText( MainActivity.this , "listen--key: " + key + " value: " + sharedPreferences.getString( key , "") , Toast.LENGTH_SHORT ).show();
30 | }
31 | });
32 |
33 | //点击
34 | findViewById( R.id.tv).setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | String value = editText.getText().toString() ;
38 | editor.putString( "key" , value ) ;
39 | editor.commit() ;
40 | }
41 | });
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxPreferences/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxPreferences/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxPreferences/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxPreferences/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/RxPreferences/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/RxPreferences/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RxPreferences/src/test/java/com/app/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.app;
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 | }
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .gradle/
3 | build/
4 | *.iml
5 | local.properties
6 | *.apk
7 | *.ap_
8 | bin/
9 | gen/
10 | .classpath
11 | .project
12 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "app.com.myapplication"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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:23.1.1'
26 | compile 'com.android.support:design:23.1.1'
27 | compile 'io.reactivex:rxandroid:1.2.0'
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/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 D:\soft\SDKandroidStudio/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/app/com/myapplication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
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 |
7 |
8 |
14 |
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 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity1.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 | import android.app.Activity;
3 | import android.os.Bundle;
4 |
5 | import rx.Observable;
6 | import rx.Subscriber;
7 |
8 | /**
9 | * Created by ${zyj} on 2016/2/15.
10 | */
11 | public class Activity1 extends Activity {
12 |
13 | String TAG = "Activity1-->" ;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 |
19 | //注册事件
20 | myObservable.subscribe( mySubscriber ) ;
21 |
22 | //一旦mySubscriber订阅了myObservable,
23 | // myObservable就是调用mySubscriber对象的onNext和onComplete方法,mySubscriber就会打印出Hello World!
24 | }
25 |
26 | //创建一个事件源对象
27 | Observable myObservable = Observable.create(
28 | new Observable.OnSubscribe() {
29 | @Override
30 | public void call(Subscriber super String> sub) {
31 | sub.onNext("Hello, world! 1");
32 | sub.onNext("Hello, world! 2");
33 | sub.onCompleted();
34 | }
35 | }
36 |
37 |
38 | );
39 |
40 | //创建一个观察者对象
41 | Subscriber mySubscriber = new Subscriber() {
42 | @Override
43 | public void onNext(String s) {
44 | System.out.println( TAG + s);
45 | }
46 |
47 | @Override
48 | public void onCompleted() { }
49 | @Override
50 | public void onError(Throwable e) { }
51 | };
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity10.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.Subscription;
11 | import rx.functions.Action1;
12 |
13 | /**
14 | * Created by ${zyj} on 2016/2/15.
15 | *
16 | */
17 | public class Activity10 extends Activity {
18 |
19 | private String TAG = "Activity10-->" ;
20 | private List list = new ArrayList<>() ;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 |
26 | list.add( "hello 1" ) ;
27 | list.add( "hello 2" ) ;
28 | list.add( "hello 3" ) ;
29 | list.add( "hello 4" ) ;
30 |
31 | //创建一个事件源对象
32 | Subscription subscription = Observable.from(list).subscribe(onNextAction) ;
33 |
34 | //取消两者的关系
35 | //RxJava处理取消订阅漂亮的地方在于它停止了链。如果你有一堆复合的操作链,不论当前执行的是什么代码,
36 | // 利用unsubscribe都将会终止链,其他工作都不需要做。
37 | subscription.unsubscribe();
38 |
39 | }
40 |
41 | //创建一个观察者对象 (简化版) 简化Subscriber
42 | Action1 onNextAction = new Action1() {
43 | @Override
44 | public void call(String s) {
45 | out( s );
46 | }
47 | };
48 |
49 | void out( String s ){
50 | System.out.println( TAG + s );
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity2.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 |
9 | /**
10 | * Created by ${zyj} on 2016/2/15.
11 | * 简化版操作
12 | */
13 | public class Activity2 extends Activity {
14 |
15 | String TAG = "Activity2-->" ;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 |
21 | //注册事件
22 | // myObservable.subscribe(onNextAction);
23 |
24 | //或者
25 |
26 | myObservable.subscribe(new Action1() {
27 | @Override
28 | public void call(String s) {
29 |
30 | }
31 | }) ;
32 |
33 | }
34 |
35 | //创建一个事件源对象 (简化版)
36 | // Observable.just就是用来创建只发出一个事件就结束的Observable对象
37 | Observable myObservable = Observable.just("Hello, world!");
38 |
39 | //创建一个观察者对象 (简化版) 简化Subscriber
40 | Action1 onNextAction = new Action1() {
41 | @Override
42 | public void call(String s) {
43 | System.out.println( TAG + s);
44 | }
45 | };
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity3.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 | import rx.functions.Func1;
9 |
10 | /**
11 | * Created by ${zyj} on 2016/2/15.
12 | * map操作符
13 | */
14 | public class Activity3 extends Activity {
15 |
16 | String TAG = "Activity3-->" ;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 |
22 | //注册事件 一map操作符,就是用来把个事件转换为另一个事件的。
23 | //map()操作符就是用于变换Observable对象的,map操作符返回一个Observable对象,
24 | // 这样就可以实现链式调用,在一个Observable对象上多次使用map操作符,最终将最简洁的数据传递给Subscriber对象。
25 | myObservable.map(new Func1() {
26 | @Override
27 | public String call(String s) {
28 | return s + "哈哈";
29 | }
30 | }).subscribe( onNextAction ) ;
31 |
32 |
33 | //或者
34 | myObservable.map(new Func1() {
35 | @Override
36 | public String call(String s) {
37 | return s + "哈哈";
38 | }
39 | }).subscribe(new Action1() {
40 | @Override
41 | public void call(String s) {
42 | System.out.println( TAG + s );
43 | }
44 | }) ;
45 |
46 |
47 | //或者
48 | Observable.just( "测试" ).map(new Func1() {
49 | @Override
50 | public String call(String s) {
51 | return s + "哈哈";
52 | }
53 | }).subscribe(new Action1() {
54 | @Override
55 | public void call(String s) {
56 | System.out.println( TAG + s );
57 | }
58 | }) ;
59 |
60 | }
61 |
62 | //创建一个事件源对象 (简化版)
63 | // Observable.just就是用来创建只发出一个事件就结束的Observable对象
64 | Observable myObservable = Observable.just("Hello, world!");
65 |
66 | //创建一个观察者对象 (简化版) 简化Subscriber
67 | Action1 onNextAction = new Action1() {
68 | @Override
69 | public void call(String s) {
70 | System.out.println( TAG + s );
71 | }
72 | };
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity4.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.functions.Action1;
11 |
12 | /**
13 | * Created by ${zyj} on 2016/2/15.
14 | * Observable的from 方法接收一个集合数据
15 | * Observable.from()这个方法可以获得一组数据,并且每次发出他们中的一个。
16 | */
17 | public class Activity4 extends Activity {
18 |
19 | private List list = new ArrayList<>() ;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 |
25 | list.add( "hello 1" ) ;
26 | list.add( "hello 2" ) ;
27 | list.add( "hello 3" ) ;
28 | list.add( "hello 4" ) ;
29 |
30 | //创建一个事件源对象 (简化版)
31 | Observable observable = Observable.from( list ) ;
32 | observable.subscribe( onNextAction ) ;
33 |
34 | }
35 |
36 | //创建一个观察者对象 (简化版) 简化Subscriber
37 | Action1 onNextAction = new Action1() {
38 | @Override
39 | public void call(String s) {
40 | System.out.println(s);
41 | }
42 | };
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity5.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.functions.Action1;
11 | import rx.functions.Func1;
12 |
13 | /**
14 | * Created by ${zyj} on 2016/2/15.
15 | * Activity5 Observable的from 方法接收一个集合数据 和 map 方法混用
16 | */
17 | public class Activity5 extends Activity {
18 |
19 | private List list = new ArrayList<>() ;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 |
25 | list.add( "hello 1" ) ;
26 | list.add( "hello 2" ) ;
27 | list.add( "hello 3" ) ;
28 | list.add( "hello 4" ) ;
29 |
30 | //创建一个事件源对象 (简化版)
31 | Observable observable = Observable.from( list ) ;
32 | observable.subscribe( onNextAction ) ;
33 |
34 |
35 | //map 的用法
36 | Observable.from( list ).map(new Func1() {
37 | @Override
38 | public String call(String s) {
39 | return "from " + s ;
40 | }
41 | }).subscribe( onNextAction ) ;
42 |
43 | }
44 |
45 | //创建一个观察者对象 (简化版) 简化Subscriber
46 | Action1 onNextAction = new Action1() {
47 | @Override
48 | public void call(String s) {
49 | System.out.println(s);
50 | }
51 | };
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity6.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import rx.Observable;
11 | import rx.Subscriber;
12 | import rx.functions.Action1;
13 | import rx.functions.Func1;
14 |
15 | /**
16 | * Created by ${zyj} on 2016/2/15.
17 | * Observable.from()这个方法可以获得一组数据,并且每次发出他们中的一个。
18 | * 注意 flatMap() 方法其实就是把 Observable> 转化成一个个 Observable
19 | */
20 | public class Activity6 extends Activity {
21 |
22 | private List list = new ArrayList<>() ;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 |
28 | list.add( "hello 1" ) ;
29 | list.add( "hello 2" ) ;
30 | list.add( "hello 3" ) ;
31 | list.add("hello 4") ;
32 |
33 | //创建一个事件源对象
34 | //注意 flatMap() 方法其实就是把 Observable> 转化成一个个 Observable
35 | query().flatMap(new Func1, Observable>() {
36 | @Override
37 | public Observable call(List strings) {
38 | return Observable.from(strings);
39 | }
40 | }).subscribe( onNextAction );
41 |
42 |
43 | //或者这样的
44 | query().flatMap(new Func1, Observable>() {
45 | @Override
46 | public Observable call(List strings) {
47 | return Observable.from( strings );
48 | }
49 | }).flatMap(new Func1>() {
50 | @Override
51 | public Observable call(String s) {
52 | return Observable.just( s + "哈哈哈" ) ;
53 | }
54 | }).subscribe( onNextAction ) ;
55 |
56 | //这样也是可以的
57 | query().subscribe(new Action1>() {
58 | @Override
59 | public void call(List strings) {
60 | Toast.makeText(Activity6.this, "" + strings.size(), Toast.LENGTH_SHORT).show();
61 | }
62 | }) ;
63 |
64 | //或者这样也是可以的
65 | Observable.from( list ).subscribe( onNextAction ) ;
66 |
67 | }
68 |
69 | //创建一个观察者对象 (简化版) 简化Subscriber
70 | Action1 onNextAction = new Action1() {
71 | @Override
72 | public void call(String s) {
73 | System.out.println(s);
74 | }
75 | };
76 |
77 | /**
78 | * 创建一个事件源
79 | * @return
80 | */
81 | public Observable> query( ) {
82 | return Observable.create(new Observable.OnSubscribe>() {
83 | @Override
84 | public void call(Subscriber super List> subscriber) {
85 | subscriber.onNext( list );
86 | subscriber.onCompleted();
87 | }
88 | }) ;
89 |
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity7.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.Subscriber;
11 | import rx.functions.Action1;
12 | import rx.functions.Func1;
13 |
14 | /**
15 | * Created by ${zyj} on 2016/2/15.
16 | * filter() 过滤
17 | * 返回true ,代表保留 。 返回false 代表过滤掉
18 | * 就是返回我们想要的数据
19 | */
20 | public class Activity7 extends Activity {
21 |
22 | private List list = new ArrayList<>() ;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 |
28 | list.add("hello 1") ;
29 | list.add( "hello 2" ) ;
30 | list.add( "hello 3" ) ;
31 | list.add( null ) ;
32 | list.add("hello 4") ;
33 |
34 | //创建一个事件源对象
35 | //注意 flatMap() 方法其实就是把 Observable> 转化成一个个 Observable
36 | query().flatMap(new Func1, Observable>() {
37 | @Override
38 | public Observable call(List strings) {
39 | return Observable.from( strings );
40 | }
41 | }).filter(new Func1() {
42 | @Override
43 | public Boolean call(String s) {
44 | return s != null ; //返回true ,代表保留 。 返回false 代表过滤掉
45 | }
46 | }).flatMap(new Func1>() {
47 | @Override
48 | public Observable call(String s) {
49 | return Observable.just(s + "哈哈哈");
50 | }
51 | }).subscribe( onNextAction ) ;
52 |
53 | }
54 |
55 | //创建一个观察者对象 (简化版) 简化Subscriber
56 | Action1 onNextAction = new Action1() {
57 | @Override
58 | public void call(String s) {
59 | System.out.println(s);
60 | }
61 | };
62 |
63 | /**
64 | * 创建一个事件源
65 | * @return
66 | */
67 | public Observable> query( ) {
68 | return Observable.create(new Observable.OnSubscribe>() {
69 | @Override
70 | public void call(Subscriber super List> subscriber) {
71 | subscriber.onNext( list );
72 | subscriber.onCompleted();
73 | }
74 | }) ;
75 |
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/Activity8.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.Subscriber;
11 | import rx.functions.Action1;
12 | import rx.functions.Func1;
13 |
14 | /**
15 | * Created by ${zyj} on 2016/2/15.
16 | * filter() 过滤
17 | * 返回true ,代表保留 。 返回false 代表过滤掉
18 | * 就是返回我们想要的数据
19 | *
20 | * take()操作符的使用。(最多发出指定数量的内容)
21 | */
22 | public class Activity8 extends Activity {
23 |
24 | private List list = new ArrayList<>() ;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 |
30 | list.add("hello 1") ;
31 | list.add( "hello 2" ) ;
32 | list.add( "hello 3" ) ;
33 | list.add( null ) ;
34 | list.add("hello 4") ;
35 | list.add("hello 5") ;
36 | list.add("hello 6") ;
37 |
38 | //创建一个事件源对象
39 | //注意 flatMap() 方法其实就是把 Observable> 转化成一个个 Observable
40 | query().flatMap(new Func1, Observable>() {
41 | @Override
42 | public Observable call(List strings) {
43 | return Observable.from( strings );
44 | }
45 | }).filter(new Func1() {
46 | @Override
47 | public Boolean call(String s) {
48 | return s != null ; //返回true ,代表保留 。 返回false 代表过滤掉
49 | }
50 | }).take( 5 )
51 | .flatMap(new Func1>() {
52 | @Override
53 | public Observable call(String s) {
54 | return Observable.just(s + "哈哈哈");
55 | }
56 | }).subscribe( onNextAction ) ;
57 |
58 | }
59 |
60 | //创建一个观察者对象 (简化版) 简化Subscriber
61 | Action1 onNextAction = new Action1() {
62 | @Override
63 | public void call(String s) {
64 | System.out.println(s);
65 | }
66 | };
67 |
68 | /**
69 | * 创建一个事件源
70 | * @return
71 | */
72 | public Observable> query( ) {
73 | return Observable.create(new Observable.OnSubscribe>() {
74 | @Override
75 | public void call(Subscriber super List> subscriber) {
76 | subscriber.onNext( list );
77 | subscriber.onCompleted();
78 | }
79 | }) ;
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/BufferActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import rx.Observable;
8 | import rx.functions.Action1;
9 |
10 | public class BufferActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_buffer);
16 |
17 | List list = new ArrayList<>();
18 | for (int i = 1; i < 10; i++) {
19 | list.add("" + i);
20 | }
21 |
22 | Observable observable = Observable.from(list);
23 | observable
24 | .buffer(2) //把每两个数据为一组打成一个包,然后发送
25 | .subscribe(new Action1>() {
26 | @Override
27 | public void call(List strings) {
28 | System.out.println( "buffer---------------" );
29 | Observable.from( strings ).subscribe(new Action1() {
30 | @Override
31 | public void call(String s) {
32 | System.out.println( "buffer data --" + s );
33 | }
34 | }) ;
35 | }
36 | });
37 |
38 | //第1、2 个数据打成一个数据包,跳过第三个数据 ; 第4、5个数据打成一个包,跳过第6个数据
39 | observable.buffer( 2 , 3 ) //把每两个数据为一组打成一个包,然后发送。第三个数据跳过去
40 | .subscribe(new Action1>() {
41 | @Override
42 | public void call(List strings) {
43 |
44 | System.out.println( "buffer22---------------" );
45 | Observable.from( strings ).subscribe(new Action1() {
46 | @Override
47 | public void call(String s) {
48 | System.out.println( "buffer22 data --" + s );
49 | }
50 | }) ;
51 | }
52 | }) ;
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/CombineLatestActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 |
8 | import rx.Observable;
9 | import rx.Subscriber;
10 | import rx.functions.Action1;
11 | import rx.functions.Func2;
12 |
13 | public class CombineLatestActivity extends AppCompatActivity {
14 |
15 | Observable observable1 ;
16 | int nn = 0 ;
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_combine_latest);
21 |
22 | observable1 = Observable.create(new Observable.OnSubscribe() {
23 | @Override
24 | public void call(final Subscriber super String> subscriber){
25 | findViewById( R.id.bt).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | subscriber.onNext( "0s1" ) ;
29 | }
30 | });
31 | }
32 | }) ;
33 |
34 | Observable observable2 = Observable.create(new Observable.OnSubscribe() {
35 | @Override
36 | public void call(final Subscriber super String> subscriber) {
37 | findViewById( R.id.bt2).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | nn = nn + 1 ;
41 | subscriber.onNext( "55" + nn ) ;
42 | }
43 | });
44 | }
45 | }) ;
46 |
47 | Observable.combineLatest(observable1, observable2, new Func2() {
48 | @Override
49 | public String call(String s, String s2) {
50 | return s + s2 ;
51 | }
52 | }).subscribe(new Action1() {
53 | @Override
54 | public void call(String s) {
55 | Log.v( "com-- " , s ) ;
56 | }
57 | }) ;
58 |
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/DeferActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 | import rx.functions.Func0;
9 |
10 | public class DeferActivity extends AppCompatActivity {
11 |
12 | String i = "10" ;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_defer);
18 |
19 | i = "11 " ;
20 |
21 | Observable defer = Observable.defer(new Func0>() {
22 | @Override
23 | public Observable call() {
24 | return Observable.just( i ) ;
25 | }
26 | }) ;
27 |
28 | Observable test = Observable.just( i ) ;
29 |
30 | i = "12" ;
31 |
32 | defer.subscribe(new Action1() {
33 | @Override
34 | public void call(String s) {
35 | Log.v( "rx_defer " , "" + s ) ;
36 | }
37 | }) ;
38 |
39 | test.subscribe(new Action1() {
40 | @Override
41 | public void call(Object o) {
42 | Log.v( "rx_just " , "" + o ) ;
43 | }
44 | }) ;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/DelayActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | import rx.Observable;
9 | import rx.functions.Action1;
10 |
11 | public class DelayActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_delay);
17 |
18 | Observable observable = Observable.just( "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" ) ;
19 |
20 | //延迟数据发射的时间,仅仅延时一次,也就是发射第一个数据前延时。发射后面的数据不延时
21 | observable.delay( 3 , TimeUnit.SECONDS ) //延迟3秒钟
22 | .subscribe(new Action1() {
23 | @Override
24 | public void call(Object o) {
25 | System.out.println("delay-- " + o);
26 | }
27 | }) ;
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/DoOnNextActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import rx.Observable;
7 | import rx.Observer;
8 | import rx.functions.Action1;
9 |
10 | public class DoOnNextActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 |
16 | Observable observable = Observable.just( "1" , "2" , "3" , "4" ) ;
17 | observable.doOnNext(new Action1() {
18 | @Override
19 | public void call(Object o) {
20 | System.out.println( "doOnNext--缓存数据" + o );
21 | }
22 | })
23 | .subscribe(new Observer() {
24 | @Override
25 | public void onCompleted() {
26 |
27 | }
28 |
29 | @Override
30 | public void onError(Throwable e) {
31 |
32 | }
33 |
34 | @Override
35 | public void onNext(Object o) {
36 | System.out.println( "onNext--" + o );
37 | }
38 | }) ;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/ElementAtActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 |
9 | public class ElementAtActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_element_at);
15 |
16 | //elementAt() 发送数据序列中第n个数据 ,序列号从0开始
17 | //如果该序号大于数据序列中的最大序列号,则会抛出异常,程序崩溃
18 | //所以在用elementAt操作符的时候,要注意判断发送的数据序列号是否越界
19 |
20 | Observable observable7 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
21 | observable7.elementAt( 3 )
22 | .subscribe(new Action1() {
23 | @Override
24 | public void call(Object o) {
25 | System.out.println( "elementAt-- " + o );
26 | }
27 | }) ;
28 |
29 | //elementAtOrDefault( int n , Object default ) 发送数据序列中第n个数据 ,序列号从0开始。
30 | //如果序列中没有该序列号,则发送默认值
31 | Observable observable9 = Observable.just( 1 , 2 , 3 , 4 , 5 ) ;
32 | observable9.elementAtOrDefault( 8 , 666 )
33 | .subscribe(new Action1() {
34 | @Override
35 | public void call(Object o) {
36 | System.out.println( "elementAtOrDefault-- " + o );
37 | }
38 | }) ;
39 |
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/FilterActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 | import rx.functions.Func1;
9 |
10 | public class FilterActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_filter);
16 |
17 |
18 | Observable observable = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
19 | observable.filter(new Func1() {
20 | @Override
21 | public Boolean call(Integer o) {
22 | //数据大于4的时候才会被发送
23 | return o > 4 ;
24 | }
25 | })
26 | .subscribe(new Action1() {
27 | @Override
28 | public void call(Object o) {
29 | System.out.println( "filter-- " + o );
30 | }
31 | }) ;
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/IntervalActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 | import android.support.v7.app.AppCompatActivity;
3 | import android.os.Bundle;
4 | import java.util.concurrent.TimeUnit;
5 | import rx.Observable;
6 | import rx.Subscription;
7 | import rx.functions.Action1;
8 |
9 | public class IntervalActivity extends AppCompatActivity {
10 |
11 | Subscription subscription ;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_interval);
17 |
18 | //参数一:延迟时间 参数二:间隔时间 参数三:时间颗粒度
19 | Observable observable = Observable.interval(3000, 3000, TimeUnit.MILLISECONDS) ;
20 | subscription = observable.subscribe(new Action1() {
21 | @Override
22 | public void call(Object o) {
23 | System.out.println( "interval- " + o );
24 | }
25 | }) ;
26 | }
27 |
28 | @Override
29 | protected void onDestroy() {
30 | super.onDestroy();
31 | if ( subscription != null ){
32 | subscription.unsubscribe();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.HandlerThread;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.Log;
8 | import android.view.View ;
9 | import android.content.Intent;
10 | import java.util.concurrent.TimeUnit;
11 | import rx.Observable;
12 | import rx.Subscriber;
13 | import rx.android.schedulers.AndroidSchedulers;
14 | import rx.android.schedulers.HandlerScheduler;
15 | import rx.exceptions.OnErrorThrowable;
16 | import rx.functions.Func0;
17 |
18 | import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | private static final String TAG = "RxAndroidSamples";
23 | private Handler backgroundHandler;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | //基本原理
31 | findViewById( R.id.bt1 ).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | startActivity(new Intent(MainActivity.this, Activity1.class));
35 | }
36 | });
37 |
38 | //简化版用法
39 | findViewById( R.id.bt2 ).setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | startActivity( new Intent( MainActivity.this , Activity2.class ));
43 | }
44 | });
45 |
46 | //map() 操作符
47 | findViewById( R.id.bt3 ).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | startActivity( new Intent( MainActivity.this , Activity3.class ));
51 | }
52 | });
53 |
54 | //Observable的from 方法接收一个集合数据
55 | findViewById( R.id.bt4 ).setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | startActivity( new Intent( MainActivity.this , Activity4.class ));
59 | }
60 | });
61 |
62 | //Activity5 Observable的from 方法接收一个集合数据 和 map 方法混用
63 | findViewById( R.id.bt5 ).setOnClickListener(new View.OnClickListener() {
64 | @Override
65 | public void onClick(View v) {
66 | startActivity( new Intent( MainActivity.this , Activity5.class ));
67 | }
68 | });
69 |
70 | //Activity6 flatMap() 方法的使用
71 | findViewById( R.id.bt6 ).setOnClickListener(new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | startActivity( new Intent( MainActivity.this , Activity6.class ));
75 | }
76 | });
77 |
78 | //Activity7 filter() 过滤方法的使用
79 | findViewById( R.id.bt7 ).setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | startActivity( new Intent( MainActivity.this , Activity7.class ));
83 | }
84 | });
85 |
86 | //Activity8 take()操作符的使用。(最多发出指定数量的内容)
87 | findViewById( R.id.bt8 ).setOnClickListener(new View.OnClickListener() {
88 | @Override
89 | public void onClick(View v) {
90 | startActivity( new Intent( MainActivity.this , Activity8.class ));
91 | }
92 | });
93 |
94 |
95 | //Activity10 Subscription的unsubscribe方法,取消订阅
96 | findViewById( R.id.bt10 ).setOnClickListener(new View.OnClickListener() {
97 | @Override
98 | public void onClick(View v) {
99 | startActivity( new Intent( MainActivity.this , Activity10.class ));
100 | }
101 | });
102 |
103 | //Merge 操作符的使用
104 | findViewById( R.id.merge ).setOnClickListener(new View.OnClickListener() {
105 | @Override
106 | public void onClick(View v) {
107 | startActivity( new Intent( MainActivity.this , MergeActivity.class ));
108 | }
109 | });
110 |
111 | findViewById( R.id.scan ).setOnClickListener(new View.OnClickListener() {
112 | @Override
113 | public void onClick(View v) {
114 | startActivity( new Intent( MainActivity.this , ScanActivity.class ));
115 | }
116 | });
117 |
118 | findViewById( R.id.filter ).setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | startActivity( new Intent( MainActivity.this , FilterActivity.class ));
122 | }
123 | });
124 |
125 | findViewById( R.id.take ).setOnClickListener(new View.OnClickListener() {
126 | @Override
127 | public void onClick(View v) {
128 | startActivity( new Intent( MainActivity.this , TakeActivity.class ));
129 | }
130 | });
131 |
132 | findViewById( R.id.elementAt ).setOnClickListener(new View.OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | startActivity( new Intent( MainActivity.this , ElementAtActivity.class ));
136 | }
137 | });
138 |
139 | findViewById( R.id.startWith ).setOnClickListener(new View.OnClickListener() {
140 | @Override
141 | public void onClick(View v) {
142 | startActivity( new Intent( MainActivity.this , StartWithActivity.class ));
143 | }
144 | });
145 |
146 | findViewById( R.id.delay ).setOnClickListener(new View.OnClickListener() {
147 | @Override
148 | public void onClick(View v) {
149 | startActivity( new Intent( MainActivity.this , DelayActivity.class ));
150 | }
151 | });
152 |
153 | findViewById( R.id.interval ).setOnClickListener(new View.OnClickListener() {
154 | @Override
155 | public void onClick(View v) {
156 | startActivity( new Intent( MainActivity.this , IntervalActivity.class ));
157 | }
158 | });
159 |
160 | findViewById( R.id.timer ).setOnClickListener(new View.OnClickListener() {
161 | @Override
162 | public void onClick(View v) {
163 | startActivity( new Intent( MainActivity.this , TimerActivity.class ));
164 | }
165 | });
166 |
167 | findViewById( R.id.doOnNext ).setOnClickListener(new View.OnClickListener() {
168 | @Override
169 | public void onClick(View v) {
170 | startActivity( new Intent( MainActivity.this , DoOnNextActivity.class ));
171 | }
172 | });
173 |
174 | findViewById( R.id.buffer ).setOnClickListener(new View.OnClickListener() {
175 | @Override
176 | public void onClick(View v) {
177 | startActivity( new Intent( MainActivity.this , BufferActivity.class ));
178 | }
179 | });
180 |
181 | findViewById( R.id.combineLatestActivity ).setOnClickListener(new View.OnClickListener() {
182 | @Override
183 | public void onClick(View v) {
184 | startActivity( new Intent( MainActivity.this , CombineLatestActivity.class ));
185 | }
186 | });
187 |
188 | findViewById( R.id.rangeActivity ).setOnClickListener(new View.OnClickListener() {
189 | @Override
190 | public void onClick(View v) {
191 | startActivity( new Intent( MainActivity.this , RangeActivity.class ));
192 | }
193 | });
194 |
195 | findViewById( R.id.deferActivity ).setOnClickListener(new View.OnClickListener() {
196 | @Override
197 | public void onClick(View v) {
198 | startActivity( new Intent( MainActivity.this , DeferActivity.class ));
199 | }
200 | });
201 |
202 | BackgroundThread backgroundThread = new BackgroundThread();
203 | backgroundThread.start();
204 | backgroundHandler = new Handler(backgroundThread.getLooper());
205 |
206 | findViewById(R.id.button_run_scheduler).setOnClickListener(new View.OnClickListener() {
207 | @Override public void onClick(View v) {
208 | onRunSchedulerExampleButtonClicked();
209 | }
210 | });
211 | }
212 |
213 | void onRunSchedulerExampleButtonClicked() {
214 | sampleObservable()
215 | // Run on a background thread
216 | .subscribeOn(HandlerScheduler.from(backgroundHandler))
217 | // Be notified on the main thread
218 | .observeOn(AndroidSchedulers.mainThread())
219 | .subscribe(new Subscriber() {
220 | @Override public void onCompleted() {
221 | Log.d(TAG, "onCompleted()");
222 | }
223 |
224 | @Override public void onError(Throwable e) {
225 | Log.e(TAG, "onError()", e);
226 | }
227 |
228 | @Override public void onNext(String string) {
229 | Log.d(TAG, "onNext(" + string + ")");
230 | }
231 | });
232 | }
233 |
234 | static Observable sampleObservable() {
235 | return Observable.defer(new Func0>() {
236 | @Override public Observable call() {
237 | try {
238 | // Do some long running operation
239 | Thread.sleep(TimeUnit.SECONDS.toMillis(5));
240 | } catch (InterruptedException e) {
241 | throw OnErrorThrowable.from(e);
242 | }
243 | return Observable.just("one", "two", "three", "four", "five");
244 | }
245 | });
246 | }
247 |
248 | static class BackgroundThread extends HandlerThread {
249 | BackgroundThread() {
250 | super("SchedulerSample-BackgroundThread", THREAD_PRIORITY_BACKGROUND);
251 | }
252 | }
253 |
254 | }
255 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/MergeActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.functions.Action1;
11 | import rx.functions.Func2;
12 |
13 | public class MergeActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_merge);
19 |
20 | List list1 = new ArrayList<>() ;
21 | List list2 = new ArrayList<>() ;
22 |
23 | list1.add( "1" ) ;
24 | list1.add( "2" ) ;
25 | list1.add( "3" ) ;
26 |
27 | list2.add( "a" ) ;
28 | list2.add( "b" ) ;
29 | list2.add( "c" ) ;
30 | list2.add( "d" ) ;
31 |
32 | Observable observable1 = Observable.from( list1 ) ;
33 | Observable observable2 = Observable.from( list2 ) ;
34 |
35 | //合并数据 先发送observable2的全部数据,然后发送 observable1的全部数据
36 | Observable observable = Observable.merge( observable2 , observable1 ) ;
37 |
38 | observable.subscribe(new Action1() {
39 | @Override
40 | public void call(Object o) {
41 | System.out.println( "rx-- " + o );
42 | }
43 | }) ;
44 |
45 |
46 | /////////////////////////////////////////////////////////////////////////////////
47 | //zip操作符的使用
48 |
49 | Observable observable3 = Observable.zip(observable1, observable2, new Func2() {
50 | @Override
51 | public String call(String s1 , String s2 ) {
52 | return s1 + s2 ;
53 | }
54 | }) ;
55 |
56 | observable3.subscribe(new Action1() {
57 | @Override
58 | public void call(Object o) {
59 | System.out.println( "zip-- " + o );
60 | }
61 | }) ;
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/RangeActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 |
7 | import rx.Observable;
8 | import rx.functions.Action1;
9 |
10 | public class RangeActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_range);
16 |
17 | Observable.range( 10 , 3 )
18 | .subscribe(new Action1() {
19 | @Override
20 | public void call(Integer integer) {
21 | Log.v( "rx_range " , "" + integer ) ;
22 | }
23 | }) ;
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/ScanActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 | import rx.functions.Func2;
9 |
10 | public class ScanActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_scan);
16 |
17 | Observable observable = Observable.just( 1 , 2 , 3 , 4 , 5 ) ;
18 | observable.scan(new Func2() {
19 | @Override
20 | public Integer call(Integer o, Integer o2) {
21 | return o + o2 ;
22 | }
23 | })
24 | .subscribe(new Action1() {
25 | @Override
26 | public void call(Object o) {
27 | System.out.println( "scan-- " + o );
28 | }
29 | }) ;
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/StartWithActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import rx.Observable;
10 | import rx.functions.Action1;
11 |
12 | public class StartWithActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_start_with);
18 |
19 | //插入普通数据
20 | //startWith 数据序列的开头插入一条指定的项 , 最多插入9条数据
21 | Observable observable = Observable.just( "aa" , "bb" , "cc" ) ;
22 | observable
23 | .startWith( "11" , "22" )
24 | .subscribe(new Action1() {
25 | @Override
26 | public void call(Object o) {
27 | System.out.println( "startWith-- " + o );
28 | }
29 | }) ;
30 |
31 | //插入Observable对象
32 | List list = new ArrayList<>() ;
33 | list.add( "ww" ) ;
34 | list.add( "tt" ) ;
35 | observable.startWith( Observable.from( list ))
36 | .subscribe(new Action1() {
37 | @Override
38 | public void call(Object o) {
39 | System.out.println( "startWith2 -- " + o );
40 | }
41 | }) ;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/TakeActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import rx.Observable;
7 | import rx.functions.Action1;
8 |
9 | public class TakeActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_take);
15 |
16 | //take 发送前3个数据
17 | Observable observable = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
18 | observable.take( 3 )
19 | .subscribe(new Action1() {
20 | @Override
21 | public void call(Object o) {
22 | System.out.println( "take-- " + o );
23 | }
24 | }) ;
25 |
26 | //takeLast 发送最后三个数据
27 | Observable observable2 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
28 | observable2.takeLast( 3 )
29 | .subscribe(new Action1() {
30 | @Override
31 | public void call(Object o) {
32 | System.out.println( "takeLast-- " + o );
33 | }
34 | }) ;
35 |
36 | //first 只发送第一个数据
37 | Observable observable3 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
38 | observable3.first()
39 | .subscribe(new Action1() {
40 | @Override
41 | public void call(Object o) {
42 | System.out.println( "first-- " + o );
43 | }
44 | }) ;
45 |
46 | //last 只发送最后一个数据
47 | Observable observable4 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
48 | observable4.last()
49 | .subscribe(new Action1() {
50 | @Override
51 | public void call(Object o) {
52 | System.out.println( "last-- " + o );
53 | }
54 | }) ;
55 |
56 | //skip() 跳过前2个数据发送后面的数据
57 | Observable observable5 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
58 | observable5.skip( 2 )
59 | .subscribe(new Action1() {
60 | @Override
61 | public void call(Object o) {
62 | System.out.println( "skip-- " + o );
63 | }
64 | }) ;
65 |
66 | //skipLast() 跳过最后两个数据,发送前面的数据
67 | Observable observable6 = Observable.just( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) ;
68 | observable6.skipLast( 2 )
69 | .subscribe(new Action1() {
70 | @Override
71 | public void call(Object o) {
72 | System.out.println( "skipLast-- " + o );
73 | }
74 | }) ;
75 |
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/app/com/myapplication/TimerActivity.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
2 | import android.os.Bundle;
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.view.View;
5 |
6 | import java.util.concurrent.TimeUnit;
7 | import rx.Observable;
8 | import rx.android.schedulers.AndroidSchedulers;
9 | import rx.functions.Action1;
10 |
11 | public class TimerActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_timer);
17 |
18 | //5秒后输出 hello world , 然后显示一张图片
19 | Observable.timer( 5 , TimeUnit.SECONDS )
20 | .observeOn(AndroidSchedulers.mainThread() )
21 | .subscribe(new Action1() {
22 | @Override
23 | public void call(Long aLong) {
24 | System.out.println( "timer--hello world " + aLong );
25 | findViewById( R.id.image).setVisibility(View.VISIBLE );
26 | }
27 | }) ;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_buffer.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_combine_latest.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
28 |
29 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_defer.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_delay.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_element_at.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_finally_do.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_interval.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
61 |
62 |
67 |
68 |
73 |
74 |
79 |
80 |
86 |
87 |
93 |
94 |
100 |
101 |
107 |
108 |
114 |
115 |
121 |
122 |
128 |
129 |
130 |
136 |
137 |
138 |
144 |
145 |
146 |
152 |
153 |
154 |
159 |
160 |
165 |
166 |
171 |
172 |
177 |
178 |
179 |
180 |
181 |
182 |
187 |
188 |
189 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_merge.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_range.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
15 |
16 |
23 |
24 |
31 |
32 |
39 |
40 |
47 |
48 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scan.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_start_with.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_take.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_timer.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/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 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/app/com/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package app.com.myapplication;
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.2'
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/zyj1609wz/RxJava_RxAndroid/62a2b63ac60813f56e312605a96c46d9992e7ef8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 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-2.10-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', ':RxAndroid', ':RxLifecycle', ':RxBinding', ':Retrofit', ':RxPreferences'
2 |
--------------------------------------------------------------------------------