|
|
@@ -0,0 +1,147 @@
|
|
|
+package com.umano.message.supertoasts.utils;
|
|
|
+
|
|
|
+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.support.v7.app.NotificationCompat;
|
|
|
+import android.text.Layout;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.umano.message.supertoasts.R;
|
|
|
+import com.umano.message.supertoasts.interfacepack.BaseToast;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by FANGlh on 2017/8/10.
|
|
|
+ * function:
|
|
|
+ */
|
|
|
+
|
|
|
+public class ToastImpl implements BaseToast {
|
|
|
+ private static ToastImpl instance;
|
|
|
+ public static ToastImpl getInstance(){
|
|
|
+ if (instance==null){
|
|
|
+ synchronized (ToastImpl.class){
|
|
|
+ if (instance==null){
|
|
|
+ instance=new ToastImpl();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return instance;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void show(String text,int messageColor, int background) {
|
|
|
+// ToastUtils.showLong(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtTop(String text,int messageColor, int background) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtCenter(String text,int messageColor, int background) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtBottom(String text,int messageColor, int background) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtNotiftion(Class<? extends Activity> clazz, String title, String text) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void CustomLayout(Layout layout) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void show(Context ct, String text,int messageColor, int background) {
|
|
|
+ Toast toast = null;
|
|
|
+ toast = Toast.makeText(ct, text, Toast.LENGTH_LONG);
|
|
|
+ View view = toast.getView();
|
|
|
+ TextView message=((TextView) view.findViewById(android.R.id.message));
|
|
|
+ if (background != -1)
|
|
|
+ message.setBackgroundColor(background);
|
|
|
+ if (messageColor != -1)
|
|
|
+ message.setTextColor(messageColor);
|
|
|
+ toast.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtTop(Context ct, String text,int messageColor, int background) {
|
|
|
+ Toast toast = null;
|
|
|
+ toast = Toast.makeText(ct, text, Toast.LENGTH_LONG);
|
|
|
+ //设置Toast的位置
|
|
|
+ toast.setGravity(Gravity.TOP, toast.getXOffset()/2, toast.getYOffset()/5);
|
|
|
+ View view = toast.getView();
|
|
|
+ TextView message=((TextView) view.findViewById(android.R.id.message));
|
|
|
+ if (background != -1)
|
|
|
+ message.setBackgroundColor(background);
|
|
|
+ if (messageColor != -1)
|
|
|
+ message.setTextColor(messageColor);
|
|
|
+ toast.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtCenter(Context ct, String text,int messageColor, int background) {
|
|
|
+ Toast toast = null;
|
|
|
+ toast = Toast.makeText(ct, text, Toast.LENGTH_LONG);
|
|
|
+ //设置Toast的位置
|
|
|
+ toast.setGravity(Gravity.CENTER, toast.getXOffset()/2, toast.getYOffset()/2);
|
|
|
+ View view = toast.getView();
|
|
|
+ TextView message=((TextView) view.findViewById(android.R.id.message));
|
|
|
+ if (background != -1)
|
|
|
+ message.setBackgroundColor(background);
|
|
|
+ if (messageColor != -1)
|
|
|
+ message.setTextColor(messageColor);
|
|
|
+ toast.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showAtBottom(Context ct, String text,int messageColor, int background) {
|
|
|
+ Toast toast = null;
|
|
|
+ toast = Toast.makeText(ct, text, Toast.LENGTH_LONG);
|
|
|
+ //设置Toast的位置
|
|
|
+ toast.setGravity(Gravity.BOTTOM, toast.getXOffset()/2, toast.getYOffset()/5);
|
|
|
+ View view = toast.getView();
|
|
|
+ TextView message=((TextView) view.findViewById(android.R.id.message));
|
|
|
+ if (background != -1)
|
|
|
+ message.setBackgroundColor(background);
|
|
|
+ if (messageColor != -1)
|
|
|
+ message.setTextColor(messageColor);
|
|
|
+ toast.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());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void CustomLayout(Context ct, Layout layout) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|