Skip to content

Commit b04cd30

Browse files
committed
2 parents ee31ae6 + 514e2b8 commit b04cd30

58 files changed

Lines changed: 3103 additions & 0 deletions

Some content is hidden

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

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# built application files
2+
*.apk
3+
*.ap_
4+
5+
# files for the dex VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# generated files
12+
bin/
13+
gen/
14+
build/
15+
16+
# Gradle files
17+
.gradle/
18+
subProjects/facebook/build
19+
20+
# Intellij project files
21+
.idea/libraries
22+
.idea/.name
23+
.idea/compiler.xml
24+
.idea/gradle.xml
25+
.idea/modules.xml
26+
.idea/runConfigurations.xml
27+
.idea/vcs.xml
28+
.idea/workspace.xml
29+
.idea/misc.xml
30+
gen-external-apklibs/
31+
*.iml
32+
*.iws
33+
34+
# Local configuration file (sdk path, etc)
35+
local.properties
36+
37+
# Mac-specific stuff
38+
.DS_Store
39+
40+
#Maven
41+
target
42+
release.properties
43+
pom.xml.*
44+
45+
#Ant
46+
build.xml
47+
ant.properties
48+
profiles_settings.xml

.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.

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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.che58.ljb.rxjava"
9+
minSdkVersion 15
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.jakewharton:butterknife:7.0.1'
26+
compile 'com.android.support:appcompat-v7:23.2.0'
27+
compile 'io.reactivex:rxjava:1.0.14'
28+
compile 'io.reactivex:rxandroid:1.1.0'
29+
compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1'
30+
compile 'com.squareup.okhttp:okhttp:2.7.2'
31+
compile 'com.squareup.okio:okio:1.6.0'
32+
compile 'com.google.code.gson:gson:2.5'
33+
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
34+
compile 'com.trello:rxlifecycle:0.4.0'
35+
compile 'com.trello:rxlifecycle-components:0.4.0'
36+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\Android\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.che58.ljb.rxjava;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.che58.ljb.rxjava">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
7+
<uses-permission android:name="android.permission.READ_CONTACTS"/>
8+
9+
<application
10+
android:name=".DemoApplication"
11+
android:allowBackup="true"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:supportsRtl="true"
15+
android:theme="@style/AppTheme">
16+
<activity
17+
android:name=".act.MainActivity"
18+
android:screenOrientation="portrait">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.che58.ljb.rxjava;
2+
3+
import android.app.Application;
4+
5+
/**
6+
* Demo Application
7+
* Created by ljb on 2016/3/23.
8+
*/
9+
public class DemoApplication extends Application {
10+
11+
private static Application mApp;
12+
13+
@Override
14+
public void onCreate() {
15+
super.onCreate();
16+
mApp = this;
17+
}
18+
19+
public static Application getApplaction(){
20+
return mApp;
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.che58.ljb.rxjava.act;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.FragmentActivity;
5+
6+
import com.che58.ljb.rxjava.R;
7+
import com.che58.ljb.rxjava.fragment.main.MainFragment;
8+
9+
public class MainActivity extends FragmentActivity {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_main);
15+
initFragment();
16+
}
17+
18+
private void initFragment() {
19+
getSupportFragmentManager().beginTransaction()
20+
.replace(R.id.main_content, new MainFragment(), MainFragment.class.getName())
21+
.commit();
22+
}
23+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.che58.ljb.rxjava.fragment;
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+
import android.widget.Button;
9+
import android.widget.EditText;
10+
import android.widget.TextView;
11+
import android.widget.Toast;
12+
13+
import com.che58.ljb.rxjava.R;
14+
import com.jakewharton.rxbinding.view.RxView;
15+
import com.trello.rxlifecycle.components.support.RxFragment;
16+
17+
import java.util.List;
18+
19+
import butterknife.Bind;
20+
import butterknife.ButterKnife;
21+
import butterknife.OnClick;
22+
import rx.Observable;
23+
import rx.android.schedulers.AndroidSchedulers;
24+
import rx.functions.Action1;
25+
26+
/**
27+
* Buffer操作符
28+
* Created by ljb on 2016/3/25.
29+
*/
30+
public class BufferFragment extends RxFragment {
31+
32+
@Bind(R.id.btn_buffer_count)
33+
Button btn_buffer_count;
34+
35+
@Bind(R.id.btn_buffer_count_skip)
36+
Button btn_buffer_count_skip;
37+
38+
@Bind(R.id.et_input)
39+
EditText et_input;
40+
41+
@Bind(R.id.tv_output)
42+
TextView tv_output;
43+
44+
@Nullable
45+
@Override
46+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
47+
View view = inflater.inflate(R.layout.fragment_buffer, null);
48+
ButterKnife.bind(this, view);
49+
return view;
50+
}
51+
52+
53+
@Override
54+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
55+
super.onActivityCreated(savedInstanceState);
56+
demo_buffer_count();
57+
}
58+
59+
private void demo_buffer_count() {
60+
RxView.clicks(btn_buffer_count)
61+
.buffer(3)
62+
.compose(this.<List<Void>>bindToLifecycle())
63+
.observeOn(AndroidSchedulers.mainThread())
64+
.subscribe(new Action1<List<Void>>() {
65+
@Override
66+
public void call(List<Void> voids) {
67+
Toast.makeText(BufferFragment.this.getActivity(), R.string.des_demo_buffer_count, Toast.LENGTH_SHORT).show();
68+
}
69+
});
70+
}
71+
72+
@OnClick(R.id.btn_buffer_count_skip)
73+
void demo_buffer_count_skip() {
74+
tv_output.setText("");
75+
char[] cs = et_input.getText().toString().trim().toCharArray();
76+
Character[] chs = new Character[cs.length];
77+
for (int i = 0; i < chs.length; i++) {
78+
chs[i] = cs[i];
79+
}
80+
81+
Observable.from(chs)
82+
.buffer(2, 3)
83+
.compose(this.<List<Character>>bindToLifecycle())
84+
.observeOn(AndroidSchedulers.mainThread())
85+
.subscribe(new Action1<List<Character>>() {
86+
87+
@Override
88+
public void call(List<Character> characters) {
89+
tv_output.setText(tv_output.getText() + characters.toString());
90+
}
91+
});
92+
93+
}
94+
95+
}

0 commit comments

Comments
 (0)