From f8b8f475fffa3b71d6f69c4525c7a9df62da3d71 Mon Sep 17 00:00:00 2001 From: Muddassir Khan Date: Wed, 2 Sep 2020 07:33:00 +0500 Subject: [PATCH] Add toast extensions --- .../java/com/muddassir/kmacros/context.kt | 19 +++++++++++++++++++ .../java/com/muddassir/kmacros/functions.kt | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/kmacros/src/main/java/com/muddassir/kmacros/context.kt b/kmacros/src/main/java/com/muddassir/kmacros/context.kt index 4280836..ea0aca8 100644 --- a/kmacros/src/main/java/com/muddassir/kmacros/context.kt +++ b/kmacros/src/main/java/com/muddassir/kmacros/context.kt @@ -7,8 +7,27 @@ import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.os.Bundle +import android.widget.Toast import kotlin.reflect.KClass +/** + * toast - Show a short toast with the specified text. + * + * @param text The text to show + */ +fun Context.toast(text: String) { + Toast.makeText(this, text, Toast.LENGTH_SHORT).show() +} + +/** + * toast - Show a long toast with the specified text. + * + * @param text The text to show + */ +fun Context.toastLong(text: String) { + Toast.makeText(this, text, Toast.LENGTH_LONG).show() +} + /** * createIntent - Creates an intent for the specified activity . * diff --git a/kmacros/src/main/java/com/muddassir/kmacros/functions.kt b/kmacros/src/main/java/com/muddassir/kmacros/functions.kt index af96438..e32ef6d 100644 --- a/kmacros/src/main/java/com/muddassir/kmacros/functions.kt +++ b/kmacros/src/main/java/com/muddassir/kmacros/functions.kt @@ -3,7 +3,7 @@ package com.muddassir.kmacros import android.os.Handler /** - * safe - The action to perform. + * safe - Run a block of code safely. Avoiding any exceptions. * * @param action The action to perform safely. */