Example usage for android.app Notification DEFAULT_LIGHTS

List of usage examples for android.app Notification DEFAULT_LIGHTS

Introduction

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

Prototype

int DEFAULT_LIGHTS

To view the source code for android.app Notification DEFAULT_LIGHTS.

Click Source Link

Document

Use the default notification lights.

Usage

From source file:com.shafiq.mytwittle.service.BackgroundService.java

private Notification buildNotification(String message, int icon, Intent content_intent, Intent delete_intent) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker(message);//from  w  w  w .j av  a2  s .  c  o  m
    // builder.setContentTitle(getString(R.string.new_notifications));
    builder.setContentTitle("New notifications");
    builder.setContentText(message);
    builder.setAutoCancel(true);
    builder.setWhen(System.currentTimeMillis());
    builder.setSmallIcon(icon);
    builder.setDeleteIntent(
            PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT));
    builder.setContentIntent(
            PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT));
    int defaults = 0;
    // if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_SOUND,
    // false)) {
    defaults |= Notification.DEFAULT_SOUND;
    // }
    // if
    // (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_VIBRATION,
    // false)) {
    defaults |= Notification.DEFAULT_VIBRATE;
    // }
    // if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_LIGHTS,
    // false)) {
    defaults |= Notification.DEFAULT_LIGHTS;
    // }
    builder.setDefaults(defaults);
    return builder.getNotification();
}

From source file:com.uphyca.idobata.android.service.IdobataService.java

private Notification buildNotification(PendingIntent pi, CharSequence title, CharSequence text) {
    int vibrate = mNotificationEffectsVibratePref.get() ? Notification.DEFAULT_VIBRATE : 0;
    int ledFlash = mNotificationEffectsLEDFlashPref.get() ? Notification.DEFAULT_LIGHTS : 0;
    int sound = mNotificationEffectsSoundPref.get() ? Notification.DEFAULT_SOUND : 0;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(IdobataService.this)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(title).setContentText(text)
            .setTicker(new StringBuilder(title).append(' ').append(text)).setAutoCancel(true)
            .setContentIntent(pi).setDefaults(vibrate | sound | ledFlash);
    if (ledFlash != 0) {
        builder.setLights(0xFF00FF00, 200, 1000);
    }/*from  w w  w  .j  a  v  a  2  s .  c o  m*/
    return builder.build();
}

From source file:com.android.deskclock.data.TimerNotificationBuilderN.java

@Override
public Notification buildHeadsUp(Context context, List<Timer> expired) {
    final Timer timer = expired.get(0);

    // First action intent is to reset all timers.
    final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_stop_24dp);
    final Intent reset = TimerService.createResetExpiredTimersIntent(context);
    final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);

    // Generate some descriptive text, a title, and an action name based on the timer count.
    final CharSequence stateText;
    final int count = expired.size();
    final List<Notification.Action> actions = new ArrayList<>(2);
    if (count == 1) {
        final String label = timer.getLabel();
        if (TextUtils.isEmpty(label)) {
            stateText = context.getString(R.string.timer_times_up);
        } else {/*w  ww. j a va2 s.c  o  m*/
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(R.string.timer_stop);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add minute
        final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId());
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime);
        final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp);
        final CharSequence title2 = context.getString(R.string.timer_plus_1_min);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

    } else {
        stateText = context.getString(R.string.timer_multi_times_up, count);

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(R.string.timer_stop_all);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    final long base = getChronometerBase(timer);

    final String pname = context.getPackageName();
    final RemoteViews contentView = new RemoteViews(pname, R.layout.chronometer_notif_content);
    contentView.setChronometerCountDown(R.id.chronometer, true);
    contentView.setChronometer(R.id.chronometer, base, null, true);
    contentView.setTextViewText(R.id.state, stateText);

    // Content intent shows the timer full screen when clicked.
    final Intent content = new Intent(context, ExpiredTimersActivity.class);
    final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content);

    // Full screen intent has flags so it is different than the content intent.
    final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setContentIntent(contentIntent).setCustomContentView(contentView)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .setColor(ContextCompat.getColor(context, R.color.default_background))
            .setSmallIcon(R.drawable.stat_notify_timer).setFullScreenIntent(pendingFullScreen, true)
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()])).build();
}

