From 18a57d96258ce96c94f95073ff095691364a8777 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 23 Jul 2017 01:23:28 +0900
Subject: [PATCH 01/34] convert Marquee java to kt and apply kotlin plugin

---
 build.gradle                                           |  2 ++
 mobile/build.gradle                                    |  5 +++++
 .../android/apis/text/{Marquee.java => Marquee.kt}     | 10 ++++------
 3 files changed, 11 insertions(+), 6 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/text/{Marquee.java => Marquee.kt} (78%)

diff --git a/build.gradle b/build.gradle
index e4873fbe3..1ec0c41b0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,11 +2,13 @@
 // vim: ts=4 sts=4 sw=4 expandtab
 
 buildscript {
+    ext.kotlin_version = '1.1.3-2'
     repositories {
         jcenter()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:2.3.3'
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
diff --git a/mobile/build.gradle b/mobile/build.gradle
index 413448435..0f3641797 100644
--- a/mobile/build.gradle
+++ b/mobile/build.gradle
@@ -1,4 +1,5 @@
 apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
 
 android {
     compileSdkVersion 26
@@ -27,4 +28,8 @@ dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     compile 'com.android.support:support-v4:26.0.0-beta2'
     compile 'com.android.support:appcompat-v7:26.0.0-beta2'
+    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
+}
+repositories {
+    mavenCentral()
 }
diff --git a/mobile/src/main/java/com/example/android/apis/text/Marquee.java b/mobile/src/main/java/com/example/android/apis/text/Marquee.kt
similarity index 78%
rename from mobile/src/main/java/com/example/android/apis/text/Marquee.java
rename to mobile/src/main/java/com/example/android/apis/text/Marquee.kt
index ba82ed6cf..5e040ce9f 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Marquee.java
+++ b/mobile/src/main/java/com/example/android/apis/text/Marquee.kt
@@ -21,11 +21,9 @@
 import android.app.Activity;
 import android.os.Bundle;
 
-public class Marquee extends Activity {
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        
-        setContentView(R.layout.marquee);
+class Marquee : Activity() {
+   override fun onCreate(savedInstanceState:Bundle ?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.marquee)
     }
 }

From 7132a98c144ea07bc2be09c16a90b8048c585243 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 23 Jul 2017 01:28:24 +0900
Subject: [PATCH 02/34] convert text.LogTextBox1 java to kt

---
 .../text/{LogTextBox1.java => LogTextBox1.kt} | 31 ++++++++-----------
 1 file changed, 13 insertions(+), 18 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/text/{LogTextBox1.java => LogTextBox1.kt} (61%)

diff --git a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.java b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
similarity index 61%
rename from mobile/src/main/java/com/example/android/apis/text/LogTextBox1.java
rename to mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
index 18136296f..b482bec17 100644
--- a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.java
+++ b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
@@ -28,23 +28,18 @@
  * to which text is appended.
  *
  */
-public class LogTextBox1 extends Activity {
-    
-    private LogTextBox mText;
-    
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        
-        setContentView(R.layout.log_text_box_1);
-        
-        mText = (LogTextBox) findViewById(R.id.text);
-        
-        Button addButton = (Button) findViewById(R.id.add);
-        addButton.setOnClickListener(new View.OnClickListener() {
-
-            public void onClick(View v) {
-                mText.append("This is a test\n");
-            } });
+class LogTextBox1 : Activity() {
+
+    private var mText: LogTextBox? = null
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        setContentView(R.layout.log_text_box_1)
+
+        mText = findViewById<View>(R.id.text) as LogTextBox
+        val addButton = findViewById<View>(R.id.add) as Button
+        addButton.setOnClickListener { mText!!.append("This is a test\n") }
     }
 }
+

From 9d24dc931ade3deb193bd4493930bffc14858582 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 23 Jul 2017 05:49:37 +0900
Subject: [PATCH 03/34] convert LogTextBox && Link  java to kt

---
 .../android/apis/text/{Link.java => Link.kt}  | 67 +++++++++----------
 .../example/android/apis/text/LogTextBox.java | 64 ------------------
 .../example/android/apis/text/LogTextBox.kt   | 52 ++++++++++++++
 3 files changed, 85 insertions(+), 98 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/text/{Link.java => Link.kt} (54%)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/text/LogTextBox.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/text/LogTextBox.kt

diff --git a/mobile/src/main/java/com/example/android/apis/text/Link.java b/mobile/src/main/java/com/example/android/apis/text/Link.kt
similarity index 54%
rename from mobile/src/main/java/com/example/android/apis/text/Link.java
rename to mobile/src/main/java/com/example/android/apis/text/Link.kt
index cc3ed5b9a..14298c31b 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Link.java
+++ b/mobile/src/main/java/com/example/android/apis/text/Link.kt
@@ -14,27 +14,27 @@
  * limitations under the License.
  */
 
-package com.example.android.apis.text;
+package com.example.android.apis.text
 
-import com.example.android.apis.R;
+import com.example.android.apis.R
 
-import android.app.Activity;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.method.LinkMovementMethod;
-import android.text.style.StyleSpan;
-import android.text.style.URLSpan;
-import android.widget.TextView;
+import android.app.Activity
+import android.graphics.Typeface
+import android.os.Bundle
+import android.text.Html
+import android.text.SpannableString
+import android.text.Spanned
+import android.text.method.LinkMovementMethod
+import android.text.style.StyleSpan
+import android.text.style.URLSpan
+import android.view.View
+import android.widget.TextView
 
-public class Link extends Activity {
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
+class Link : Activity() {
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
 
-        setContentView(R.layout.link);
+        setContentView(R.layout.link)
 
         // text1 shows the android:autoLink property, which
         // automatically linkifies things like URLs and phone numbers
@@ -46,8 +46,8 @@ protected void onCreate(Bundle savedInstanceState) {
         // respond to user input.  To make them active, you need to
         // call setMovementMethod() on the TextView object.
 
-        TextView t2 = (TextView) findViewById(R.id.text2);
-        t2.setMovementMethod(LinkMovementMethod.getInstance());
+        val t2 = findViewById<View>(R.id.text2) as TextView
+        t2.movementMethod = LinkMovementMethod.getInstance()
 
         // text3 shows creating text with links from HTML in the Java
         // code, rather than from a string resource.  Note that for a
@@ -56,29 +56,28 @@ protected void onCreate(Bundle savedInstanceState) {
         // illustrate how you might display text that came from a
         // dynamic source (eg, the network).
 
-        TextView t3 = (TextView) findViewById(R.id.text3);
-        t3.setText(
-            Html.fromHtml(
+        val t3 = findViewById<View>(R.id.text3) as TextView
+        t3.text = Html.fromHtml(
                 "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                "<a href=\"http://www.google.com\">link</a> " +
-                "created in the Java source code using HTML."));
-        t3.setMovementMethod(LinkMovementMethod.getInstance());
+                        "<a href=\"http://www.google.com\">link</a> " +
+                        "created in the Java source code using HTML.")
+        t3.movementMethod = LinkMovementMethod.getInstance()
 
         // text4 illustrates constructing a styled string containing a
         // link without using HTML at all.  Again, for a fixed string
         // you should probably be using a string resource, not a
         // hardcoded value.
 
-        SpannableString ss = new SpannableString(
-            "text4: Manually created spans. Click here to dial the phone.");
+        val ss = SpannableString(
+                "text4: Manually created spans. Click here to dial the phone.")
 
-        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 30,
-                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-        ss.setSpan(new URLSpan("tel:4155551212"), 31+6, 31+10,
-                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        ss.setSpan(StyleSpan(Typeface.BOLD), 0, 30,
+                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+        ss.setSpan(URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
+                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
 
-        TextView t4 = (TextView) findViewById(R.id.text4);
-        t4.setText(ss);
-        t4.setMovementMethod(LinkMovementMethod.getInstance());
+        val t4 = findViewById<View>(R.id.text4) as TextView
+        t4.text = ss
+        t4.movementMethod = LinkMovementMethod.getInstance()
     }
 }
diff --git a/mobile/src/main/java/com/example/android/apis/text/LogTextBox.java b/mobile/src/main/java/com/example/android/apis/text/LogTextBox.java
deleted file mode 100644
index 09957c5bf..000000000
--- a/mobile/src/main/java/com/example/android/apis/text/LogTextBox.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.text;
-
-import android.widget.TextView;
-import android.content.Context;
-import android.text.method.ScrollingMovementMethod;
-import android.text.method.MovementMethod;
-import android.text.Editable;
-import android.util.AttributeSet;
-
-/**
- * This is a TextView that is Editable and by default scrollable,
- * like EditText without a cursor.
- *
- * <p>
- * <b>XML attributes</b>
- * <p>
- * See
- * {@link android.R.styleable#TextView TextView Attributes},
- * {@link android.R.styleable#View View Attributes}
- */
-public class LogTextBox extends TextView {
-    public LogTextBox(Context context) {
-        this(context, null);
-    }
-
-    public LogTextBox(Context context, AttributeSet attrs) {
-        this(context, attrs, android.R.attr.textViewStyle);
-    }
-
-    public LogTextBox(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-    }
-
-    @Override
-    protected MovementMethod getDefaultMovementMethod() {
-        return ScrollingMovementMethod.getInstance();
-    }
-
-    @Override
-    public Editable getText() {
-        return (Editable) super.getText();
-    }
-
-    @Override
-    public void setText(CharSequence text, BufferType type) {
-        super.setText(text, BufferType.EDITABLE);
-    }
-}
diff --git a/mobile/src/main/java/com/example/android/apis/text/LogTextBox.kt b/mobile/src/main/java/com/example/android/apis/text/LogTextBox.kt
new file mode 100644
index 000000000..1b7a93cec
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/text/LogTextBox.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.text
+
+import android.widget.TextView
+import android.content.Context
+import android.text.method.ScrollingMovementMethod
+import android.text.method.MovementMethod
+import android.text.Editable
+import android.util.AttributeSet
+
+/**
+ * This is a TextView that is Editable and by default scrollable,
+ * like EditText without a cursor.
+
+ *
+ *
+ * **XML attributes**
+ *
+ *
+ * See
+ * [TextView Attributes][android.R.styleable.TextView],
+ * [View Attributes][android.R.styleable.View]
+ */
+class LogTextBox @JvmOverloads constructor(context: Context, attrs: AttributeSet ?= null, defStyle: Int = android.R.attr.textViewStyle) : TextView(context, attrs, defStyle) {
+
+    override fun getDefaultMovementMethod(): MovementMethod {
+        return ScrollingMovementMethod.getInstance()
+    }
+
+    override fun getText(): Editable {
+        return super.getText() as Editable
+    }
+
+    override fun setText(text: CharSequence, type: TextView.BufferType) {
+        super.setText(text, TextView.BufferType.EDITABLE)
+    }
+}

From 92054df28217d0bdc3643c2c1ff78f64266fb550 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 23 Jul 2017 06:02:05 +0900
Subject: [PATCH 04/34] found </a> missing

---
 .../src/main/java/com/example/android/apis/text/_index.html   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/_index.html b/mobile/src/main/java/com/example/android/apis/text/_index.html
index c995a0cac..74c3cc474 100644
--- a/mobile/src/main/java/com/example/android/apis/text/_index.html
+++ b/mobile/src/main/java/com/example/android/apis/text/_index.html
@@ -1,8 +1,8 @@
 <dl>
   <dt><a href="Link.html">Linkify</a></dt>
-  <dd>Demonstrates the <a                                                                            
+  <dd>Demonstrates the <a
 href="../../../../../../../../../reference/android/text/util/Linkify.html"><code>Linkify</code>
-class, which converts URLs in a block of text into hyperlinks. </dd>
+class, which converts URLs in a block of text into hyperlinks.</a></dd>
 </dl>
 
 

From 48bfdd1f1d7750781689d75e0d24a84268482f46 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 23 Jul 2017 06:16:54 +0900
Subject: [PATCH 05/34] modified a depreciated Html.fromHtml() by version

---
 .../java/com/example/android/apis/text/Link.kt   | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/Link.kt b/mobile/src/main/java/com/example/android/apis/text/Link.kt
index 14298c31b..b7ae154d1 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Link.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/Link.kt
@@ -57,10 +57,18 @@ class Link : Activity() {
         // dynamic source (eg, the network).
 
         val t3 = findViewById<View>(R.id.text3) as TextView
-        t3.text = Html.fromHtml(
-                "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                        "<a href=\"http://www.google.com\">link</a> " +
-                        "created in the Java source code using HTML.")
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+            t3.text = Html.fromHtml(
+                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                            "<a href=\"http://www.google.com\">link</a> " +
+                            "created in the Java source code using HTML.", Html.FROM_HTML_MODE_LEGACY)
+        }
+        else{
+            t3.text = Html.fromHtml(
+                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                            "<a href=\"http://www.google.com\">link</a> " +
+                            "created in the Java source code using HTML.")
+        }
         t3.movementMethod = LinkMovementMethod.getInstance()
 
         // text4 illustrates constructing a styled string containing a

From eb2138c9db58536a025a53022050a62ee9f7297f Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 29 Jul 2017 13:12:18 +0900
Subject: [PATCH 06/34] convert SeekBar java to kt

---
 .../apis/view/{SeekBar1.java => SeekBar1.kt}  | 36 +++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/view/{SeekBar1.java => SeekBar1.kt} (62%)

diff --git a/mobile/src/main/java/com/example/android/apis/view/SeekBar1.java b/mobile/src/main/java/com/example/android/apis/view/SeekBar1.kt
similarity index 62%
rename from mobile/src/main/java/com/example/android/apis/view/SeekBar1.java
rename to mobile/src/main/java/com/example/android/apis/view/SeekBar1.kt
index 65d01d4e2..f39b4f501 100644
--- a/mobile/src/main/java/com/example/android/apis/view/SeekBar1.java
+++ b/mobile/src/main/java/com/example/android/apis/view/SeekBar1.kt
@@ -18,6 +18,7 @@
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.view.View
 import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
@@ -30,7 +31,7 @@
 /**
  * Demonstrates how to use a seek bar
  */
-public class SeekBar1 extends Activity implements SeekBar.OnSeekBarChangeListener {
+/*public class SeekBar1 extends Activity implements SeekBar.OnSeekBarChangeListener {
     
     SeekBar mSeekBar;
     TextView mProgressText;
@@ -70,4 +71,35 @@ public void onStartTrackingTouch(SeekBar seekBar) {
     public void onStopTrackingTouch(SeekBar seekBar) {
         mTrackingText.setText(getString(R.string.seekbar_tracking_off));
     }
-}
+}*/
+class SeekBar1 : Activity(), SeekBar.OnSeekBarChangeListener{
+    lateinit private var mSeekBar : SeekBar;
+    lateinit private var mProgressText : TextView;
+    lateinit private var mTrackingText : TextView;
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.seekbar_1)
+
+        mSeekBar = findViewById<View>(R.id.seek) as SeekBar
+        mSeekBar.setOnSeekBarChangeListener(this)
+        mProgressText = findViewById<View>(R.id.progress) as TextView
+        mTrackingText = findViewById<View>(R.id.tracking) as TextView
+
+        (findViewById<View>(R.id.enabled) as CheckBox).setOnCheckedChangeListener { buttonView, isChecked ->
+            findViewById<View>(R.id.seekMin).setEnabled(isChecked);
+            findViewById<View>(R.id.seekMax).setEnabled(isChecked);
+            mSeekBar.setEnabled(isChecked);
+        }
+    }
+    override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromTouch: Boolean) {
+        mProgressText.setText("$progress ${resources.getString(R.string.seekbar_from_touch)} = $fromTouch");
+    }
+
+    override fun onStartTrackingTouch(p0: SeekBar?) {
+        mTrackingText.setText(getString(R.string.seekbar_tracking_on));
+    }
+
+    override fun onStopTrackingTouch(p0: SeekBar?) {
+        mTrackingText.setText(getString(R.string.seekbar_tracking_off));
+    }
+}
\ No newline at end of file

From 2d22faca14a5bfcbdabe5bb89992f645bd6aa492 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 30 Jul 2017 08:55:09 +0900
Subject: [PATCH 07/34] converted AlarmController java to kt

---
 .../android/apis/app/AlarmController.java     | 168 ------------
 .../android/apis/app/AlarmController.kt       | 251 ++++++++++++++++++
 2 files changed, 251 insertions(+), 168 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmController.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmController.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmController.java b/mobile/src/main/java/com/example/android/apis/app/AlarmController.java
deleted file mode 100644
index 2ba573564..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/AlarmController.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-import android.app.Activity;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.os.SystemClock;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-import java.util.Calendar;
-
-/**
- * Example of scheduling one-shot and repeating alarms.  See
- * {@link OneShotAlarm} for the code run when the one-shot alarm goes off, and
- * {@link RepeatingAlarm} for the code run when the repeating alarm goes off.
- * <h4>Demo</h4>
-App/Service/Alarm Controller
- 
-<h4>Source files</h4>
-<table class="LinkTable">
-        <tr>
-            <td class="LinkColumn">src/com.example.android.apis/app/AlarmController.java</td>
-            <td class="DescrColumn">The activity that lets you schedule alarms</td>
-        </tr>
-        <tr>
-            <td class="LinkColumn">src/com.example.android.apis/app/OneShotAlarm.java</td>
-            <td class="DescrColumn">This is an intent receiver that executes when the
-                one-shot alarm goes off</td>
-        </tr>
-        <tr>
-            <td class="LinkColumn">src/com.example.android.apis/app/RepeatingAlarm.java</td>
-            <td class="DescrColumn">This is an intent receiver that executes when the
-                repeating alarm goes off</td>
-        </tr>
-        <tr>
-            <td class="LinkColumn">/res/any/layout/alarm_controller.xml</td>
-            <td class="DescrColumn">Defines contents of the screen</td>
-        </tr>
-</table>
-
- */
-public class AlarmController extends Activity {
-    Toast mToast;
-
-    @Override
-	protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.alarm_controller);
-
-        // Watch for button clicks.
-        Button button = (Button)findViewById(R.id.one_shot);
-        button.setOnClickListener(mOneShotListener);
-        button = (Button)findViewById(R.id.start_repeating);
-        button.setOnClickListener(mStartRepeatingListener);
-        button = (Button)findViewById(R.id.stop_repeating);
-        button.setOnClickListener(mStopRepeatingListener);
-    }
-
-    private OnClickListener mOneShotListener = new OnClickListener() {
-        public void onClick(View v) {
-            // When the alarm goes off, we want to broadcast an Intent to our
-            // BroadcastReceiver.  Here we make an Intent with an explicit class
-            // name to have our own receiver (which has been published in
-            // AndroidManifest.xml) instantiated and called, and then create an
-            // IntentSender to have the intent executed as a broadcast.
-            Intent intent = new Intent(AlarmController.this, OneShotAlarm.class);
-            PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
-                    0, intent, 0);
-
-            // We want the alarm to go off 30 seconds from now.
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTimeInMillis(System.currentTimeMillis());
-            calendar.add(Calendar.SECOND, 30);
-
-            // Schedule the alarm!
-            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
-            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
-
-            // Tell the user about what we did.
-            if (mToast != null) {
-                mToast.cancel();
-            }
-            mToast = Toast.makeText(AlarmController.this, R.string.one_shot_scheduled,
-                    Toast.LENGTH_LONG);
-            mToast.show();
-        }
-    };
-
-    private OnClickListener mStartRepeatingListener = new OnClickListener() {
-        public void onClick(View v) {
-            // When the alarm goes off, we want to broadcast an Intent to our
-            // BroadcastReceiver.  Here we make an Intent with an explicit class
-            // name to have our own receiver (which has been published in
-            // AndroidManifest.xml) instantiated and called, and then create an
-            // IntentSender to have the intent executed as a broadcast.
-            // Note that unlike above, this IntentSender is configured to
-            // allow itself to be sent multiple times.
-            Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
-            PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
-                    0, intent, 0);
-            
-            // We want the alarm to go off 30 seconds from now.
-            long firstTime = SystemClock.elapsedRealtime();
-            firstTime += 15*1000;
-
-            // Schedule the alarm!
-            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
-            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                            firstTime, 15*1000, sender);
-
-            // Tell the user about what we did.
-            if (mToast != null) {
-                mToast.cancel();
-            }
-            mToast = Toast.makeText(AlarmController.this, R.string.repeating_scheduled,
-                    Toast.LENGTH_LONG);
-            mToast.show();
-        }
-    };
-
-    private OnClickListener mStopRepeatingListener = new OnClickListener() {
-        public void onClick(View v) {
-            // Create the same intent, and thus a matching IntentSender, for
-            // the one that was scheduled.
-            Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
-            PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
-                    0, intent, 0);
-            
-            // And cancel the alarm.
-            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
-            am.cancel(sender);
-
-            // Tell the user about what we did.
-            if (mToast != null) {
-                mToast.cancel();
-            }
-            mToast = Toast.makeText(AlarmController.this, R.string.repeating_unscheduled,
-                    Toast.LENGTH_LONG);
-            mToast.show();
-        }
-    };
-}
-
diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
new file mode 100644
index 000000000..4ad05a04b
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R
+
+import android.app.Activity
+import android.app.AlarmManager
+import android.app.PendingIntent
+import android.content.Intent
+import android.os.SystemClock
+import android.os.Bundle
+import android.view.View
+import android.view.View.OnClickListener
+import android.widget.Button
+import android.widget.Toast
+
+import java.util.Calendar
+
+/**
+ * Example of scheduling one-shot and repeating alarms.  See
+ * [OneShotAlarm] for the code run when the one-shot alarm goes off, and
+ * [RepeatingAlarm] for the code run when the repeating alarm goes off.
+ * <h4>Demo</h4>
+ * App/Service/Alarm Controller
+
+ * <h4>Source files</h4>
+ * <table class="LinkTable">
+ * <tr>
+ * <td class="LinkColumn">src/com.example.android.apis/app/AlarmController.java</td>
+ * <td class="DescrColumn">The activity that lets you schedule alarms</td>
+</tr> *
+ * <tr>
+ * <td class="LinkColumn">src/com.example.android.apis/app/OneShotAlarm.java</td>
+ * <td class="DescrColumn">This is an intent receiver that executes when the
+ * one-shot alarm goes off</td>
+</tr> *
+ * <tr>
+ * <td class="LinkColumn">src/com.example.android.apis/app/RepeatingAlarm.java</td>
+ * <td class="DescrColumn">This is an intent receiver that executes when the
+ * repeating alarm goes off</td>
+</tr> *
+ * <tr>
+ * <td class="LinkColumn">/res/any/layout/alarm_controller.xml</td>
+ * <td class="DescrColumn">Defines contents of the screen</td>
+</tr> *
+</table> *
+
+ */
+
+class AlarmController : Activity (){
+    var mToast: Toast? = null
+    override fun onCreate(savedInstanceState:Bundle?) : Unit {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.alarm_controller)
+
+        // Watch for button clicks.
+        var button = findViewById<View>(R.id.one_shot) as (Button)
+        button.setOnClickListener(mOneShotListener)
+        button = findViewById<View>(R.id.start_repeating) as (Button)
+        button.setOnClickListener(mStartRepeatingListener);
+        button = findViewById<View>(R.id.stop_repeating) as (Button)
+        button.setOnClickListener(mStopRepeatingListener);
+    }
+   val mOneShotListener = OnClickListener{
+            // When the alarm goes off, we want to broadcast an Intent to our
+            // BroadcastReceiver.  Here we make an Intent with an explicit class
+            // name to have our own receiver (which has been published in
+            // AndroidManifest.xml) instantiated and called, and then create an
+            // IntentSender to have the intent executed as a broadcast.
+            val intent:Intent = Intent(this@AlarmController, OneShotAlarm::class.java)
+            val sender:PendingIntent = PendingIntent.getBroadcast(this@AlarmController, 0, intent, 0)
+
+            // We want the alarm to go off 30 seconds from now.
+            var calendar:Calendar  = Calendar.getInstance();
+            calendar.setTimeInMillis(System.currentTimeMillis())
+            calendar.add(Calendar.SECOND, 30);
+
+            // Schedule the alarm!
+             val am:AlarmManager = getSystemService(ALARM_SERVICE) as (AlarmManager)
+            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender)
+
+            // Tell the user about what we did.
+            if (mToast != null) {
+                mToast!!.cancel()
+            }
+            mToast = Toast.makeText(this@AlarmController, R.string.one_shot_scheduled,Toast.LENGTH_LONG)
+            mToast!!.show()
+
+    };
+   val mStartRepeatingListener = OnClickListener{
+            // When the alarm goes off, we want to broadcast an Intent to our
+            // BroadcastReceiver.  Here we make an Intent with an explicit class
+            // name to have our own receiver (which has been published in
+            // AndroidManifest.xml) instantiated and called, and then create an
+            // IntentSender to have the intent executed as a broadcast.
+            // Note that unlike above, this IntentSender is configured to
+            // allow itself to be sent multiple times.
+            val intent:Intent = Intent(this@AlarmController, RepeatingAlarm::class.java)
+            val sender:PendingIntent = PendingIntent.getBroadcast(this@AlarmController,0, intent, 0)
+
+            // We want the alarm to go off 30 seconds from now.
+           var  firstTime : Long = SystemClock.elapsedRealtime()
+            firstTime += 15*1000L
+
+            // Schedule the alarm!
+            val am:AlarmManager  = getSystemService(ALARM_SERVICE) as AlarmManager
+            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime, 15*1000, sender)
+
+            // Tell the user about what we did.
+            if (mToast != null) {
+                mToast!!.cancel()
+            }
+            mToast = Toast.makeText(this@AlarmController, R.string.repeating_scheduled, Toast.LENGTH_LONG)
+            mToast!!.show()
+
+    };
+    val mStopRepeatingListener = OnClickListener {
+            // Create the same intent, and thus a matching IntentSender, for
+            // the one that was scheduled.
+            val intent:Intent  = Intent(this@AlarmController, RepeatingAlarm::class.java)
+             val sender:PendingIntent  = PendingIntent.getBroadcast(this@AlarmController, 0, intent, 0)
+
+            // And cancel the alarm.
+            val am :AlarmManager= getSystemService(ALARM_SERVICE) as (AlarmManager)
+            am.cancel(sender)
+
+            // Tell the user about what we did.
+            if (mToast != null) {
+                mToast!!.cancel();
+            }
+            mToast = Toast.makeText(this@AlarmController, R.string.repeating_unscheduled,Toast.LENGTH_LONG)
+            mToast!!.show()
+
+    };
+}
+/*
+
+class AlarmController : Activity() {
+    internal var mToast: Toast? = null
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        setContentView(R.layout.alarm_controller)
+
+        // Watch for button clicks.
+        var button = findViewById<View>(R.id.one_shot) as Button
+        button.setOnClickListener(mOneShotListener)
+        button = findViewById<View>(R.id.start_repeating) as Button
+        button.setOnClickListener(mStartRepeatingListener)
+        button = findViewById<View>(R.id.stop_repeating) as Button
+        button.setOnClickListener(mStopRepeatingListener)
+    }
+
+    private val mOneShotListener = OnClickListener {
+        // When the alarm goes off, we want to broadcast an Intent to our
+        // BroadcastReceiver.  Here we make an Intent with an explicit class
+        // name to have our own receiver (which has been published in
+        // AndroidManifest.xml) instantiated and called, and then create an
+        // IntentSender to have the intent executed as a broadcast.
+        val intent = Intent(this@AlarmController, OneShotAlarm::class.java)
+        val sender = PendingIntent.getBroadcast(this@AlarmController,
+                0, intent, 0)
+
+        // We want the alarm to go off 30 seconds from now.
+        val calendar = Calendar.getInstance()
+        calendar.timeInMillis = System.currentTimeMillis()
+        calendar.add(Calendar.SECOND, 30)
+
+        // Schedule the alarm!
+        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
+        am.set(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, sender)
+
+        // Tell the user about what we did.
+        if (mToast != null) {
+            mToast!!.cancel()
+        }
+        mToast = Toast.makeText(this@AlarmController, R.string.one_shot_scheduled,
+                Toast.LENGTH_LONG)
+        mToast!!.show()
+    }
+
+    private val mStartRepeatingListener = OnClickListener {
+        // When the alarm goes off, we want to broadcast an Intent to our
+        // BroadcastReceiver.  Here we make an Intent with an explicit class
+        // name to have our own receiver (which has been published in
+        // AndroidManifest.xml) instantiated and called, and then create an
+        // IntentSender to have the intent executed as a broadcast.
+        // Note that unlike above, this IntentSender is configured to
+        // allow itself to be sent multiple times.
+        val intent = Intent(this@AlarmController, RepeatingAlarm::class.java)
+        val sender = PendingIntent.getBroadcast(this@AlarmController,
+                0, intent, 0)
+
+        // We want the alarm to go off 30 seconds from now.
+        var firstTime = SystemClock.elapsedRealtime()
+        firstTime += (15 * 1000).toLong()
+
+        // Schedule the alarm!
+        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
+        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                firstTime, (15 * 1000).toLong(), sender)
+
+        // Tell the user about what we did.
+        if (mToast != null) {
+            mToast!!.cancel()
+        }
+        mToast = Toast.makeText(this@AlarmController, R.string.repeating_scheduled,
+                Toast.LENGTH_LONG)
+        mToast!!.show()
+    }
+
+    private val mStopRepeatingListener = OnClickListener {
+        // Create the same intent, and thus a matching IntentSender, for
+        // the one that was scheduled.
+        val intent = Intent(this@AlarmController, RepeatingAlarm::class.java)
+        val sender = PendingIntent.getBroadcast(this@AlarmController,
+                0, intent, 0)
+
+        // And cancel the alarm.
+        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
+        am.cancel(sender)
+
+        // Tell the user about what we did.
+        if (mToast != null) {
+            mToast!!.cancel()
+        }
+        mToast = Toast.makeText(this@AlarmController, R.string.repeating_unscheduled,
+                Toast.LENGTH_LONG)
+        mToast!!.show()
+    }
+}
+*/
+

