diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3fc1be --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Kotlin-sample +Android kotlin sample project as done and given below 1) Listview 2) Recycler view 3) Navigation drawer 4) Tab layout 5) Bottom sheet view + + +Android kotlin sample. + +Implemented the sample application in kotlin language. + + +![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/1.png "Main screen") + +1) Listview : + +We will build an Android App that uses ListView to show list of items: + +![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/2.png "List view") + +2) Recycler view : + + ![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/3.png "Recycler view") + + 3) Navigation drawer: + + ![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/4.png "Navigation drawer") + + 4) Tab layout: + +![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/6.png "Tab layout") + +5) Bottom sheet : + +![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/8.png "bottom sheet layout") + +6) Android deafult Alert dialog and anko library using Alert dialog + +![alt text](https://github.com/Manikandan92/Kotlin-sample/blob/master/assets/device-2018-03-21-103617.png "alert dialog") diff --git a/app/app.iml b/app/app.iml index 4b98aac..6c8ca2c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -148,6 +148,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 764fcc0..d8204b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,4 +34,6 @@ dependencies { compile 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:design:26.1.0' implementation 'com.android.support:support-v4:26.1.0' + // Initializing anko library + compile "org.jetbrains.anko:anko-sdk15:0.10.1" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f4314c9..63bcf31 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,6 +19,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/manikandan/samplekotlinproject/AlertDialogActivity.kt b/app/src/main/java/com/manikandan/samplekotlinproject/AlertDialogActivity.kt new file mode 100644 index 0000000..2b0a64c --- /dev/null +++ b/app/src/main/java/com/manikandan/samplekotlinproject/AlertDialogActivity.kt @@ -0,0 +1,149 @@ +package com.manikandan.samplekotlinproject + +import android.os.Bundle +import android.support.v7.app.AlertDialog +import android.support.v7.app.AppCompatActivity +import kotlinx.android.synthetic.main.activity_alert_dialog.* +import org.jetbrains.anko.* + +/** + * Created by manikandan on 21/03/18. + */ +class AlertDialogActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_alert_dialog) + + toolBar.setTitle("Alert Dialog") + simpleAlert.setOnClickListener { + showSimpleAlert() + } + + alertTwoButton.setOnClickListener { + showAlertWithTwoButton() + } + + alertThreeButton.setOnClickListener { + showAlertWithThreeButton() + } + + // ***** Anko Library button click action here ****** // + ankoSimpleAlert.setOnClickListener { + ankoShowSimpleAlert() + } + + ankoAlertTwoButton.setOnClickListener { + ankoShowAlertWithTwoButton() + } + + ankoAlertThreeButton.setOnClickListener { + ankoShowAlertWithThreeButton() + } + + // Custom alert dialogs using Anko lib + ankoCustomAlertButton.setOnClickListener { + ankoCustomAlertDialog() + } + } + + private fun ankoCustomAlertDialog() { + alert("Custom alert dialog messages", "Alert dialog") { + positiveButton("POSITIVE") { + + } + customView { + verticalLayout { + textView("Sample textview") + button("Sample button") + editText("").setHint("Sample edit text") + padding = dip(16) + } + } + + }.show() + } + + // ***** Anko Library Example code here ****** // + private fun ankoShowAlertWithThreeButton() { + alert("Simple Alert dialog positive, negative and neutral buttons", "Alert dialog") { + positiveButton("POSITIVE") { + // your code here + } + negativeButton("NEGATIVE") { + // your code here + } + neutralPressed("NEUTRAL") { + // your code here + } + }.show() + } + + private fun ankoShowAlertWithTwoButton() { + alert("Simple Alert dialog positive and negative buttons", "Alert dialog") { + positiveButton("YES") { + // your code here + } + negativeButton("NO") { + // your code here + } + }.show() + } + + private fun ankoShowSimpleAlert() { + alert("Simple Alert dialog", "Alert dialog") { + positiveButton("OK") { + // your code here + } + }.show() + } + + //General code here + private fun showAlertWithThreeButton() { + val alertDialog = AlertDialog.Builder(this).create() + alertDialog.setTitle("Alert dialog") + alertDialog.setMessage("Simple Alert dialog positive, negative and neutral buttons") + + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "POSITIVE", { dialogInterface, i -> + // your code here + }) + + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "NEGATIVE", { dialogInterface, j -> + // your code here + }) + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "NEUTRAL", { dialogInterface, k -> + // your code here + }) + + alertDialog.show() + } + + private fun showAlertWithTwoButton() { + val alertDialog = AlertDialog.Builder(this).create() + alertDialog.setTitle("Alert dialog") + alertDialog.setMessage("Simple Alert dialog positive and negative buttons") + + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "YES", { dialogInterface, i -> + // your code here + }) + + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "NO", { dialogInterface, i -> + // your code here + }) + + alertDialog.show() + } + + private fun showSimpleAlert() { + + val alertDialog = AlertDialog.Builder(this).create() + alertDialog.setTitle("Alert dialog") + alertDialog.setMessage("Simple Alert dialog") + + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", { dialogInterface, i -> + // your code here + }) + + alertDialog.show() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/manikandan/samplekotlinproject/BottomSheetActivity.kt b/app/src/main/java/com/manikandan/samplekotlinproject/BottomSheetActivity.kt new file mode 100644 index 0000000..af8fae3 --- /dev/null +++ b/app/src/main/java/com/manikandan/samplekotlinproject/BottomSheetActivity.kt @@ -0,0 +1,68 @@ +package com.manikandan.samplekotlinproject + +import android.os.Bundle +import android.support.design.widget.BottomSheetBehavior +import android.support.design.widget.CoordinatorLayout +import android.support.v7.app.AppCompatActivity +import android.util.Log +import android.view.View +import android.widget.Button +import android.widget.FrameLayout + +/** + * Created by manikandan on 20/03/18. + */ +class BottomSheetActivity : AppCompatActivity() { + + lateinit var coordinatorLayout: CoordinatorLayout + lateinit var bottomSheet: FrameLayout + lateinit var button: Button + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.bottom_sheet_activity) + + + coordinatorLayout = findViewById(R.id.main_content) as CoordinatorLayout + button = findViewById