From source file:org.linphone.compatibility.ApiFivePlus.java

public static Notification createMessageNotification(Context context, String title, String msg,
        PendingIntent intent) {/*from   w  ww  . j  av  a 2  s  . c o  m*/
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.chat_icon_over).setContentTitle(title).setContentText(msg)
            .setContentIntent(intent);

    Notification notif = notifBuilder.build();
    notif.defaults |= Notification.DEFAULT_VIBRATE;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_LIGHTS;

    return notif;
}

From source file:com.onefishtwo.bbqtimer.Notifier.java

/** Builds a notification. */
protected Notification buildNotification(ApplicationState state, boolean show) {
    NotificationBuilder builder = NotificationBuilderFactory.builder(context)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    if (show) {/*  w w  w  . j  a  va  2 s  .c o  m*/
        TimeCounter timer = state.getTimeCounter();
        boolean isRunning = timer.isRunning();
        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_large_notification);

        builder.setSmallIcon(R.drawable.notification_icon).setLargeIcon(largeIcon)
                .setContentTitle(context.getString(R.string.app_name));

        if (isRunning) {
            builder.setWhen(System.currentTimeMillis() - timer.getElapsedTime()).setUsesChronometer(true); // added in API 17
        } else {
            // Hide the "when" field, which isn't useful while Paused, so it doesn't take space
            // in the compact view along with 3 action buttons (Reset, Start, Stop).
            // This doesn't actually work in API 17-18, so in API 18- it'd show the time of day
            // when the notification is built, but it's even more broken after changing the
            // "When" info in an open notification.
            builder.setShowWhen(false);
        }

        // Set the notification body text to explain the run state.
        if (isRunning && state.isEnableReminders()) {
            int reminderSecs = state.getSecondsPerReminder();
            int minutes = reminderSecs / 60;
            String contentText = context.getResources().getQuantityString(R.plurals.notification_body, minutes,
                    minutes);
            int numReminders = AlarmReceiver.numRemindersSoFar(state);

            builder.setContentText(contentText);

            if (numReminders > 0) {
                builder.setNumber(numReminders);
            }
        } else {
            builder.setContentText(timerRunState(timer));
            if (timer.isPaused()) {
                builder.setSubText(context.getString(R.string.dismiss_tip));
            } else if (isRunning) {
                builder.setSubText(context.getString(R.string.no_reminders_tip));
            }
        }

        // Make an Intent to launch the Activity from the notification.
        Intent activityIntent = new Intent(context, MainActivity.class);

        // So navigating back from the Activity goes from the app to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(MainActivity.class)
                .addNextIntent(activityIntent);
        PendingIntent activityPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(activityPendingIntent);

        numActions = 0;

        // Action button to reset the timer.
        PendingIntent resetIntent = makeActionIntent(TimerAppWidgetProvider.ACTION_RESET);
        if (timer.isPaused() && !timer.isReset()) {
            addAction(builder, R.drawable.ic_action_replay, R.string.reset, resetIntent);
        }

        // Action button to run (start) the timer.
        PendingIntent runIntent = makeActionIntent(TimerAppWidgetProvider.ACTION_RUN);
        if (!isRunning) {
            addAction(builder, R.drawable.ic_action_play, R.string.start, runIntent);
        }

        // Action button to pause the timer.
        PendingIntent pauseIntent = makeActionIntent(TimerAppWidgetProvider.ACTION_PAUSE);
        if (!timer.isPaused()) {
            addAction(builder, R.drawable.ic_action_pause, R.string.pause, pauseIntent);
        }

        // Action button to stop the timer.
        PendingIntent stopIntent = makeActionIntent(TimerAppWidgetProvider.ACTION_STOP);
        if (PAUSEABLE_NOTIFICATIONS && !timer.isStopped()) {
            addAction(builder, R.drawable.ic_action_stop, R.string.stop, stopIntent);
        }

        // Allow stopping via dismissing the notification (unless it's "ongoing").
        builder.setDeleteIntent(stopIntent);

        setMediaStyleActionsInCompactView(builder);

        if (isRunning) {
            builder.setOngoing(true);
        }
    }

    if (playChime || vibrate) {
        int defaults = Notification.DEFAULT_LIGHTS;

        if (playChime) {
            builder.setSound(getSoundUri(R.raw.cowbell4));
        }

        if (vibrate) {
            builder.setVibrate(VIBRATE_PATTERN);
        }
        builder.setDefaults(defaults);
    }

    return builder.build();
}

