public void dismissNotifications(long providerId) {
   synchronized (mNotificationInfos) {
     NotificationInfo info = mNotificationInfos.get(providerId);
     if (info != null) {
       mNotificationManager.cancel(info.computeNotificationId());
       mNotificationInfos.remove(providerId);
     }
   }
 }
  public void dismissChatNotification(long providerId, String username) {
    NotificationInfo info;
    boolean removed;
    synchronized (mNotificationInfos) {
      info = mNotificationInfos.get(providerId);
      if (info == null) {
        return;
      }
      removed = info.removeItem(username);
    }

    if (removed) {
      if (info.getMessage() == null) {
        if (DBG) log("dismissChatNotification: removed notification for " + providerId);
        mNotificationManager.cancel(info.computeNotificationId());
      } else {
        if (DBG) {
          log(
              "cancelNotify: new notification"
                  + " mTitle="
                  + info.getTitle()
                  + " mMessage="
                  + info.getMessage()
                  + " mIntent="
                  + info.getIntent());
        }
        mNotificationManager.notify(
            info.computeNotificationId(), info.createNotification("", true));
      }
    }
  }
  private void handleAddNotification(NotificationInfo n) {

    // validation for ADD reference
    if (n.isReferenceNotification()) {

      // non model element references must be marked transient
      if (!(n.getNewValue() instanceof EObject)) {
        n.setValid(false);
        n.setValidationMessage(
            "Non-transient non-EObject reference feature detected: "
                + n.getNotifier().getClass().getCanonicalName()
                + "-"
                + n.getReference().getName());
        return;
      }

      // checking up on EMF...
      if (!n.getReference().isMany()) {
        n.setValid(false);
        n.setValidationMessage(
            "Unkown notification state: ADD notification on reference "
                + "feature with isMany==false");
      }
    }

    // no validation for ADD attribute

  }
  private void handleAddManyNotification(NotificationInfo n) {

    // TODO add validation
    // // attributes not allowed for ADD_MANY (yet)
    // if (n.isAttributeNotification()) {
    // n.setValid(false);
    // n.setValidationMessage("ADD_MANY on attribute feature with multiplicity greater than 1 not
    // yet supported.");
    // return;
    // }

    // reference validation
    if (n.isReferenceNotification()) {

      // the new guys must come in a list
      if (!(n.getNewValue() instanceof List<?>)) {
        n.setValid(false);
        n.setValidationMessage(
            "Non-List newValue argument for ADD_MANY notification on: "
                + n.getNotifier().getClass().getCanonicalName()
                + "-"
                + n.getReference().getName());
        return;
      }

      // checking up on EMF, the reference must have max multiplicity greater than 1...
      if (!n.getReference().isMany()) {
        n.setValid(false);
        n.setValidationMessage(
            "Unkown notification state: ADD_MANY notification on reference "
                + "feature with isMany==false");
        return;
      }
    }
  }
  private void handleSetNotification(NotificationInfo n) {

    // validation for SET reference

    if (n.isReferenceNotification()) {

      // sanity check newValue and oldValue must be ModelElements or null
      Object newValueObject = n.getNewValue();
      Object oldValueObject = n.getOldValue();

      boolean newValIsNoME = newValueObject != null && !(newValueObject instanceof EObject);
      boolean oldValIsNoME = oldValueObject != null && !(oldValueObject instanceof EObject);
      if (newValIsNoME || oldValIsNoME) {
        // non model element references must be marked transient
        n.setValid(false);
        n.setValidationMessage(
            "Non-transient non-EObject reference feature detected: "
                + n.getNotifier().getClass().getCanonicalName()
                + "-"
                + n.getReference().getName());
        return;
      }
    }

    // no validation for SET attribute
  }
  /**
   * Validates a notification and sets its valid flag and validationmessage string.
   *
   * @param n the notification to validate
   * @return
   */
  protected void validate(NotificationInfo n) {

    if (n == null) {
      throw new IllegalArgumentException("NotificationInfo argument cannot be null");
    }

    // assume notification is valid, handlers will reset state and message, if something is wrong
    n.setValid(true);
    n.setValidationMessage("OK");

    // consider touch and transient notification to always be valid
    if (n.isTouch() || n.isTransient()) {
      return;
    }

    switch (n.getEventType()) {
      case Notification.SET:
        handleSetNotification(n);
        break;
      case Notification.ADD:
        handleAddNotification(n);
        break;
      case Notification.REMOVE:
        handleRemoveNotification(n);
        break;
      case Notification.ADD_MANY:
        handleAddManyNotification(n);
        break;
      case Notification.REMOVE_MANY:
        handleRemoveManyNotification(n);
        break;
      case Notification.UNSET:
        handleUnsetNotification(n);
        break;
      case Notification.MOVE:
        handleMoveNotification(n);
        break;
      default:
        handleUnknownNotification(n);
        break;
    }
  }
  private void notify(
      String sender,
      String title,
      String tickerText,
      String message,
      long providerId,
      long accountId,
      Intent intent,
      boolean lightWeightNotify) {
    NotificationInfo info;
    synchronized (mNotificationInfos) {
      info = mNotificationInfos.get(providerId);
      if (info == null) {
        info = new NotificationInfo(providerId, accountId);
        mNotificationInfos.put(providerId, info);
      }
      info.addItem(sender, title, message, intent);
    }

    mNotificationManager.notify(
        info.computeNotificationId(), info.createNotification(tickerText, lightWeightNotify));
  }
  public static void showNotification(
      Context context, Updater.PackageInfo[] infosRom, Updater.PackageInfo[] infosGapps) {
    Resources resources = context.getResources();

    if (infosRom != null) {
      sPackageInfosRom = infosRom;
    } else {
      infosRom = sPackageInfosRom;
    }
    if (infosGapps != null) {
      sPackageInfosGapps = infosGapps;
    } else {
      infosGapps = sPackageInfosGapps;
    }

    int contentTitleResourceId = -1;
    if (infosRom.length > 0 && infosGapps.length > 0) {
      contentTitleResourceId =
          !Utils.weAreInBS() ? R.string.update_all_to_bs : R.string.new_all_found_title;
    } else if (infosRom.length == 0) {
      contentTitleResourceId =
          !Utils.weAreInBS() ? R.string.update_gapps_to_bs : R.string.new_gapps_found_title;
    } else {
      contentTitleResourceId =
          !Utils.weAreInBS() ? R.string.update_rom_to_bs : R.string.new_rom_found_title;
    }

    Intent intent = new Intent(context, MainActivity.class);
    NotificationInfo fileInfo = new NotificationInfo();
    fileInfo.mNotificationId = Updater.NOTIFICATION_ID;
    fileInfo.mPackageInfosRom = infosRom;
    fileInfo.mPackageInfosGapps = infosGapps;
    intent.putExtra(FILES_INFO, fileInfo);
    PendingIntent pIntent =
        PendingIntent.getActivity(
            context, Updater.NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(contentTitleResourceId))
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent);

    String contextText = "";
    if (infosRom.length + infosGapps.length == 1) {
      String filename =
          infosRom.length == 1 ? infosRom[0].getFilename() : infosGapps[0].getFilename();
      contextText = resources.getString(R.string.new_package_name, new Object[] {filename});
    } else {
      contextText =
          resources.getString(
              R.string.new_packages, new Object[] {infosRom.length + infosGapps.length});
    }
    builder.setContentText(contextText);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(context.getResources().getString(contentTitleResourceId));
    if (infosRom.length + infosGapps.length > 1) {
      inboxStyle.addLine(contextText);
    }
    for (int i = 0; i < infosRom.length; i++) {
      inboxStyle.addLine(infosRom[i].getFilename());
    }
    for (int i = 0; i < infosGapps.length; i++) {
      inboxStyle.addLine(infosGapps[i].getFilename());
    }
    builder.setStyle(inboxStyle);

    Notification notif = builder.build();

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);

    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(Updater.NOTIFICATION_ID, notif);
  }
