Java Code Examples for android.app.Notification#BigTextStyle

The following examples show how to use android.app.Notification#BigTextStyle . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GcmService.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
private void handleBroadcast(Bundle data) {
    int id = data.getInt("id");
    String title = data.getString("title");
    String text = data.getString("text");
    boolean privat = data.getBoolean("private");

    Notification.Builder notificationBuilder = new Notification.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.backpacker_white);
    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(text);
    notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    notificationBuilder.setUsesChronometer(true);
    notificationBuilder.setWhen(new Date().getTime());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setOngoing(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
        notificationBuilder.setVisibility(privat ? Notification.VISIBILITY_PRIVATE : Notification.VISIBILITY_PUBLIC);
    }
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification.BigTextStyle notification = new Notification.BigTextStyle(notificationBuilder);
    notification.bigText(text);
    nm.notify(id, notification.build());
}
 
Example 2
Source File: DownloadService.java    From AntennaPodSP with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void setupNotificationBuilders() {
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
                    this, MainActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT
    );

    Bitmap icon = BitmapFactory.decodeResource(getResources(),
            R.drawable.stat_notify_sync);

    if (android.os.Build.VERSION.SDK_INT >= 16) {
        notificationBuilder = new Notification.BigTextStyle(
                new Notification.Builder(this).setOngoing(true)
                        .setContentIntent(pIntent).setLargeIcon(icon)
                        .setSmallIcon(R.drawable.stat_notify_sync)
        );
    } else {
        notificationCompatBuilder = new NotificationCompat.Builder(this)
                .setOngoing(true).setContentIntent(pIntent)
                .setLargeIcon(icon)
                .setSmallIcon(R.drawable.stat_notify_sync);
    }
    if (AppConfig.DEBUG)
        Log.d(TAG, "Notification set up");
}
 
Example 3
Source File: NotificationController.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
public static void test(Context context, String packageName, String title, String description) {
    NotificationController.registerChannelIfNeeded(context, packageName);

    int id = (int) (System.currentTimeMillis() / 1000L);

    Notification.Builder localBuilder = new Notification.Builder(context);

    Notification.BigTextStyle style = new Notification.BigTextStyle();
    style.bigText(description);
    style.setBigContentTitle(title);
    style.setSummaryText(description);
    localBuilder.setStyle(style);
    NotificationController.processSmallIcon(context, packageName, localBuilder);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        localBuilder.setWhen(System.currentTimeMillis());
        localBuilder.setShowWhen(true);
    }

    NotificationController.publish(context, id, packageName, localBuilder);
}
 
Example 4
Source File: NotificationCompatJellybean.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void addBigTextStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, CharSequence bigText) {
    Notification.BigTextStyle style = new Notification.BigTextStyle(b)
        .setBigContentTitle(bigContentTitle)
        .bigText(bigText);
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 5
Source File: NotificationCompatJellybean.java    From guideshow with MIT License 5 votes vote down vote up
public void addBigTextStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, CharSequence bigText) {
    Notification.BigTextStyle style = new Notification.BigTextStyle(b)
        .setBigContentTitle(bigContentTitle)
        .bigText(bigText);
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 6
Source File: NotificationCompatJellybean.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public void addBigTextStyle(CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, CharSequence bigText) {
    Notification.BigTextStyle style = new Notification.BigTextStyle(b)
        .setBigContentTitle(bigContentTitle)
        .bigText(bigText);
    if (useSummary) {
        style.setSummaryText(summaryText);
     }
}
 
Example 7
Source File: NotificationCompatJellybean.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static void addBigTextStyle(NotificationBuilderWithBuilderAccessor b,
        CharSequence bigContentTitle, boolean useSummary,
        CharSequence summaryText, CharSequence bigText) {
    Notification.BigTextStyle style = new Notification.BigTextStyle(b.getBuilder())
        .setBigContentTitle(bigContentTitle)
        .bigText(bigText);
    if (useSummary) {
        style.setSummaryText(summaryText);
    }
}
 
Example 8
Source File: NotificationBuilder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Notification buildWithBigTextStyle(String bigText) {
    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
    bigTextStyle.setBuilder(mBuilder);
    bigTextStyle.bigText(bigText);
    return bigTextStyle.build();
}
 
Example 9
Source File: SendReplyToCommentService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendReplyToCommentService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteReplyToCommentActivity.startBecauseSendFailed(SendReplyToCommentService.this,
            account, content, oriMsg, replyDraftBean,
            repostContent, e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendReplyToCommentService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendReplyToCommentService.this, SendReplyToCommentService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);
        intent.putExtra("repostContent", repostContent);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendReplyToCommentService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);

    NotificationUtility.show(notification, id);

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 10
Source File: SendRepostService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendRepostService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteRepostActivity.startBecauseSendFailed(SendRepostService.this, account, content,
            oriMsg, repostDraftBean, e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendRepostService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendRepostService.this, SendRepostService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra("is_comment", is_comment);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendRepostService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);

    NotificationUtility.show(notification, id);

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 11
Source File: SendCommentService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendCommentService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteCommentActivity.startBecauseSendFailed(SendCommentService.this, account, content,
            oriMsg, commentDraftBean, comment_ori,
            e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendCommentService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendCommentService.this, SendCommentService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra("comment_ori", comment_ori);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendCommentService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);
    NotificationUtility.show(notification, id);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 12