From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java

private void sendNotificationAndFinish() {
    if (streamingUser != null) {
        Intent intent = new Intent(getApplicationContext(), MediaPlayerActivity.class);
        Bundle extras = new Bundle();
        extras.putString(MediaPlayerActivity.MEDIA_URL, streamingUser.getStream().getFullVideoUrl());
        extras.putString(MediaPlayerActivity.THUMBNAIL_URL, streamingUser.getStream().getFullThumbnailUrl());
        extras.putString(MediaPlayerActivity.USER_ID, streamingUser.getUuid());
        intent.putExtras(extras);//ww  w .j ava  2 s .  c om
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder b = new NotificationCompat.Builder(getApplicationContext());
        String notificationTitle = userName + " " + getResources().getString(R.string.isLiveSuffix);
        String notificationText = "";// getResources().getString(R.string.missedCallNotification) + " " + streamingUser.getName();
        String mediaUrl = streamingUser.getStream().getFullVideoUrl();

        if ((streamingUser.getStream() != null) && (streamingUser.getStream().getTitle() != null)) {
            notificationText = streamingUser.getStream().getTitle(); //notificationText + "(" + streamingUser.getStream().getTitle() + ")";
        }
        ImageView incomingCallUserImageView = (ImageView) findViewById(R.id.incomingCallUserImageView);
        Bitmap bitmap = ((BitmapDrawable) incomingCallUserImageView.getDrawable()).getBitmap();
        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        b.setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher).setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis()).setTicker("X").setContentTitle(notificationTitle)
                .setContentText(notificationText)
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
                .setContentIntent(contentIntent);
        //            if (bitmap != null) {
        //                b.setLargeIcon(bitmap);
        //            }

        NotificationManager notificationManager = (NotificationManager) getApplicationContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(++NOTIFICATION_COUNTER, b.build());

    }
    finish();
}

From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderN.java

@Override
public Notification buildHeadsUp(Context context, List<Timer> expired) {
    final Timer timer = expired.get(0);

    // First action intent is to reset all timers.
    final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_stop_24dp);
    final Intent reset = TimerService.createResetExpiredTimersIntent(context);
    final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);

    // Generate some descriptive text, a title, and an action name based on the timer count.
    final CharSequence stateText;
    final int count = expired.size();
    final List<Notification.Action> actions = new ArrayList<>(2);
    if (count == 1) {
        final String label = timer.getLabel();
        if (TextUtils.isEmpty(label)) {
            stateText = context.getString(com.wizardsofm.deskclock.R.string.timer_times_up);
        } else {/*from   ww  w  . j  av  a  2  s.  c  o m*/
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(com.wizardsofm.deskclock.R.string.timer_stop);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add minute
        final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId());
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime);
        final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_add_24dp);
        final CharSequence title2 = context.getString(com.wizardsofm.deskclock.R.string.timer_plus_1_min);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

    } else {
        stateText = context.getString(com.wizardsofm.deskclock.R.string.timer_multi_times_up, count);

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(com.wizardsofm.deskclock.R.string.timer_stop_all);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    final long base = getChronometerBase(timer);

    final String pname = context.getPackageName();
    final RemoteViews contentView = new RemoteViews(pname,
            com.wizardsofm.deskclock.R.layout.chronometer_notif_content);
    contentView.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true);
    contentView.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, true);
    contentView.setTextViewText(com.wizardsofm.deskclock.R.id.state, stateText);

    // Content intent shows the timer full screen when clicked.
    final Intent content = new Intent(context, ExpiredTimersActivity.class);
    final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content);

    // Full screen intent has flags so it is different than the content intent.
    final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setContentIntent(contentIntent).setCustomContentView(contentView)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer)
            .setFullScreenIntent(pendingFullScreen, true).setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()])).build();
}

