Created
March 23, 2016 07:53
-
-
Save devrath/26a182559a643fc5085b to your computer and use it in GitHub Desktop.
Utilities For Snackbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.godiswithme.Utils; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.graphics.Color; | |
import android.support.design.widget.Snackbar; | |
import android.view.View; | |
import com.godiswithme.R; | |
/** | |
* Created by Devrath on 23-03-2016. | |
*/ | |
public class UtilSnackbar { | |
/************************************ ShowSnackbar with message, KeepItDisplayedOnScreen for few seconds*****************************/ | |
public static void showSnakbarTypeOne(View rootView, String mMessage) { | |
Snackbar.make(rootView, mMessage, Snackbar.LENGTH_LONG) | |
.setAction("Action", null) | |
.show(); | |
} | |
/************************************ ShowSnackbar with message, KeepItDisplayedOnScreen*****************************/ | |
public static void showSnakbarTypeTwo(View rootView, String mMessage) { | |
Snackbar.make(rootView, mMessage, Snackbar.LENGTH_LONG) | |
.make(rootView, mMessage, Snackbar.LENGTH_INDEFINITE) | |
.setAction("Action", null) | |
.show(); | |
} | |
/************************************ ShowSnackbar without message, KeepItDisplayedOnScreen, OnClickOfOk restrat the activity*****************************/ | |
public static void showSnakbarTypeThree(View rootView, final Activity activity) { | |
Snackbar | |
.make(rootView, "NoInternetConnectivity", Snackbar.LENGTH_INDEFINITE) | |
.setAction("TryAgain", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent intent = activity.getIntent(); | |
activity.finish(); | |
activity.startActivity(intent); | |
} | |
}) | |
.setActionTextColor(Color.CYAN) | |
.setCallback(new Snackbar.Callback() { | |
@Override | |
public void onDismissed(Snackbar snackbar, int event) { | |
super.onDismissed(snackbar, event); | |
} | |
@Override | |
public void onShown(Snackbar snackbar) { | |
super.onShown(snackbar); | |
} | |
}) | |
.show(); | |
} | |
/************************************ ShowSnackbar with message, KeepItDisplayedOnScreen, OnClickOfOk restrat the activity*****************************/ | |
public static void showSnakbarTypeFour(View rootView, final Activity activity, String mMessage) { | |
Snackbar | |
.make(rootView, mMessage, Snackbar.LENGTH_INDEFINITE) | |
.setAction("TryAgain", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent intent = activity.getIntent(); | |
activity.finish(); | |
activity.startActivity(intent); | |
} | |
}) | |
.setActionTextColor(Color.CYAN) | |
.setCallback(new Snackbar.Callback() { | |
@Override | |
public void onDismissed(Snackbar snackbar, int event) { | |
super.onDismissed(snackbar, event); | |
} | |
@Override | |
public void onShown(Snackbar snackbar) { | |
super.onShown(snackbar); | |
} | |
}) | |
.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment