1
0
mirror of https://github.com/yexuejc/rrxjava.git synced 2025-10-04 02:43:31 +08:00
This commit is contained in:
2017-07-07 15:50:45 +08:00
commit c595467e6f
105 changed files with 3161 additions and 0 deletions

1
app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

40
app/build.gradle Normal file
View File

@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.yexue.android.rrxjava"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//下面两个即为引入的依赖
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'io.reactivex:rxjava:1.0.9'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
//Butter Knife注解
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'
}

25
app/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,26 @@
package com.yexue.android.rrxjava;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.yexue.android.rrxjava", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yexue.android.rrxjava">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapActivity"
android:label="@string/title_activity_map"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".HttpActivity" />
<activity android:name=".ActionActivity" />
<activity android:name=".TestActivity"></activity>
</application>
</manifest>

View File

@@ -0,0 +1,93 @@
package com.yexue.android.rrxjava;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Action1;
public class ActionActivity extends AppCompatActivity {
private static String log = "ActionActivityLOG";
Button action_btn1, action_btn2, action_btn3;
Observable<String> observable;
Action0 onCompletedAction;
Action1<Throwable> onErrorAction;
Action1<String> onNextAction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action);
action_btn1 = (Button) findViewById(R.id.action_btn1);
action_btn2 = (Button) findViewById(R.id.action_btn2);
action_btn3 = (Button) findViewById(R.id.action_btn3);
method1();
action_btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 自动创建 Subscriber ,并使用 onNextAction 来定义 onNext()
observable.subscribe(onNextAction);
}
});
action_btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 自动创建 Subscriber ,并使用 onNextAction 和 onErrorAction 来定义 onNext() 和 onError()
observable.subscribe(onNextAction, onErrorAction);
}
});
action_btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 自动创建 Subscriber ,并使用 onNextAction、 onErrorAction 和 onCompletedAction 来定义 onNext()、 onError() 和 onCompleted()
observable.subscribe(onNextAction, onErrorAction, onCompletedAction);
}
});
}
/**
* 除了 subscribe(Observer) 和 subscribe(Subscriber)
* subscribe() 还支持不完整定义的回调RxJava 会自动根据定义创建出 Subscriber 。形式如下:
*/
private void method1() {
//onNext
onNextAction = new Action1<String>() {
@Override
public void call(String s) {
Log.d(log, s);
}
};
//onError
onErrorAction = new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.d(log, throwable.getMessage());
}
};
//onCompleted
onCompletedAction = new Action0() {
@Override
public void call() {
Log.d(log, "onCompletedAction");
}
};
observable = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("he");
subscriber.onCompleted();
//TODO 未执行onErrorAction原因未知
int a[] = {1, 3, 5, 6, 5, 4, 54, 8, 4};
Log.d(log, a[100] + "");
}
});
}
}

View File

@@ -0,0 +1,46 @@
package com.yexue.android.rrxjava;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.yexue.android.rrxjava.utils.HttpConn;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class HttpActivity extends AppCompatActivity {
ImageView img;
Button img_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_http);
img = (ImageView) findViewById(R.id.img);
img_btn = (Button) findViewById(R.id.img_btn);
final String picStr = "http://www.shixiu.net/d/file/p/2bc22002a6a61a7c5694e7e641bf1e6e.jpg";
final Handler handler = new Handler();
img_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new HttpConn(picStr, handler, new HttpConn.CallBack() {
@Override
public void onCompleted(Bitmap bitmap) {
img.setImageBitmap(bitmap);
}
}).start();
}
});
}
}

View File

