Skip to content

Commit fb75290

Browse files
committed
first commit
0 parents  commit fb75290

File tree

155 files changed

+5979
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+5979
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/caches/build_file_checksums.ser

540 Bytes
Binary file not shown.

.idea/checkstyle-idea.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

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

app/build.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
defaultConfig {
6+
applicationId "com.hensen.rxjavalearning"
7+
minSdkVersion 14
8+
targetSdkVersion 26
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation 'com.android.support:appcompat-v7:26.1.0'
24+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25+
testImplementation 'junit:junit:4.12'
26+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
27+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28+
29+
implementation "io.reactivex.rxjava2:rxjava:2.1.12"
30+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
31+
implementation 'io.reactivex:rxjava-math:1.0.0'
32+
33+
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
34+
//retrofit
35+
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
36+
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
37+
//rx+retrofit
38+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
39+
//rxlifecycle
40+
implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
41+
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
42+
implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.1'
43+
implementation 'com.trello.rxlifecycle2:rxlifecycle-android-lifecycle:2.2.1'
44+
45+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.hensen.rxjavalearning;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.hensen.rxjavalearning", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hensen.rxjavalearning">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".MainActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
<activity android:name=".Chapter9.Chapter9o1o2o3.Main2Activity" />
22+
<activity android:name=".Chapter9.Chapter9o1o2o3.Main3Activity" />
23+
<activity android:name=".Chapter9.Chapter9o4.RealView" />
24+
</application>
25+
26+
</manifest>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.hensen.rxjavalearning.Chapter1.Chapter1o3;
2+
3+
/**
4+
* Created by handsomexu on 2018/4/7.
5+
*/
6+
7+
public class Main {
8+
9+
public static void main(String[] args) {
10+
Observable milkFactory = new MilkFactory();
11+
12+
Observer milkConsumer1 = new MilkConsumer("顾客1");
13+
Observer milkConsumer2 = new MilkConsumer("顾客2");
14+
//订阅过程
15+
milkFactory.subscribe(milkConsumer1);
16+
milkFactory.subscribe(milkConsumer2);
17+
//发布过程
18+
System.out.println("此时,牛奶店已经产出早餐奶,通知并发送给各位顾客");
19+
milkFactory.onNext();
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.hensen.rxjavalearning.Chapter1.Chapter1o3;
2+
3+
/**
4+
* Created by handsomexu on 2018/4/7.
5+
*/
6+
7+
//顾客
8+
public class MilkConsumer implements Observer {
9+
10+
private String name;
11+
12+
public MilkConsumer(String name) {
13+
this.name = name;
14+
}
15+
16+
@Override
17+
public void onNotify() {
18+
System.out.println(this.name + " 收到牛奶");
19+
}
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.hensen.rxjavalearning.Chapter1.Chapter1o3;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Created by handsomexu on 2018/4/7.
8+
*/
9+
10+
//牛奶店
11+
public class MilkFactory implements Observable{
12+
13+
private List<Observer> observers;
14+
15+
public MilkFactory() {
16+
this.observers = new ArrayList<>();
17+
}
18+
19+
@Override
20+
public void subscribe(Observer observer) {
21+
observers.add(observer);
22+
}
23+
24+
@Override
25+
public void cancel(Observer observer) {
26+
observers.remove(observer);
27+
}
28+
29+
@Override
30+
public void onNext() {
31+
for (Observer observer : observers) {
32+
observer.onNotify();
33+
}
34+
}
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.hensen.rxjavalearning.Chapter1.Chapter1o3;
2+
3+
/**
4+
* Created by handsomexu on 2018/4/7.
5+
*/
6+
7+
//被观察者
8+
public interface Observable {
9+
//订阅
10+
void subscribe(Observer observer);
11+
//取消订阅
12+
void cancel(Observer observer);
13+
//发布
14+
void onNext();
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.hensen.rxjavalearning.Chapter1.Chapter1o3;
2+
3+
/**
4+
* Created by handsomexu on 2018/4/7.
5+
*/
6+
7+
//观察者
8+
public interface Observer {
9+
//接收通知
10+
void onNotify();
11+
}

0 commit comments

Comments
 (0)