Commit 7aa28c8d04a54e7c79a70c361b634173fabf91e2
1 parent
39a90229
add test java8 code
Showing
6 changed files
with
71 additions
and
5 deletions
.idea/misc.xml
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 | <ConfirmationsSetting value="0" id="Add" /> |
| 45 | 45 | <ConfirmationsSetting value="0" id="Remove" /> |
| 46 | 46 | </component> |
| 47 | - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
| 47 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
| 48 | 48 | <output url="file://$PROJECT_DIR$/build/classes" /> |
| 49 | 49 | </component> |
| 50 | 50 | <component name="ProjectType"> | ... | ... |
app/build.gradle
| ... | ... | @@ -3,6 +3,12 @@ apply plugin: 'com.android.application' |
| 3 | 3 | android { |
| 4 | 4 | compileSdkVersion 26 |
| 5 | 5 | buildToolsVersion "26.0.0" |
| 6 | + | |
| 7 | + compileOptions { | |
| 8 | + sourceCompatibility JavaVersion.VERSION_1_8 | |
| 9 | + targetCompatibility JavaVersion.VERSION_1_8 | |
| 10 | + } | |
| 11 | + | |
| 6 | 12 | defaultConfig { |
| 7 | 13 | applicationId "com.cnlive.libs.demo" |
| 8 | 14 | minSdkVersion 16 |
| ... | ... | @@ -10,6 +16,9 @@ android { |
| 10 | 16 | versionCode 1 |
| 11 | 17 | versionName "1.0" |
| 12 | 18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| 19 | + jackOptions { | |
| 20 | + enabled true | |
| 21 | + } | |
| 13 | 22 | } |
| 14 | 23 | buildTypes { |
| 15 | 24 | release { |
| ... | ... | @@ -33,6 +42,6 @@ dependencies { |
| 33 | 42 | compile 'com.android.support.constraint:constraint-layout:1.0.2' |
| 34 | 43 | // TODO 本地酷使用说明 代码仓库标识 |
| 35 | 44 | // compile 'com.cnlive.libs:base:1.0.0@aar' |
| 36 | - // compile 'com.cnlive:cnlive:0.1.0' | |
| 37 | - compile project(':cnlive') | |
| 45 | +// compile 'com.cnlive:cnlive:0.1.1' | |
| 46 | + compile project(':cnlive') | |
| 38 | 47 | } | ... | ... |
app/src/main/java/com/cnlive/libs/demo/Java8Test.java
0 → 100644
| 1 | +package com.cnlive.libs.demo; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.util.Log; | |
| 5 | + | |
| 6 | +import java.util.Arrays; | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +import java8.util.stream.Collectors; | |
| 10 | + | |
| 11 | +import static com.cnlive.libs.base.util.LambdaUtil.stream; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Created by xiansong on 2017/8/17. | |
| 15 | + */ | |
| 16 | + | |
| 17 | +public class Java8Test { | |
| 18 | + public static void test(Activity activity){ | |
| 19 | + | |
| 20 | + | |
| 21 | + List<String> list = Arrays.asList("1", "2", "3"); | |
| 22 | + | |
| 23 | + activity.findViewById(R.id.progressBar).setOnClickListener(view -> Log.e("DemoView", "view " + view.getClass().getName())); | |
| 24 | + | |
| 25 | + stream(list).filter(str -> str.startsWith("1")).forEach(item ->Log.e("DemoView","New " + item)); | |
| 26 | + | |
| 27 | + stream(list).forEach(item -> Log.e("DemoView", "n item " + item)); | |
| 28 | + | |
| 29 | + String str = stream(list).map(x -> x.toUpperCase()).collect(Collectors.joining(", ")); | |
| 30 | + } | |
| 31 | +} | ... | ... |
build.gradle
cnlive/build.gradle
| 1 | 1 | apply plugin: 'com.android.library' |
| 2 | 2 | apply plugin: 'maven' |
| 3 | +apply plugin: 'me.tatarka.retrolambda' | |
| 3 | 4 | |
| 4 | 5 | android { |
| 5 | 6 | compileSdkVersion 26 |
| ... | ... | @@ -10,10 +11,9 @@ android { |
| 10 | 11 | targetSdkVersion 26 |
| 11 | 12 | versionCode 1 |
| 12 | 13 | versionName "1.0" |
| 13 | - | |
| 14 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| 15 | - | |
| 16 | 15 | } |
| 16 | + | |
| 17 | 17 | buildTypes { |
| 18 | 18 | release { |
| 19 | 19 | minifyEnabled false |
| ... | ... | @@ -44,6 +44,13 @@ dependencies { |
| 44 | 44 | compile 'com.squareup.okhttp3:okhttp:3.8.1' |
| 45 | 45 | compile 'com.squareup.okhttp3:logging-interceptor:3.8.1' |
| 46 | 46 | |
| 47 | + //Java8 | |
| 48 | + compile 'net.sourceforge.streamsupport:streamsupport:1.5.5' | |
| 49 | + compile 'net.sourceforge.streamsupport:streamsupport-cfuture:1.5.5' | |
| 50 | + compile 'net.sourceforge.streamsupport:streamsupport-atomic:1.5.5' | |
| 51 | + compile 'net.sourceforge.streamsupport:streamsupport-flow:1.5.5' | |
| 52 | + compile 'net.sourceforge.streamsupport:streamsupport-literal:1.5.5' | |
| 53 | + | |
| 47 | 54 | } |
| 48 | 55 | |
| 49 | 56 | ext { | ... | ... |
cnlive/src/main/java/com/cnlive/libs/base/util/LambdaUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | |
| 2 | + | |
| 3 | +import java.util.Collection; | |
| 4 | + | |
| 5 | +import java8.util.stream.RefStreams; | |
| 6 | +import java8.util.stream.Stream; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by xiansong on 2017/8/17. | |
| 10 | + */ | |
| 11 | + | |
| 12 | +public class LambdaUtil { | |
| 13 | + public static <T> Stream<T> stream(Collection<T> collection) { | |
| 14 | + if (collection == null) return null; | |
| 15 | + return RefStreams.of((T[]) collection.toArray()); | |
| 16 | + } | |
| 17 | +} | ... | ... |