From 4baef90ee880b63a199b722b41ef12c2faccc072 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 21:58:41 +0900
Subject: [PATCH 08/34] removed comment

---
 .../android/apis/app/AlarmController.kt       | 99 -------------------
 1 file changed, 99 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
index 4ad05a04b..37aff5d75 100644
--- a/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
@@ -61,7 +61,6 @@ import java.util.Calendar
  * <td class="DescrColumn">Defines contents of the screen</td>
 </tr> *
 </table> *
-
  */
 
 class AlarmController : Activity (){
@@ -150,102 +149,4 @@ class AlarmController : Activity (){
 
     };
 }
-/*
-
-class AlarmController : Activity() {
-    internal var mToast: Toast? = null
-
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
-
-        setContentView(R.layout.alarm_controller)
-
-        // Watch for button clicks.
-        var button = findViewById<View>(R.id.one_shot) as Button
-        button.setOnClickListener(mOneShotListener)
-        button = findViewById<View>(R.id.start_repeating) as Button
-        button.setOnClickListener(mStartRepeatingListener)
-        button = findViewById<View>(R.id.stop_repeating) as Button
-        button.setOnClickListener(mStopRepeatingListener)
-    }
-
-    private val mOneShotListener = OnClickListener {
-        // When the alarm goes off, we want to broadcast an Intent to our
-        // BroadcastReceiver.  Here we make an Intent with an explicit class
-        // name to have our own receiver (which has been published in
-        // AndroidManifest.xml) instantiated and called, and then create an
-        // IntentSender to have the intent executed as a broadcast.
-        val intent = Intent(this@AlarmController, OneShotAlarm::class.java)
-        val sender = PendingIntent.getBroadcast(this@AlarmController,
-                0, intent, 0)
-
-        // We want the alarm to go off 30 seconds from now.
-        val calendar = Calendar.getInstance()
-        calendar.timeInMillis = System.currentTimeMillis()
-        calendar.add(Calendar.SECOND, 30)
-
-        // Schedule the alarm!
-        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
-        am.set(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, sender)
-
-        // Tell the user about what we did.
-        if (mToast != null) {
-            mToast!!.cancel()
-        }
-        mToast = Toast.makeText(this@AlarmController, R.string.one_shot_scheduled,
-                Toast.LENGTH_LONG)
-        mToast!!.show()
-    }
-
-    private val mStartRepeatingListener = OnClickListener {
-        // When the alarm goes off, we want to broadcast an Intent to our
-        // BroadcastReceiver.  Here we make an Intent with an explicit class
-        // name to have our own receiver (which has been published in
-        // AndroidManifest.xml) instantiated and called, and then create an
-        // IntentSender to have the intent executed as a broadcast.
-        // Note that unlike above, this IntentSender is configured to
-        // allow itself to be sent multiple times.
-        val intent = Intent(this@AlarmController, RepeatingAlarm::class.java)
-        val sender = PendingIntent.getBroadcast(this@AlarmController,
-                0, intent, 0)
-
-        // We want the alarm to go off 30 seconds from now.
-        var firstTime = SystemClock.elapsedRealtime()
-        firstTime += (15 * 1000).toLong()
-
-        // Schedule the alarm!
-        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
-        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                firstTime, (15 * 1000).toLong(), sender)
-
-        // Tell the user about what we did.
-        if (mToast != null) {
-            mToast!!.cancel()
-        }
-        mToast = Toast.makeText(this@AlarmController, R.string.repeating_scheduled,
-                Toast.LENGTH_LONG)
-        mToast!!.show()
-    }
-
-    private val mStopRepeatingListener = OnClickListener {
-        // Create the same intent, and thus a matching IntentSender, for
-        // the one that was scheduled.
-        val intent = Intent(this@AlarmController, RepeatingAlarm::class.java)
-        val sender = PendingIntent.getBroadcast(this@AlarmController,
-                0, intent, 0)
-
-        // And cancel the alarm.
-        val am = getSystemService(ALARM_SERVICE) as (AlarmManager)
-        am.cancel(sender)
-
-        // Tell the user about what we did.
-        if (mToast != null) {
-            mToast!!.cancel()
-        }
-        mToast = Toast.makeText(this@AlarmController, R.string.repeating_unscheduled,
-                Toast.LENGTH_LONG)
-        mToast!!.show()
-    }
-}
-*/
 