Source File: NotificationBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public ChromeNotificationBuilder setStyle(Notification.BigTextStyle style) {
    mBuilder.setStyle(style);
    return this;
}
 
Example 13
Source File: NotificationCompatBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public ChromeNotificationBuilder setStyle(Notification.BigTextStyle bigTextStyle) {
    assert false; // unused
    return this;
}
 
Example 14
Source File: QuizListenerService.java    From android-Quiz with Apache License 2.0 4 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS,
            TimeUnit.MILLISECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient.");
        return;
    }

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            DataItem dataItem = event.getDataItem();
            DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
            if (dataMap.getBoolean(QUESTION_WAS_ANSWERED)
                    || dataMap.getBoolean(QUESTION_WAS_DELETED)) {
                // Ignore the change in data; it is used in MainActivity to update
                // the question's status (i.e. was the answer right or wrong or left blank).
                continue;
            }
            String question = dataMap.getString(QUESTION);
            int questionIndex = dataMap.getInt(QUESTION_INDEX);
            int questionNum = questionIndex + 1;
            String[] answers = dataMap.getStringArray(ANSWERS);
            int correctAnswerIndex = dataMap.getInt(CORRECT_ANSWER_INDEX);
            Intent deleteOperation = new Intent(this, DeleteQuestionService.class);
            deleteOperation.setData(dataItem.getUri());
            PendingIntent deleteIntent = PendingIntent.getService(this, 0,
                    deleteOperation, PendingIntent.FLAG_UPDATE_CURRENT);
            // First page of notification contains question as Big Text.
            Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle()
                    .setBigContentTitle(getString(R.string.question, questionNum))
                    .bigText(question);
            Notification.Builder builder = new Notification.Builder(this)
                    .setStyle(bigTextStyle)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setLocalOnly(true)
                    .setDeleteIntent(deleteIntent);

            // Add answers as actions.
            Notification.WearableExtender wearableOptions = new Notification.WearableExtender();
            for (int i = 0; i < answers.length; i++) {
                Notification answerPage = new Notification.Builder(this)
                        .setContentTitle(question)
                        .setContentText(answers[i])
                        .extend(new Notification.WearableExtender()
                                .setContentAction(i))
                        .build();

                boolean correct = (i == correctAnswerIndex);
                Intent updateOperation = new Intent(this, UpdateQuestionService.class);
                // Give each intent a unique action.
                updateOperation.setAction("question_" + questionIndex + "_answer_" + i);
                updateOperation.setData(dataItem.getUri());
                updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX,
                        questionIndex);
                updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct);
                PendingIntent updateIntent = PendingIntent.getService(this, 0, updateOperation,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                Notification.Action action = new Notification.Action.Builder(
                        questionNumToDrawableId.get(i), null, updateIntent)
                        .build();
                wearableOptions.addAction(action).addPage(answerPage);
            }
            builder.extend(wearableOptions);
            Notification notification = builder.build();
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                    .notify(questionIndex, notification);
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            Uri uri = event.getDataItem().getUri();
            // URI's are of the form "/question/0", "/question/1" etc.
            // We use the question index as the notification id.
            int notificationId = Integer.parseInt(uri.getLastPathSegment());
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                    .cancel(notificationId);
        }
        // Delete the quiz report, if it exists.
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                .cancel(QUIZ_REPORT_NOTIF_ID);
    }
    googleApiClient.disconnect();
}
 
