From 16c19761187151f806cb85d0552061cd74b3a51a Mon Sep 17 00:00:00 2001 From: pkarira Date: Wed, 5 Apr 2017 02:12:17 +0530 Subject: [PATCH] created enum for toast type --- .../com/sdsmdg/demoexample/MainActivity.java | 12 ++++----- .../com/sdsmdg/tastytoast/TastyToast.java | 27 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java b/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java index 9ede572..4a27a45 100644 --- a/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java +++ b/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java @@ -21,31 +21,31 @@ protected void onCreate(Bundle savedInstanceState) { public void showSuccessToast(View view) { TastyToast.makeText(getApplicationContext(), "Download Successful !", TastyToast.LENGTH_LONG, - TastyToast.SUCCESS); + TastyToast.Type.SUCCESS); } public void showWarningToast(View view) { TastyToast.makeText(getApplicationContext(), "Are you sure ?", TastyToast.LENGTH_LONG, - TastyToast.WARNING); + TastyToast.Type.WARNING); } public void showErrorToast(View view) { TastyToast.makeText(getApplicationContext(), "Downloading failed ! Try again later ", TastyToast.LENGTH_LONG, - TastyToast.ERROR); + TastyToast.Type.ERROR); } public void showInfoToast(View view) { TastyToast.makeText(getApplicationContext(), "Searching for username : 'Rahul' ", TastyToast.LENGTH_LONG, - TastyToast.INFO); + TastyToast.Type.INFO); } public void showDefaultToast(View view) { TastyToast.makeText(getApplicationContext(), "This is Default Toast", TastyToast.LENGTH_LONG, - TastyToast.DEFAULT); + TastyToast.Type.DEFAULT); } public void showConfusingToast(View view) { TastyToast.makeText(getApplicationContext(), "I don't Know !", TastyToast.LENGTH_LONG, - TastyToast.CONFUSING); + TastyToast.Type.CONFUSING); } } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java index bdb7400..5f7bb40 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java @@ -19,14 +19,6 @@ public class TastyToast { public static final int LENGTH_SHORT = 0; public static final int LENGTH_LONG = 1; - - 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; - static SuccessToastView successToastView; static WarningToastView warningToastView; static ErrorToastView errorToastView; @@ -34,13 +26,18 @@ public class TastyToast { static DefaultToastView defaultToastView; static ConfusingToastView confusingToastView; - public static Toast makeText(Context context, String msg, int length, int type) { + public static enum Type + { + SUCCESS,WARNING,ERROR,INFO,DEFAULT,CONFUSING + } + + public static Toast makeText(Context context, String msg, int length, Type type) { Toast toast = new Toast(context); switch (type) { - case 1: { + case SUCCESS: { View layout = LayoutInflater.from(context).inflate(R.layout.success_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); @@ -51,7 +48,7 @@ public static Toast makeText(Context context, String msg, int length, int type) toast.setView(layout); break; } - case 2: { + case WARNING: { View layout = LayoutInflater.from(context).inflate(R.layout.warning_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage); @@ -91,7 +88,7 @@ public void run() { toast.setView(layout); break; } - case 3: { + case ERROR: { View layout = LayoutInflater.from(context).inflate(R.layout.error_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage); @@ -103,7 +100,7 @@ public void run() { toast.setView(layout); break; } - case 4: { + case INFO: { View layout = LayoutInflater.from(context).inflate(R.layout.info_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage); @@ -115,7 +112,7 @@ public void run() { toast.setView(layout); break; } - case 5: { + case DEFAULT: { View layout = LayoutInflater.from(context).inflate(R.layout.default_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage); @@ -127,7 +124,7 @@ public void run() { toast.setView(layout); break; } - case 6: { + case CONFUSING: { View layout = LayoutInflater.from(context).inflate(R.layout.confusing_toast_layout, null, false); TextView text = (TextView) layout.findViewById(R.id.toastMessage);