Explorar o código

TeddeMacBook-Pro.local push @ 2017-08-17_10-27-28

Ted %!s(int64=7) %!d(string=hai) anos
pai
achega
b0b245aeb1

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 16 - 8
app/build.gradle

@@ -1,14 +1,15 @@
 apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
 
 android {
-    compileSdkVersion 26
-    buildToolsVersion "26.0.1"
+    compileSdkVersion getProject().compileSdkVersion
+    buildToolsVersion getProject().buildToolsVersion
     defaultConfig {
         applicationId "com.tedxiong.kotlin"
-        minSdkVersion 16
-        targetSdkVersion 26
-        versionCode 1
-        versionName "1.0"
+        minSdkVersion getProject().minSdkVersion
+        targetSdkVersion getProject().targetSdkVersion
+        versionCode getProject().versionCode
+        versionName getProject().versionName
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
@@ -24,7 +25,14 @@ dependencies {
     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'
     testCompile 'junit:junit:4.12'
+    compile getProject().appcompatV7
+    compile getProject().constraintLayout
+    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+    compile "org.jetbrains.anko:anko-commons:$anko_version"
+    compile "org.jetbrains.anko:anko-sqlite:$anko_version"
+    compile "org.jetbrains.anko:anko-coroutines:$anko_version"
+}
+repositories {
+    mavenCentral()
 }

+ 82 - 0
app/src/main/java/com/tedxiong/kotlin/KotlinUnit.kt

@@ -0,0 +1,82 @@
+package com.tedxiong.kotlin
+
+import java.text.SimpleDateFormat
+import java.util.*
+import kotlin.collections.ArrayList
+import kotlin.collections.HashMap
+
+/**
+ * Created by ted on 2017/8/16.
+ * in com.tedxiong.kotlin
+ */
+class KotlinUnit {
+
+    /**
+     * 姓名拆分,通过空格拆分出姓和名
+     */
+    fun nameSplit(name: String): Boolean {
+        name.let {
+            if (it.indexOf(" ") == -1) return false
+            println("Your first Name is " + it.substring(0, it.indexOf(" ")))
+            println("Your last Name is " + it.substring(it.indexOf(" ")))
+            print(this)
+            return true
+        }
+    }
+
+    /**
+     * 在一个空的数组里塞入日期和时间的字符串
+     */
+    fun getDateStr(space: ArrayList<String>): Boolean {
+        space.apply {
+            add(SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date()))
+            add(SimpleDateFormat.getTimeInstance().format(Date()))
+            println(this)
+        }.let {
+            println("The date info is " + it[0])
+            println("The time info is " + it[1])
+        }
+        return true
+    }
+
+    /**
+     * 获取到编译环境相关的系统信息
+     */
+    fun getCompileInfo(map: HashMap<String, String>): Boolean {
+        return with(map) {
+            put("Java环境版本", System.getProperties().getProperty("java.version"))
+            put("Java环境供应商", System.getProperties().getProperty("java.vendor"))
+            put("操作系统名称", System.getProperties().getProperty("os.name"))
+            put("操作系统架构", System.getProperties().getProperty("os.arch"))
+            put("操作系统版本", System.getProperties().getProperty("os.version"))
+            println(this)
+            true
+        }
+    }
+
+    /**
+     * 接收一个姓名,打印三句话
+     */
+    fun sayHiTo(name: String): Boolean {
+        println(name.run {
+            println("Hi," + name)
+            println("Nice to meet you," + this)
+            "The run has over!!!!"
+        })
+        return true
+    }
+
+    /**
+     * 计算圆周长
+     */
+    fun getCircumference(dia: Int): Boolean {
+        println("The dia is " +
+                dia.also {
+                    println("The Circumference is " + Math.PI * it)
+                    println(this)
+                }
+        )
+        return true
+    }
+
+}

+ 1 - 0
app/src/main/java/com/tedxiong/kotlin/MainActivity.java

@@ -10,4 +10,5 @@ public class MainActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     }
+
 }

+ 0 - 17
app/src/test/java/com/tedxiong/kotlin/ExampleUnitTest.java

@@ -1,17 +0,0 @@
-package com.tedxiong.kotlin;
-
-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);
-    }
-}

+ 45 - 0
app/src/test/java/com/tedxiong/kotlin/KotlinUnitTest.java

@@ -0,0 +1,45 @@
+package com.tedxiong.kotlin;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+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 KotlinUnitTest {
+    private KotlinUnit mUnit = new KotlinUnit();
+
+    @Test
+    public void testLet_0() throws Exception {
+        assertTrue("testLet_0", mUnit.nameSplit("ted xiong"));
+    }
+
+    @Test
+    public void testApply_0() throws Exception {
+        ArrayList<String> space = new ArrayList<>();
+        assertTrue("testApply_0", mUnit.getDateStr(space));
+    }
+
+    @Test
+    public void testWith_0() throws Exception {
+        HashMap<String,String> map = new HashMap<>();
+        assertTrue("testWith_0", mUnit.getCompileInfo(map));
+    }
+
+    @Test
+    public void testRun_0() throws Exception {
+        assertTrue("testRun_0", mUnit.sayHiTo("xiongwei"));
+    }
+
+    @Test
+    public void testAlso_0() throws Exception {
+        assertTrue("testAlso_0", mUnit.getCircumference(10));
+    }
+}

+ 6 - 8
build.gradle

@@ -1,22 +1,20 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
+apply from:'version.gradle'
 
 buildscript {
+    ext.kotlin_version = '1.1.4'
+    ext.anko_version = '0.10.1'
+
     repositories {
         jcenter()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:2.3.3'
-
-        // NOTE: Do not place your application dependencies here; they belong
-        // in the individual module build.gradle files
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
     }
 }
 
-allprojects {
-    repositories {
-        jcenter()
-    }
-}
 
 task clean(type: Delete) {
     delete rootProject.buildDir

+ 25 - 0
version.gradle

@@ -0,0 +1,25 @@
+def androidSupportVersion = '26.0.0'
+def androidConstraintLayout = '1.0.2'
+
+ext {
+    versionCode = 1
+    versionName = "1.0"
+    compileSdkVersion = 26
+    buildToolsVersion = "26.0.1"
+    minSdkVersion = 16
+    targetSdkVersion = 26
+    appcompatV7 = "com.android.support:appcompat-v7:$androidSupportVersion"
+    recycleView = "com.android.support:recyclerview-v7:$androidSupportVersion"
+    design = "com.android.support:design:$androidSupportVersion"
+    constraintLayout = "com.android.support.constraint:constraint-layout:$androidConstraintLayout"
+}
+
+allprojects {
+    repositories {
+        jcenter()
+        maven {
+            url "https://maven.google.com"
+        }
+    }
+}
+