智能工厂.apk(点击下载) / DefaultPushNotificationBuilder.java


package cn.jpush.android.api;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.text.TextUtils;
import android.widget.RemoteViews;
import cn.jpush.android.helper.Logger;
import cn.jpush.android.p.a;
import cn.jpush.android.p.b;
import cn.jpush.android.p.g;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import org.json.JSONObject;

public class DefaultPushNotificationBuilder implements PushNotificationBuilder {
    public static final int NOTI_STYLE_BIG_PICTURE = 3;
    public static final int NOTI_STYLE_BIG_TEXT = 1;
    public static final int NOTI_STYLE_INBOX = 2;
    private static final String TAG = "DefaultPushNotificationBuilder";
    protected Context context;
    private NotificationMessage notificationMessage;

    /* access modifiers changed from: package-private */
    public RemoteViews buildContentView(String str, String str2) {
        return null;
    }

    /* JADX WARNING: Removed duplicated region for block: B:26:0x0112  */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x0132  */
    /* JADX WARNING: Removed duplicated region for block: B:32:0x0141  */
    /* JADX WARNING: Removed duplicated region for block: B:35:0x0150  */
    @Override // cn.jpush.android.api.PushNotificationBuilder
    public Notification buildNotification(Context context2, NotificationMessage notificationMessage2) {
        String str;
        String str2;
        this.context = context2;
        this.notificationMessage = notificationMessage2;
        HashMap hashMap = new HashMap();
        if (notificationMessage2 != null) {
            Logger.d(TAG, "notificationContent:" + notificationMessage2.notificationContent + "\nnotificationTitle" + notificationMessage2.notificationTitle + "\nnotificationStyle:" + notificationMessage2.notificationStyle + "\nnotificationPriority:" + notificationMessage2.notificationPriority + "\nnotificationBigText:" + notificationMessage2.notificationBigText + "\nnotificationBigPicPath:" + notificationMessage2.notificationBigPicPath + "\nnotificationInbox:" + notificationMessage2.notificationInbox + "\nnotificationCategory:" + notificationMessage2.notificationCategory + "\nnotificationAlertType:" + notificationMessage2.notificationAlertType + "\nnotificationSmallIcon:" + notificationMessage2.notificationSmallIcon + "\nnotificationLargeIcon:" + notificationMessage2.notificationLargeIcon + "\nextraJson:" + notificationMessage2.notificationExtras);
            hashMap.put(JPushInterface.EXTRA_MSG_ID, notificationMessage2.msgId);
            hashMap.put(JPushInterface.EXTRA_ALERT, notificationMessage2.notificationContent);
            StringBuilder sb = new StringBuilder();
            sb.append(notificationMessage2.notificationAlertType);
            sb.append("");
            hashMap.put(JPushInterface.EXTRA_ALERT_TYPE, sb.toString());
            if (!TextUtils.isEmpty(notificationMessage2.notificationTitle)) {
                hashMap.put(JPushInterface.EXTRA_NOTIFICATION_TITLE, notificationMessage2.notificationTitle);
            }
            if (!TextUtils.isEmpty(notificationMessage2.notificationExtras)) {
                hashMap.put(JPushInterface.EXTRA_EXTRA, notificationMessage2.notificationExtras);
            }
            if (notificationMessage2.notificationStyle == 1 && !TextUtils.isEmpty(notificationMessage2.notificationBigText)) {
                str = JPushInterface.EXTRA_BIG_TEXT;
                str2 = notificationMessage2.notificationBigText;
            } else if (notificationMessage2.notificationStyle != 2 || TextUtils.isEmpty(notificationMessage2.notificationInbox)) {
                if (notificationMessage2.notificationStyle == 3 && !TextUtils.isEmpty(notificationMessage2.notificationBigPicPath)) {
                    str = JPushInterface.EXTRA_BIG_PIC_PATH;
                    str2 = notificationMessage2.notificationBigPicPath;
                }
                if (notificationMessage2.notificationPriority != 0) {
                    hashMap.put(JPushInterface.EXTRA_NOTI_PRIORITY, notificationMessage2.notificationPriority + "");
                }
                if (!TextUtils.isEmpty(notificationMessage2.notificationCategory)) {
                    hashMap.put(JPushInterface.EXTRA_NOTI_CATEGORY, notificationMessage2.notificationCategory);
                }
                if (!TextUtils.isEmpty(notificationMessage2.notificationSmallIcon)) {
                    hashMap.put(JPushInterface.EXTRA_NOTIFICATION_SMALL_ICON, notificationMessage2.notificationSmallIcon);
                }
                if (!TextUtils.isEmpty(notificationMessage2.notificationLargeIcon)) {
                    hashMap.put(JPushInterface.EXTRA_NOTIFICATION_LARGET_ICON, notificationMessage2.notificationSmallIcon);
                }
            } else {
                str = JPushInterface.EXTRA_INBOX;
                str2 = notificationMessage2.notificationInbox;
            }
            hashMap.put(str, str2);
            if (notificationMessage2.notificationPriority != 0) {
            }
            if (!TextUtils.isEmpty(notificationMessage2.notificationCategory)) {
            }
            if (!TextUtils.isEmpty(notificationMessage2.notificationSmallIcon)) {
            }
            if (!TextUtils.isEmpty(notificationMessage2.notificationLargeIcon)) {
            }
        }
        return buildNotification(hashMap);
    }

