コード例 #1
0
 @Override
 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   NotificationPreset preset = NotificationPresets.PRESETS[position];
   mBackgroundPickers.generatePickers(preset.countBackgroundPickersRequired());
   updateTextEditors(preset);
   updateNotifications(false /* cancelExisting */);
 }
コード例 #2
0
  /** Post the sample notification(s) using current options. */
  private void postNotifications() {
    sendBroadcast(
        new Intent(NotificationIntentReceiver.ACTION_ENABLE_MESSAGES)
            .setClass(this, NotificationIntentReceiver.class));

    NotificationPreset preset =
        NotificationPresets.PRESETS[mPresetSpinner.getSelectedItemPosition()];
    CharSequence titlePreset = mTitleEditText.getText();
    CharSequence textPreset = mTextEditText.getText();
    PriorityPreset priorityPreset =
        PriorityPresets.PRESETS[mPrioritySpinner.getSelectedItemPosition()];
    ActionsPreset actionsPreset = ActionsPresets.PRESETS[mActionsSpinner.getSelectedItemPosition()];
    if (preset.actionsRequired() && actionsPreset == ActionsPresets.NO_ACTIONS_PRESET) {
      // If actions are required, but the no-actions preset was selected, change presets.
      actionsPreset = ActionsPresets.SINGLE_ACTION_PRESET;
      mActionsSpinner.setSelection(
          Arrays.asList(ActionsPresets.PRESETS).indexOf(actionsPreset), true);
    }
    NotificationPreset.BuildOptions options =
        new NotificationPreset.BuildOptions(
            titlePreset,
            textPreset,
            priorityPreset,
            actionsPreset,
            mIncludeLargeIconCheckbox.isChecked(),
            mLocalOnlyCheckbox.isChecked(),
            mIncludeContentIntentCheckbox.isChecked(),
            mVibrateCheckbox.isChecked(),
            mBackgroundPickers.getRes());
    Notification[] notifications = preset.buildNotifications(this, options);

    // Post new notifications
    for (int i = 0; i < notifications.length; i++) {
      NotificationManagerCompat.from(this).notify(i, notifications[i]);
    }
    // Cancel any that are beyond the current count.
    for (int i = notifications.length; i < postedNotificationCount; i++) {
      NotificationManagerCompat.from(this).cancel(i);
    }
    postedNotificationCount = notifications.length;
  }