From 01b8e3654dce7c1a050ae9bfa838855f9037f22d Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 21:59:21 +0900
Subject: [PATCH 09/34] used by lazy for t2(textView)

---
 mobile/src/main/java/com/example/android/apis/text/Link.kt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/Link.kt b/mobile/src/main/java/com/example/android/apis/text/Link.kt
index b7ae154d1..6a1276fc7 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Link.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/Link.kt
@@ -46,7 +46,9 @@ class Link : Activity() {
         // respond to user input.  To make them active, you need to
         // call setMovementMethod() on the TextView object.
 
-        val t2 = findViewById<View>(R.id.text2) as TextView
+        val t2 :TextView by lazy {
+            findViewById<View>(R.id.text2) as TextView
+        }
         t2.movementMethod = LinkMovementMethod.getInstance()
 
         // text3 shows creating text with links from HTML in the Java

From b1d8c181322e25bd96834132484be80002540a09 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 22:11:00 +0900
Subject: [PATCH 10/34] used lazy for t3 (textView)

---
 .../com/example/android/apis/text/Link.kt     | 57 ++++++++++---------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/Link.kt b/mobile/src/main/java/com/example/android/apis/text/Link.kt
index 6a1276fc7..e0bacc39f 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Link.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/Link.kt
@@ -46,7 +46,7 @@ class Link : Activity() {
         // respond to user input.  To make them active, you need to
         // call setMovementMethod() on the TextView object.
 
-        val t2 :TextView by lazy {
+        val t2 by lazy {
             findViewById<View>(R.id.text2) as TextView
         }
         t2.movementMethod = LinkMovementMethod.getInstance()
@@ -58,36 +58,39 @@ class Link : Activity() {
         // illustrate how you might display text that came from a
         // dynamic source (eg, the network).
 
-        val t3 = findViewById<View>(R.id.text3) as TextView
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
-            t3.text = Html.fromHtml(
-                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                            "<a href=\"http://www.google.com\">link</a> " +
-                            "created in the Java source code using HTML.", Html.FROM_HTML_MODE_LEGACY)
+        val t3 by lazt {
+            findViewById<View>(R.id.text3) as TextView
         }
-        else{
-            t3.text = Html.fromHtml(
-                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                            "<a href=\"http://www.google.com\">link</a> " +
-                            "created in the Java source code using HTML.")
-        }
-        t3.movementMethod = LinkMovementMethod.getInstance()
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+                t3.text = Html.fromHtml(
+                        "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                                "<a href=\"http://www.google.com\">link</a> " +
+                                "created in the Java source code using HTML.", Html.FROM_HTML_MODE_LEGACY)
+            }
+            else{
+                t3.text = Html.fromHtml(
+                        "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                                "<a href=\"http://www.google.com\">link</a> " +
+                                "created in the Java source code using HTML.")
+            }
+            t3.movementMethod = LinkMovementMethod.getInstance()
 
-        // text4 illustrates constructing a styled string containing a
-        // link without using HTML at all.  Again, for a fixed string
-        // you should probably be using a string resource, not a
-        // hardcoded value.
+            // text4 illustrates constructing a styled string containing a
+            // link without using HTML at all.  Again, for a fixed string
+            // you should probably be using a string resource, not a
+            // hardcoded value.
 
-        val ss = SpannableString(
-                "text4: Manually created spans. Click here to dial the phone.")
+            val ss = SpannableString(
+                    "text4: Manually created spans. Click here to dial the phone.")
 
-        ss.setSpan(StyleSpan(Typeface.BOLD), 0, 30,
-                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
-        ss.setSpan(URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
-                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+            ss.setSpan(StyleSpan(Typeface.BOLD), 0, 30,
+                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+            ss.setSpan(URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
+                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
 
-        val t4 = findViewById<View>(R.id.text4) as TextView
-        t4.text = ss
-        t4.movementMethod = LinkMovementMethod.getInstance()
+            val t4 = findViewById<View>(R.id.text4) as TextView
+            t4.text = ss
+            t4.movementMethod = LinkMovementMethod.getInstance()
+        }
     }
 }

From fed790ff5bc946a2737d36980adff92fdd07dac3 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 22:25:36 +0900
Subject: [PATCH 11/34] used lazy for val t4

---
 .../com/example/android/apis/text/Link.kt     | 56 ++++++++++---------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/Link.kt b/mobile/src/main/java/com/example/android/apis/text/Link.kt
index e0bacc39f..ad6b2e3ef 100644
--- a/mobile/src/main/java/com/example/android/apis/text/Link.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/Link.kt
@@ -58,39 +58,41 @@ class Link : Activity() {
         // illustrate how you might display text that came from a
         // dynamic source (eg, the network).
 
-        val t3 by lazt {
+        val t3 by lazy {
             findViewById<View>(R.id.text3) as TextView
         }
-            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
-                t3.text = Html.fromHtml(
-                        "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                                "<a href=\"http://www.google.com\">link</a> " +
-                                "created in the Java source code using HTML.", Html.FROM_HTML_MODE_LEGACY)
-            }
-            else{
-                t3.text = Html.fromHtml(
-                        "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
-                                "<a href=\"http://www.google.com\">link</a> " +
-                                "created in the Java source code using HTML.")
-            }
-            t3.movementMethod = LinkMovementMethod.getInstance()
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+            t3.text = Html.fromHtml(
+                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                            "<a href=\"http://www.google.com\">link</a> " +
+                            "created in the Java source code using HTML.", Html.FROM_HTML_MODE_LEGACY)
+        }
+        else{
+            t3.text = Html.fromHtml(
+                    "<b>text3: Constructed from HTML programmatically.</b>  Text with a " +
+                            "<a href=\"http://www.google.com\">link</a> " +
+                            "created in the Java source code using HTML.")
+        }
+        t3.movementMethod = LinkMovementMethod.getInstance()
 
-            // text4 illustrates constructing a styled string containing a
-            // link without using HTML at all.  Again, for a fixed string
-            // you should probably be using a string resource, not a
-            // hardcoded value.
+        // text4 illustrates constructing a styled string containing a
+        // link without using HTML at all.  Again, for a fixed string
+        // you should probably be using a string resource, not a
+        // hardcoded value.
 
-            val ss = SpannableString(
-                    "text4: Manually created spans. Click here to dial the phone.")
+        val ss = SpannableString(
+                "text4: Manually created spans. Click here to dial the phone.")
 
-            ss.setSpan(StyleSpan(Typeface.BOLD), 0, 30,
-                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
-            ss.setSpan(URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
-                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+        ss.setSpan(StyleSpan(Typeface.BOLD), 0, 30,
+                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+        ss.setSpan(URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
+                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
 
-            val t4 = findViewById<View>(R.id.text4) as TextView
-            t4.text = ss
-            t4.movementMethod = LinkMovementMethod.getInstance()
+        val t4 by lazy{
+            findViewById<View>(R.id.text4) as TextView
         }
+        t4.text = ss
+        t4.movementMethod = LinkMovementMethod.getInstance()
     }
 }
+

From 88ec3aeec53b4cb902039450f9ae519a5f2f7623 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 22:27:42 +0900
Subject: [PATCH 12/34] used lazy to init var mText and removed !!.apend

---
 .../main/java/com/example/android/apis/text/LogTextBox1.kt | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
index b482bec17..d0c332c26 100644
--- a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
@@ -30,16 +30,17 @@ import android.widget.Button;
  */
 class LogTextBox1 : Activity() {
 
-    private var mText: LogTextBox? = null
+
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
         setContentView(R.layout.log_text_box_1)
 
-        mText = findViewById<View>(R.id.text) as LogTextBox
+        val mText by lazy {
+            findViewById<View>(R.id.text) as LogTextBox }
         val addButton = findViewById<View>(R.id.add) as Button
-        addButton.setOnClickListener { mText!!.append("This is a test\n") }
+        addButton.setOnClickListener { mText.append("This is a test\n") }
     }
 }
 

From 37930846bfe72eb75edcce6d18cee2ec1a078ff0 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Fri, 11 Aug 2017 22:42:05 +0900
Subject: [PATCH 13/34] use Kotlin synthetic property instead of java
 calendar.set()

---
 .../example/android/apis/app/AlarmController.kt  | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
index 37aff5d75..ad81fecfc 100644
--- a/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/AlarmController.kt
@@ -70,12 +70,12 @@ class AlarmController : Activity (){
         setContentView(R.layout.alarm_controller)
 
         // Watch for button clicks.
-        var button = findViewById<View>(R.id.one_shot) as (Button)
+        var button = findViewById<View>(R.id.one_shot)
         button.setOnClickListener(mOneShotListener)
-        button = findViewById<View>(R.id.start_repeating) as (Button)
-        button.setOnClickListener(mStartRepeatingListener);
-        button = findViewById<View>(R.id.stop_repeating) as (Button)
-        button.setOnClickListener(mStopRepeatingListener);
+        button = findViewById<View>(R.id.start_repeating)
+        button.setOnClickListener(mStartRepeatingListener)
+        button = findViewById<View>(R.id.stop_repeating)
+        button.setOnClickListener(mStopRepeatingListener)
     }
    val mOneShotListener = OnClickListener{
             // When the alarm goes off, we want to broadcast an Intent to our
@@ -87,9 +87,9 @@ class AlarmController : Activity (){
             val sender:PendingIntent = PendingIntent.getBroadcast(this@AlarmController, 0, intent, 0)
 
             // We want the alarm to go off 30 seconds from now.
-            var calendar:Calendar  = Calendar.getInstance();
-            calendar.setTimeInMillis(System.currentTimeMillis())
-            calendar.add(Calendar.SECOND, 30);
+            var calendar:Calendar = Calendar.getInstance()
+            calendar.timeInMillis=System.currentTimeMillis()
+            calendar.add(Calendar.SECOND, 30)
 
             // Schedule the alarm!
              val am:AlarmManager = getSystemService(ALARM_SERVICE) as (AlarmManager)

From f96574809bfd9831079ccf97ad9cfa784b518eba Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 03:05:23 +0900
Subject: [PATCH 14/34] apply plugin: 'kotlin-android-extensions'

---
 mobile/build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mobile/build.gradle b/mobile/build.gradle
index 0f3641797..d9279e47e 100644
--- a/mobile/build.gradle
+++ b/mobile/build.gradle
@@ -1,6 +1,6 @@
 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
-
+apply plugin: 'kotlin-android-extensions'
 android {
     compileSdkVersion 26
     buildToolsVersion "26.0.0"

From b3a28ad5c03430809b4bb9c3b3b1bdda80bb03b4 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 03:09:36 +0900
Subject: [PATCH 15/34] used extention code instead of findViewById

---
 .../main/java/com/example/android/apis/text/LogTextBox1.kt   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
index d0c332c26..75e5010e8 100644
--- a/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
+++ b/mobile/src/main/java/com/example/android/apis/text/LogTextBox1.kt
@@ -21,7 +21,7 @@ import com.example.android.apis.R;
 import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
-import android.widget.Button;
+import kotlinx.android.synthetic.main.log_text_box_1.*
 
 /**
  * Using a LogTextBox to display a scrollable text area
@@ -39,8 +39,7 @@ class LogTextBox1 : Activity() {
 
         val mText by lazy {
             findViewById<View>(R.id.text) as LogTextBox }
-        val addButton = findViewById<View>(R.id.add) as Button
-        addButton.setOnClickListener { mText.append("This is a test\n") }
+        add.setOnClickListener { mText.append("This is a test\n") }
     }
 }
 

From 1ae905ec95cd48b8c08c96972e72bdb7de4de5aa Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 03:41:36 +0900
Subject: [PATCH 16/34] convert AlarmService to kt

---
 .../android/apis/app/AlarmService.java        | 89 -------------------
 .../example/android/apis/app/AlarmService.kt  | 77 ++++++++++++++++
 2 files changed, 77 insertions(+), 89 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmService.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmService.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmService.java b/mobile/src/main/java/com/example/android/apis/app/AlarmService.java
deleted file mode 100644
index 151838ae2..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/AlarmService.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-import android.app.Activity;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.os.SystemClock;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-
-/**
- * This demonstrates how you can schedule an alarm that causes a service to
- * be started.  This is useful when you want to schedule alarms that initiate
- * long-running operations, such as retrieving recent e-mails.
- */
-public class AlarmService extends Activity {
-    private PendingIntent mAlarmSender;
-    
-    @Override
-	protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        // Create an IntentSender that will launch our service, to be scheduled
-        // with the alarm manager.
-        mAlarmSender = PendingIntent.getService(AlarmService.this,
-                0, new Intent(AlarmService.this, AlarmService_Service.class), 0);
-        
-        setContentView(R.layout.alarm_service);
-
-        // Watch for button clicks.
-        Button button = (Button)findViewById(R.id.start_alarm);
-        button.setOnClickListener(mStartAlarmListener);
-        button = (Button)findViewById(R.id.stop_alarm);
-        button.setOnClickListener(mStopAlarmListener);
-    }
-
-    private OnClickListener mStartAlarmListener = new OnClickListener() {
-        public void onClick(View v) {
-            // We want the alarm to go off 30 seconds from now.
-            long firstTime = SystemClock.elapsedRealtime();
-
-            // Schedule the alarm!
-            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
-            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                            firstTime, 30*1000, mAlarmSender);
-
-            // Tell the user about what we did.
-            Toast.makeText(AlarmService.this, R.string.repeating_scheduled,
-                    Toast.LENGTH_LONG).show();
-        }
-    };
-
-    private OnClickListener mStopAlarmListener = new OnClickListener() {
-        public void onClick(View v) {
-            // And cancel the alarm.
-            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
-            am.cancel(mAlarmSender);
-
-            // Tell the user about what we did.
-            Toast.makeText(AlarmService.this, R.string.repeating_unscheduled,
-                    Toast.LENGTH_LONG).show();
-
-        }
-    };
-}
diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmService.kt b/mobile/src/main/java/com/example/android/apis/app/AlarmService.kt
new file mode 100644
index 000000000..15b7e617f
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/AlarmService.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app;
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.os.SystemClock;
+import android.os.Bundle;
+import android.view.View.OnClickListener;
+import android.widget.Toast;
+import kotlinx.android.synthetic.main.alarm_service.*
+
+
+class AlarmService :  Activity() {
+     lateinit var  mAlarmSender : PendingIntent
+
+    override fun onCreate( savedInstanceState : Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        // Create an IntentSender that will launch our service, to be scheduled
+        // with the alarm manager.
+        mAlarmSender = PendingIntent.getService(this@AlarmService,
+                0, Intent(this@AlarmService, AlarmService_Service::class.java), 0)
+
+        setContentView(R.layout.alarm_service)
+
+        // Watch for button clicks.
+        start_alarm.setOnClickListener(mStartAlarmListener)
+        stop_alarm.setOnClickListener(mStopAlarmListener)
+    }
+
+    private val  mStartAlarmListener=  OnClickListener {
+            // We want the alarm to go off 30 seconds from now.
+            var firstTime : Long = SystemClock.elapsedRealtime()
+
+            // Schedule the alarm!
+            var am :AlarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
+            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                    firstTime, 30*1000, mAlarmSender)
+
+            // Tell the user about what we did.
+            Toast.makeText(this@AlarmService, R.string.repeating_scheduled,
+                    Toast.LENGTH_LONG).show()
+    }
+
+    private val  mStopAlarmListener = OnClickListener{
+            // And cancel the alarm.
+            var am :AlarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
+            am.cancel(mAlarmSender)
+
+            // Tell the user about what we did.
+            Toast.makeText(this@AlarmService, R.string.repeating_unscheduled,
+                    Toast.LENGTH_LONG).show()
+
+
+    }
+}
\ No newline at end of file

From aa830bf2c13024832c6472c219122009d3d9f820 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 19:02:09 +0900
Subject: [PATCH 17/34] FragmentAlertDialog converted to kt

---
 ...lertDialog.java => FragmentAlertDialog.kt} | 77 ++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)
 rename mobile/src/main/java/com/example/android/apis/app/{FragmentAlertDialog.java => FragmentAlertDialog.kt} (58%)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.java b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
similarity index 58%
rename from mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.java
rename to mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index 56ddc6b91..9efab7207 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.java
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -33,7 +33,7 @@
 /**
  * Demonstrates how to show an AlertDialog that is managed by a Fragment.
  */
-public class FragmentAlertDialog extends Activity {
+/*public class FragmentAlertDialog extends Activity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -106,4 +106,79 @@ public void onClick(DialogInterface dialog, int whichButton) {
         }
     }
 //END_INCLUDE(dialog)
+}*/
+class FragmentAlertDialog : Activity() {
+
+    override protected fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.fragment_dialog)
+
+        val tv = findViewById<TextView>(R.id.text)
+        tv.setText("Example of displaying an alert dialog with a DialogFragment")
+
+        // Watch for button clicks.
+        val button = findViewById<Button>(R.id.show)
+        button.setOnClickListener(OnClickListener {
+            showDialog()
+        })
+    }
+
+    //BEGIN_INCLUDE(activity)
+    fun showDialog() {
+        val newFragment: DialogFragment = MyAlertDialogFragment.newInstance(
+                R.string.alert_dialog_two_buttons_title)
+        newFragment.show(getFragmentManager(), "dialog")
+    }
+
+    fun doPositiveClick() {
+        // Do stuff here.
+        Log.i("FragmentAlertDialog", "Positive click!")
+    }
+
+    fun doNegativeClick() {
+        // Do stuff here.
+        Log.i("FragmentAlertDialog", "Negative click!")
+    }
+//END_INCLUDE(activity)
+
+    //BEGIN_INCLUDE(dialog)
+    //Question :: static class 는 어떻게 처리하는지 , static method const
+    public class MyAlertDialogFragment : DialogFragment() {
+        companion object {
+            @JvmStatic
+            fun newInstance(title: Int): MyAlertDialogFragment {
+                val frag = MyAlertDialogFragment()
+                val args = Bundle()
+                args.putInt("title", title)
+                frag.arguments = args
+                return frag
+            }
+        }
+
+
+        override
+        public fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+            val title: Int = arguments.getInt("title")
+
+            return AlertDialog.Builder(getActivity())
+                    .setIcon(R.drawable.alert_dialog_icon)
+                    .setTitle(title)
+                    .setPositiveButton(R.string.alert_dialog_ok,
+                            DialogInterface.OnClickListener {
+                                fun onClick(dialog: DialogInterface, whichButton: Int) {
+                                    FragmentAlertDialog::doPositiveClick
+                                }
+                            }
+                    )
+                    .setNegativeButton(R.string.alert_dialog_cancel,
+                            DialogInterface.OnClickListener{
+                                fun onClick(dialog: DialogInterface, whichButton: Int) {
+                                    FragmentAlertDialog::doNegativeClick
+                                }
+                            }
+                    )
+                    .create()
+        }
+    }
+//END_INCLUDE(dialog)
 }

From 294f902de2c24ff4f80efe225699ce7dcc21e29f Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 19:42:32 +0900
Subject: [PATCH 18/34] simplify DialogInterface.OnClickListener with Lamda

---
 .../android/apis/app/FragmentAlertDialog.kt   | 116 +++---------------
 1 file changed, 18 insertions(+), 98 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index 9efab7207..e5124879d 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -14,99 +14,26 @@
  * limitations under the License.
  */
 
-package com.example.android.apis.app;
-
-import com.example.android.apis.R;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.TextView;
+package com.example.android.apis.app
+
+import com.example.android.apis.R
+
+import android.app.Activity
+import android.app.AlertDialog
+import android.app.Dialog
+import android.app.DialogFragment
+import android.content.DialogInterface
+import android.os.Bundle
+import android.util.Log
+import android.view.View
+import android.view.View.OnClickListener
+import android.widget.Button
+import android.widget.TextView
 
 /**
  * Demonstrates how to show an AlertDialog that is managed by a Fragment.
  */
-/*public class FragmentAlertDialog extends Activity {
 
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.fragment_dialog);
-
-        View tv = findViewById(R.id.text);
-        ((TextView)tv).setText("Example of displaying an alert dialog with a DialogFragment");
-
-        // Watch for button clicks.
-        Button button = (Button)findViewById(R.id.show);
-        button.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-                showDialog();
-            }
-        });
-    }
-
-//BEGIN_INCLUDE(activity)
-    void showDialog() {
-        DialogFragment newFragment = MyAlertDialogFragment.newInstance(
-                R.string.alert_dialog_two_buttons_title);
-        newFragment.show(getFragmentManager(), "dialog");
-    }
-
-    public void doPositiveClick() {
-        // Do stuff here.
-        Log.i("FragmentAlertDialog", "Positive click!");
-    }
-    
-    public void doNegativeClick() {
-        // Do stuff here.
-        Log.i("FragmentAlertDialog", "Negative click!");
-    }
-//END_INCLUDE(activity)
-    
-//BEGIN_INCLUDE(dialog)
-    public static class MyAlertDialogFragment extends DialogFragment {
-
-        public static MyAlertDialogFragment newInstance(int title) {
-            MyAlertDialogFragment frag = new MyAlertDialogFragment();
-            Bundle args = new Bundle();
-            args.putInt("title", title);
-            frag.setArguments(args);
-            return frag;
-        }
-        
-        @Override
-        public Dialog onCreateDialog(Bundle savedInstanceState) {
-            int title = getArguments().getInt("title");
-            
-            return new AlertDialog.Builder(getActivity())
-                    .setIcon(R.drawable.alert_dialog_icon)
-                    .setTitle(title)
-                    .setPositiveButton(R.string.alert_dialog_ok,
-                        new DialogInterface.OnClickListener() {
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                ((FragmentAlertDialog)getActivity()).doPositiveClick();
-                            }
-                        }
-                    )
-                    .setNegativeButton(R.string.alert_dialog_cancel,
-                        new DialogInterface.OnClickListener() {
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                ((FragmentAlertDialog)getActivity()).doNegativeClick();
-                            }
-                        }
-                    )
-                    .create();
-        }
-    }
-//END_INCLUDE(dialog)
-}*/
 class FragmentAlertDialog : Activity() {
 
     override protected fun onCreate(savedInstanceState: Bundle?) {
@@ -164,21 +91,14 @@ class FragmentAlertDialog : Activity() {
                     .setIcon(R.drawable.alert_dialog_icon)
                     .setTitle(title)
                     .setPositiveButton(R.string.alert_dialog_ok,
-                            DialogInterface.OnClickListener {
-                                fun onClick(dialog: DialogInterface, whichButton: Int) {
-                                    FragmentAlertDialog::doPositiveClick
-                                }
-                            }
+                            {dialog, whichButton ->FragmentAlertDialog::doPositiveClick}
                     )
                     .setNegativeButton(R.string.alert_dialog_cancel,
-                            DialogInterface.OnClickListener{
-                                fun onClick(dialog: DialogInterface, whichButton: Int) {
-                                    FragmentAlertDialog::doNegativeClick
-                                }
-                            }
+                            {dialog, whichButton ->FragmentAlertDialog::doNegativeClick }
                     )
                     .create()
         }
     }
 //END_INCLUDE(dialog)
 }
+

From 5c595f5c9dd062c012f829058dab8610b06258da Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 19:46:13 +0900
Subject: [PATCH 19/34] add string resource for Fragment Alert Dialog msg

---
 .../java/com/example/android/apis/app/FragmentAlertDialog.kt    | 2 +-
 mobile/src/main/res/values/strings.xml                          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index e5124879d..70fce7269 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -41,7 +41,7 @@ class FragmentAlertDialog : Activity() {
         setContentView(R.layout.fragment_dialog)
 
         val tv = findViewById<TextView>(R.id.text)
-        tv.setText("Example of displaying an alert dialog with a DialogFragment")
+        tv.setText(R.string.fragment_alert_dialog_msg)
 
         // Watch for button clicks.
         val button = findViewById<Button>(R.id.show)
diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml
index 81df88925..2fe86221b 100644
--- a/mobile/src/main/res/values/strings.xml
+++ b/mobile/src/main/res/values/strings.xml
@@ -171,7 +171,7 @@
             screenshots and will not be mirrored to non-secure displays.</string>
 
     <string name="fragment_alert_dialog">App/Fragment/Alert Dialog</string>
-
+    <string name="fragment_alert_dialog_msg">Example of displaying an alert dialog with a DialogFragment</string>
     <string name="fragment_arguments">App/Fragment/Arguments</string>
     <string name="fragment_arguments_msg">Demonstrates a fragment that takes arguments
         as a Bundle at runtime (on the right) or from attributes in a layout (on the left).</string>

From 9fd3753fc2893d2864a90bb7139eb055467b3233 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 23:35:38 +0900
Subject: [PATCH 20/34] used extention code instead of findViewById

---
 .../com/example/android/apis/app/FragmentAlertDialog.kt    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index 70fce7269..38a25030f 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -29,6 +29,7 @@ import android.view.View
 import android.view.View.OnClickListener
 import android.widget.Button
 import android.widget.TextView
+import kotlinx.android.synthetic.main.fragment_dialog.*
 
 /**
  * Demonstrates how to show an AlertDialog that is managed by a Fragment.
@@ -40,12 +41,10 @@ class FragmentAlertDialog : Activity() {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.fragment_dialog)
 
-        val tv = findViewById<TextView>(R.id.text)
-        tv.setText(R.string.fragment_alert_dialog_msg)
+        text.setText(R.string.fragment_alert_dialog_msg)
 
         // Watch for button clicks.
-        val button = findViewById<Button>(R.id.show)
-        button.setOnClickListener(OnClickListener {
+        show.setOnClickListener(OnClickListener {
             showDialog()
         })
     }

From 957b74dc2290ec05e5a224489330c91248d37385 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 23:39:40 +0900
Subject: [PATCH 21/34] applied lamda to onClickListener

---
 .../java/com/example/android/apis/app/FragmentAlertDialog.kt  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index 38a25030f..b98611150 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -44,9 +44,9 @@ class FragmentAlertDialog : Activity() {
         text.setText(R.string.fragment_alert_dialog_msg)
 
         // Watch for button clicks.
-        show.setOnClickListener(OnClickListener {
+        show.setOnClickListener {
             showDialog()
-        })
+        }
     }
 
     //BEGIN_INCLUDE(activity)

From fe87cbab392e849e40d21dcc0a21b4d1e1694dbd Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 12 Aug 2017 23:46:19 +0900
Subject: [PATCH 22/34] used kotlin properies instead

---
 .../com/example/android/apis/app/FragmentAlertDialog.kt     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index b98611150..30cc16ee0 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -41,6 +41,7 @@ class FragmentAlertDialog : Activity() {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.fragment_dialog)
 
+        //Display text on Screen
         text.setText(R.string.fragment_alert_dialog_msg)
 
         // Watch for button clicks.
@@ -53,7 +54,7 @@ class FragmentAlertDialog : Activity() {
     fun showDialog() {
         val newFragment: DialogFragment = MyAlertDialogFragment.newInstance(
                 R.string.alert_dialog_two_buttons_title)
-        newFragment.show(getFragmentManager(), "dialog")
+        newFragment.show(fragmentManager, "dialog")
     }
 
     fun doPositiveClick() {
@@ -68,7 +69,7 @@ class FragmentAlertDialog : Activity() {
 //END_INCLUDE(activity)
 
     //BEGIN_INCLUDE(dialog)
-    //Question :: static class 는 어떻게 처리하는지 , static method const
+    //-> static class 는 어떻게 처리하는지 , static method const
     public class MyAlertDialogFragment : DialogFragment() {
         companion object {
             @JvmStatic
@@ -81,7 +82,6 @@ class FragmentAlertDialog : Activity() {
             }
         }
 
-
         override
         public fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
             val title: Int = arguments.getInt("title")

From 829252c79094e2781726efe1c61830d19b16b53e Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 13 Aug 2017 00:32:35 +0900
Subject: [PATCH 23/34] fixed FragmentAlertDialog::doPositiceClick to (activity
 as Fragment) , if not ,  doesn't work

---
 .../android/apis/app/FragmentAlertDialog.kt   | 27 +++++++------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
index 30cc16ee0..77394080f 100644
--- a/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/FragmentAlertDialog.kt
@@ -12,12 +12,11 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */
+*/
 
 package com.example.android.apis.app
 
 import com.example.android.apis.R
-
 import android.app.Activity
 import android.app.AlertDialog
 import android.app.Dialog
@@ -25,15 +24,10 @@ import android.app.DialogFragment
 import android.content.DialogInterface
 import android.os.Bundle
 import android.util.Log
-import android.view.View
-import android.view.View.OnClickListener
-import android.widget.Button
-import android.widget.TextView
+import android.widget.Toast
 import kotlinx.android.synthetic.main.fragment_dialog.*
 
-/**
- * Demonstrates how to show an AlertDialog that is managed by a Fragment.
- */
+/** Demonstrates how to show an AlertDialog that is managed by a Fragment.*/
 
 class FragmentAlertDialog : Activity() {
 
@@ -69,7 +63,7 @@ class FragmentAlertDialog : Activity() {
 //END_INCLUDE(activity)
 
     //BEGIN_INCLUDE(dialog)
-    //-> static class 는 어떻게 처리하는지 , static method const
+    //-> static class , static method const
     public class MyAlertDialogFragment : DialogFragment() {
         companion object {
             @JvmStatic
@@ -86,18 +80,15 @@ class FragmentAlertDialog : Activity() {
         public fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
             val title: Int = arguments.getInt("title")
 
-            return AlertDialog.Builder(getActivity())
+            return AlertDialog.Builder(activity)
                     .setIcon(R.drawable.alert_dialog_icon)
                     .setTitle(title)
-                    .setPositiveButton(R.string.alert_dialog_ok,
-                            {dialog, whichButton ->FragmentAlertDialog::doPositiveClick}
-                    )
-                    .setNegativeButton(R.string.alert_dialog_cancel,
-                            {dialog, whichButton ->FragmentAlertDialog::doNegativeClick }
-                    )
+                    .setPositiveButton(R.string.alert_dialog_ok
+                    ) { dialog, whichButton -> (activity as FragmentAlertDialog).doPositiveClick() }
+                    .setNegativeButton(R.string.alert_dialog_cancel
+                    ) { dialog, whichButton -> (activity as FragmentAlertDialog).doNegativeClick() }
                     .create()
         }
     }
 //END_INCLUDE(dialog)
 }
-

From dad4a72e9c7515527a6d688c020034edb5a25bbe Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sat, 26 Aug 2017 21:36:27 +0900
Subject: [PATCH 24/34] Convert AlarmService_service to kotlin

---
 .../apis/app/AlarmService_Service.java        | 133 ------------------
 .../android/apis/app/AlarmService_Service.kt  | 127 +++++++++++++++++
 2 files changed, 127 insertions(+), 133 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.java b/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.java
deleted file mode 100644
index cede9dced..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.RemoteException;
-import android.widget.Toast;
-
-/**
- * This is an example of implementing an application service that will run in
- * response to an alarm, allowing us to move long duration work out of an
- * intent receiver.
- * 
- * @see AlarmService
- * @see AlarmService_Alarm
- */
-public class AlarmService_Service extends Service {
-    NotificationManager mNM;
-
-    @Override
-    public void onCreate() {
-        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
-
-        // show the icon in the status bar
-        showNotification();
-
-        // Start up the thread running the service.  Note that we create a
-        // separate thread because the service normally runs in the process's
-        // main thread, which we don't want to block.
-        Thread thr = new Thread(null, mTask, "AlarmService_Service");
-        thr.start();
-    }
-
-    @Override
-    public void onDestroy() {
-        // Cancel the notification -- we use the same ID that we had used to start it
-        mNM.cancel(R.string.alarm_service_started);
-
-        // Tell the user we stopped.
-        Toast.makeText(this, R.string.alarm_service_finished, Toast.LENGTH_SHORT).show();
-    }
-
-    /**
-     * The function that runs in our worker thread
-     */
-    Runnable mTask = new Runnable() {
-        public void run() {
-            // Normally we would do some work here...  for our sample, we will
-            // just sleep for 30 seconds.
-            long endTime = System.currentTimeMillis() + 15*1000;
-            while (System.currentTimeMillis() < endTime) {
-                synchronized (mBinder) {
-                    try {
-                        mBinder.wait(endTime - System.currentTimeMillis());
-                    } catch (Exception e) {
-                    }
-                }
-            }
-
-            // Done with our work...  stop the service!
-            AlarmService_Service.this.stopSelf();
-        }
-    };
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return mBinder;
-    }
-
-    /**
-     * Show a notification while this service is running.
-     */
-    private void showNotification() {
-        // In this sample, we'll use the same text for the ticker and the expanded notification
-        CharSequence text = getText(R.string.alarm_service_started);
-
-        // The PendingIntent to launch our activity if the user selects this notification
-        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-                new Intent(this, AlarmService.class), 0);
-
-        // Set the info for the views that show in the notification panel.
-        Notification notification = new Notification.Builder(this)
-                .setSmallIcon(R.drawable.stat_sample)  // the status icon
-                .setTicker(text)  // the status text
-                .setWhen(System.currentTimeMillis())  // the time stamp
-                .setContentTitle(getText(R.string.alarm_service_label))  // the label of the entry
-                .setContentText(text)  // the contents of the entry
-                .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
-                .build();
-
-        // Send the notification.
-        // We use a layout id because it is a unique number.  We use it later to cancel.
-        mNM.notify(R.string.alarm_service_started, notification);
-    }
-
-    /**
-     * This is the object that receives interactions from clients.  See RemoteService
-     * for a more complete example.
-     */
-    private final IBinder mBinder = new Binder() {
-        @Override
-		protected boolean onTransact(int code, Parcel data, Parcel reply,
-		        int flags) throws RemoteException {
-            return super.onTransact(code, data, reply, flags);
-        }
-    };
-}
-
diff --git a/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.kt b/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.kt
new file mode 100644
index 000000000..49cc3edef
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/AlarmService_Service.kt
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Intent
+import android.os.Binder
+import android.os.IBinder
+import android.os.Parcel
+import android.os.RemoteException
+import android.widget.Toast
+
+/**
+ * This is an example of implementing an application service that will run in
+ * response to an alarm, allowing us to move long duration work out of an
+ * intent receiver.
+
+ * @see AlarmService
+
+ * @see AlarmService_Alarm
+ */
+class AlarmService_Service : Service() {
+    lateinit var mNM: NotificationManager
+
+    override fun onCreate() {
+        mNM = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
+
+        // show the icon in the status bar
+        showNotification()
+
+        // Start up the thread running the service.  Note that we create a
+        // separate thread because the service normally runs in the process's
+        // main thread, which we don't want to block.
+        var thr: Thread = Thread(null, mTask, "AlarmService_Service")
+        thr.start()
+    }
+
+    override fun onDestroy() {
+        // Cancel the notification -- we use the same ID that we had used to start it
+        mNM.cancel(R.string.alarm_service_started)
+
+        // Tell the user we stopped.
+        Toast.makeText(this, R.string.alarm_service_finished, Toast.LENGTH_SHORT).show()
+    }
+
+
+    // The function that runs in our worker thread
+
+    val mTask: Runnable = Runnable {
+        // Normally we would do some work here...  for our sample, we will
+        // just sleep for 30 seconds.
+        var endTime: Long = System.currentTimeMillis() + 15 * 1000
+        while (System.currentTimeMillis() < endTime) {
+            synchronized(mBinder) {
+                try {
+                    // mBinder.wait(endTime - System.currentTimeMillis())
+                } catch (e: Exception) {
+                }
+
+            }
+        }
+
+        // Done with our work...  stop the service!
+        this@AlarmService_Service.stopSelf()
+    }
+
+    override public fun onBind(intent: Intent?): IBinder {
+        return mBinder
+    }
+
+    // Show a notification while this service is running.
+
+    private fun showNotification() {
+        // In this sample, we'll use the same text for the ticker and the expanded notification
+        val text: CharSequence = getText(R.string.alarm_service_started)
+
+        // The PendingIntent to launch our activity if the user selects this notification
+        var contentIntent: PendingIntent = PendingIntent.getActivity(this, 0,
+                Intent(applicationContext, AlarmService::class.java), 0)
+
+        // Set the info for the views that show in the notification panel.
+        var notification: Notification = Notification.Builder(this)
+                .setSmallIcon(R.drawable.stat_sample)  // the status icon
+                .setTicker(text)  // the status text
+                .setWhen(System.currentTimeMillis())  // the time stamp
+                .setContentTitle(getText(R.string.alarm_service_label))  // the label of the entry
+                .setContentText(text)  // the contents of the entry
+                .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
+                .build()
+
+        // Send the notification.
+        // We use a layout id because it is a unique number.  We use it later to cancel.
+        mNM.notify(R.string.alarm_service_started, notification)
+    }
+
+    /* * This is the object that receives interactions from clients.  See RemoteService
+     * for a more complete example.*/
+    
+    private val mBinder = object : Binder() {
+        @Throws(RemoteException::class)
+        override fun onTransact(code: Int, data: Parcel, reply: Parcel,
+                                flags: Int): Boolean {
+            return super.onTransact(code, data, reply, flags)
+        }
+    }
+}

From 94cabb8f24dedc73e3ce3f07e0752701f75d2edc Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 02:18:52 +0900
Subject: [PATCH 25/34] Convert IsolatedService to Kotlin

---
 .../android/apis/app/IsolatedService.java     | 206 ------------------
 .../android/apis/app/IsolatedService.kt       | 188 ++++++++++++++++
 2 files changed, 188 insertions(+), 206 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/IsolatedService.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/IsolatedService.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/IsolatedService.java b/mobile/src/main/java/com/example/android/apis/app/IsolatedService.java
deleted file mode 100644
index bf3c52384..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/IsolatedService.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-import android.app.Activity;
-import android.app.Service;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.IBinder;
-import android.os.RemoteCallbackList;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.TextView;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-/**
- * This is an example if implementing a Service that uses android:isolatedProcess.
- */
-public class IsolatedService extends Service {
-    /**
-     * This is a list of callbacks that have been registered with the
-     * service.  Note that this is package scoped (instead of private) so
-     * that it can be accessed more efficiently from inner classes.
-     */
-    final RemoteCallbackList<IRemoteServiceCallback> mCallbacks
-            = new RemoteCallbackList<IRemoteServiceCallback>();
-    
-    int mValue = 0;
-    
-    @Override
-    public void onCreate() {
-        Log.i("IsolatedService", "Creating IsolatedService: " + this);
-    }
-
-    @Override
-    public void onDestroy() {
-        Log.i("IsolatedService", "Destroying IsolatedService: " + this);
-        // Unregister all callbacks.
-        mCallbacks.kill();
-    }
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return mBinder;
-    }
-
-    /**
-     * The IRemoteInterface is defined through IDL
-     */
-    private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
-        public void registerCallback(IRemoteServiceCallback cb) {
-            if (cb != null) mCallbacks.register(cb);
-        }
-        public void unregisterCallback(IRemoteServiceCallback cb) {
-            if (cb != null) mCallbacks.unregister(cb);
-        }
-    };
-    
-    @Override
-    public void onTaskRemoved(Intent rootIntent) {
-        Log.i("IsolatedService", "Task removed in " + this + ": " + rootIntent);
-        stopSelf();
-    }
-
-    private void broadcastValue(int value) {
-        // Broadcast to all clients the new value.
-        final int N = mCallbacks.beginBroadcast();
-        for (int i=0; i<N; i++) {
-            try {
-                mCallbacks.getBroadcastItem(i).valueChanged(value);
-            } catch (RemoteException e) {
-                // The RemoteCallbackList will take care of removing
-                // the dead object for us.
-            }
-        }
-        mCallbacks.finishBroadcast();
-    }
-    
-    // ----------------------------------------------------------------------
-    
-    public static class Controller extends Activity {
-        static class ServiceInfo {
-            final Activity mActivity;
-            final Class<?> mClz;
-            final TextView mStatus;
-            boolean mServiceBound;
-            IRemoteService mService;
-
-            ServiceInfo(Activity activity, Class<?> clz,
-                    int start, int stop, int bind, int status) {
-                mActivity = activity;
-                mClz = clz;
-                Button button = (Button)mActivity.findViewById(start);
-                button.setOnClickListener(mStartListener);
-                button = (Button)mActivity.findViewById(stop);
-                button.setOnClickListener(mStopListener);
-                CheckBox cb = (CheckBox)mActivity.findViewById(bind);
-                cb.setOnClickListener(mBindListener);
-                mStatus = (TextView)mActivity.findViewById(status);
-            }
-
-            void destroy() {
-                if (mServiceBound) {
-                    mActivity.unbindService(mConnection);
-                }
-            }
-
-            private OnClickListener mStartListener = new OnClickListener() {
-                public void onClick(View v) {
-                    mActivity.startService(new Intent(mActivity, mClz));
-                }
-            };
-
-            private OnClickListener mStopListener = new OnClickListener() {
-                public void onClick(View v) {
-                    mActivity.stopService(new Intent(mActivity, mClz));
-                }
-            };
-
-            private OnClickListener mBindListener = new OnClickListener() {
-                public void onClick(View v) {
-                    if (((CheckBox)v).isChecked()) {
-                        if (!mServiceBound) {
-                            if (mActivity.bindService(new Intent(mActivity, mClz),
-                                    mConnection, Context.BIND_AUTO_CREATE)) {
-                                mServiceBound = true;
-                                mStatus.setText("BOUND");
-                            }
-                        }
-                    } else {
-                        if (mServiceBound) {
-                            mActivity.unbindService(mConnection);
-                            mServiceBound = false;
-                            mStatus.setText("");
-                        }
-                    }
-                }
-            };
-
-            private ServiceConnection mConnection = new ServiceConnection() {
-                public void onServiceConnected(ComponentName className,
-                        IBinder service) {
-                    mService = IRemoteService.Stub.asInterface(service);
-                    if (mServiceBound) {
-                        mStatus.setText("CONNECTED");
-                    }
-                }
-
-                public void onServiceDisconnected(ComponentName className) {
-                    // This is called when the connection with the service has been
-                    // unexpectedly disconnected -- that is, its process crashed.
-                    mService = null;
-                    if (mServiceBound) {
-                        mStatus.setText("DISCONNECTED");
-                    }
-                }
-            };
-        }
-
-        ServiceInfo mService1;
-        ServiceInfo mService2;
-
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-
-            setContentView(R.layout.isolated_service_controller);
-
-            mService1 = new ServiceInfo(this, IsolatedService.class, R.id.start1, R.id.stop1,
-                    R.id.bind1, R.id.status1);
-            mService2 = new ServiceInfo(this, IsolatedService2.class, R.id.start2, R.id.stop2,
-                    R.id.bind2, R.id.status2);
-        }
-
-        @Override
-        protected void onDestroy() {
-            super.onDestroy();
-            mService1.destroy();
-            mService2.destroy();
-        }
-    }
-}
diff --git a/mobile/src/main/java/com/example/android/apis/app/IsolatedService.kt b/mobile/src/main/java/com/example/android/apis/app/IsolatedService.kt
new file mode 100644
index 000000000..874051470
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/IsolatedService.kt
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+import android.app.Activity
+import android.app.Service
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.content.ServiceConnection
+import android.os.Bundle
+import android.os.RemoteException
+import android.os.IBinder
+import android.os.RemoteCallbackList
+import android.util.Log
+import android.view.View
+import android.view.View.OnClickListener
+import android.widget.Button
+import android.widget.CheckBox
+import android.widget.TextView
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R
+
+/**
+ * This is an example if implementing a Service that uses android:isolatedProcess.
+ */
+open class IsolatedService : Service() {
+    /**
+     * This is a list of callbacks that have been registered with the
+     * service.  Note that this is package scoped (instead of private) so
+     * that it can be accessed more efficiently from inner classes.
+     */
+    internal val mCallbacks = RemoteCallbackList<IRemoteServiceCallback>()
+
+    internal var mValue = 0
+
+    override fun onCreate() {
+        Log.i("IsolatedService", "Creating IsolatedService: " + this)
+    }
+
+    override fun onDestroy() {
+        Log.i("IsolatedService", "Destroying IsolatedService: " + this)
+        // Unregister all callbacks.
+        mCallbacks.kill()
+    }
+
+    override fun onBind(intent: Intent): IBinder? {
+        return mBinder
+    }
+
+    /**
+     * The IRemoteInterface is defined through IDL
+     */
+    private val mBinder = object : IRemoteService.Stub() {
+        override fun registerCallback(cb: IRemoteServiceCallback?) {
+            if (cb != null) mCallbacks.register(cb)
+        }
+
+        override fun unregisterCallback(cb: IRemoteServiceCallback?) {
+            if (cb != null) mCallbacks.unregister(cb)
+        }
+    }
+
+    override fun onTaskRemoved(rootIntent: Intent) {
+        Log.i("IsolatedService", "Task removed in " + this + ": " + rootIntent)
+        stopSelf()
+    }
+
+    private fun broadcastValue(value: Int) {
+        // Broadcast to all clients the new value.
+        val N = mCallbacks.beginBroadcast()
+        for (i in 0..N - 1) {
+            try {
+                mCallbacks.getBroadcastItem(i).valueChanged(value)
+            } catch (e: RemoteException) {
+                // The RemoteCallbackList will take care of removing
+                // the dead object for us.
+            }
+
+        }
+        mCallbacks.finishBroadcast()
+    }
+
+    // ----------------------------------------------------------------------
+
+    class Controller : Activity() {
+        internal class ServiceInfo(val mActivity: Activity, val mClz: Class<*>,
+                                   start: Int, stop: Int, bind: Int, status: Int) {
+            lateinit var mStatus: TextView
+            var mServiceBound: Boolean = false
+            var mService: IRemoteService? = null
+
+
+
+            fun destroy() {
+                if (mServiceBound) {
+                    mActivity.unbindService(mConnection)
+                }
+            }
+
+            private val mStartListener = OnClickListener { mActivity.startService(Intent(mActivity, mClz)) }
+
+            private val mStopListener = OnClickListener { mActivity.stopService(Intent(mActivity, mClz)) }
+
+            private val mBindListener = OnClickListener { v ->
+                if ((v as CheckBox).isChecked) {
+                    if (!mServiceBound) {
+                        if (mActivity.bindService(Intent(mActivity, mClz),
+                                mConnection, Context.BIND_AUTO_CREATE)) {
+                            mServiceBound = true
+                            mStatus.text = "BOUND"
+                        }
+                    }
+                } else {
+                    if (mServiceBound) {
+                        mActivity.unbindService(mConnection)
+                        mServiceBound = false
+                        mStatus.text = ""
+                    }
+                }
+            }
+            init {
+                var button = mActivity.findViewById<View>(start) as Button
+                button.setOnClickListener(mStartListener)
+                button = mActivity.findViewById<View>(stop) as Button
+                button.setOnClickListener(mStopListener)
+                val cb = mActivity.findViewById<View>(bind) as CheckBox
+                cb.setOnClickListener(mBindListener)
+                mStatus = mActivity.findViewById<View>(status) as TextView
+            }
+
+            private val mConnection = object : ServiceConnection {
+                override fun onServiceConnected(className: ComponentName,
+                                                service: IBinder) {
+                    mService = IRemoteService.Stub.asInterface(service)
+                    if (mServiceBound) {
+                        mStatus.text = "CONNECTED"
+                    }
+                }
+
+                override fun onServiceDisconnected(className: ComponentName) {
+                    // This is called when the connection with the service has been
+                    // unexpectedly disconnected -- that is, its process crashed.
+                    mService = null
+                    if (mServiceBound) {
+                        mStatus.text = "DISCONNECTED"
+                    }
+                }
+            }
+        }
+
+        internal lateinit var mService1: ServiceInfo
+        internal lateinit var mService2: ServiceInfo
+
+        override fun onCreate(savedInstanceState: Bundle?) {
+            super.onCreate(savedInstanceState)
+
+            setContentView(R.layout.isolated_service_controller)
+
+            mService1 = ServiceInfo(this, IsolatedService::class.java, R.id.start1, R.id.stop1,
+                    R.id.bind1, R.id.status1)
+            mService2 = ServiceInfo(this, IsolatedService2::class.java, R.id.start2, R.id.stop2,
+                    R.id.bind2, R.id.status2)
+        }
+
+        override fun onDestroy() {
+            super.onDestroy()
+            mService1.destroy()
+            mService2.destroy()
+        }
+    }
+}

From f186edd04ceb50c7263927453ebd49e3173921d8 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 02:19:23 +0900
Subject: [PATCH 26/34] Convert IsolatedService2 to Kotlin

---
 .../apis/app/{IsolatedService2.java => IsolatedService2.kt} | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/app/{IsolatedService2.java => IsolatedService2.kt} (87%)

diff --git a/mobile/src/main/java/com/example/android/apis/app/IsolatedService2.java b/mobile/src/main/java/com/example/android/apis/app/IsolatedService2.kt
similarity index 87%
rename from mobile/src/main/java/com/example/android/apis/app/IsolatedService2.java
rename to mobile/src/main/java/com/example/android/apis/app/IsolatedService2.kt
index d313a67a8..a87f7065b 100644
--- a/mobile/src/main/java/com/example/android/apis/app/IsolatedService2.java
+++ b/mobile/src/main/java/com/example/android/apis/app/IsolatedService2.kt
@@ -14,11 +14,9 @@
  * limitations under the License.
  */
 
-package com.example.android.apis.app;
+package com.example.android.apis.app
 
 /**
  * Stub to be able to have another instance of IsolatedService running.
  */
-public class IsolatedService2 extends IsolatedService {
-
-}
+class IsolatedService2 : IsolatedService()

From df1376199200848d72d493ce5e26da30ec796109 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 02:24:44 +0900
Subject: [PATCH 27/34] Convert LocalService to Kotlin

---
 .../{LocalService.java => LocalService.kt}    | 90 +++++++++----------
 1 file changed, 43 insertions(+), 47 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/app/{LocalService.java => LocalService.kt} (57%)

diff --git a/mobile/src/main/java/com/example/android/apis/app/LocalService.java b/mobile/src/main/java/com/example/android/apis/app/LocalService.kt
similarity index 57%
rename from mobile/src/main/java/com/example/android/apis/app/LocalService.java
rename to mobile/src/main/java/com/example/android/apis/app/LocalService.kt
index a3742ca6a..a34a3a334 100644
--- a/mobile/src/main/java/com/example/android/apis/app/LocalService.java
+++ b/mobile/src/main/java/com/example/android/apis/app/LocalService.kt
@@ -14,108 +14,104 @@
  * limitations under the License.
  */
 
-package com.example.android.apis.app;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.PowerManager;
-import android.util.Log;
-import android.widget.Toast;
+package com.example.android.apis.app
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Intent
+import android.os.Binder
+import android.os.IBinder
+import android.os.PowerManager
+import android.util.Log
+import android.widget.Toast
 
 // Need the following import to get access to the app resources, since this
 // class is in a sub-package.
-import com.example.android.apis.R;
+import com.example.android.apis.R
 
 /**
  * This is an example of implementing an application service that runs locally
- * in the same process as the application.  The {@link LocalServiceActivities.Controller}
- * and {@link LocalServiceActivities.Binding} classes show how to interact with the
+ * in the same process as the application.  The [LocalServiceActivities.Controller]
+ * and [LocalServiceActivities.Binding] classes show how to interact with the
  * service.
+
  *
- * <p>Notice the use of the {@link NotificationManager} when interesting things
+ * Notice the use of the [NotificationManager] when interesting things
  * happen in the service.  This is generally how background services should
  * interact with the user, rather than doing something more disruptive such as
  * calling startActivity().
  */
 //BEGIN_INCLUDE(service)