@@ -0,0 +1,180 @@
package com.yexue.android.rrxjava;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;
public class MainActivity extends AppCompatActivity {
private static String tag = "MainActivityLOG";
TextView te;
Button toMap, toHttp, btn3, btn4, btn5, btn6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
te = (TextView) findViewById(R.id.te);
toMap = (Button) findViewById(R.id.toMap);
toHttp = (Button) findViewById(R.id.toHttp);
btn3 = (Button) findViewById(R.id.btn3);
btn4 = (Button) findViewById(R.id.btn4);
btn5 = (Button) findViewById(R.id.btn5);
btn6 = (Button) findViewById(R.id.btn6);
method0();
toMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, MapActivity.class));
}
});
toHttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, HttpActivity.class));
}
});
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, ActionActivity.class));
}
});
btn4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, TestActivity.class));
}
});
}
public void method0() {
/**
* 观察者
*/
Observer<String> observer = new Observer<String>() {
@Override
public void onCompleted() {
Log.d(tag, "Completed!");
}
@Override
public void onError(Throwable e) {
Log.d(tag, "Error!");
}
@Override
public void onNext(String s) {
Log.d(tag, "Item: " + s);
}
};
/**
* 订阅内容
*/
Subscriber<String> subscriber = new Subscriber<String>() {
@Override
public void onCompleted() {
Log.d(tag, ">>>Completed!");
}
@Override
public void onError(Throwable e) {
Log.d(tag, ">>>Error!");
}
@Override
public void onNext(String s) {
Log.d(tag, ">>>Item: " + s);
}
};
/**
* 被观察者
*/
Observable observable = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("Hello");
subscriber.onNext("Hi");
subscriber.onNext("Aloha");
subscriber.onCompleted();
}
});
//关联订阅
//订阅观察者的事件
observable.subscribe(observer);
//直接订阅事件
observable.subscribe(subscriber);
}
/**
* 原理
*/
public void method1() {
//创建 Observable--被观察者 对象
Observable<String> observable = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("Hello world RxJava");
subscriber.onCompleted();
}
});
//订阅内容
Subscriber subscriber = new Subscriber() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Object o) {
te.setText(o.toString());
}
};
//将Observable和Subscriber相关联即完成subscriber和observable的订阅
observable.subscribe(subscriber);
}
/**
* 原理
*/
public void method2() {
//被观察者
Observable<String> observable = Observable.just("简化 RXJAVA");
//订阅
Action1<String> onNextAction = new Action1<String>() {
@Override
public void call(String s) {
te.setText(s);
}
};
//关联
observable.subscribe(onNextAction);
}
/**
* 正常写法
*/
public void method3() {
Observable.just("更简化 De RxJava").subscribe(new Action1<String>() {
@Override
public void call(String s) {
te.setText(s);
}
});
}
}

View File

@@ -0,0 +1,68 @@
package com.yexue.android.rrxjava;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;
public class MapActivity extends AppCompatActivity {
TextView rxmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
rxmap = (TextView) findViewById(R.id.rxmap);
method2();
}
/**
* Observable可以进行数据查询Subscriber用来显示结果
*
* Observable是屏幕上的点击事件Subscriber用来响应事件
*
* Observable可以是网络请求Subscriber用来显示请求结果。
*
*/
public void method1(){
Observable.just("RxJava Map").map(new Func1<String, String>() {
@Override
public String call(String str) {
return str + "map后缀";
}
}).subscribe(new Action1<String>() {
@Override
public void call(String s) {
rxmap.setText(s);
}
});
}
public void method2(){
Observable.just("map").map(new Func1<String, Integer>() {
@Override
public Integer call(String s) {
return s.hashCode();
}
}).map(new Func1<Integer, String>() {
@Override
public String call(Integer integer) {
return integer.toString()+"->2th";
}
}).subscribe(new Action1<String>() {
@Override
public void call(String s) {
rxmap.setText(s);
}
});
}
}

View File

@@ -0,0 +1,114 @@
package com.yexue.android.rrxjava;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;
public class TestActivity extends AppCompatActivity {
private static String log = "TestActivity";
@BindView(R.id.p1_btn)
Button p1Btn;
@BindView(R.id.p1_tv)
TextView p1Tv;
@BindView(R.id.p1_btn_c)
Button p1BtnC;
@BindView(R.id.p2_btn)
Button p2Btn;
@BindView(R.id.p2_btn_c)
Button p2BtnC;
@BindView(R.id.p2_img)
ImageView p2Img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
ButterKnife.bind(this);
p1Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
method1();
}
});
p1BtnC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
p1Tv.setText("");
}
});
}
/**
* 将字符串数组 names 中的所有字符串依次打印出来:
*/
private void method1() {
String[] names = {"张三", "lisi", "王麻子"};
Observable.from(names).subscribe(new Action1<String>() {
@Override
public void call(String s) {
String oldStr = p1Tv.getText().toString();
p1Tv.setText(oldStr + "\n" + s);
}
});
}
@OnClick({R.id.p2_btn, R.id.p2_btn_c})
public void onClick(View view) {
switch (view.getId()) {
case R.id.p2_btn:
method2(R.mipmap.a);
break;
case R.id.p2_btn_c:
method2(0);
break;
}
}
private void method2(int a) {
final int drawableRes = a;//-->改个没有的就会激发onError();
Observable.create(new Observable.OnSubscribe<Drawable>() {
@Override
public void call(Subscriber<? super Drawable> subscriber) {
Drawable drawable = null;
drawable = ContextCompat.getDrawable(TestActivity.this, drawableRes);
subscriber.onNext(drawable);
subscriber.onCompleted();
}
}).subscribe(new Observer<Drawable>() {
@Override
public void onCompleted() {
Log.d(log, "onCompleted");
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
Log.d(log, e.getStackTrace().toString());
Toast.makeText(TestActivity.this, "Error!", Toast.LENGTH_SHORT).show();
}
@Override
public void onNext(Drawable drawable) {
p2Img.setImageDrawable(drawable);
}
});
}
}