Example 15
Source File: SendCommentService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendCommentService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteCommentActivity.startBecauseSendFailed(SendCommentService.this, account, content,
            oriMsg, commentDraftBean, comment_ori,
            e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendCommentService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendCommentService.this, SendCommentService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra("comment_ori", comment_ori);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendCommentService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);
    NotificationUtility.show(notification, id);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 16
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public Notification buildNotification(Context context) {
    Notification.Builder builder = buildBasicNotification(context);

    Notification.BigTextStyle style = new Notification.BigTextStyle();

    SpannableStringBuilder title = new SpannableStringBuilder();
    appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
    title.append(" title");
    SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
    appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
    appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
    appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
    appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
    appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
    appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
    text.append("; ");
    appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
    text.append("; ");
    appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
    text.append("; ");
    appendStyled(text, "underline", new UnderlineSpan());
    text.append("; ");
    appendStyled(text, "strikethrough", new StrikethroughSpan());
    text.append("; ");
    appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
    text.append("; ");
    appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
    text.append("; ");
    appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
    text.append("; ");
    appendStyled(text, "monospace", new TypefaceSpan("monospace"));
    text.append("; ");
    appendStyled(text, "sub", new SubscriptSpan());
    text.append("script");
    appendStyled(text, "super", new SuperscriptSpan());

    style.setBigContentTitle(title);
    style.bigText(text);

    builder.setStyle(style);
    return builder.build();
}
 
Example 17
Source File: BackgroundService.java    From BackPackTrackII with GNU General Public License v3.0 4 votes vote down vote up
private static void showRainNotification(Weather weather, String geocoded, Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Uri sound = Uri.parse(prefs.getString(SettingsFragment.PREF_WEATHER_RAIN_SOUND, SettingsFragment.DEFAULT_WEATHER_RAIN_SOUND));
    boolean light = prefs.getBoolean(SettingsFragment.PREF_WEATHER_RAIN_LIGHT, SettingsFragment.DEFAULT_WEATHER_RAIN_LIGHT);
    DecimalFormat DF1 = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ROOT));
    DecimalFormat DF2 = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.ROOT));

    int last_probability = prefs.getInt(SettingsFragment.PREF_LAST_RAIN_PROBABILITY, 0);
    prefs.edit().putInt(SettingsFragment.PREF_LAST_RAIN_PROBABILITY, (int) Math.round(weather.rain_probability)).apply();

    String content = null;
    double rain_1h = weather.rain_1h;
    if (!Double.isNaN(rain_1h)) {
        String rain_unit = prefs.getString(SettingsFragment.PREF_PRECIPITATION, SettingsFragment.DEFAULT_PRECIPITATION);
        if ("in".equals(rain_unit))
            rain_1h = rain_1h / 25.4f;

        if ("in".equals(rain_unit))
            content = getRainIntensity(weather.rain_1h, context) + " " + DF2.format(rain_1h) + " " + context.getString(R.string.header_inch);
        else
            content = getRainIntensity(weather.rain_1h, context) + " " + DF1.format(rain_1h) + " " + context.getString(R.string.header_mm);
    }

    Notification.Builder notificationBuilder = new Notification.Builder(context);

    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? R.drawable.umbrella_white : R.drawable.umbrella_black);
    notificationBuilder.setLargeIcon(largeIcon.copy(Bitmap.Config.ARGB_8888, true));
    notificationBuilder.setSmallIcon(R.drawable.umbrella_white);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        notificationBuilder.setColor(context.getResources().getColor(R.color.color_teal_600, null));
    else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        notificationBuilder.setColor(context.getResources().getColor(R.color.color_teal_600));

    notificationBuilder.setContentTitle(context.getString(R.string.msg_rain_warning, Math.round(weather.rain_probability)));
    if (content != null) {
        notificationBuilder.setContentText(content);

        Notification.BigTextStyle bts = new Notification.BigTextStyle();
        bts.bigText(content);
        if (geocoded != null)
            bts.setSummaryText(geocoded);
        notificationBuilder.setStyle(bts);
    }

    notificationBuilder.setSound(sound);
    if (light)
        notificationBuilder.setLights(Color.YELLOW, 1000, 1000);
    if (weather.rain_probability < last_probability * 1.5)
        notificationBuilder.setOnlyAlertOnce(true);
    notificationBuilder.setPriority(Notification.PRIORITY_HIGH);

    // Build main intent
    Intent riMain = new Intent(context, SettingsActivity.class);
    riMain.putExtra(SettingsFragment.EXTRA_ACTION, SettingsFragment.ACTION_FORECAST);
    PendingIntent piMain = PendingIntent.getActivity(context, REQUEST_RAIN, riMain, PendingIntent.FLAG_CANCEL_CURRENT);
    notificationBuilder.setContentIntent(piMain);

    // Build refresh intent
    Intent riRefresh = new Intent(context, BackgroundService.class);
    riRefresh.setAction(BackgroundService.ACTION_UPDATE_WEATHER);
    PendingIntent piRefresh = PendingIntent.getService(context, REQUEST_REFRESH, riRefresh, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build forecast intent
    Intent riForecast = new Intent(context, SettingsActivity.class);
    riForecast.putExtra(SettingsFragment.EXTRA_ACTION, SettingsFragment.ACTION_FORECAST);
    PendingIntent piForecast = PendingIntent.getActivity(context, REQUEST_FORECAST, riForecast, PendingIntent.FLAG_UPDATE_CURRENT);

    // Add action
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notificationBuilder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.refresh_black), context.getString(R.string.title_refresh), piRefresh).build());
        notificationBuilder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.cloud_download_black), context.getString(R.string.title_forecast), piForecast).build());
    } else {
        notificationBuilder.addAction(R.drawable.refresh_black, context.getString(R.string.title_refresh), piRefresh);
        notificationBuilder.addAction(R.drawable.cloud_download_black, context.getString(R.string.title_forecast), piForecast);
    }

    notificationBuilder.setUsesChronometer(true);
    notificationBuilder.setWhen(weather.time);
    notificationBuilder.setAutoCancel(false);
    notificationBuilder.setOngoing(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setCategory(Notification.CATEGORY_STATUS);
        notificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    NotificationManager nm = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_RAIN, notificationBuilder.build());
}
 
