-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
WordPressUtils/src/main/java/org/wordpress/android/util/ToastUtils.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.content.Context; | ||
import android.view.Gravity; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Provides a simplified way to show toast messages without having to create the toast, set the | ||
* desired gravity, etc. | ||
*/ | ||
public class ToastUtils { | ||
public enum Duration {SHORT, LONG} | ||
|
||
private ToastUtils() { | ||
throw new AssertionError(); | ||
} | ||
|
||
public static void showToast(Context context, int stringResId) { | ||
showToast(context, stringResId, Duration.SHORT); | ||
} | ||
|
||
public static void showToast(Context context, int stringResId, Duration duration) { | ||
showToast(context, context.getString(stringResId), duration); | ||
} | ||
|
||
public static void showToast(Context context, String text) { | ||
showToast(context, text, Duration.SHORT); | ||
} | ||
|
||
public static void showToast(Context context, String text, Duration duration) { | ||
Toast toast = Toast.makeText(context, text, | ||
(duration == Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)); | ||
toast.setGravity(Gravity.CENTER, 0, 0); | ||
toast.show(); | ||
} | ||
} |