android 悬浮通知
来源:互联网 发布:linux terminal 命令 编辑:程序博客网 时间:2024/05/17 14:19
public class FloatView { TextView txtTitle; TextView txtContent; TextView txtTime; private String keyWord; private int type; private static Bundle bundle; private WindowManager wm; private WindowManager.LayoutParams wmParams; private View view; private Context context; CountDownTimer countDownTimer; private long timeIndex = 6000; private long timeTemp = 500; private static FloatView floatView; private JPushEntity jPushEntity; public static FloatView getInstance(Bundle bundle, Context context) { if (floatView == null) { floatView = new FloatView(bundle, context); } floatView.bundle = bundle; return floatView; } private FloatView() { } private FloatView(Bundle bundle, Context context) { this.context = context; this.bundle = bundle; } private void createWindowManager(View view) { getWindowManager(view); } private WindowManager getWindowManager(View view) { if (wm == null) { wm = (WindowManager) context.getSystemService(context.WINDOW_SERVICE); wm.addView(view, createLayoutParams()); } else { wm.updateViewLayout(view, createLayoutParams()); } return wm; } private WindowManager.LayoutParams createLayoutParams() { if (wmParams == null) { wmParams = new WindowManager.LayoutParams(); wmParams.type = WindowManager.LayoutParams.TYPE_TOAST; wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; /** *这里的flags也很关键 *代码实际是wmParams.flags |= FLAG_NOT_FOCUSABLE; *40的由来是wmParams的默认属性(32)+ FLAG_NOT_FOCUSABLE(8) */// wmParams.alpha= 0.89f; wmParams.format = PixelFormat.TRANSPARENT; wmParams.gravity = Gravity.TOP; wmParams.width = WindowManager.LayoutParams.MATCH_PARENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; } return wmParams; } public void initViews() { createView(); setData(bundle); createWindowManager(view); getCountDownTimer(timeIndex, timeTemp); countDownTimer.start(); } private void setData(Bundle bundle) { String title = "", message = ""; jPushEntity = new JPushEntity(bundle); type = jPushEntity.getType(); keyWord = jPushEntity.getKeyWord(); title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE); message = bundle.getString(JPushInterface.EXTRA_ALERT); createView(); txtTitle.setText(title); txtContent.setText(message); txtTime.setText(DateUtil.getCurrentTimeHHMM()); } private View createView() { if (view == null) { LayoutInflater inflater = LayoutInflater.from(context); view = inflater.inflate(R.layout.float_view_layout, null); if(view!=null&&view.getBackground()!=null){ view.getBackground().setAlpha(204);//0~255透明度值 } txtTitle = (TextView) view.findViewById(R.id.txt_title); txtContent = (TextView) view.findViewById(R.id.txt_content); txtTime = (TextView) view.findViewById(R.id.txt_time); } view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); ActivityUtils.JpushJump(context, type, keyWord); JPushInterface.clearNotificationById(context, bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID)); } }); return view; } private void dismiss() { if (wm != null && view != null) { wm.removeView(view); } if (countDownTimer != null) countDownTimer.cancel(); wm = null; wmParams = null; view = null; }// private CountDownTimer getCountTimerInstance(long timeIndex, long timeTemp) {// if (countDownTimer != null) {// countDownTimer.cancel();// }// countDownTimer = getCountDownTimer(timeIndex, timeTemp);// return countDownTimer;// } private CountDownTimer getCountDownTimer(final long timeIndex, long timeTemp) { if (countDownTimer != null) { countDownTimer.cancel(); } countDownTimer = new CountDownTimer(timeIndex, timeTemp) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { dismiss(); } }; return countDownTimer; }}
阅读全文
0 0
- android 悬浮通知
- Android悬浮通知无效的问题
- Android 使用 WindowManager 打造悬浮通知
- android 应用内通知,仿通知栏通知效果,通知Toast,悬浮窗
- android 设置背景不跟随通知栏显示和隐藏变化(就如通知栏悬浮在窗口之上)
- dialog悬浮于通知栏上
- Android通知栏通知
- Android悬浮框应用--悬浮笔记
- Android悬浮控件
- Android中悬浮窗口
- android 悬浮窗口
- android 悬浮窗口
- Android悬浮窗口基本知识
- android 悬浮窗口
- Android悬浮窗功能
- Android 桌面悬浮框
- Android中悬浮窗口
- Android桌面悬浮窗
- VR技术推动学生的深度学习还真不是“扯淡”
- nodejs 对象保存redis 去除propotype
- App启动画面问题
- QT 生成EXE执行文件
- 51 nod 最高奖励(贪心+优先队列)
- android 悬浮通知
- mysql树形查询语句
- PullToFreshListView
- RAID常用级别的比较
- header("Content-type:text/html;charset=gb2312")所引起的POST接收乱码
- 阿里云前端工程化工具 Dawn 正式开源!
- 设计模式的学习之路 --- 第一站(模板模式)
- 记第一次使用线程池管理多线程
- Git官方教程 --gittutorial