From 4e1e83a7fcb81139598f5a60320c27acd72fafe8 Mon Sep 17 00:00:00 2001 From: MarsadMaqsood Date: Sat, 19 Mar 2022 18:49:00 +0500 Subject: [PATCH] Added kotlin code examples --- .../marsad/stylishdialogs/ExampleActivity.kt | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 app/src/main/java/com/marsad/stylishdialogs/ExampleActivity.kt diff --git a/app/src/main/java/com/marsad/stylishdialogs/ExampleActivity.kt b/app/src/main/java/com/marsad/stylishdialogs/ExampleActivity.kt new file mode 100644 index 0000000..d812406 --- /dev/null +++ b/app/src/main/java/com/marsad/stylishdialogs/ExampleActivity.kt @@ -0,0 +1,83 @@ +package com.marsad.stylishdialogs + +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import java.sql.DriverManager.println + +class ExampleActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + findViewById(R.id.simpleMsgDialog) + .setOnClickListener { + StylishAlertDialog(this, StylishAlertDialog.NORMAL) + .setContentText("Hey, You try me") + .show() + } + findViewById(R.id.titleWTextDialog) + .setOnClickListener { + StylishAlertDialog(this, StylishAlertDialog.NORMAL) + .setTitleText("Hey, This is title") + .setContentText("Content text") //.setCancellable(false) + .setCancelledOnTouchOutside(false) + .setConfirmButton( + "Dismiss" + ) { obj: StylishAlertDialog -> obj.dismissWithAnimation() } + .show() + } + findViewById(R.id.successMsgDialog) + .setOnClickListener { + StylishAlertDialog(this, StylishAlertDialog.SUCCESS) + .setContentText("Hey, You try me") + .show() + } + findViewById(R.id.errorMsgDialog) + .setOnClickListener { + StylishAlertDialog(this, StylishAlertDialog.ERROR) + .setContentText("Hey, You try me") + .show() + } + findViewById(R.id.successWithNormalDialog) + .setOnClickListener { + val alertDialog = + StylishAlertDialog(this, StylishAlertDialog.PROGRESS) + alertDialog.setContentText("Processing...") + .show() + Handler(Looper.getMainLooper()) + .postDelayed({ + alertDialog.changeAlertType(StylishAlertDialog.SUCCESS) + alertDialog.contentText = "Task Completed" + alertDialog.setConfirmButton( + "OK" + ) { obj: StylishAlertDialog -> obj.dismissWithAnimation() } + alertDialog.setCancelButton( + "Cancel" + ) { obj: StylishAlertDialog -> obj.dismissWithAnimation() } + }, 2500) + } + findViewById(R.id.warnWithConfirmBtn) + .setOnClickListener { + val alertDialog = + StylishAlertDialog(this, StylishAlertDialog.WARNING) + alertDialog.setContentText("Are you sure you want to proceed") + .setConfirmButton( + "Yes, Proceed" + ) { + alertDialog.changeAlertType(StylishAlertDialog.SUCCESS) + alertDialog.setContentText("Job Done") + .setDismissOnClick(true) + alertDialog.setConfirmButton( + "OK" + ) { + println( + "Completed" + ) + } + } + .show() + } + } +} \ No newline at end of file