├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── render.experimental.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── atilsamancioglu │ │ └── classesandfunctions │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── atilsamancioglu │ │ │ └── classesandfunctions │ │ │ ├── MainActivity.kt │ │ │ └── Simpson.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── atilsamancioglu │ └── classesandfunctions │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/render.experimental.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 33 7 | buildToolsVersion "29.0.1" 8 | defaultConfig { 9 | applicationId "com.atilsamancioglu.classesandfunctions" 10 | minSdkVersion 23 11 | targetSdkVersion 33 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | namespace 'com.atilsamancioglu.classesandfunctions' 23 | compileOptions { 24 | sourceCompatibility JavaVersion.VERSION_11 25 | targetCompatibility JavaVersion.VERSION_11 26 | } 27 | 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 33 | implementation 'androidx.appcompat:appcompat:1.6.1' 34 | implementation 'androidx.core:core-ktx:1.10.0' 35 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 36 | testImplementation 'junit:junit:4.13.2' 37 | androidTestImplementation 'androidx.test:runner:1.5.2' 38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/atilsamancioglu/classesandfunctions/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.atilsamancioglu.classesandfunctions 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.atilsamancioglu.classesandfunctions", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/atilsamancioglu/classesandfunctions/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.atilsamancioglu.classesandfunctions 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.View 6 | import android.widget.Button 7 | import android.widget.EditText 8 | import android.widget.TextView 9 | 10 | class MainActivity : AppCompatActivity() { 11 | 12 | private lateinit var myTextView : TextView 13 | private lateinit var myButton : Button 14 | private lateinit var nameText : EditText 15 | private lateinit var ageText : EditText 16 | private lateinit var jobText : EditText 17 | var name = "" 18 | 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_main) 23 | 24 | myTextView = findViewById(R.id.textView) 25 | myButton = findViewById(R.id.button) 26 | nameText = findViewById(R.id.nameText) 27 | ageText = findViewById(R.id.ageText) 28 | jobText = findViewById(R.id.jobText) 29 | 30 | 31 | /* 32 | myButton.setOnClickListener { 33 | myTextView.text = "button clicked 2" 34 | } 35 | 36 | */ 37 | 38 | // 1) code block, reusable 2) input 3) output - return 39 | 40 | //println("hello kotlin") 41 | test() 42 | mySum(10,15) 43 | 44 | val sumResult = mySum(40,35) 45 | val result = myMultiply(10,20) 46 | 47 | println(sumResult) 48 | println(result) 49 | 50 | 51 | //Class 52 | 53 | val homer = Simpson("Homer", 50, "Nuclear") 54 | 55 | homer.setHeight(50) 56 | 57 | 58 | //Nullability 59 | 60 | var myString : String? = null 61 | myString = "test" 62 | println(myString) 63 | 64 | var myAge : Int? = null 65 | //myAge = 50 66 | // !! ? 67 | 68 | //1) !! 69 | //println(myAge!! * 10) 70 | 71 | //2) safe call 72 | 73 | println(myAge?.minus(10)) 74 | 75 | //3) 76 | 77 | if(myAge != null) { 78 | println(myAge.minus(10)) 79 | } else { 80 | println("myAge is null") 81 | } 82 | 83 | 84 | //4) elvis operator 85 | 86 | println(myAge?.minus(10) ?: -10) 87 | 88 | //5) 89 | myAge?.let { 90 | println(it * 10) 91 | } 92 | 93 | } 94 | 95 | fun test() { 96 | //println("test function") 97 | 98 | } 99 | 100 | fun mySum(a:Int, b:Int) { 101 | 102 | } 103 | 104 | fun myMultiply(x: Int, y: Int) : Int { 105 | 106 | //println(x*y) 107 | val result = x * y 108 | myTextView.text = "Result: ${result}" 109 | 110 | return result 111 | } 112 | 113 | fun buttonClicked(view : View) { 114 | name = nameText.text.toString() 115 | val age = ageText.text.toString().toIntOrNull() 116 | val job = jobText.text.toString() 117 | if (age != null) { 118 | val simpson = Simpson(name, age, job) 119 | myTextView.text = "Name: ${simpson.name} Age: ${simpson.age} Job: ${simpson.job}" 120 | } else { 121 | myTextView.text = "Enter your age!" 122 | } 123 | 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/atilsamancioglu/classesandfunctions/Simpson.kt: -------------------------------------------------------------------------------- 1 | package com.atilsamancioglu.classesandfunctions 2 | 3 | //primary constructor 4 | class Simpson( var name : String, var age: Int, var job: String) { 5 | 6 | private var height = 0 7 | 8 | fun setHeight(num : Int) { 9 | if (num > 100) { 10 | height = num 11 | } 12 | } 13 | 14 | /* 15 | //Property 16 | var name = "" 17 | var age = 0 18 | var job = "" 19 | var weight = 0 20 | var height = 0 21 | 22 | //Secondary Constructor 23 | constructor(name : String, age : Int, job : String, weight : Int) { 24 | this.name = name 25 | this.age = age 26 | this.job = job 27 | this.weight = weight 28 | } 29 | 30 | */ 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 24 | 25 | 39 | 40 | 54 | 55 | 67 | 68 |