View File

@@ -0,0 +1,61 @@
package com.yexue.android.rrxjava.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Created by admin on 2017/7/6.
*/
public class HttpConn extends Thread {
String picStr;
CallBack callBack;
private Handler handler;
public HttpConn(String picStr, Handler handler, CallBack callBack) {
this.picStr = picStr;
this.callBack = callBack;
this.handler = handler;
}
@Override
public void run() {
URL imgUrl = null;
try {
imgUrl = new URL(picStr);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
/*取得联机*/
HttpURLConnection conn = (HttpURLConnection) imgUrl.openConnection();
conn.connect();
/*取得回传的InputStream*/
InputStream is = conn.getInputStream();
/*将InputStream转化为Bitmap*/
final Bitmap bitmap = BitmapFactory.decodeStream(is);
//用Handler post()方法通知主线程
handler.post(new Runnable() {
@Override
public void run() {
callBack.onCompleted(bitmap);
}
});
/*关闭InputStream*/
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public interface CallBack {
public void onCompleted(Bitmap bitmap);
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.yexue.android.rrxjava.ActionActivity">
<Button
android:id="@+id/action_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动创建 Subscriber ,并使用 onNextAction 来定义 onNext()" />
<Button
android:id="@+id/action_btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动创建 Subscriber ,并使用 onNextAction 和 onErrorAction 来定义 onNext() 和 onError()" />
<Button
android:id="@+id/action_btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动创建 Subscriber ,并使用 onNextAction、 onErrorAction 和 onCompletedAction 来定义 onNext()、 onError() 和 onCompleted()" />
</LinearLayout>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.yexue.android.rrxjava.HttpActivity">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop" />
<Button
android:id="@+id/img_btn"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="获取图片" />
</android.support.constraint.ConstraintLayout>

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.yexue.android.rrxjava.MainActivity">
<TextView
android:id="@+id/te"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/toMap"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="RxJava map" />
<Button
android:id="@+id/toHttp"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="访问网络" />
<Button
android:id="@+id/btn3"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="btn3" />
<Button
android:id="@+id/btn4"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="btn4" />
<Button
android:id="@+id/btn5"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="btn5" />
<Button
android:id="@+id/btn6"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="btn6" />
</LinearLayout>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.yexue.android.rrxjava.MapActivity">
<TextView
android:id="@+id/rxmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="map" />
</android.support.design.widget.CoordinatorLayout>

View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.yexue.android.rrxjava.TestActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/p1_btn_c"
android:layout_toStartOf="@+id/p1_btn_c"
android:text="将字符串数组 names 中的所有字符串依次打印出来:" />
<Button
android:id="@+id/p1_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="go" />
<Button
android:id="@+id/p1_btn_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/p1_btn"
android:layout_toStartOf="@+id/p1_btn"
android:text="clean" />
</RelativeLayout>
<TextView
android:id="@+id/p1_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/p2_btn_c"
android:layout_toStartOf="@+id/p2_btn_c"
android:text="由指定的一个 drawable 文件 id drawableRes 取得图片,并显示在 ImageView 中,并在出现异常的时候打印 Toast 报错:" />
<Button
android:id="@+id/p2_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="onCompleted" />
<Button
android:id="@+id/p2_btn_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/p2_btn"
android:layout_toStartOf="@+id/p2_btn"
android:text="onError" />
</RelativeLayout>
<ImageView
android:id="@+id/p2_img"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.yexue.android.rrxjava.MapActivity"
tools:showIn="@layout/activity_map">
</android.support.constraint.ConstraintLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@@ -0,0 +1,4 @@
<resources>
<string name="app_name">rrxjava</string>
<string name="title_activity_map">MapActivity</string>
</resources>

View File

@@ -0,0 +1,20 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

View File

@@ -0,0 +1,17 @@
package com.yexue.android.rrxjava;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}