├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── github │ │ └── vatsal │ │ └── kandy │ │ ├── AnkoActivity.kt │ │ ├── ExtensionFun.kt │ │ ├── KotlinActivity.kt │ │ └── SharedPrefDemo.java │ └── res │ ├── drawable-hdpi │ ├── ic_action_name.png │ └── ic_edit.png │ ├── drawable-mdpi │ ├── ic_action_name.png │ └── ic_edit.png │ ├── drawable-nodpi │ ├── hero.png │ └── kotlin_800x320.png │ ├── drawable-xhdpi │ ├── ic_action_name.png │ └── ic_edit.png │ ├── drawable-xxhdpi │ ├── ic_action_name.png │ └── ic_edit.png │ ├── drawable-xxxhdpi │ ├── ic_edit.png │ └── ic_github_logo.png │ ├── layout │ ├── activity_kotlin.xml │ └── content_kotlin.xml │ ├── menu │ └── menu_kotlin.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | .gradle/ 4 | local.properties 5 | gradle/ 6 | build/ 7 | gradlew* -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | KAndy -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | Android API 23 Platform 58 | 59 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #learn-kotlin 2 | 3 | This application is a demo to explain kotlin components and syntax. Please refer these blogs along with this app 4 | 5 | * [Setting Up Kotlin in Android Studio - Medium](https://medium.com/@code_crusher/setting-up-kotlin-in-android-studio-d8cc9f4e9108#.mkhjhd9eh) 6 | * [Understanding Kotlin Language - Medium](https://medium.com/@code_crusher/understanding-kotlin-language-de72c7ba9af5) 7 | * [ANKO Kotlin](https://github.com/Kotlin/anko) 8 | 9 | ###Official Links 10 | * Website - [kotlinlang.org](kotlinlang.org) 11 | * Slack Channel - [kotlinlang.slack.com](kotlinlang.slack.com) 12 | * Twitter - [https://twitter.com/kotlin](https://twitter.com/kotlin) 13 | 14 | ###Kotlin User Group New Delhi 15 | * Twitter - [https://twitter.com/KotlinNewDelhi](https://twitter.com/KotlinNewDelhi) 16 | * Facebook - [https://www.facebook.com/kotlinNewDelhi/](https://www.facebook.com/kotlinNewDelhi/) 17 | 18 | ###Reach out to me 19 | * Twitter - [@Vatsal Bajpai](https://twitter.com/Vatsal__Bajpai) 20 | * Facebook - [Vatsal Bajpai](https://www.facebook.com/bajpai.vatsal) 21 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 25 7 | buildToolsVersion "25.0.1" 8 | 9 | defaultConfig { 10 | applicationId "github.vatsal.kandy" 11 | minSdkVersion 14 12 | targetSdkVersion 25 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | sourceSets { 23 | main.java.srcDirs += 'src/main/kotlin' 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | compile 'com.android.support:appcompat-v7:25.1.0' 30 | compile 'com.android.support:design:25.1.0' 31 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 32 | 33 | // Anko 34 | compile 'org.jetbrains.anko:anko-sdk15:0.9.1' 35 | compile 'org.jetbrains.anko:anko-support-v4:0.9.1' 36 | compile 'org.jetbrains.anko:anko-appcompat-v7:0.9.1' 37 | } 38 | repositories { 39 | mavenCentral() 40 | } 41 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/appyware/Documents/AndroidSdk/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/github/vatsal/kandy/AnkoActivity.kt: -------------------------------------------------------------------------------- 1 | package github.vatsal.kandy 2 | 3 | import android.graphics.Color 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import org.jetbrains.anko.* 7 | 8 | class AnkoActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | 13 | setLayout() 14 | } 15 | 16 | private fun setLayout() { 17 | verticalLayout { 18 | padding = dip(16) 19 | editText { 20 | hint = "Name" 21 | textSize = 18f 22 | } 23 | editText { 24 | hint = "Password" 25 | textSize = 24f 26 | } 27 | button("Login") { 28 | backgroundColor = getResources().getColor(R.color.colorAccent) 29 | textColor = Color.parseColor("#ffffff") 30 | elevation = 3f 31 | textSize = 18f 32 | }.lparams(width = wrapContent) { 33 | horizontalMargin = dip(5) 34 | topMargin = dip(10) 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/github/vatsal/kandy/ExtensionFun.kt: -------------------------------------------------------------------------------- 1 | package github.vatsal.kandy 2 | 3 | import android.content.SharedPreferences 4 | import java.util.* 5 | 6 | class ExtensionFun { 7 | 8 | // extension functions 9 | fun Date.isMonday(): Boolean { 10 | return true 11 | } 12 | 13 | fun Date.isTuesday() = true 14 | 15 | var date: Date? = null 16 | 17 | // using extension function as a part of the object 18 | val isMonday = date?.isMonday() 19 | val isTuesday = date?.isTuesday() 20 | 21 | 22 | // high order extension functions 23 | fun SharedPreferences.edit(func: SharedPreferences.Editor.() -> Unit) { 24 | val editor = edit() 25 | editor.func() 26 | editor.apply() 27 | } 28 | 29 | var sharedPref: SharedPreferences? = null 30 | 31 | // using high order extension functions 32 | fun spDemo() { 33 | sharedPref!!.edit { 34 | putString("key", "name") 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/github/vatsal/kandy/KotlinActivity.kt: -------------------------------------------------------------------------------- 1 | package github.vatsal.kandy 2 | 3 | import android.content.Intent 4 | import android.net.Uri 5 | import android.os.Bundle 6 | import android.support.design.widget.FloatingActionButton 7 | import android.support.v7.app.AppCompatActivity 8 | import android.support.v7.widget.Toolbar 9 | import android.view.KeyEvent 10 | import android.view.View 11 | import android.view.inputmethod.EditorInfo 12 | import android.widget.TextView 13 | import kotlinx.android.synthetic.main.content_kotlin.* 14 | import org.jetbrains.anko.startActivity 15 | 16 | class KotlinActivity : AppCompatActivity() { 17 | 18 | // declaring value 19 | // does not need any type 20 | // Kotlin does it automatically 21 | // also notice no more semi-colon(;) needed 22 | // rad right! 23 | val textStart = "Made with" 24 | val textEnd = "using Kotlin!" 25 | var tvDemo = null as TextView? 26 | 27 | // the ? is used to ensure the null exception never comes 28 | // we are thy saved 29 | override fun onCreate(savedInstanceState: Bundle?) { 30 | super.onCreate(savedInstanceState) 31 | setContentView(R.layout.activity_kotlin) 32 | 33 | // the initialising method call 34 | init() 35 | } 36 | 37 | // no more return type for a method :@ 38 | // fun is a keyword to declare a function 39 | private fun init() { 40 | 41 | // declaring and assigning a val as a ToolBar 42 | val toolbar = findViewById(R.id.toolbar) as Toolbar? 43 | setSupportActionBar(toolbar) 44 | 45 | // eliminate the NULL by using question mark 46 | val tvStart = findViewById(R.id.tv_start) as TextView? 47 | 48 | // var can be reassigned but a val cannot be 49 | tvDemo = findViewById(R.id.tv_demo) as TextView? 50 | 51 | // easy val setting 52 | // not-null assertions(!!) 53 | tvStart?.text = textStart 54 | tv_end!!.text = textEnd 55 | 56 | val fab = findViewById(R.id.fab) as FloatingActionButton? 57 | 58 | // finally no more big ClickListeners!! 59 | // just single line 60 | fab!!.setOnClickListener { openRepo() } 61 | 62 | etDemo!!.setOnEditorActionListener(TextView.OnEditorActionListener { textView, i, keyEvent -> 63 | 64 | if (i == EditorInfo.IME_ACTION_SEARCH || i == EditorInfo.IME_ACTION_DONE || 65 | keyEvent!!.action == KeyEvent.ACTION_DOWN && 66 | keyEvent!!.keyCode == KeyEvent.KEYCODE_ENTER) { 67 | tvDemo!!.text = "\"" + textView.text + "\"" 68 | tvDemo!!.visibility = View.VISIBLE 69 | etDemo!!.visibility = View.GONE 70 | true 71 | } 72 | false 73 | 74 | }) 75 | 76 | et_demo!!.setOnClickListener { editTextView() } 77 | 78 | bt_start_anko.setOnClickListener { startActivity() } 79 | } 80 | 81 | private fun editTextView() { 82 | tvDemo!!.visibility = View.GONE 83 | etDemo!!.text = null 84 | etDemo!!.visibility = View.VISIBLE 85 | } 86 | 87 | private fun openRepo() { 88 | val url = "https://github.com/code-crusher/KAndy" 89 | val i = Intent(Intent.ACTION_VIEW) 90 | i.data = Uri.parse(url) 91 | startActivity(i) 92 | } 93 | 94 | // referencing the imported ids 95 | private val etDemo by lazy { 96 | et_demo 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/github/vatsal/kandy/SharedPrefDemo.java: -------------------------------------------------------------------------------- 1 | package github.vatsal.kandy; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by 8 | * --Vatsal Bajpai on 9 | * --31/07/16 at 10 | * --12:36 PM 11 | */ 12 | public class SharedPrefDemo { 13 | 14 | SharedPreferences sharedPreferences; 15 | Context context; 16 | 17 | public void editSharedPref() { 18 | sharedPreferences = context.getSharedPreferences("sharedPreferences", Context.MODE_PRIVATE); 19 | SharedPreferences.Editor editor = sharedPreferences.edit(); 20 | editor.putString("key", "name"); 21 | editor.apply(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-hdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-hdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-mdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-mdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/hero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-nodpi/hero.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/kotlin_800x320.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-nodpi/kotlin_800x320.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xxhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xxhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xxxhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_github_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-crusher/learn-kotlin/085054b47663c3e6632f80afdf49e0503664a81d/app/src/main/res/drawable-xxxhdpi/ic_github_logo.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_kotlin.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 24 | 25 | 32 | 33 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_kotlin.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 32 | 33 | 36 | 37 | 38 | 39 | 44 | 45 | 50 | 51 | 55 | 56 | 59 | 60 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | 84 | 90 | 91 | 92 | 93 |