diff --git a/modules/mogo-module-warning/src/main/java/com/mogo/module/warning/notification/WarningNotificationManager.java b/modules/mogo-module-warning/src/main/java/com/mogo/module/warning/notification/WarningNotificationManager.java
index fd8cfedaa4..42ffdf136d 100644
--- a/modules/mogo-module-warning/src/main/java/com/mogo/module/warning/notification/WarningNotificationManager.java
+++ b/modules/mogo-module-warning/src/main/java/com/mogo/module/warning/notification/WarningNotificationManager.java
@@ -1,10 +1,12 @@
package com.mogo.module.warning.notification;
-import android.app.Activity;
+import android.app.Service;
+import android.content.Context;
+import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.Toast;
+import android.view.WindowManager;
import com.mogo.module.warning.R;
@@ -14,16 +16,42 @@ import com.mogo.module.warning.R;
* 通知管理
*/
public class WarningNotificationManager {
+ // 这里采用添加View的方式,配合动画完成弹窗的效果,仅限应用内部弹窗,伴随着Activity后台也会隐藏
+
+ private static WindowManager mWindowManager;
+ private static WindowManager.LayoutParams mLayoutParams;
+
+ private static View mView;
- public static void show(Activity activity) {
- LayoutInflater inflater = activity.getLayoutInflater();
- View view = inflater.inflate(R.layout.notification_v2x_msg_vr, null);
- Toast toast = new Toast(activity.getApplicationContext());
- toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
- toast.setDuration(Toast.LENGTH_SHORT);
- toast.setView(view);
- toast.show();
+ public static void show(Context context) {
+ // 获取 WindowManager
+ mWindowManager = (WindowManager) context.getSystemService(Service.WINDOW_SERVICE);
+ mLayoutParams = new WindowManager.LayoutParams(
+ WindowManager.LayoutParams.WRAP_CONTENT,
+ WindowManager.LayoutParams.WRAP_CONTENT,
+ 0, 0,
+ PixelFormat.TRANSPARENT);
+ // flag 设置 Window 属性,悬浮窗的行为,比如说不可聚焦,非模态对话框等等
+ mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
+ // type 设置 Window 类别(层级),悬浮窗的类型,一般设为2002,表示在所有应用程序之上,但在状态栏之下
+ mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
+ // 悬浮窗的对齐方式
+ mLayoutParams.gravity = Gravity.TOP;
+ //
+ mLayoutParams.format = PixelFormat.RGBA_8888;
+ // 悬浮窗X的位置
+ mLayoutParams.x = 0;
+ //悬浮窗Y的位置,此时需要减去statusBar的高度
+ mLayoutParams.y = 110;
+ //添加动画
+ mLayoutParams.windowAnimations = R.style.notice_dialog_anim_bottom2top;
+
+ if (mView != null) {
+ mWindowManager.removeView(mView);
+ }
+ mView = LayoutInflater.from(context).inflate(R.layout.notification_v2x_msg_vr, null, false);
+ mWindowManager.addView(mView, mLayoutParams);
}
}
diff --git a/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_in.xml b/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_in.xml
new file mode 100644
index 0000000000..9f59ce777c
--- /dev/null
+++ b/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_in.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_out.xml b/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_out.xml
new file mode 100644
index 0000000000..da2ea9ff7b
--- /dev/null
+++ b/modules/mogo-module-warning/src/main/res/anim/notice_dialog_anim_top2bottom_out.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/modules/mogo-module-warning/src/main/res/values/notice_dialog_anim_bottom2top.xml b/modules/mogo-module-warning/src/main/res/values/notice_dialog_anim_bottom2top.xml
new file mode 100644
index 0000000000..61d0f84750
--- /dev/null
+++ b/modules/mogo-module-warning/src/main/res/values/notice_dialog_anim_bottom2top.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file