diff --git a/app/build.gradle b/app/build.gradle index 1d2ac04..099211c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { applicationId "com.shashank.sony.fancytoastlibrary" minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -23,7 +23,7 @@ dependencies { androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) - implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' implementation project(':fancytoastlib') diff --git a/build.gradle b/build.gradle index 9a99918..e5f2552 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ buildscript { classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0' classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.10.2' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20' } } allprojects { diff --git a/fancytoastlib/build.gradle b/fancytoastlib/build.gradle index 2ae181f..5844aeb 100644 --- a/fancytoastlib/build.gradle +++ b/fancytoastlib/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'org.jetbrains.kotlin.android' allprojects { plugins.withId("com.vanniktech.maven.publish") { @@ -9,11 +10,11 @@ allprojects { } android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { minSdkVersion 15 - targetSdkVersion 31 + targetSdkVersion 33 } buildTypes { release { @@ -25,7 +26,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.appcompat:appcompat:1.5.1' } apply plugin: 'com.vanniktech.maven.publish' diff --git a/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.java b/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.java deleted file mode 100644 index ef7b7de..0000000 --- a/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.shashank.sony.fancytoastlib; - -import android.app.Activity; -import android.app.Application; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.NonNull; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -public class FancyToast extends Toast { - - @Retention(RetentionPolicy.SOURCE) - @IntDef({SUCCESS, WARNING, ERROR, INFO, DEFAULT, CONFUSING}) - public @interface LayoutType {} - public static final int SUCCESS = 1; - public static final int WARNING = 2; - public static final int ERROR = 3; - public static final int INFO = 4; - public static final int DEFAULT = 5; - public static final int CONFUSING = 6; - - - @IntDef({ LENGTH_SHORT, LENGTH_LONG }) - @Retention(RetentionPolicy.SOURCE) - public @interface Duration {} - public static final int LENGTH_SHORT = Toast.LENGTH_SHORT; - public static final int LENGTH_LONG = Toast.LENGTH_LONG; - - /** - * Construct an empty Toast object. You must call {@link #setView} before you - * can call {@link #show}. - *
- *
- * @param context The context to use. Usually your {@link Application}
- * or {@link Activity} object.
- */
- public FancyToast(@NonNull Context context) {
- super(context);
- }
-
- public static Toast makeText(@NonNull Context context, CharSequence message, @Duration int duration, @LayoutType int type, boolean androidIcon) {
- Toast toast = new Toast(context);
- toast.setDuration(duration);
- View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
- TextView l1 = layout.findViewById(R.id.toast_text);
- LinearLayout linearLayout = layout.findViewById(R.id.toast_type);
- ImageView img = layout.findViewById(R.id.toast_icon);
- ImageView img1 = layout.findViewById(R.id.imageView4);
- l1.setText(message);
- if (androidIcon)
- img1.setVisibility(View.VISIBLE);
- else img1.setVisibility(View.GONE);
- switch (type) {
- case SUCCESS:
- linearLayout.setBackgroundResource(R.drawable.success_shape);
- img.setImageResource(R.drawable.ic_check_black_24dp);
- break;
- case WARNING:
- linearLayout.setBackgroundResource(R.drawable.warning_shape);
- img.setImageResource(R.drawable.ic_pan_tool_black_24dp);
- break;
- case ERROR:
- linearLayout.setBackgroundResource(R.drawable.error_shape);
- img.setImageResource(R.drawable.ic_clear_black_24dp);
- break;
- case INFO:
- linearLayout.setBackgroundResource(R.drawable.info_shape);
- img.setImageResource(R.drawable.ic_info_outline_black_24dp);
- break;
- case DEFAULT:
- linearLayout.setBackgroundResource(R.drawable.default_shape);
- img.setVisibility(View.GONE);
- break;
- case CONFUSING:
- linearLayout.setBackgroundResource(R.drawable.confusing_shape);
- img.setImageResource(R.drawable.ic_refresh_black_24dp);
- break;
- }
- toast.setView(layout);
- return toast;
- }
-
-
- public static Toast makeText(@NonNull Context context, CharSequence message, @Duration int duration, @LayoutType int type, @DrawableRes int ImageResource, boolean androidIcon) {
- Toast toast = new Toast(context);
- toast.setDuration(duration);
- View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
- TextView l1 = layout.findViewById(R.id.toast_text);
- LinearLayout linearLayout = layout.findViewById(R.id.toast_type);
- ImageView img = layout.findViewById(R.id.toast_icon);
- ImageView img1 = layout.findViewById(R.id.imageView4);
- l1.setText(message);
- img.setImageResource(ImageResource);
- if (androidIcon)
- img1.setVisibility(View.VISIBLE);
- else img1.setVisibility(View.GONE);
- switch (type) {
- case SUCCESS:
- linearLayout.setBackgroundResource(R.drawable.success_shape);
- break;
- case WARNING:
- linearLayout.setBackgroundResource(R.drawable.warning_shape);
- break;
- case ERROR:
- linearLayout.setBackgroundResource(R.drawable.error_shape);
- break;
- case INFO:
- linearLayout.setBackgroundResource(R.drawable.info_shape);
- break;
- case DEFAULT: {
- linearLayout.setBackgroundResource(R.drawable.default_shape);
- img.setVisibility(View.GONE);
- break;
- }
- case CONFUSING:
- linearLayout.setBackgroundResource(R.drawable.confusing_shape);
- break;
- default:
- linearLayout.setBackgroundResource(R.drawable.default_shape);
- img.setVisibility(View.GONE);
- break;
- }
- toast.setView(layout);
- return toast;
- }
-
-}
diff --git a/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.kt b/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.kt
new file mode 100644
index 0000000..dbcc41e
--- /dev/null
+++ b/fancytoastlib/src/main/java/com/shashank/sony/fancytoastlib/FancyToast.kt
@@ -0,0 +1,137 @@
+package com.shashank.sony.fancytoastlib
+
+import android.content.Context
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.ImageView
+import android.widget.LinearLayout
+import android.widget.TextView
+import android.widget.Toast
+import androidx.annotation.DrawableRes
+import androidx.annotation.IntDef
+
+class FancyToast(context: Context) : Toast(context) {
+
+ companion object {
+ @Retention(AnnotationRetention.SOURCE)
+ @IntDef(SUCCESS, WARNING, ERROR, INFO, DEFAULT, CONFUSING)
+ annotation class LayoutType
+
+ const val SUCCESS = 1
+ const val WARNING = 2
+ const val ERROR = 3
+ const val INFO = 4
+ const val DEFAULT = 5
+ const val CONFUSING = 6
+
+
+ @IntDef(LENGTH_SHORT, LENGTH_LONG)
+ @Retention(AnnotationRetention.SOURCE)
+ annotation class Duration
+
+ const val LENGTH_SHORT = Toast.LENGTH_SHORT
+ const val LENGTH_LONG = Toast.LENGTH_LONG
+
+ @JvmStatic
+ fun makeText(
+ context: Context,
+ message: CharSequence,
+ @Duration duration: Int,
+ @LayoutType type: Int,
+ androidIcon: Boolean,
+ ): Toast {
+ val layout = LayoutInflater.from(context)
+ .inflate(R.layout.fancytoast_layout, null, false)
+ val linearLayout = layout.findViewById