当前位置:   article > 正文

9.0 自定义SystemUI下拉状态栏和通知栏视图(十五)之悬浮通知布局_systemui 通知下拉流程

systemui 通知下拉流程

1.前言

在进行9.0的系统rom产品定制化开发中,在9.0中针对systemui下拉状态栏和通知栏的定制UI的工作开发中,原生系统的下拉状态栏和通知栏的视图UI在产品开发中会不太满足功能,

所以根据产品需要来自定义SystemUI的下拉状态栏和通知栏功能,首选实现的就是下拉通知栏左滑删除通知的部分功能,接下来就来实现第十五部分关于实现systemui关于悬浮

通知的相关布局实现

效果图如图:

2. 自定义SystemUI下拉状态栏和通知栏视图(十五)之悬浮通知布局的核心类

  1. frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java
  2. frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java
  3. frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java

3.自定义SystemUI下拉状态栏和通知栏视图(十五)之悬浮通知布局的核心功能分析和实现

在9.0的systemui系统中的悬浮通知也是调用的下拉状态栏的相关的悬浮通知来显示悬浮通知的,所以也需要监听系统关于悬浮通知的相关流程,然后

在这里添加自定义的悬浮通知的接口,首先需要实现对悬浮通知的监听

3.1NotificationInflater.java 弹窗类型分析

  1. public class NotificationInflater {
  2. public void inflateNotificationViews() {
  3. inflateNotificationViews(FLAG_REINFLATE_ALL);
  4. }
  5. /**
  6. * Reinflate all views for the specified flags on a background thread. This is asynchronous and
  7. * will notify the callback once it's finished.
  8. *
  9. * @param reInflateFlags flags which views should be reinflated. Use {@link #FLAG_REINFLATE_ALL}
  10. * to reinflate all of views.
  11. */
  12. @VisibleForTesting
  13. void inflateNotificationViews(int reInflateFlags) {
  14. if (mRow.isRemoved()) {
  15. // We don't want to reinflate anything for removed notifications. Otherwise views might
  16. // be readded to the stack, leading to leaks. This may happen with low-priority groups
  17. // where the removal of already removed children can lead to a reinflation.
  18. return;
  19. }
  20. StatusBarNotification sbn = mRow.getEntry().notification;
  21. AsyncInflationTask task = new AsyncInflationTask(sbn, reInflateFlags, mRow,
  22. mIsLowPriority,
  23. mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight, mRedactAmbient,
  24. mCallback, mRemoteViewClickHandler);
  25. if (mCallback != null && mCallback.doInflateSynchronous()) {
  26. task.onPostExecute(task.doInBackground());
  27. } else {
  28. task.execute();
  29. }
  30. }
  31. @VisibleForTesting
  32. InflationProgress inflateNotificationViews(int reInflateFlags,
  33. Notification.Builder builder, Context packageContext) {
  34. InflationProgress result = createRemoteViews(reInflateFlags, builder, mIsLowPriority,
  35. mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight,
  36. mRedactAmbient, packageContext);
  37. apply(result, reInflateFlags, mRow, mRedactAmbient, mRemoteViewClickHandler, null);
  38. return result;
  39. }

通过NotificationInflater.java中的上述几个常量发现那就是通知的几种类型 而弹窗通知具体是由NotificationAlertingManager来管理NotificationAlertingManager 构造函数中给NotificationEntryManager 加 NotificationEntryListener ,

以便在通知视图首次填充(onEntryInflated) 时 感知并弹出悬浮通知。

而在NotificationAlertingManager.java 负责管理弹出悬浮通知,接下来分析下NotificationAlertingManager.java悬浮通知的方法

3.2 NotificationEntryManager.java 弹窗通知分析

  1. public NotificationEntryManager(Context context) {
  2. mContext = context;
  3. mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
  4. mBarService = IStatusBarService.Stub.asInterface(
  5. ServiceManager.getService(Context.STATUS_BAR_SERVICE));
  6. mMessagingUtil = new NotificationMessagingUtil(context);
  7. mSystemServicesProxy = SystemServicesProxy.getInstance(mContext);
  8. mGroupManager.setPendingEntries(mPendingNotifications);
  9. mFGSExtender.setCallback(key -> removeNotification(key, mLatestRankingMap));
  10. }
  11. private void addEntry(NotificationData.Entry shadeEntry) {
  12. boolean isHeadsUped = shouldPeek(shadeEntry);
  13. if (isHeadsUped) {
  14. mHeadsUpManager.showNotification(shadeEntry);
  15. + Log.e("NotificationPanelViewController", "entry:"+ entry.notification);
  16. + if(shadeEntry.notification!=null)NotificationHelper.getInstance().addAlertNotification(shadeEntry.notification);
  17. // Mark as seen immediately
  18. setNotificationShown(shadeEntry.notification);
  19. }
  20. addNotificationViews(shadeEntry);
  21. mCallback.onNotificationAdded(shadeEntry);
  22. }

通过NotificationEntryManager.java上述代码发现

addEntry(NotificationData.Entry shadeEntry) 就是监听悬浮通知的 所以在addEntry(NotificationData.Entry shadeEntry)

就是负责悬浮通知弹窗的相关方法,所以在这里增加自定义的悬浮通知回调方法

NotificationHelper.getInstance().addAlertNotification(shadeEntry.notification);;然后在NotificationPanelView.java中接收自定义悬浮

通知,然后显示悬浮通知

3.3 NotificationPanelView.java关于显示悬浮通知的相关方法

  1. public class NotificationPanelView extends PanelView implements
  2. + com.android.systemui.notification.NotificationListener,
  3. ExpandableView.OnHeightChangedListener,
  4. + private com.android.systemui.notification.NotificationEntry mNotificationEntry;
  5. + @Override
  6. + public void addAlertNotification(StatusBarNotification sbn) {
  7. + Log.e("NotificationPanelViewController", "addAlertNotification:packageName=" + sbn.getPackageName());
  8. + try {
  9. + Notification notification = sbn.getNotification();
  10. + String packageName = sbn.getPackageName();
  11. + long when = notification.when;
  12. + Bundle bundle = notification.extras;
  13. + String title = bundle.getString("android.title");
  14. + String content = bundle.getString("android.text");
  15. + Log.e("NotificationPanelViewController", "addAlertNotification-packageName:" + "-----" + packageName+"--notification:"+notification);
  16. + Log.e("NotificationPanelViewController", "addAlertNotification-tickerText:" + "------" + notification.tickerText);
  17. + Log.e("NotificationPanelViewController", "addAlertNotification-title:" + "-----" + notification.extras.get("android.title"));
  18. + Log.e("NotificationPanelViewController", "addAlertNotification-text:" + "-----" + notification.extras.get("android.text"));
  19. + if(TextUtils.isEmpty(title)&&TextUtils.isEmpty(content))return;
  20. + PackageManager pm = getContext().getPackageManager();
  21. + ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
  22. + mNotificationEntry = new com.android.systemui.notification.NotificationEntry();
  23. + mNotificationEntry.setNotification_content(content);
  24. + mNotificationEntry.setNotification_title(title);
  25. + mNotificationEntry.setPackageName(packageName);
  26. + mNotificationEntry.setStatusBarNotification(sbn);
  27. + if (applicationInfo != null) {
  28. + mNotificationEntry.setmAppName(pm.getApplicationLabel(applicationInfo).toString());
  29. + mNotificationEntry.setmAppDrawable(pm.getApplicationIcon(applicationInfo));
  30. + } else {
  31. + if (packageName.equals("android")) mNotificationEntry.setmAppName("Android 系统");
  32. + }
  33. + mSwipeMeunListView.setVisibility(mBarState == StatusBarState.KEYGUARD?View.GONE:View.VISIBLE);
  34. + } catch (Exception e) {
  35. + e.printStackTrace();
  36. + }
  37. + }

在NotificationPanelView.java的上述方法中,通过增加addAlertNotification(StatusBarNotification sbn)接口来实现接收悬浮通知的相关布局

中,添加到显示悬浮通知的列表中,

  1. @@ -2667,12 +2934,23 @@ public class NotificationPanelView extends PanelView implements
  2. public void onHeadsUpPinnedModeChanged(final boolean inPinnedMode) {
  3. mNotificationStackScroller.setInHeadsUpPinnedMode(inPinnedMode);
  4. if (inPinnedMode) {
  5. + ArrayList<com.android.systemui.notification.NotificationEntry> alertNotification = new ArrayList<>();
  6. + if(mNotificationEntry!=null)alertNotification.add(mNotificationEntry);
  7. + mNFDataAdapter = new NotificationDataAdapter(alertNotification, getContext());
  8. + mSwipeMeunListView.setAdapter(mNFDataAdapter);
  9. mHeadsUpExistenceChangedRunnable.run();
  10. updateNotificationTranslucency();
  11. } else {
  12. setHeadsUpAnimatingAway(true);
  13. mNotificationStackScroller.runAfterAnimationFinished(
  14. mHeadsUpExistenceChangedRunnable);
  15. + mKeyguardBottomArea.postDelayed(new Runnable() {
  16. + @Override
  17. + public void run() {
  18. + mNFDataAdapter = new NotificationDataAdapter(mAllNotification, getContext());
  19. + mSwipeMeunListView.setAdapter(mNFDataAdapter);
  20. + }
  21. + },2000);
  22. }
  23. }

在NotificationPanelView.java的上述方法中,通过 onHeadsUpPinnedModeChanged(final boolean inPinnedMode)中,根据inPinnedMode的值来判断

当前悬浮通知是否显示和隐藏,当为true时表示悬浮通知弹窗,这时候就更新显示悬浮通知列表,

当inPinnedMode为false 就是悬浮通知消失的时候,这时候也是延时刷新悬浮通知列表,通过上面布局的修改

就可以实现在NotificationPanelView.java中,通过在悬浮通知弹窗的时候,来刷新自定义通知列表来实现功能

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号