2016-06-07 21:48:17 +02:00
|
|
|
package info.nightscout.utils;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-08-02 18:39:14 +02:00
|
|
|
import android.media.MediaPlayer;
|
2016-06-07 21:48:17 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
2016-08-02 18:39:14 +02:00
|
|
|
public class ToastUtils {
|
2016-06-07 21:48:17 +02:00
|
|
|
public static void showToastInUiThread(final Context ctx,
|
|
|
|
final String string) {
|
|
|
|
|
|
|
|
Handler mainThread = new Handler(Looper.getMainLooper());
|
|
|
|
mainThread.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-08-02 18:39:14 +02:00
|
|
|
|
|
|
|
public static void showToastInUiThread(final Context ctx,
|
|
|
|
final String string, int soundID) {
|
|
|
|
|
|
|
|
showToastInUiThread(ctx, string);
|
|
|
|
playSound(ctx, soundID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void playSound(final Context ctx, final int soundID) {
|
|
|
|
final MediaPlayer soundMP = MediaPlayer.create(ctx, soundID);
|
|
|
|
soundMP.start();
|
|
|
|
soundMP.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
|
|
|
@Override
|
|
|
|
public void onCompletion(MediaPlayer mp) {
|
|
|
|
mp.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-06-07 21:48:17 +02:00
|
|
|
}
|