-public class LocalService extends Service {
-    private NotificationManager mNM;
+class LocalService : Service() {
+    private var mNM: NotificationManager? = null
 
     // Unique Identification Number for the Notification.
     // We use it on Notification start, and to cancel it.
-    private int NOTIFICATION = R.string.local_service_started;
+    private val NOTIFICATION = R.string.local_service_started
 
     /**
      * Class for clients to access.  Because we know this service always
      * runs in the same process as its clients, we don't need to deal with
      * IPC.
      */
-    public class LocalBinder extends Binder {
-        LocalService getService() {
-            return LocalService.this;
-        }
+    inner class LocalBinder : Binder() {
+        internal val service: LocalService
+            get() = this@LocalService
     }
-    
-    @Override
-    public void onCreate() {
-        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
+
+    override fun onCreate() {
+        mNM = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
 
         // Display a notification about us starting.  We put an icon in the status bar.
-        showNotification();
+        showNotification()
     }
 
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
-        Log.i("LocalService", "Received start id " + startId + ": " + intent);
-        return START_NOT_STICKY;
+    override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
+        Log.i("LocalService", "Received start id $startId: $intent")
+        return Service.START_NOT_STICKY
     }
 
-    @Override
-    public void onDestroy() {
+    override fun onDestroy() {
         // Cancel the persistent notification.
-        mNM.cancel(NOTIFICATION);
+        mNM!!.cancel(NOTIFICATION)
 
         // Tell the user we stopped.
-        Toast.makeText(this, R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
+        Toast.makeText(this, R.string.local_service_stopped, Toast.LENGTH_SHORT).show()
     }
 
-    @Override
-    public IBinder onBind(Intent intent) {
-        return mBinder;
+    override fun onBind(intent: Intent): IBinder? {
+        return mBinder
     }
 
     // This is the object that receives interactions from clients.  See
     // RemoteService for a more complete example.
-    private final IBinder mBinder = new LocalBinder();
+    private val mBinder = LocalBinder()
 
     /**
      * Show a notification while this service is running.
      */
-    private void showNotification() {
+    private fun showNotification() {
         // In this sample, we'll use the same text for the ticker and the expanded notification
-        CharSequence text = getText(R.string.local_service_started);
+        val text = getText(R.string.local_service_started)
 
         // The PendingIntent to launch our activity if the user selects this notification
-        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-                new Intent(this, LocalServiceActivities.Controller.class), 0);
+        val contentIntent = PendingIntent.getActivity(this, 0,
+                Intent(this, LocalServiceActivities.Controller::class.java), 0)
 
         // Set the info for the views that show in the notification panel.
-        Notification notification = new Notification.Builder(this)
+        val notification = Notification.Builder(this)
                 .setSmallIcon(R.drawable.stat_sample)  // the status icon
                 .setTicker(text)  // the status text
                 .setWhen(System.currentTimeMillis())  // the time stamp
                 .setContentTitle(getText(R.string.local_service_label))  // the label of the entry
                 .setContentText(text)  // the contents of the entry
                 .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
-                .build();
+                .build()
 
         // Send the notification.
-        mNM.notify(NOTIFICATION, notification);
+        mNM!!.notify(NOTIFICATION, notification)
     }
 }
 //END_INCLUDE(service)

From 5f54bf2ef587dffab8b181f791ed948866ac7159 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 02:26:15 +0900
Subject: [PATCH 28/34] Import Context

---
 .../src/main/java/com/example/android/apis/app/LocalService.kt   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mobile/src/main/java/com/example/android/apis/app/LocalService.kt b/mobile/src/main/java/com/example/android/apis/app/LocalService.kt
index a34a3a334..b0e5a39b6 100644
--- a/mobile/src/main/java/com/example/android/apis/app/LocalService.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/LocalService.kt
@@ -20,6 +20,7 @@ import android.app.Notification
 import android.app.NotificationManager
 import android.app.PendingIntent
 import android.app.Service
+import android.content.Context
 import android.content.Intent
 import android.os.Binder
 import android.os.IBinder

From 45480b890c94ae0eaee992f451012a7fb8e6cbc5 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 02:26:40 +0900
Subject: [PATCH 29/34] Convert LocalServiceActivies to Kotlin

---
 .../apis/app/LocalServiceActivities.java      | 171 ------------------
 .../apis/app/LocalServiceActivities.kt        | 158 ++++++++++++++++
 2 files changed, 158 insertions(+), 171 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.java b/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.java
deleted file mode 100644
index a6c3fd822..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-import com.example.android.apis.R;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-public class LocalServiceActivities {
-    /**
-     * <p>Example of explicitly starting and stopping the local service.
-     * This demonstrates the implementation of a service that runs in the same
-     * process as the rest of the application, which is explicitly started and stopped
-     * as desired.</p>
-     * 
-     * <p>Note that this is implemented as an inner class only keep the sample
-     * all together; typically this code would appear in some separate class.
-     */
-    public static class Controller extends Activity {
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-
-            setContentView(R.layout.local_service_controller);
-
-            // Watch for button clicks.
-            Button button = (Button)findViewById(R.id.start);
-            button.setOnClickListener(mStartListener);
-            button = (Button)findViewById(R.id.stop);
-            button.setOnClickListener(mStopListener);
-        }
-
-        private OnClickListener mStartListener = new OnClickListener() {
-            public void onClick(View v) {
-                // Make sure the service is started.  It will continue running
-                // until someone calls stopService().  The Intent we use to find
-                // the service explicitly specifies our service component, because
-                // we want it running in our own process and don't want other
-                // applications to replace it.
-                startService(new Intent(Controller.this,
-                        LocalService.class));
-            }
-        };
-
-        private OnClickListener mStopListener = new OnClickListener() {
-            public void onClick(View v) {
-                // Cancel a previous call to startService().  Note that the
-                // service will not actually stop at this point if there are
-                // still bound clients.
-                stopService(new Intent(Controller.this,
-                        LocalService.class));
-            }
-        };
-    }
-
-    // ----------------------------------------------------------------------
-
-    /**
-     * Example of binding and unbinding to the local service.
-     * This demonstrates the implementation of a service which the client will
-     * bind to, receiving an object through which it can communicate with the service.</p>
-     * 
-     * <p>Note that this is implemented as an inner class only keep the sample
-     * all together; typically this code would appear in some separate class.
-     */
-    public static class Binding extends Activity {
-        private boolean mIsBound;
-
-// BEGIN_INCLUDE(bind)
-        private LocalService mBoundService;
-        
-        private ServiceConnection mConnection = new ServiceConnection() {
-            public void onServiceConnected(ComponentName className, IBinder service) {
-                // This is called when the connection with the service has been
-                // established, giving us the service object we can use to
-                // interact with the service.  Because we have bound to a explicit
-                // service that we know is running in our own process, we can
-                // cast its IBinder to a concrete class and directly access it.
-                mBoundService = ((LocalService.LocalBinder)service).getService();
-                
-                // Tell the user about this for our demo.
-                Toast.makeText(Binding.this, R.string.local_service_connected,
-                        Toast.LENGTH_SHORT).show();
-            }
-
-            public void onServiceDisconnected(ComponentName className) {
-                // This is called when the connection with the service has been
-                // unexpectedly disconnected -- that is, its process crashed.
-                // Because it is running in our same process, we should never
-                // see this happen.
-                mBoundService = null;
-                Toast.makeText(Binding.this, R.string.local_service_disconnected,
-                        Toast.LENGTH_SHORT).show();
-            }
-        };
-        
-        void doBindService() {
-            // Establish a connection with the service.  We use an explicit
-            // class name because we want a specific service implementation that
-            // we know will be running in our own process (and thus won't be
-            // supporting component replacement by other applications).
-            bindService(new Intent(Binding.this, 
-                    LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
-            mIsBound = true;
-        }
-        
-        void doUnbindService() {
-            if (mIsBound) {
-                // Detach our existing connection.
-                unbindService(mConnection);
-                mIsBound = false;
-            }
-        }
-        
-        @Override
-        protected void onDestroy() {
-            super.onDestroy();
-            doUnbindService();
-        }
-// END_INCLUDE(bind)
-
-        private OnClickListener mBindListener = new OnClickListener() {
-            public void onClick(View v) {
-                doBindService();
-            }
-        };
-
-        private OnClickListener mUnbindListener = new OnClickListener() {
-            public void onClick(View v) {
-                doUnbindService();
-            }
-        };
-        
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-
-            setContentView(R.layout.local_service_binding);
-
-            // Watch for button clicks.
-            Button button = (Button)findViewById(R.id.bind);
-            button.setOnClickListener(mBindListener);
-            button = (Button)findViewById(R.id.unbind);
-            button.setOnClickListener(mUnbindListener);
-        }
-    }
-}
diff --git a/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt b/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt
new file mode 100644
index 000000000..2ea927497
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+import com.example.android.apis.R
+
+import android.app.Activity
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.content.ServiceConnection
+import android.os.Bundle
+import android.os.IBinder
+import android.view.View
+import android.view.View.OnClickListener
+import android.widget.Button
+import android.widget.Toast
+import kotlinx.android.synthetic.main.local_service_binding.*
+
+class LocalServiceActivities {
+    /**
+     *
+     * Example of explicitly starting and stopping the local service.
+     * This demonstrates the implementation of a service that runs in the same
+     * process as the rest of the application, which is explicitly started and stopped
+     * as desired.
+
+     *
+     * Note that this is implemented as an inner class only keep the sample
+     * all together; typically this code would appear in some separate class.
+     */
+    class Controller : Activity() {
+        override fun onCreate(savedInstanceState: Bundle?) {
+            super.onCreate(savedInstanceState)
+
+            setContentView(R.layout.local_service_controller)
+
+            // Watch for button clicks.
+            var button = findViewById<View>(R.id.start) as Button
+            button.setOnClickListener(mStartListener)
+            button = findViewById<View>(R.id.stop) as Button
+            button.setOnClickListener(mStopListener)
+        }
+
+        private val mStartListener = OnClickListener {
+            // Make sure the service is started.  It will continue running
+            // until someone calls stopService().  The Intent we use to find
+            // the service explicitly specifies our service component, because
+            // we want it running in our own process and don't want other
+            // applications to replace it.
+            startService(Intent(this@Controller,
+                    LocalService::class.java))
+        }
+
+        private val mStopListener = OnClickListener {
+            // Cancel a previous call to startService().  Note that the
+            // service will not actually stop at this point if there are
+            // still bound clients.
+            stopService(Intent(this@Controller,
+                    LocalService::class.java))
+        }
+    }
+
+    // ----------------------------------------------------------------------
+
+    /**
+     * Example of binding and unbinding to the local service.
+     * This demonstrates the implementation of a service which the client will
+     * bind to, receiving an object through which it can communicate with the service.
+
+     *
+     * Note that this is implemented as an inner class only keep the sample
+     * all together; typically this code would appear in some separate class.
+     */
+    class Binding : Activity() {
+        private var mIsBound: Boolean = false
+
+        // BEGIN_INCLUDE(bind)
+        private var mBoundService: LocalService? = null
+
+        private val mConnection = object : ServiceConnection {
+            override fun onServiceConnected(className: ComponentName, service: IBinder) {
+                // This is called when the connection with the service has been
+                // established, giving us the service object we can use to
+                // interact with the service.  Because we have bound to a explicit
+                // service that we know is running in our own process, we can
+                // cast its IBinder to a concrete class and directly access it.
+                mBoundService = (service as LocalService.LocalBinder).service
+
+                // Tell the user about this for our demo.
+                Toast.makeText(this@Binding, R.string.local_service_connected,
+                        Toast.LENGTH_SHORT).show()
+            }
+
+            override fun onServiceDisconnected(className: ComponentName) {
+                // This is called when the connection with the service has been
+                // unexpectedly disconnected -- that is, its process crashed.
+                // Because it is running in our same process, we should never
+                // see this happen.
+                mBoundService = null
+                Toast.makeText(this@Binding, R.string.local_service_disconnected,
+                        Toast.LENGTH_SHORT).show()
+            }
+        }
+
+        internal fun doBindService() {
+            // Establish a connection with the service.  We use an explicit
+            // class name because we want a specific service implementation that
+            // we know will be running in our own process (and thus won't be
+            // supporting component replacement by other applications).
+            bindService(Intent(this@Binding,
+                    LocalService::class.java), mConnection, Context.BIND_AUTO_CREATE)
+            mIsBound = true
+        }
+
+        internal fun doUnbindService() {
+            if (mIsBound) {
+                // Detach our existing connection.
+                unbindService(mConnection)
+                mIsBound = false
+            }
+        }
+
+        override fun onDestroy() {
+            super.onDestroy()
+            doUnbindService()
+        }
+        // END_INCLUDE(bind)
+
+        private val mBindListener = OnClickListener { doBindService() }
+
+        private val mUnbindListener = OnClickListener { doUnbindService() }
+
+        override fun onCreate(savedInstanceState: Bundle?) {
+            super.onCreate(savedInstanceState)
+
+            setContentView(R.layout.local_service_binding)
+
+            // Watch for button clicks.
+            bind.setOnClickListener(mBindListener)
+            unbind.setOnClickListener(mUnbindListener)
+        }
+    }
+}

From 61d55d880168e4c71777b50e26adb9a8bed3d83f Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 03:28:48 +0900
Subject: [PATCH 30/34] Convert NotificationBackgroundService to Kotlin

---
 ....java => NotificationBackgroundService.kt} | 81 +++++++++----------
 1 file changed, 37 insertions(+), 44 deletions(-)
 rename mobile/src/main/java/com/example/android/apis/app/{NotificationBackgroundService.java => NotificationBackgroundService.kt} (52%)

diff --git a/mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.java b/mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.kt
similarity index 52%
rename from mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.java
rename to mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.kt
index bd5f0601f..c0a6122a0 100644
--- a/mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.java
+++ b/mobile/src/main/java/com/example/android/apis/app/NotificationBackgroundService.kt
@@ -14,85 +14,78 @@
  * limitations under the License.
  */
 
-package com.example.android.apis.app;
+package com.example.android.apis.app
 
 // Need the following import to get access to the app resources, since this
 // class is in a sub-package.
-import com.example.android.apis.R;
+import com.example.android.apis.R
 
-import android.app.Activity;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
+import android.app.Activity
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Context
+import android.content.Intent
+import android.os.Bundle
+import android.os.IBinder
+import android.view.View
+import android.view.View.OnClickListener
+import android.widget.Button
+import kotlinx.android.synthetic.main.notification_background_service.*
 
 /**
  * Example service that gets launched from a notification and runs in the background.
  */
-public class NotificationBackgroundService extends Service {
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
-        ((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE))
-                .cancel(R.layout.notification_background_service);
-        stopSelf(startId);
-        return START_NOT_STICKY;
+class NotificationBackgroundService : Service() {
+    override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
+        (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
+                .cancel(R.layout.notification_background_service)
+        stopSelf(startId)
+        return Service.START_NOT_STICKY
     }
 
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
+    override fun onBind(intent: Intent): IBinder? {
+        return null
     }
 
     /**
      * Demo UI that allows the user to post the notification.
      */
-    public static class Controller extends Activity {
-        private NotificationManager mNM;
+    class Controller : Activity() {
+        lateinit private var mNM: NotificationManager
 
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
+        override fun onCreate(savedInstanceState: Bundle?) {
+            super.onCreate(savedInstanceState)
 
-            mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            mNM = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
 
-            setContentView(R.layout.notification_background_service);
+            setContentView(R.layout.notification_background_service)
 
-            Button button = (Button) findViewById(R.id.notify);
-            button.setOnClickListener(mNotify);
+            notify.setOnClickListener(mNotify)
         }
 
-        private void showNotification(CharSequence text) {
+        private fun showNotification(text: CharSequence) {
             // The PendingIntent to launch our activity if the user selects this notification
-            PendingIntent contentIntent = PendingIntent.getService(this, 0,
-                    new Intent(this, NotificationBackgroundService.class), 0);
+            val contentIntent = PendingIntent.getService(this, 0,
+                    Intent(this, NotificationBackgroundService::class.java), 0)
 
             // Set the info for the views that show in the notification panel.
-            Notification notification = new Notification.Builder(this)
+            val notification = Notification.Builder(this)
                     .setSmallIcon(R.drawable.stat_sample)  // the status icon
                     .setTicker(text)  // the status text
                     .setWhen(System.currentTimeMillis())  // the time stamp
                     .setContentTitle(getText(R.string.notification_background_label))  // the label of the entry
                     .setContentText(text)  // the contents of the entry
                     .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
-                    .build();
+                    .build()
 
             // Send the notification.
             // We use a layout id because it is a unique number.  We use it later to cancel.
-            mNM.notify(R.layout.notification_background_service, notification);
+            mNM.notify(R.layout.notification_background_service, notification)
         }
 
-        private OnClickListener mNotify = new OnClickListener() {
-            public void onClick(View v) {
-                showNotification("Selecting this will cause a background service to run.");
-            }
-        };
+        private val mNotify = OnClickListener { showNotification("Selecting this will cause a background service to run.") }
     }
 }
 

From a5e599a7f011d2610bb1298a16badab8b9a8c239 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 03:31:22 +0900
Subject: [PATCH 31/34] changed to  extension code

---
 .../com/example/android/apis/app/LocalServiceActivities.kt | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt b/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt
index 2ea927497..67ac9fa46 100644
--- a/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt
+++ b/mobile/src/main/java/com/example/android/apis/app/LocalServiceActivities.kt
@@ -30,6 +30,7 @@ import android.view.View.OnClickListener
 import android.widget.Button
 import android.widget.Toast
 import kotlinx.android.synthetic.main.local_service_binding.*
+import kotlinx.android.synthetic.main.local_service_controller.*
 
 class LocalServiceActivities {
     /**
@@ -50,10 +51,8 @@ class LocalServiceActivities {
             setContentView(R.layout.local_service_controller)
 
             // Watch for button clicks.
-            var button = findViewById<View>(R.id.start) as Button
-            button.setOnClickListener(mStartListener)
-            button = findViewById<View>(R.id.stop) as Button
-            button.setOnClickListener(mStopListener)
+            start.setOnClickListener(mStartListener)
+            stop.setOnClickListener(mStopListener)
         }
 
         private val mStartListener = OnClickListener {

From c980368432e0aa06ebe1c449995eafdb0bea59f7 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 03:35:40 +0900
Subject: [PATCH 32/34] Convert NotifyingController to Kotlin

---
 .../android/apis/app/NotifyingController.java | 61 -------------------
 .../android/apis/app/NotifyingController.kt   | 53 ++++++++++++++++
 2 files changed, 53 insertions(+), 61 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/NotifyingController.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/NotifyingController.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/NotifyingController.java b/mobile/src/main/java/com/example/android/apis/app/NotifyingController.java
deleted file mode 100644
index b8b4e3f7f..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/NotifyingController.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-/**
- * Controller to start and stop a service. The serivce will update a status bar
- * notification every 5 seconds for a minute.
- */
-public class NotifyingController extends Activity {
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.notifying_controller);
-
-        Button button = (Button) findViewById(R.id.notifyStart);
-        button.setOnClickListener(mStartListener);
-        button = (Button) findViewById(R.id.notifyStop);
-        button.setOnClickListener(mStopListener);
-    }
-
-    private OnClickListener mStartListener = new OnClickListener() {
-        public void onClick(View v) {
-            startService(new Intent(NotifyingController.this, 
-                    NotifyingService.class));
-        }
-    };
-
-    private OnClickListener mStopListener = new OnClickListener() {
-        public void onClick(View v) {
-            stopService(new Intent(NotifyingController.this, 
-                    NotifyingService.class));
-        }
-    };
-}
-
diff --git a/mobile/src/main/java/com/example/android/apis/app/NotifyingController.kt b/mobile/src/main/java/com/example/android/apis/app/NotifyingController.kt
new file mode 100644
index 000000000..866c6744e
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/NotifyingController.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R
+
+import android.app.Activity
+import android.content.Intent
+import android.os.Bundle
+import android.view.View.OnClickListener
+import kotlinx.android.synthetic.main.notifying_controller.*
+
+/**
+ * Controller to start and stop a service. The serivce will update a status bar
+ * notification every 5 seconds for a minute.
+ */
+class NotifyingController : Activity() {
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        setContentView(R.layout.notifying_controller)
+
+        notifyStart.setOnClickListener(mStartListener)
+        notifyStop.setOnClickListener(mStopListener)
+    }
+
+    private val mStartListener = OnClickListener {
+        startService(Intent(this@NotifyingController,
+                NotifyingService::class.java))
+    }
+
+    private val mStopListener = OnClickListener {
+        stopService(Intent(this@NotifyingController,
+                NotifyingService::class.java))
+    }
+}
+

From a0398a38586b277ecbd35772be3e8457a6b0fe69 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 03:45:45 +0900
Subject: [PATCH 33/34] Convert NotifyingService to Kotlin

---
 .../android/apis/app/NotifyingService.java    | 131 ------------------
 .../android/apis/app/NotifyingService.kt      | 128 +++++++++++++++++
 2 files changed, 128 insertions(+), 131 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/NotifyingService.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/NotifyingService.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/NotifyingService.java b/mobile/src/main/java/com/example/android/apis/app/NotifyingService.java
deleted file mode 100644
index acb00950c..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/NotifyingService.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-// Need the following import to get access to the app resources, since this
-// class is in a sub-package.
-import com.example.android.apis.R;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.ConditionVariable;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.RemoteException;
-
-/**
- * This is an example of service that will update its status bar balloon 
- * every 5 seconds for a minute.
- * 
- */
-public class NotifyingService extends Service {
-    
-    // Use a layout id for a unique identifier
-    private static int MOOD_NOTIFICATIONS = R.layout.status_bar_notifications;
-
-    // variable which controls the notification thread 
-    private ConditionVariable mCondition;
- 
-    @Override
-    public void onCreate() {
-        mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-
-        // Start up the thread running the service.  Note that we create a
-        // separate thread because the service normally runs in the process's
-        // main thread, which we don't want to block.
-        Thread notifyingThread = new Thread(null, mTask, "NotifyingService");
-        mCondition = new ConditionVariable(false);
-        notifyingThread.start();
-    }
-
-    @Override
-    public void onDestroy() {
-        // Cancel the persistent notification.
-        mNM.cancel(MOOD_NOTIFICATIONS);
-        // Stop the thread from generating further notifications
-        mCondition.open();
-    }
-
-    private Runnable mTask = new Runnable() {
-        public void run() {
-            for (int i = 0; i < 4; ++i) {
-                showNotification(R.drawable.stat_happy,
-                        R.string.status_bar_notifications_happy_message);
-                if (mCondition.block(5 * 1000)) 
-                    break;
-                showNotification(R.drawable.stat_neutral,
-                        R.string.status_bar_notifications_ok_message);
-                if (mCondition.block(5 * 1000)) 
-                    break;
-                showNotification(R.drawable.stat_sad,
-                        R.string.status_bar_notifications_sad_message);
-                if (mCondition.block(5 * 1000)) 
-                    break;
-            }
-            // Done with our work...  stop the service!
-            NotifyingService.this.stopSelf();
-        }
-    };
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return mBinder;
-    }
-    
-    private void showNotification(int moodId, int textId) {
-        // In this sample, we'll use the same text for the ticker and the expanded notification
-        CharSequence text = getText(textId);
-
-        // The PendingIntent to launch our activity if the user selects this notification
-        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-                new Intent(this, NotifyingController.class), 0);
-
-        // Set the icon and timestamp.
-        // Note that in this example, we do not set the tickerText.  We update the icon enough that
-        // it is distracting to show the ticker text every time it changes.  We strongly suggest
-        // that you do this as well.  (Think of of the "New hardware found" or "Network connection
-        // changed" messages that always pop up)
-        // Set the info for the views that show in the notification panel.
-        Notification notification = new Notification.Builder(this)
-                .setSmallIcon(moodId)
-                .setWhen(System.currentTimeMillis())
-                .setContentTitle(getText(R.string.status_bar_notifications_mood_title))
-                .setContentText(text)  // the contents of the entry
-                .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
-                .build();
-
-        // Send the notification.
-        // We use a layout id because it is a unique number.  We use it later to cancel.
-        mNM.notify(MOOD_NOTIFICATIONS, notification);
-    }
-
-    // This is the object that receives interactions from clients.  See
-    // RemoteService for a more complete example.
-    private final IBinder mBinder = new Binder() {
-        @Override
-        protected boolean onTransact(int code, Parcel data, Parcel reply,
-                int flags) throws RemoteException {
-            return super.onTransact(code, data, reply, flags);
-        }
-    };
-
-    private NotificationManager mNM;
-}
diff --git a/mobile/src/main/java/com/example/android/apis/app/NotifyingService.kt b/mobile/src/main/java/com/example/android/apis/app/NotifyingService.kt
new file mode 100644
index 000000000..cad3b133c
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/NotifyingService.kt
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+// Need the following import to get access to the app resources, since this
+// class is in a sub-package.
+import com.example.android.apis.R
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Context
+import android.content.Intent
+import android.os.Binder
+import android.os.ConditionVariable
+import android.os.IBinder
+import android.os.Parcel
+import android.os.RemoteException
+
+/**
+ * This is an example of service that will update its status bar balloon
+ * every 5 seconds for a minute.
+
+ */
+class NotifyingService : Service() {
+
+    // variable which controls the notification thread
+   lateinit private var mCondition: ConditionVariable
+
+    override fun onCreate() {
+        mNM = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+        // Start up the thread running the service.  Note that we create a
+        // separate thread because the service normally runs in the process's
+        // main thread, which we don't want to block.
+        val notifyingThread = Thread(null, mTask, "NotifyingService")
+        mCondition = ConditionVariable(false)
+        notifyingThread.start()
+    }
+
+    override fun onDestroy() {
+        // Cancel the persistent notification.
+        mNM.cancel(MOOD_NOTIFICATIONS)
+        // Stop the thread from generating further notifications
+        mCondition.open()
+    }
+
+    private val mTask = Runnable {
+        for (i in 0..3) {
+            showNotification(R.drawable.stat_happy,
+                    R.string.status_bar_notifications_happy_message)
+            if (mCondition.block((5 * 1000).toLong()))
+                break
+            showNotification(R.drawable.stat_neutral,
+                    R.string.status_bar_notifications_ok_message)
+            if (mCondition.block((5 * 1000).toLong()))
+                break
+            showNotification(R.drawable.stat_sad,
+                    R.string.status_bar_notifications_sad_message)
+            if (mCondition.block((5 * 1000).toLong()))
+                break
+        }
+        // Done with our work...  stop the service!
+        this@NotifyingService.stopSelf()
+    }
+
+    override fun onBind(intent: Intent): IBinder? {
+        return mBinder
+    }
+
+    private fun showNotification(moodId: Int, textId: Int) {
+        // In this sample, we'll use the same text for the ticker and the expanded notification
+        val text = getText(textId)
+
+        // The PendingIntent to launch our activity if the user selects this notification
+        val contentIntent = PendingIntent.getActivity(this, 0,
+                Intent(this, NotifyingController::class.java), 0)
+
+        // Set the icon and timestamp.
+        // Note that in this example, we do not set the tickerText.  We update the icon enough that
+        // it is distracting to show the ticker text every time it changes.  We strongly suggest
+        // that you do this as well.  (Think of of the "New hardware found" or "Network connection
+        // changed" messages that always pop up)
+        // Set the info for the views that show in the notification panel.
+        val notification = Notification.Builder(this)
+                .setSmallIcon(moodId)
+                .setWhen(System.currentTimeMillis())
+                .setContentTitle(getText(R.string.status_bar_notifications_mood_title))
+                .setContentText(text)  // the contents of the entry
+                .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
+                .build()
+
+        // Send the notification.
+        // We use a layout id because it is a unique number.  We use it later to cancel.
+        mNM.notify(MOOD_NOTIFICATIONS, notification)
+    }
+
+    // This is the object that receives interactions from clients.  See
+    // RemoteService for a more complete example.
+    private val mBinder = object : Binder() {
+        @Throws(RemoteException::class)
+        override fun onTransact(code: Int, data: Parcel, reply: Parcel,
+                                flags: Int): Boolean {
+            return super.onTransact(code, data, reply, flags)
+        }
+    }
+
+    lateinit private var mNM: NotificationManager
+
+    companion object {
+        // Use a layout id for a unique identifier
+        private val MOOD_NOTIFICATIONS = R.layout.status_bar_notifications
+    }
+}

From 9c906941c59be9d6e61bff356fe156b9f3a89375 Mon Sep 17 00:00:00 2001
From: lyn <lync2846@gmail.com>
Date: Sun, 27 Aug 2017 05:21:07 +0900
Subject: [PATCH 34/34] Convert ServiceStartArguments to Kotlin

---
 .../apis/app/ServiceStartArguments.java       | 273 ------------------
 .../android/apis/app/ServiceStartArguments.kt | 257 +++++++++++++++++
 .../service_start_arguments_controller.xml    |   2 +-
 3 files changed, 258 insertions(+), 274 deletions(-)
 delete mode 100644 mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.java
 create mode 100644 mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.kt

diff --git a/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.java b/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.java
deleted file mode 100644
index 584dff35c..000000000
--- a/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.apis.app;
-
-import android.app.Activity;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Process;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-import com.example.android.apis.R;
-
-/**
- * This is an example of implementing an application service that runs locally
- * in the same process as the application.  The {@link Controller}
- * class shows how to interact with the service. 
- *
- * <p>Notice the use of the {@link NotificationManager} when interesting things
- * happen in the service.  This is generally how background services should
- * interact with the user, rather than doing something more disruptive such as
- * calling startActivity().
- * 
- * <p>For applications targeting Android 1.5 or beyond, you may want consider
- * using the {@link android.app.IntentService} class, which takes care of all the
- * work of creating the extra thread and dispatching commands to it.
- */
-public class ServiceStartArguments extends Service {
-    private NotificationManager mNM;
-    private Intent mInvokeIntent;
-    private volatile Looper mServiceLooper;
-    private volatile ServiceHandler mServiceHandler;
-    
-    private final class ServiceHandler extends Handler {
-        public ServiceHandler(Looper looper) {
-            super(looper);
-        }
-        
-        @Override
-        public void handleMessage(Message msg) {
-            Bundle arguments = (Bundle)msg.obj;
-        
-            String txt = arguments.getString("name");
-            
-            Log.i("ServiceStartArguments", "Message: " + msg + ", "
-                    + arguments.getString("name"));
-        
-            if ((msg.arg2&Service.START_FLAG_REDELIVERY) == 0) {
-                txt = "New cmd #" + msg.arg1 + ": " + txt;
-            } else {
-                txt = "Re-delivered #" + msg.arg1 + ": " + txt;
-            }
-            
-            showNotification(txt);
-        
-            // Normally we would do some work here...  for our sample, we will
-            // just sleep for 5 seconds.
-            long endTime = System.currentTimeMillis() + 5*1000;
-            while (System.currentTimeMillis() < endTime) {
-                synchronized (this) {
-                    try {
-                        wait(endTime - System.currentTimeMillis());
-                    } catch (Exception e) {
-                    }
-                }
-            }
-        
-            hideNotification();
-            
-            Log.i("ServiceStartArguments", "Done with #" + msg.arg1);
-            stopSelf(msg.arg1);
-        }
-
-    };
-    
-    @Override
-    public void onCreate() {
-        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
-
-        Toast.makeText(this, R.string.service_created,
-                Toast.LENGTH_SHORT).show();
-        
-        // This is who should be launched if the user selects our persistent
-        // notification.
-        mInvokeIntent = new Intent(this, Controller.class);
-
-        // Start up the thread running the service.  Note that we create a
-        // separate thread because the service normally runs in the process's
-        // main thread, which we don't want to block.  We also make it
-        // background priority so CPU-intensive work will not disrupt our UI.
-        HandlerThread thread = new HandlerThread("ServiceStartArguments",
-                Process.THREAD_PRIORITY_BACKGROUND);
-        thread.start();
-        
-        mServiceLooper = thread.getLooper();
-        mServiceHandler = new ServiceHandler(mServiceLooper);
-    }
-
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
-        Log.i("ServiceStartArguments",
-                "Starting #" + startId + ": " + intent.getExtras());
-        Message msg = mServiceHandler.obtainMessage();
-        msg.arg1 = startId;
-        msg.arg2 = flags;
-        msg.obj = intent.getExtras();
-        mServiceHandler.sendMessage(msg);
-        Log.i("ServiceStartArguments", "Sending: " + msg);
-        
-        // For the start fail button, we will simulate the process dying
-        // for some reason in onStartCommand().
-        if (intent.getBooleanExtra("fail", false)) {
-            // Don't do this if we are in a retry... the system will
-            // eventually give up if we keep crashing.
-            if ((flags&START_FLAG_RETRY) == 0) {
-                // Since the process hasn't finished handling the command,
-                // it will be restarted with the command again, regardless of
-                // whether we return START_REDELIVER_INTENT.
-                Process.killProcess(Process.myPid());
-            }
-        }
-        
-        // Normally we would consistently return one kind of result...
-        // however, here we will select between these two, so you can see
-        // how they impact the behavior.  Try killing the process while it
-        // is in the middle of executing the different commands.
-        return intent.getBooleanExtra("redeliver", false)
-                ? START_REDELIVER_INTENT : START_NOT_STICKY;
-    }
-
-    @Override
-    public void onDestroy() {
-        mServiceLooper.quit();
-
-        hideNotification();
-
-        // Tell the user we stopped.
-        Toast.makeText(ServiceStartArguments.this, R.string.service_destroyed,
-                Toast.LENGTH_SHORT).show();
-    }
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
-    }
-
-    /**
-     * Show a notification while this service is running.
-     */
-    private void showNotification(String text) {
-        // The PendingIntent to launch our activity if the user selects this notification
-        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-                new Intent(this, Controller.class), 0);
-
-        // Set the info for the views that show in the notification panel.
-        Notification.Builder noteBuilder = new Notification.Builder(this)
-                .setSmallIcon(R.drawable.stat_sample)  // the status icon
-                .setTicker(text)  // the status text
-                .setWhen(System.currentTimeMillis())  // the time stamp
-                .setContentTitle(getText(R.string.service_start_arguments_label))  // the label
-                .setContentText(text)  // the contents of the entry
-                .setContentIntent(contentIntent);  // The intent to send when the entry is clicked
-
-        // We show this for as long as our service is processing a command.
-        noteBuilder.setOngoing(true);
-        
-        // Send the notification.
-        // We use a string id because it is a unique number.  We use it later to cancel.
-        mNM.notify(R.string.service_created, noteBuilder.build());
-    }
-    
-    private void hideNotification() {
-        mNM.cancel(R.string.service_created);
-    }
-    
-    // ----------------------------------------------------------------------
-
-    /**
-     * Example of explicitly starting the {@link ServiceStartArguments}.
-     * 
-     * <p>Note that this is implemented as an inner class only keep the sample
-     * all together; typically this code would appear in some separate class.
-     */
-    public static class Controller extends Activity {
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-
-            setContentView(R.layout.service_start_arguments_controller);
-
-            // Watch for button clicks.
-            Button button = (Button)findViewById(R.id.start1);
-            button.setOnClickListener(mStart1Listener);
-            button = (Button)findViewById(R.id.start2);
-            button.setOnClickListener(mStart2Listener);
-            button = (Button)findViewById(R.id.start3);
-            button.setOnClickListener(mStart3Listener);
-            button = (Button)findViewById(R.id.startfail);
-            button.setOnClickListener(mStartFailListener);
-            button = (Button)findViewById(R.id.kill);
-            button.setOnClickListener(mKillListener);
-        }
-
-        private OnClickListener mStart1Listener = new OnClickListener() {
-            public void onClick(View v) {
-                startService(new Intent(Controller.this,
-                        ServiceStartArguments.class)
-                                .putExtra("name", "One"));
-            }
-        };
-
-        private OnClickListener mStart2Listener = new OnClickListener() {
-            public void onClick(View v) {
-                startService(new Intent(Controller.this,
-                        ServiceStartArguments.class)
-                                .putExtra("name", "Two"));
-            }
-        };
-
-        private OnClickListener mStart3Listener = new OnClickListener() {
-            public void onClick(View v) {
-                startService(new Intent(Controller.this,
-                        ServiceStartArguments.class)
-                                .putExtra("name", "Three")
-                                .putExtra("redeliver", true));
-            }
-        };
-
-        private OnClickListener mStartFailListener = new OnClickListener() {
-            public void onClick(View v) {
-                startService(new Intent(Controller.this,
-                        ServiceStartArguments.class)
-                                .putExtra("name", "Failure")
-                                .putExtra("fail", true));
-            }
-        };
-
-        private OnClickListener mKillListener = new OnClickListener() {
-            public void onClick(View v) {
-                // This is to simulate the service being killed while it is
-                // running in the background.
-                Process.killProcess(Process.myPid());
-            }
-        };
-    }
-}
-
diff --git a/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.kt b/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.kt
new file mode 100644
index 000000000..a00827f9f
--- /dev/null
+++ b/mobile/src/main/java/com/example/android/apis/app/ServiceStartArguments.kt
@@ -0,0 +1,257 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app
+
+import android.app.Activity
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Intent
+import android.os.Bundle
+import android.os.Handler
+import android.os.HandlerThread
+import android.os.IBinder
+import android.os.Looper
+import android.os.Message
+import android.os.Process
+import android.util.Log
+import android.view.View.OnClickListener
+import android.widget.Toast
+
+import com.example.android.apis.R
+import com.example.android.apis.R.id.*
+import kotlinx.android.synthetic.main.service_start_arguments_controller.*
+
+/**
+ * This is an example of implementing an application service that runs locally
+ * in the same process as the application.  The [Controller]
+ * class shows how to interact with the service.
+
+ *
+ * Notice the use of the [NotificationManager] when interesting things
+ * happen in the service.  This is generally how background services should
+ * interact with the user, rather than doing something more disruptive such as
+ * calling startActivity().
+
+ *
+ * For applications targeting Android 1.5 or beyond, you may want consider
+ * using the [android.app.IntentService] class, which takes care of all the
+ * work of creating the extra thread and dispatching commands to it.
+ */
+
+class ServiceStartArguments : Service() {
+    lateinit private var mNM: NotificationManager
+    lateinit private var mInvokeIntent: Intent
+    @Volatile
+    lateinit private var mServiceLooper: Looper
+    @Volatile
+    lateinit private var mServiceHandler: ServiceHandler
+
+    private inner class ServiceHandler( looper:Looper ): Handler(looper) {
+       init { }
+
+               override fun handleMessage(msg: Message) {
+            val arguments = msg.obj as Bundle
+
+            var txt: String = arguments.getString("name")
+
+            Log.i("ServiceStartArguments", "Message: " + msg + ", "
+                    + arguments.getString("name"))
+
+            if (msg.arg2 and Service.START_FLAG_REDELIVERY == 0) {
+                txt = "New cmd #" + msg.arg1 + ": " + txt
+            } else {
+                txt = "Re-delivered #" + msg.arg1 + ": " + txt
+            }
+
+            showNotification(txt)
+
+            // Normally we would do some work here...  for our sample, we will
+            // just sleep for 5 seconds.
+            val endTime = System.currentTimeMillis() + 5 * 1000
+            while (System.currentTimeMillis() < endTime) {
+                synchronized(this) {
+                    try {
+                        //wait(endTime - System.currentTimeMillis())
+                    } catch (e: Exception) {
+                    }
+
+                }
+            }
+
+            hideNotification()
+
+            Log.i("ServiceStartArguments", "Done with #" + msg.arg1)
+            stopSelf(msg.arg1)
+        }
+
+    }
+
+    override public fun onCreate() {
+        mNM = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
+
+        Toast.makeText(this, R.string.service_created,
+                Toast.LENGTH_SHORT).show()
+
+        // This is who should be launched if the user selects our persistent
+        // notification.
+        mInvokeIntent = Intent(this, Controller::class.java)
+
+        // Start up the thread running the service.  Note that we create a
+        // separate thread because the service normally runs in the process's
+        // main thread, which we don't want to block.  We also make it
+        // background priority so CPU-intensive work will not disrupt our UI.
+        var thread: HandlerThread = HandlerThread("ServiceStartArguments",
+                Process.THREAD_PRIORITY_BACKGROUND)
+        thread.start()
+
+        mServiceLooper = thread.getLooper()
+        mServiceHandler = ServiceHandler(mServiceLooper)
+    }
+
+    override public fun onStartCommand( intent:Intent,  flags:Int,  startId :Int):Int
+    {
+        Log.i("ServiceStartArguments",
+                "Starting #" + startId + ": " + intent.getExtras())
+        var msg = mServiceHandler . obtainMessage ()
+        msg.arg1 = startId
+        msg.arg2 = flags
+        msg.obj = intent.getExtras()
+        mServiceHandler.sendMessage(msg)
+        Log.i("ServiceStartArguments", "Sending: " + msg);
+
+        // For the start fail button, we will simulate the process dying
+        // for some reason in onStartCommand().
+        if (intent.getBooleanExtra("fail", false)) {
+            // Don't do this if we are in a retry... the system will
+            // eventually give up if we keep crashing.
+            if ((flags and START_FLAG_RETRY) == 0) {
+                // Since the process hasn't finished handling the command,
+                // it will be restarted with the command again, regardless of
+                // whether we return START_REDELIVER_INTENT.
+                Process.killProcess(Process.myPid())
+            }
+        }
+
+        // Normally we would consistently return one kind of result...
+        // however, here we will select between these two, so you can see
+        // how they impact the behavior.  Try killing the process while it
+        // is in the middle of executing the different commands.
+        var flag: Int= START_NOT_STICKY
+         if (intent.getBooleanExtra("redeliver", false))
+             flag = START_REDELIVER_INTENT
+
+        return flag
+    }
+
+   override
+    public fun onDestroy()
+    {
+        mServiceLooper.quit()
+
+        hideNotification()
+
+        // Tell the user we stopped.
+        Toast.makeText(this@ServiceStartArguments, R.string.service_destroyed,
+                Toast.LENGTH_SHORT).show()
+    }
+
+    override public fun onBind(intent:Intent):IBinder?
+    {
+        return null
+    }
+
+    //Show a notification while this service is running.
+
+    private  fun showNotification(text:String)
+    {
+        // The PendingIntent to launch our activity if the user selects this notification
+        val contentIntent :PendingIntent= PendingIntent . getActivity (this, 0,
+         Intent (this, Controller::class.java), 0)
+
+        // Set the info for the views that show in the notification panel.
+        var noteBuilder =  Notification.Builder(this)
+                .setSmallIcon(R.drawable.stat_sample)  // the status icon
+                .setTicker(text)  // the status text
+                .setWhen(System.currentTimeMillis())  // the time stamp
+                .setContentTitle(getText(R.string.service_start_arguments_label))  // the label
+                .setContentText(text)  // the contents of the entry
+                .setContentIntent(contentIntent)  // The intent to send when the entry is clicked
+
+        // We show this for as long as our service is processing a command.
+        noteBuilder.setOngoing(true)
+
+        // Send the notification.
+        // We use a string id because it is a unique number.  We use it later to cancel.
+        mNM.notify(R.string.service_created, noteBuilder.build())
+    }
+
+    private fun hideNotification()
+    {
+        mNM.cancel(R.string.service_created)
+    }
+
+
+/**
+ * Example of explicitly starting the [ServiceStartArguments].
+ * Note that this is implemented as an inner class only keep the sample
+ * all together; typically this code would appear in some separate class. */
+
+    class Controller : Activity() {
+        override protected fun onCreate(savedInstanceState: Bundle?) {
+            super.onCreate(savedInstanceState)
+
+            setContentView(R.layout.service_start_arguments_controller)
+
+            start1.setOnClickListener(mStart1Listener)
+            start2.setOnClickListener(mStart2Listener)
+            start3.setOnClickListener(mStart3Listener)
+            startfail.setOnClickListener(mStartFailListener)
+            kill.setOnClickListener(mKillListener)
+        }
+
+        private val mStart1Listener = OnClickListener {
+            startService(Intent(this@Controller,
+                    ServiceStartArguments::class.java).putExtra("name", "One"))
+        }
+
+        private val mStart2Listener = OnClickListener {
+            startService(Intent(this@Controller,
+                    ServiceStartArguments::class.java).putExtra("name", "Two"))
+        }
+        private val mStart3Listener = OnClickListener {
+            startService(Intent(this@Controller,
+                    ServiceStartArguments::class.java).putExtra("name", "Three")
+                    .putExtra("redeliver", true))
+        }
+
+
+        private val mStartFailListener = OnClickListener {
+            startService(Intent(this@Controller,
+                    ServiceStartArguments::class.java)
+                    .putExtra("name", "Three")
+                    .putExtra("name", "Failure")
+                    .putExtra("fail", true))
+        }
+
+        private val mKillListener = OnClickListener {
+            Process.killProcess(Process.myPid())
+        }
+
+    }
+}
diff --git a/mobile/src/main/res/layout/service_start_arguments_controller.xml b/mobile/src/main/res/layout/service_start_arguments_controller.xml
index bcf4a65ff..154b67cf5 100644
--- a/mobile/src/main/res/layout/service_start_arguments_controller.xml
+++ b/mobile/src/main/res/layout/service_start_arguments_controller.xml
@@ -15,7 +15,7 @@
 -->
 
 <!-- Demonstrates starting and stopping a local service.
-     See corresponding Java code com.android.sdk.app.ServiceStartArguments.java. -->
+     See corresponding Java code com.android.sdk.ServiceStartArguments.ktjava. -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
     android:gravity="center_horizontal"