示例#9
0
 /** Configure notification setting for this site. */
 public void setNotificationPermission(ContentSetting value) {
   if (mNotificationInfo != null) {
     mNotificationInfo.setContentSetting(value);
   }
 }
示例#10
0
 /** Returns what setting governs notification access. */
 public ContentSetting getNotificationPermission() {
   return mNotificationInfo != null ? mNotificationInfo.getContentSetting() : null;
 }
  private void handleMoveNotification(NotificationInfo n) {

    // if (n.isAttributeNotification()) {
    // n.setValid(false);
    // n.setValidationMessage("MOVE notification on attribute feature with multiplicty"
    // + "greater 1 not supported yet!");
    // return;
    // }

    if (n.isReferenceNotification()) {
      // sanity checks
      if (n.getNewValue() == null || n.getOldValue() == null) {
        n.setValid(false);
        n.setValidationMessage(
            "Null detected in oldValue or NewValue of move notification about: "
                + n.getNotifier().getClass().getCanonicalName()
                + "-"
                + n.getReference().getName());
        return;
      }

      if (!(n.getNewValue() instanceof EObject)) {
        // non model element references must be marked transient

        n.setValid(false);
        n.setValidationMessage(
            "Non-transient non-EObject reference feature detected: "
                + n.getNotifier().getClass().getCanonicalName()
                + "-"
                + n.getReference().getName());
        return;
      }

      if (!(n.getOldValue() instanceof Integer)) {
        n.setValid(false);
        n.setValidationMessage("Error with old position in move: not an Integer");
        return;
      }
    }
  }
 private void handleUnknownNotification(NotificationInfo n) {
   n.setValid(false);
   n.setValidationMessage("Error: unknown notification event type. " + n.toString());
 }
 private void handleUnsetNotification(NotificationInfo n) {
   n.setValid(false);
   n.setValidationMessage("Cannot handle UNSET notifications");
 }