public static NotificationCompat create() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new NotificationCompatCompatV21(); } else { return new NotificationCompatCompatV14(); } }
NotificationCompat() { loadSystemLayoutRes(); mNotificationFixer = new NotificationFixer(this); }
@Override public boolean dealNotification(int id, Notification notification, String packageName) { Context appContext = getAppContext(packageName); return resolveRemoteViews(appContext, packageName, notification) || resolveRemoteViews(appContext, packageName, notification.publicVersion); }
@Override public boolean dealNotification(int id, Notification notification, final String packageName) { Context appContext = getAppContext(packageName); if (appContext == null) { return false; getNotificationFixer().fixIconImage(appContext.getResources(), notification.contentView, false, notification); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getNotificationFixer().fixIconImage(appContext.getResources(), notification.bigContentView, false, notification); notification.icon = getHostContext().getApplicationInfo().icon; if (isSystemLayout(notification.tickerView)) { getNotificationFixer().fixRemoteViewActions(appContext, false, notification.tickerView); } else { notification.tickerView = getRemoteViewsFixer().makeRemoteViews(id + ":tickerView", appContext, notification.tickerView, false, false); if (isSystemLayout(notification.contentView)) { boolean hasIconBitmap = getNotificationFixer().fixRemoteViewActions(appContext, false, notification.contentView); getNotificationFixer().fixIconImage(appContext.getResources(), notification.contentView, hasIconBitmap, notification); } else { notification.contentView = getRemoteViewsFixer().makeRemoteViews(id + ":contentView", appContext, notification.contentView, false, true); if (isSystemLayout(notification.bigContentView)) { getNotificationFixer().fixRemoteViewActions(appContext, false, notification.bigContentView); } else { notification.bigContentView = getRemoteViewsFixer().makeRemoteViews(id + ":bigContentView", appContext, notification.bigContentView, true, true);
final PendIntentCompat pendIntentCompat = new PendIntentCompat(contentView); final int layoutId; if (!click || pendIntentCompat.findPendIntents() <= 0) { layoutId = R.layout.custom_notification_lite; } else { RemoteViews remoteViews = new RemoteViews(mNotificationCompat.getHostContext().getPackageName(), layoutId); VLog.v(TAG, "remoteViews to view"); View cache = toView(pluginContext, contentView, isBig, systemId); final Bitmap bmp = createBitmap(cache); if (bmp == null) { VLog.e(TAG, "bmp is null,contentView=" + contentView); VLog.v(TAG, "start setPendIntent"); try { pendIntentCompat.setPendIntent(remoteViews, toView(mNotificationCompat.getHostContext(), remoteViews, isBig, systemId), cache); } catch (Exception e) {
private View createView(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) { if (remoteViews == null) return null; Context base = mNotificationCompat.getHostContext(); init(base); VLog.v(TAG, "createView:big=" + isBig + ",system=" + systemId); int width = mWidthCompat.getNotificationWidth(base, notification_panel_width, height, notification_side_padding); VLog.v(TAG, "createView:getNotificationWidth=" + width); VLog.v(TAG, "createView:apply"); View view1 = apply(context, remoteViews); if (view1 instanceof ViewGroup) { VLog.v(TAG, "createView:fixTextView"); fixTextView((ViewGroup) view1);
private void fixTextView(ViewGroup viewGroup) { int count = viewGroup.getChildCount(); for (int i = 0; i < count; i++) { View v = viewGroup.getChildAt(i); if (v instanceof TextView) { TextView tv = (TextView) v; if (isSingleLine(tv)) { tv.setSingleLine(false); tv.setMaxLines(1); } } else if (v instanceof ViewGroup) { fixTextView((ViewGroup) v); } } }
RemoteViewsFixer(NotificationCompat notificationCompat) { mWidthCompat = new WidthCompat(); mNotificationCompat = notificationCompat; }
NotificationCompatCompatV14() { super(); mRemoteViewsFixer = new RemoteViewsFixer(this); }
private VNotificationManager() { mNotificationCompat = NotificationCompat.create(); }
private ApplicationInfo getApplicationInfo(Notification notification) { ApplicationInfo ai = getApplicationInfo(notification.tickerView); if (ai != null) { return ai; } ai = getApplicationInfo(notification.contentView); if (ai != null) { return ai; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ai = getApplicationInfo(notification.bigContentView); if (ai != null) { return ai; } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ai = getApplicationInfo(notification.headsUpContentView); if (ai != null) { return ai; } } return null; }
public int findPendIntents() { if (clickIntents == null) { clickIntents = getClickIntents(mRemoteViews); } return clickIntents.size(); }
public static void systemReady(Context context) { VNotificationManagerService instance = new VNotificationManagerService(context); gService.set(instance); }
private RectInfo findIntent(Rect rect, List<RectInfo> list) { int maxArea = 0; RectInfo next = null; for (RectInfo rectInfo : list) { int size = getOverlapArea(rect, rectInfo.rect); if (size > maxArea) { if (size == 0) { Log.w("PendingIntentCompat", "find two:" + rectInfo.rect); } maxArea = size; next = rectInfo; } } return next; }
notification_side_padding = 0; } else { notification_side_padding = getDimem(context, systemUi, "notification_side_padding", R.dimen.notification_side_padding); notification_panel_width = getDimem(context, systemUi, "notification_panel_width", R.dimen.notification_panel_width); if (notification_panel_width <= 0) { notification_panel_width = context.getResources().getDisplayMetrics().widthPixels; notification_min_height = getDimem(context, systemUi, "notification_min_height", R.dimen.notification_min_height); notification_max_height = getDimem(context, systemUi, "notification_max_height", R.dimen.notification_max_height); notification_mid_height = getDimem(context, systemUi, "notification_mid_height", R.dimen.notification_mid_height); notification_padding = getDimem(context, systemUi, "notification_padding", R.dimen.notification_padding);
Context getAppContext(final String packageName) { Context context = null; try { context = getHostContext().createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return context; }
private Rect getRect(View view) { Rect rect = new Rect(); rect.top = view.getTop(); rect.left = view.getLeft(); rect.right = view.getRight(); rect.bottom = view.getBottom(); ViewParent viewParent = view.getParent(); if (viewParent != null) { if (viewParent instanceof ViewGroup) { Rect prect = getRect((ViewGroup) viewParent); rect.top += prect.top; rect.left += prect.left; rect.right += prect.left; rect.bottom += prect.top; } } return rect; }
@Override public void addNotification(int id, String tag, String packageName, int userId) { NotificationInfo notificationInfo = new NotificationInfo(id, tag, packageName, userId); synchronized (mNotifications) { List<NotificationInfo> list = mNotifications.get(packageName); if (list == null) { list = new ArrayList<>(); mNotifications.put(packageName, list); } if (!list.contains(notificationInfo)) { list.add(notificationInfo); } } }
public boolean dealNotification(int id, Notification notification, String packageName) { if(notification == null)return false; return VirtualCore.get().getHostPkg().equals(packageName) || mNotificationCompat.dealNotification(id, notification, packageName); }
View toView(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) { View mCache = null; try { mCache = createView(context, remoteViews, isBig, systemId); } catch (Throwable throwable) { VLog.w(TAG, "toView 1", throwable); try { mCache = LayoutInflater.from(context).inflate(remoteViews.getLayoutId(), null); } catch (Throwable e) { VLog.w(TAG, "toView 2", e); } } return mCache; }