From source file:com.android.messaging.receiver.SmsReceiver.java

public static void postNewMessageSecondaryUserNotification() {
    final Context context = Factory.get().getApplicationContext();
    final Resources resources = context.getResources();
    final PendingIntent pendingIntent = UIIntents.get()
            .getPendingIntentForSecondaryUserNewMessageNotification(context);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(resources.getString(R.string.secondary_user_new_message_title))
            .setTicker(resources.getString(R.string.secondary_user_new_message_ticker))
            .setSmallIcon(R.drawable.ic_sms_light)
            // Returning PRIORITY_HIGH causes L to put up a HUD notification. Without it, the ticker
            // isn't displayed.
            .setPriority(Notification.PRIORITY_HIGH).setContentIntent(pendingIntent);

    final NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(builder);
    bigTextStyle.bigText(resources.getString(R.string.secondary_user_new_message_title));
    final Notification notification = bigTextStyle.build();

    final NotificationManagerCompat notificationManager = NotificationManagerCompat
            .from(Factory.get().getApplicationContext());

    int defaults = Notification.DEFAULT_LIGHTS;
    if (BugleNotifications.shouldVibrate(new SecondaryUserNotificationState())) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }/*from  w ww . jav  a  2 s.c o  m*/
    notification.defaults = defaults;

    notificationManager.notify(getNotificationTag(), PendingIntentConstants.SMS_SECONDARY_USER_NOTIFICATION_ID,
            notification);
}

From source file:com.xabber.android.data.notification.NotificationManager.java

/**
 * Sound, vibration and lightning flags.
 *
 * @param notificationBuilder/*w  w  w.  j a  va 2  s.c  o  m*/
 * @param streamType
 */
public void setNotificationDefaults(NotificationCompat.Builder notificationBuilder, boolean vibration,
        Uri sound, int streamType) {
    notificationBuilder.setSound(sound, streamType);
    notificationBuilder.setDefaults(0);

    int defaults = 0;

    if (vibration) {
        if (SettingsManager.eventsIgnoreSystemVibro()) {
            startVibration();
        } else {
            defaults |= Notification.DEFAULT_VIBRATE;

        }
    }

    if (SettingsManager.eventsLightning()) {
        defaults |= Notification.DEFAULT_LIGHTS;
    }

    notificationBuilder.setDefaults(defaults);
}

From source file:com.google.android.apps.paco.NotificationCreator.java

private Notification createNotification(Context context, Experiment experiment,
        NotificationHolder notificationHolder, String message) {
    int icon = R.drawable.paco32;

    String tickerText = context.getString(R.string.time_for_notification_title) + experiment.getTitle();
    if (notificationHolder.isCustomNotification()) {
        tickerText = message;//from ww w . j  a  v a  2  s  . c om
    }

    //Notification notification = new Notification(icon, tickerText, notificationHolder.getAlarmTime());

    Intent surveyIntent = new Intent(context, ExperimentExecutor.class);
    surveyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Uri uri = Uri.withAppendedPath(ExperimentColumns.JOINED_EXPERIMENTS_CONTENT_URI,
            experiment.getId().toString());
    surveyIntent.setData(uri);
    surveyIntent.putExtra(Experiment.SCHEDULED_TIME, notificationHolder.getAlarmTime());
    surveyIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());

    PendingIntent notificationIntent = PendingIntent.getActivity(context, 1, surveyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // new wearable compatible way to do it
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(experiment.getTitle()).setTicker(tickerText).setContentText(message)
            .setWhen(notificationHolder.getAlarmTime()).setContentIntent(notificationIntent)
            .setAutoCancel(true);

    int defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;
    String ringtoneUri = new UserPreferences(context).getRingtone();
    if (ringtoneUri != null) {
        notificationBuilder.setSound(Uri.parse(ringtoneUri));
    } else {
        defaults |= Notification.DEFAULT_SOUND;
        //    notification.sound = Uri.parse(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
        //                                   + "/Android/data/" + context.getPackageName() + "/" +
        //                                   "deepbark_trial.mp3");
    }
    notificationBuilder.setDefaults(defaults);

    //end wearable

    return notificationBuilder.build();
}