Skip to content

Instantly share code, notes, and snippets.

@Pkmmte
Created April 4, 2017 23:36
Show Gist options
  • Save Pkmmte/6bc7e1566602af2c933bb0a5e082e01b to your computer and use it in GitHub Desktop.
Save Pkmmte/6bc7e1566602af2c933bb0a5e082e01b to your computer and use it in GitHub Desktop.
import android.support.annotation.IntDef;
import android.support.annotation.StringRes;
import android.widget.Toast;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static android.widget.Toast.LENGTH_LONG;
import static android.widget.Toast.LENGTH_SHORT;
/**
* Created on 3/27/2017
*
* @author Pkmmte Xeleon
*/
public class Toaster {
// Length constants
@IntDef({LENGTH_LONG, LENGTH_SHORT})
@Retention(RetentionPolicy.SOURCE)
public @interface Length {}
public static void make(@StringRes int resId) {
make(resId, LENGTH_SHORT);
}
public static void make(@StringRes int resId, @Length int length) {
Toast.makeText(Contextor.getContext(), resId, length).show();
}
public static void make(Object object) {
make(String.valueOf(object));
}
public static void make(CharSequence text) {
make(text, LENGTH_SHORT);
}
public static void make(CharSequence text, @Length int length) {
Toast.makeText(Contextor.getContext(), text, length).show();
}
public static void make(@StringRes int resId, Object... formatArgs) {
make(resId, LENGTH_SHORT, formatArgs);
}
public static void make(@StringRes int resId, @Length int length, Object... formatArgs) {
Toast.makeText(Contextor.getContext(), Contextor.getContext().getString(resId, formatArgs), length).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment