Example usage for android.app Notification.InboxStyle Notification.InboxStyle

List of usage examples for android.app Notification.InboxStyle Notification.InboxStyle

Introduction

In this page you can find the example usage for android.app Notification.InboxStyle Notification.InboxStyle.

Prototype

@Deprecated
public InboxStyle(Builder builder) 

Source Link

Usage

From source file:com.metinkale.prayerapp.vakit.WidgetService.java

public static void updateOngoing() {
    extractColors();/*from  w  ww  .  java 2 s.c  o m*/
    NotificationManager nm = (NotificationManager) App.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = mOngoing.size() - 1; i >= 0; i--) {
        long id = mOngoing.get(i);
        Times t = Times.getTimes(id);

        if ((t == null) || !t.isOngoingNotificationActive()) {
            nm.cancel(id + "", NotIds.ONGOING);
            mOngoing.remove(i);
        }
    }
    List<Long> ids = Times.getIds();
    for (long id : ids) {

        Times t = Times.getTimes(id);

        if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) {
            mOngoing.add(id);
        }
    }

    LocalDate cal = LocalDate.now();
    String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
    for (long id : mOngoing) {

        Times t = Times.getTimes(id);

        String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3),
                t.getTime(cal, 4), t.getTime(cal, 5) };
        boolean icon = Prefs.showOngoingIcon();
        boolean number = Prefs.showOngoingNumber();
        Crashlytics.setBool("showIcon", icon);
        Crashlytics.setBool("showNumber", number);

        Notification noti;
        if (Prefs.getAlternativeOngoing()) {
            RemoteViews views = new RemoteViews(App.getContext().getPackageName(),
                    R.layout.notification_layout);

            int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 };
            int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi };

            int next = t.getNext();
            if (Prefs.getVakitIndicator().equals("next"))
                next++;
            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(timeIds[i],
                            Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>"));
                } else {
                    views.setTextViewText(timeIds[i], Utils.fixTime(dt[i]));
                }
            }

            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(vakitIds[i],
                            Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>"));
                } else {
                    views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString());
                }
            }

            views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false));
            views.setTextViewText(R.id.city, t.getName());

            views.setTextColor(R.id.imsak, COLOR_1ST);
            views.setTextColor(R.id.gunes, COLOR_1ST);
            views.setTextColor(R.id.ogle, COLOR_1ST);
            views.setTextColor(R.id.ikindi, COLOR_1ST);
            views.setTextColor(R.id.aksam, COLOR_1ST);
            views.setTextColor(R.id.yatsi, COLOR_1ST);

            views.setTextColor(R.id.time0, COLOR_1ST);
            views.setTextColor(R.id.time1, COLOR_1ST);
            views.setTextColor(R.id.time2, COLOR_1ST);
            views.setTextColor(R.id.time3, COLOR_1ST);
            views.setTextColor(R.id.time4, COLOR_1ST);
            views.setTextColor(R.id.time5, COLOR_1ST);

            views.setTextColor(R.id.time, COLOR_1ST);
            views.setTextColor(R.id.city, COLOR_1ST);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.Builder(App.getContext()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon
                                ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                        : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon))
                                : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder))
                        .setOngoing(true).build();
            } else {
                noti = new NotificationCompat.Builder(App.getContext()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true)
                        .build();
            }
        } else {
            int n = t.getNext();
            String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(),
                    left_part[n], t.getLeft().substring(0, 5));

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.InboxStyle(
                        new Notification.Builder(App.getContext())
                                .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                                .setLargeIcon(mAbIcon)
                                .setSmallIcon(icon
                                        ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                                : Icon.createWithResource(App.getContext(),
                                                        R.drawable.ic_abicon))
                                        : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder))
                                .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t))
                                .setOngoing(true))
                                        .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                        .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                        .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                        .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                        .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                        .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                        .setSummaryText("").build();
            } else {
                noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext())
                        .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                        .setLargeIcon(mAbIcon)
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder)
                        .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true))
                                .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                .setSummaryText("").build();
            }

        }

        if (Build.VERSION.SDK_INT >= 16) {
            noti.priority = Notification.PRIORITY_LOW;
        }
        noti.when = icon ? System.currentTimeMillis() : 0;
        try {
            nm.notify(id + "", NotIds.ONGOING, noti);
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

    }

}