    @Override // cn.jpush.android.api.PushNotificationBuilder
    public Notification buildNotification(Map<String, String> map) {
        String str;
        Context context2 = this.context;
        if (context2 == null) {
            Logger.w(TAG, "Can't find valid context when build notification.");
            return null;
        }
        try {
            str = context2.getApplicationInfo().loadLabel(this.context.getPackageManager()).toString();
        } catch (Throwable unused) {
            str = null;
        }
        String str2 = "";
        String str3 = "";
        String str4 = "";
        String str5 = "";
        String str6 = "";
        String str7 = "";
        if (map.containsKey(JPushInterface.EXTRA_MSG_ID)) {
            map.get(JPushInterface.EXTRA_MSG_ID);
        }
        if (map.containsKey(JPushInterface.EXTRA_ALERT)) {
            str2 = map.get(JPushInterface.EXTRA_ALERT);
        }
        if (TextUtils.isEmpty(str2)) {
            Logger.ww(TAG, "No notification content to show. Give up.");
            return null;
        }
        if (map.containsKey(JPushInterface.EXTRA_NOTIFICATION_SMALL_ICON)) {
            map.get(JPushInterface.EXTRA_NOTIFICATION_SMALL_ICON);
        }
        if (map.containsKey(JPushInterface.EXTRA_NOTIFICATION_LARGET_ICON)) {
            str7 = map.get(JPushInterface.EXTRA_NOTIFICATION_LARGET_ICON);
        }
        if (map.containsKey(JPushInterface.EXTRA_NOTIFICATION_TITLE)) {
            str = map.get(JPushInterface.EXTRA_NOTIFICATION_TITLE);
        }
        if (map.containsKey(JPushInterface.EXTRA_BIG_TEXT)) {
            str3 = map.get(JPushInterface.EXTRA_BIG_TEXT);
        }
        if (map.containsKey(JPushInterface.EXTRA_INBOX)) {
            str4 = map.get(JPushInterface.EXTRA_INBOX);
        }
        int parseInt = map.containsKey(JPushInterface.EXTRA_NOTI_PRIORITY) ? Integer.parseInt(map.get(JPushInterface.EXTRA_NOTI_PRIORITY)) : 0;
        if (map.containsKey(JPushInterface.EXTRA_NOTI_CATEGORY)) {
            str5 = map.get(JPushInterface.EXTRA_NOTI_CATEGORY);
        }
        if (map.containsKey(JPushInterface.EXTRA_BIG_PIC_PATH)) {
            str6 = map.get(JPushInterface.EXTRA_BIG_PIC_PATH);
        }
        int parseInt2 = map.containsKey(JPushInterface.EXTRA_ALERT_TYPE) ? Integer.parseInt(map.get(JPushInterface.EXTRA_ALERT_TYPE)) : -1;
        int i = (parseInt2 < -1 || parseInt2 > 7) ? -1 : parseInt2;
        RemoteViews buildContentView = buildContentView(str2, str);
        if (Build.VERSION.SDK_INT >= 11) {
            Notification.Builder builder = new Notification.Builder(this.context);
            builder.setContentTitle(str).setContentText(str2).setTicker(str2);
            int a = g.a(this.context);
            if (a != 0) {
                Logger.dd(TAG, "setSmallIcon with resId:" + a);
            } else {
                Logger.ww(TAG, "not found small icon in your app,will setSmallIcon with android.R.color.transparent ");
                a = 17170445;
            }
            builder.setSmallIcon(a);
            Object c = b.c(this.context, str7);
            if (Build.VERSION.SDK_INT >= 23) {
                if (c instanceof Icon) {
                    builder.setLargeIcon((Icon) c);
                }
            } else if (c instanceof Bitmap) {
                builder.setLargeIcon((Bitmap) c);
            }
            if (Build.VERSION.SDK_INT >= 17) {
                builder.setShowWhen(true);
            }
            Context context3 = this.context;
            NotificationMessage notificationMessage2 = this.notificationMessage;
            a.a(context3, builder, notificationMessage2 != null ? notificationMessage2.notificationChannelId : "", "", parseInt, i, (String) null);
            if (Build.VERSION.SDK_INT >= 16) {
                if (buildContentView == null) {
                    if (!TextUtils.isEmpty(str3)) {
                        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
                        bigTextStyle.bigText(str3);
                        builder.setStyle(bigTextStyle);
                    }
                    if (!TextUtils.isEmpty(str4)) {
                        Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
                        try {
                            TreeMap treeMap = new TreeMap();
                            JSONObject jSONObject = new JSONObject(str4);
                            Iterator<String> keys = jSONObject.keys();
                            while (keys.hasNext()) {
                                String next = keys.next();
                                treeMap.put(next, jSONObject.optString(next));
                            }
                            for (String str8 : treeMap.values()) {
                                inboxStyle.addLine(str8);
                            }
                            inboxStyle.setSummaryText(" + " + jSONObject.length() + " new messages");
                        } catch (Throwable th) {
                            Logger.ee(TAG, "Set inbox style error: " + th.getMessage());
                        }
                        builder.setStyle(inboxStyle);
                    }
                    if (!TextUtils.isEmpty(str6)) {
                        Logger.i(TAG, "Set notification BPS with picture path:" + str6);
                        try {
                            Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle();
                            bigPictureStyle.bigPicture(BitmapFactory.decodeFile(str6));
                            builder.setStyle(bigPictureStyle);
                        } catch (Throwable unused2) {
                            Logger.ww(TAG, "Create big picture style failed.");
                        }
                    }
                }
                if (parseInt != 0) {
                    if (parseInt == 1) {
                        builder.setPriority(1);
                    } else {
                        int i2 = 2;
                        if (parseInt != 2) {
                            if (parseInt == -1) {
                                builder.setPriority(-1);
                            } else {
                                i2 = -2;
                                if (parseInt != -2) {
                                    builder.setPriority(0);
                                }
                            }
                        }
                        builder.setPriority(i2);
                    }
                }
                if (!TextUtils.isEmpty(str5) && Build.VERSION.SDK_INT >= 21) {
                    builder.setCategory(str5);
                }
            }
            if (buildContentView != null) {
                builder.setContent(buildContentView);
            } else {
                Logger.i(TAG, " Use default notification view! ");
            }
            builder.setDefaults(i);
            return getNotification(builder);
        }
        Notification notification = new Notification(g.a(this.context), str2, System.currentTimeMillis());
        resetNotificationParams(notification);
        notification.defaults = i;
        if (buildContentView != null) {
            notification.contentView = buildContentView;
        } else {
            b.a(notification, this.context, str, str2, (PendingIntent) null);
        }
        return notification;
    }

    @Override // cn.jpush.android.api.PushNotificationBuilder
    public String getDeveloperArg0() {
        return null;
    }

    /* access modifiers changed from: package-private */
    public Notification getNotification(Notification.Builder builder) {
        try {
            return Build.VERSION.SDK_INT >= 16 ? builder.build() : builder.getNotification();
        } catch (Throwable th) {
            Logger.ww(TAG, "Build notification error:", th);
            return null;
        }
    }

    /* access modifiers changed from: package-private */
    public void resetNotificationParams(Notification notification) {
    }

    public String toString() {
        return "";
    }
}