Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #26 #27

Open
wants to merge 1 commit into
base: lib
Choose a base branch
from
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
12 changes: 6 additions & 6 deletions app/src/main/java/com/sdsmdg/demoexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
27 changes: 12 additions & 15 deletions tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,25 @@ 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;
static InfoToastView infoToastView;
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down