|
|
@@ -0,0 +1,154 @@
|
|
|
+package com.umano.message.supertoasts.imp;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.Notification;
|
|
|
+import android.app.NotificationManager;
|
|
|
+import android.app.PendingIntent;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.support.v7.app.NotificationCompat;
|
|
|
+import android.view.Gravity;
|
|
|
+
|
|
|
+import com.github.johnpersano.supertoasts.library.Style;
|
|
|
+import com.github.johnpersano.supertoasts.library.SuperToast;
|
|
|
+import com.github.johnpersano.supertoasts.library.utils.PaletteUtils;
|
|
|
+import com.umano.message.supertoasts.R;
|
|
|
+import com.umano.message.supertoasts.interfacepack.BaseToast;
|
|
|
+import com.umano.message.supertoasts.utils.Utils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 暂时做成工具类,后面调整灵活切换,这里不设置颜色
|
|
|
+ * Created by Arison on 2017/5/25.
|
|
|
+ * 自定义工具实现,主要是位置,其他默认
|
|
|
+ */
|
|
|
+public class BaseToastImpl implements BaseToast {
|
|
|
+
|
|
|
+ private static BaseToastImpl instance;
|
|
|
+
|
|
|
+ public static BaseToastImpl getInstance(){
|
|
|
+ if (instance==null){
|
|
|
+ synchronized (BaseToastImpl.class){
|
|
|
+ if (instance==null){
|
|
|
+ instance=new BaseToastImpl();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return instance;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void show(String text) {
|
|
|
+ new SuperToast(Utils.getContext()).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtTop(String text) {
|
|
|
+ new SuperToast(Utils.getContext()).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(Color.parseColor("#A6424242"))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .setGravity(Gravity.TOP)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtCenter(String text) {
|
|
|
+ new SuperToast(Utils.getContext()).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .setGravity(Gravity.CENTER)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtBottom(String text) {
|
|
|
+ new SuperToast(Utils.getContext()).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .setGravity(Gravity.BOTTOM)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtNotiftion(Class<? extends Activity> clazz, String title, String text) {
|
|
|
+ NotificationManager mNotificationManager = (NotificationManager) Utils.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(Utils.getContext().getApplicationContext());
|
|
|
+ builder.setSmallIcon(R.drawable.uuu);
|
|
|
+ builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
|
|
|
+ builder.setAutoCancel(true);
|
|
|
+ builder.setContentTitle(title);
|
|
|
+ builder.setContentText(text);
|
|
|
+ Intent intent = new Intent(Utils.getContext(), clazz);
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getActivity(Utils.getContext().getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
+ builder.setContentIntent(pendingIntent);
|
|
|
+ mNotificationManager.notify(1000, builder.build());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void show(Context ct, String text) {
|
|
|
+ new SuperToast(Utils.getContext()).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtTop(Context ct, String text) {
|
|
|
+ new SuperToast(ct).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtCenter(Context ct, String text) {
|
|
|
+ new SuperToast(ct).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .setGravity(Gravity.CENTER)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtBottom(Context ct, String text) {
|
|
|
+ new SuperToast(ct).setText(text)
|
|
|
+ .setDuration(Style.DURATION_VERY_LONG)
|
|
|
+ .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
|
|
|
+ .setAnimations(Style.ANIMATIONS_FADE)
|
|
|
+ .setFrame(Style.FRAME_STANDARD)
|
|
|
+ .setGravity(Gravity.BOTTOM)
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtNotiftion(Context ct, Class<? extends Activity> clazz, String title, String text) {
|
|
|
+ NotificationManager mNotificationManager = (NotificationManager) ct.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(ct.getApplicationContext());
|
|
|
+ builder.setSmallIcon(R.drawable.uuu);
|
|
|
+ builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
|
|
|
+ builder.setAutoCancel(true);
|
|
|
+ builder.setContentTitle(title);
|
|
|
+ builder.setContentText(text);
|
|
|
+ Intent intent = new Intent(ct, clazz);
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getActivity(ct.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
+ builder.setContentIntent(pendingIntent);
|
|
|
+ mNotificationManager.notify(1000, builder.build());
|
|
|
+ }
|
|
|
+}
|