first
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/libraries
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
||||||
|
.externalNativeBuild
|
22
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<resourceExtensions />
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.java" />
|
||||||
|
<entry name="!?*.form" />
|
||||||
|
<entry name="!?*.class" />
|
||||||
|
<entry name="!?*.groovy" />
|
||||||
|
<entry name="!?*.scala" />
|
||||||
|
<entry name="!?*.flex" />
|
||||||
|
<entry name="!?*.kt" />
|
||||||
|
<entry name="!?*.clj" />
|
||||||
|
<entry name="!?*.aj" />
|
||||||
|
</wildcardResourcePatterns>
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
3
.idea/copyright/profiles_settings.xml
generated
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<component name="CopyrightManager">
|
||||||
|
<settings default="" />
|
||||||
|
</component>
|
18
.idea/gradle.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
10
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AndroidLintMissingConstraints" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
|
||||||
|
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
|
||||||
|
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
7
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
49
.idea/misc.xml
generated
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0" />
|
||||||
|
</component>
|
||||||
|
<component name="NullableNotNullManager">
|
||||||
|
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||||
|
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||||
|
<option name="myNullables">
|
||||||
|
<value>
|
||||||
|
<list size="4">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="myNotNulls">
|
||||||
|
<value>
|
||||||
|
<list size="4">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||||
|
<OptionsSetting value="true" id="Add" />
|
||||||
|
<OptionsSetting value="true" id="Remove" />
|
||||||
|
<OptionsSetting value="true" id="Checkout" />
|
||||||
|
<OptionsSetting value="true" id="Update" />
|
||||||
|
<OptionsSetting value="true" id="Status" />
|
||||||
|
<OptionsSetting value="true" id="Edit" />
|
||||||
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="Android" />
|
||||||
|
</component>
|
||||||
|
<component name="SvnBranchConfigurationManager">
|
||||||
|
<option name="mySupportsUserInfoFilter" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/modules.xml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/rrxjava.iml" filepath="$PROJECT_DIR$/rrxjava.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
12
.idea/runConfigurations.xml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RunConfigurationProducerService">
|
||||||
|
<option name="ignoredProducers">
|
||||||
|
<set>
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="svn" />
|
||||||
|
</component>
|
||||||
|
</project>
|
1
.svn/entries
Normal file
@ -0,0 +1 @@
|
|||||||
|
12
|
1
.svn/format
Normal file
@ -0,0 +1 @@
|
|||||||
|
12
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?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="访问网络" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,131 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="android-gradle" name="Android-Gradle">
|
||||||
|
<configuration>
|
||||||
|
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
<facet type="android" name="Android">
|
||||||
|
<configuration>
|
||||||
|
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||||
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||||
|
<afterSyncTasks>
|
||||||
|
<task>generateDebugSources</task>
|
||||||
|
</afterSyncTasks>
|
||||||
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
|
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||||
|
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" exported="" name="support-core-ui-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="runner-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="espresso-idling-resource-2.2.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-fragment-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="constraint-layout-1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-v4-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-media-compat-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="design-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="butterknife-annotations-8.5.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-core-utils-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="constraint-layout-solver-1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="rxjava-1.0.9" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="rxandroid-0.24.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="transition-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-vector-drawable-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="appcompat-v7-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="recyclerview-v7-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="butterknife-8.5.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-compat-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-annotations-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="animated-vector-drawable-26.0.0-alpha1" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -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>
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,4 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">rrxjava</string>
|
||||||
|
<string name="title_activity_map">MapActivity</string>
|
||||||
|
</resources>
|
@ -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>
|
After Width: | Height: | Size: 6.0 KiB |
@ -0,0 +1,17 @@
|
|||||||
|
# Project-wide Gradle settings.
|
||||||
|
|
||||||
|
# IDE (e.g. Android Studio) users:
|
||||||
|
# Gradle settings configured through the IDE *will override*
|
||||||
|
# any settings specified in this file.
|
||||||
|
|
||||||
|
# For more details on how to configure your build environment visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
|
||||||
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
|
org.gradle.jvmargs=-Xmx1536m
|
||||||
|
|
||||||
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
|
# org.gradle.parallel=true
|
After Width: | Height: | Size: 9.8 KiB |
@ -0,0 +1 @@
|
|||||||
|
/build
|
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id="rrxjava" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="java-gradle" name="Java-Gradle">
|
||||||
|
<configuration>
|
||||||
|
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||||
|
<option name="BUILDABLE" value="false" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -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>
|
@ -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] + "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,160 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn ( ) {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die ( ) {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
(0) set -- ;;
|
||||||
|
(1) set -- "$args0" ;;
|
||||||
|
(2) set -- "$args0" "$args1" ;;
|
||||||
|
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||||
|
function splitJvmOpts() {
|
||||||
|
JVM_OPTS=("$@")
|
||||||
|
}
|
||||||
|
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||||
|
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||||
|
|
||||||
|
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
@ -0,0 +1 @@
|
|||||||
|
include ':app'
|
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,6 @@
|
|||||||
|
#Thu Jul 06 13:57:00 CST 2017
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
@ -0,0 +1,24 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
|
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
|
||||||
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
// in the individual module build.gradle files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
After Width: | Height: | Size: 9.5 KiB |
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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'
|
||||||
|
}
|
@ -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>
|
@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
</resources>
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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>
|
@ -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>
|
@ -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>
|
After Width: | Height: | Size: 3.3 KiB |
@ -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());
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 2.2 KiB |
@ -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>
|
@ -0,0 +1,10 @@
|
|||||||
|
## This file is automatically generated by Android Studio.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file should *NOT* be checked into Version Control Systems,
|
||||||
|
# as it contains information specific to your local configuration.
|
||||||
|
#
|
||||||
|
# Location of the SDK. This is only used by Gradle.
|
||||||
|
# For customization when using a Version Control System, please read the
|
||||||
|
# header note.
|
||||||
|
sdk.dir=C\:\\Users\\admin\\AppData\\Local\\Android\\Sdk
|
@ -0,0 +1,103 @@
|
|||||||
|
package com.yexue.android.rrxjava;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
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 {
|
||||||
|
TextView te;
|
||||||
|
Button toMap,toHttp;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
method3();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原理
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -0,0 +1,128 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="android-gradle" name="Android-Gradle">
|
||||||
|
<configuration>
|
||||||
|
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
<facet type="android" name="Android">
|
||||||
|
<configuration>
|
||||||
|
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||||
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||||
|
<afterSyncTasks>
|
||||||
|
<task>generateDebugSources</task>
|
||||||
|
</afterSyncTasks>
|
||||||
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
|
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||||
|
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" exported="" name="support-core-ui-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="runner-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="espresso-idling-resource-2.2.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-fragment-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="constraint-layout-1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-v4-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-media-compat-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="design-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-core-utils-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="constraint-layout-solver-1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="rxjava-1.0.9" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="rxandroid-0.24.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="transition-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-vector-drawable-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="appcompat-v7-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="recyclerview-v7-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-compat-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-annotations-26.0.0-alpha1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="animated-vector-drawable-26.0.0-alpha1" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
After Width: | Height: | Size: 4.7 KiB |
@ -0,0 +1,90 @@
|
|||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windowz variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
goto execute
|
||||||
|
|
||||||
|
:4NT_args
|
||||||
|
@rem Get arguments from the 4NT Shell from JP Software
|
||||||
|
set CMD_LINE_ARGS=%$
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
@ -0,0 +1,28 @@
|
|||||||
|
<?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"></uses-permission>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
|
|
||||||
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
// in the individual module build.gradle files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
学习RxJAava所写demo
|
@ -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>
|
@ -0,0 +1,34 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
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(dir: 'libs', include: ['*.jar'])
|
||||||
|
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'
|
||||||
|
}
|
After Width: | Height: | Size: 4.1 KiB |
BIN
.svn/wc.db
Normal file
0
.svn/wc.db-journal
Normal file
1
README.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
学习RxJAava所写demo
|
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/build
|
40
app/build.gradle
Normal 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
@ -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
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/AndroidManifest.xml
Normal 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>
|
@ -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] + "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
180
app/src/main/java/com/yexue/android/rrxjava/MainActivity.java
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
68
app/src/main/java/com/yexue/android/rrxjava/MapActivity.java
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
114
app/src/main/java/com/yexue/android/rrxjava/TestActivity.java
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
27
app/src/main/res/layout/activity_action.xml
Normal 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>
|
20
app/src/main/res/layout/activity_http.xml
Normal 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>
|
52
app/src/main/res/layout/activity_main.xml
Normal 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>
|
15
app/src/main/res/layout/activity_map.xml
Normal 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>
|
93
app/src/main/res/layout/activity_test.xml
Normal 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>
|
13
app/src/main/res/layout/content_map.xml
Normal 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>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/a.jpg
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 14 KiB |
6
app/src/main/res/values/colors.xml
Normal 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>
|
3
app/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
</resources>
|
4
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">rrxjava</string>
|
||||||
|
<string name="title_activity_map">MapActivity</string>
|
||||||
|
</resources>
|
20
app/src/main/res/values/styles.xml
Normal 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>
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
24
build.gradle
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
|
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
|
||||||
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
// in the individual module build.gradle files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
17
gradle.properties
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Project-wide Gradle settings.
|
||||||
|
|
||||||
|
# IDE (e.g. Android Studio) users:
|
||||||
|
# Gradle settings configured through the IDE *will override*
|
||||||
|
# any settings specified in this file.
|
||||||
|
|
||||||
|
# For more details on how to configure your build environment visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
|
||||||
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
|
org.gradle.jvmargs=-Xmx1536m
|
||||||
|
|
||||||
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
|
# org.gradle.parallel=true
|