Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions fancytoastlib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

allprojects {
plugins.withId("com.vanniktech.maven.publish") {
Expand All @@ -9,11 +10,11 @@ allprojects {
}

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
minSdkVersion 15
targetSdkVersion 31
targetSdkVersion 33
}
buildTypes {
release {
Expand All @@ -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'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<LinearLayout>(R.id.toast_type)
val imgIcon = layout.findViewById<ImageView>(R.id.toast_icon)
val imgAndroid = layout.findViewById<ImageView>(R.id.imageView4)
val toastText = layout.findViewById<TextView>(R.id.toast_text)
toastText.text = message
imgAndroid.visibility = if (androidIcon) View.VISIBLE else View.GONE

when (type) {
SUCCESS -> {
linearLayout.setBackgroundResource(R.drawable.success_shape)
imgIcon.setImageResource(R.drawable.ic_check_black_24dp)
}
WARNING -> {
linearLayout.setBackgroundResource(R.drawable.warning_shape)
imgIcon.setImageResource(R.drawable.ic_pan_tool_black_24dp)
}
ERROR -> {
linearLayout.setBackgroundResource(R.drawable.error_shape)
imgIcon.setImageResource(R.drawable.ic_clear_black_24dp)
}
INFO -> {
linearLayout.setBackgroundResource(R.drawable.info_shape)
imgIcon.setImageResource(R.drawable.ic_info_outline_black_24dp)
}
CONFUSING -> {
linearLayout.setBackgroundResource(R.drawable.confusing_shape)
imgIcon.setImageResource(R.drawable.ic_refresh_black_24dp)
}
DEFAULT -> {
linearLayout.setBackgroundResource(R.drawable.default_shape)
imgIcon.visibility = View.GONE
}
}

val toast = Toast(context)
toast.duration = duration
toast.view = layout
return toast
}


@JvmStatic
fun makeText(
context: Context,
message: CharSequence?,
@Duration duration: Int,
@LayoutType type: Int,
@DrawableRes ImageResource: Int,
androidIcon: Boolean
): Toast {
val layout =
LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false)
val linearLayout = layout.findViewById<LinearLayout>(R.id.toast_type)
val imgIcon = layout.findViewById<ImageView>(R.id.toast_icon)
val imgAndroid = layout.findViewById<ImageView>(R.id.imageView4)
val toastText = layout.findViewById<TextView>(R.id.toast_text)
toastText.text = message
imgIcon.setImageResource(ImageResource)
imgAndroid.visibility = if (androidIcon) View.VISIBLE else View.GONE

when (type) {
SUCCESS -> {
linearLayout.setBackgroundResource(R.drawable.success_shape)
}
WARNING -> {
linearLayout.setBackgroundResource(R.drawable.warning_shape)
}
ERROR -> {
linearLayout.setBackgroundResource(R.drawable.error_shape)
}
INFO -> {
linearLayout.setBackgroundResource(R.drawable.info_shape)
}
DEFAULT -> {
linearLayout.setBackgroundResource(R.drawable.default_shape)
imgIcon.visibility = View.GONE
}
CONFUSING -> {
linearLayout.setBackgroundResource(R.drawable.confusing_shape)
}
else -> {
linearLayout.setBackgroundResource(R.drawable.default_shape)
imgIcon.visibility = View.GONE
}
}

val toast = Toast(context)
toast.duration = duration
toast.view = layout
return toast
}
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 29 20:22:51 IST 2019
#Mon Oct 17 16:08:15 WIB 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip