{"id":894,"date":"2021-04-25T03:07:46","date_gmt":"2021-04-25T10:07:46","guid":{"rendered":"http:\/\/cywang.no-ip.org\/wordpress\/?p=894"},"modified":"2021-04-29T21:55:11","modified_gmt":"2021-04-30T04:55:11","slug":"unit-1-kotlin-basics-for-android-notes","status":"publish","type":"post","link":"http:\/\/cywang.no-ip.org\/wordpress\/?p=894","title":{"rendered":"[Android Study Jam] Unit 1: Kotlin basics for Android (Notes)"},"content":{"rendered":"<p><a href=\"https:\/\/developer.android.com\/training\/kotlinplayground\" target=\"_blank\" rel=\"noopener\">Kotlin Playground<\/a><\/p>\n<p><!--more--><\/p>\n<h1>Introduction to Kotlin<\/h1>\n<p><a href=\"https:\/\/developer.android.com\/codelabs\/basic-android-kotlin-training-kotlin-birthday-message\" target=\"_blank\" rel=\"noopener\">Create a birthday message in Kotlin<\/a><\/p>\n<pre>Important: A variable declared using the <strong>val<\/strong> keyword can only be set once. You cannot change its value later in the program.\r\n\r\nYou can declare a changeable variable with the <strong>var<\/strong> keyword, which you will do in a later codelab.<\/pre>\n<pre class=\"line-numbers\"><code class=\"language-kotlin\">fun main() {\r\n    \r\n    val age = 5 * 365\r\n    val name = \"John\"\r\n    \r\n    println(\"Happy Birthday, ${name}!\")\r\n    \r\n    \/\/ Let's print a cake!\r\n    println(\"   ,,,,,   \")\r\n    println(\"   |||||   \")\r\n    println(\" =========\")\r\n    println(\"@@@@@@@@@@@\")\r\n    println(\"{~@~@~@~@~}\")\r\n    println(\"@@@@@@@@@@@\")\r\n    \r\n    \/\/ This prints an empty line.\r\n    println(\"\")\r\n\r\n    println(\"You are already ${age} days old, ${name}!\")\r\n    println(\"${age} days old is the very best age to celebrate!\")\r\n}<\/code><\/pre>\n<p><a href=\"https:\/\/developer.android.com\/kotlin\/style-guide\" target=\"_blank\" rel=\"noopener\">Kotlin style guide<\/a><\/p>\n<pre class=\"line-numbers\"><code class=\"language-kotlin\">fun main() {\r\n    printBorder()\r\n    println(\"Happy Birthday, John!\")\r\n    printBorder()\r\n}\r\n\r\nfun printBorder() {\r\n    repeat(21) {\r\n        print(\"=\")\r\n    }\r\n    println()\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Passing arguments to the function to make it more flexible.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-kotlin\">fun main() {\r\n    val border = \"`-._,-'\"\r\n    val timesToRepeat = 4\r\n    printBorder(border, timesToRepeat)\r\n    println(\"  Happy Birthday, John!\")\r\n    printBorder(border, timesToRepeat)\r\n}\r\n\r\nfun printBorder(border: String, timesToRepeat: Int) {\r\n    repeat(timesToRepeat) {\r\n        print(border)\r\n    }\r\n    println()\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"line-numbers\"><code class=\"language-kotlin\">fun main() {\r\n    val age = 24\r\n    val layers = 5\r\n    \r\n    printCakeCandles(age)\r\n    \r\n    printCakeTop(age)\r\n    \r\n    printCakeBottom(age, layers)\r\n    \r\n}\r\n\r\nfun printCakeCandles(age: Int) {\r\n    print(\" \")\r\n    repeat(age) {\r\n        print(\",\")\r\n    }\r\n    println()\r\n    print(\" \")\r\n    repeat(age) {\r\n        print(\"|\")\r\n    }\r\n    println()\r\n}\r\n\r\nfun printCakeTop(age: Int) {\r\n    repeat(age + 2) {\r\n        print(\"=\")\r\n    }\r\n    println()\r\n}\r\n\r\nfun printCakeBottom(age: Int, layers: Int) {\r\n    repeat(layers) {\r\n        repeat(age + 2) {\r\n            print(\"@\")\r\n        }\r\n        println()\r\n    }\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h1>Create your first Android app<\/h1>\n<p>&nbsp;<\/p>\n<h1>Build a basic layout<\/h1>\n<p>Qualities of a great app<\/p>\n<ul>\n<li>Effective<\/li>\n<li>Efficient<\/li>\n<li>Beautiful<\/li>\n<li>Accessible<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kotlin Playground<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[40],"tags":[],"class_list":["post-894","post","type-post","status-publish","format-standard","hentry","category-android-study-jam"],"_links":{"self":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=894"}],"version-history":[{"count":7,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/894\/revisions"}],"predecessor-version":[{"id":909,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/894\/revisions\/909"}],"wp:attachment":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=894"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}