Example 18
Source File: SendReplyToCommentService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendReplyToCommentService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteReplyToCommentActivity.startBecauseSendFailed(SendReplyToCommentService.this,
            account, content, oriMsg, replyDraftBean,
            repostContent, e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendReplyToCommentService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendReplyToCommentService.this, SendReplyToCommentService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);
        intent.putExtra("repostContent", repostContent);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendReplyToCommentService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);

    NotificationUtility.show(notification, id);

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 19
Source File: SendRepostService.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showFailedNotification(final WeiboSendTask task) {
    Notification.Builder builder = new Notification.Builder(SendRepostService.this)
            .setTicker(getString(R.string.send_failed))
            .setContentTitle(getString(R.string.send_faile_click_to_open)).setContentText(content)
            .setOnlyAlertOnce(true).setAutoCancel(true)
            .setSmallIcon(R.drawable.send_failed).setOngoing(false);

    Intent notifyIntent = WriteRepostActivity.startBecauseSendFailed(SendRepostService.this, account, content,
            oriMsg, repostDraftBean, e.getError());

    PendingIntent pendingIntent = PendingIntent.getActivity(SendRepostService.this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notification notification;
    if (Utility.isJB()) {
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
        bigTextStyle.setBigContentTitle(getString(R.string.send_faile_click_to_open));
        bigTextStyle.bigText(content);
        bigTextStyle.setSummaryText(account.getUsernick());
        builder.setStyle(bigTextStyle);

        Intent intent = new Intent(SendRepostService.this, SendRepostService.class);
        intent.putExtra("oriMsg", oriMsg);
        intent.putExtra("content", content);
        intent.putExtra("is_comment", is_comment);
        intent.putExtra(Constants.TOKEN, token);
        intent.putExtra(Constants.ACCOUNT, account);

        intent.putExtra("lastNotificationId", tasksNotifications.get(task));

        PendingIntent retrySendIntent = PendingIntent.getService(SendRepostService.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
        notification = builder.build();

    } else {
        notification = builder.getNotification();
    }

    final int id = tasksNotifications.get(task);

    NotificationUtility.show(notification, id);

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            stopServiceIfTasksAreEnd(task);
        }
    }, 3000);
}
 
Example 20
Source File: ChromeNotificationBuilder.java    From 365browser with Apache License 2.0 votes vote down vote up
ChromeNotificationBuilder setStyle(Notification.BigTextStyle bigTextStyle);