Exemplo n.º 1
0
  /**
   * Persist the information of this notification to the Android Shared Preferences. This will allow
   * the application to restore the notification upon device reboot, app restart, retrieve
   * notifications, aso.
   */
  private void persist() {
    SharedPreferences.Editor editor = getPrefs().edit();

    editor.putString(options.getId(), options.toString());

    if (Build.VERSION.SDK_INT < 9) {
      editor.commit();
    } else {
      editor.apply();
    }
  }
Exemplo n.º 2
0
  /**
   * Set intent to handle the delete event. Will clean up some persisted preferences.
   *
   * @param builder Local notification builder instance
   */
  private void applyDeleteReceiver(NotificationCompat.Builder builder) {

    if (clearReceiver == null) return;

    Intent deleteIntent =
        new Intent(context, clearReceiver)
            .setAction(options.getId())
            .putExtra(Options.EXTRA, options.toString());

    PendingIntent dpi =
        PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setDeleteIntent(dpi);
  }
Exemplo n.º 3
0
  /** Schedule the local notification. */
  public void schedule() {
    long triggerTime = getNextTriggerTime();

    persist();

    // Intent gets called when the Notification gets fired
    Intent intent =
        new Intent(context, receiver)
            .setAction(options.getId())
            .putExtra(Options.EXTRA, options.toString());

    PendingIntent pi =
        PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
  }
Exemplo n.º 4
0
  /**
   * Set intent to handle the click event. Will bring the app to foreground.
   *
   * @param builder Local notification builder instance
   */
  private void applyContentReceiver(NotificationCompat.Builder builder) {

    if (clickActivity == null) return;

    Intent intent =
        new Intent(context, clickActivity)
            .putExtra(Options.EXTRA, options.toString())
            .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    int requestCode = new Random().nextInt();

    PendingIntent contentIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(contentIntent);
  }
Exemplo n.º 5
0
  @Override
  public void action(final Object comp) {
    final String pth = path();
    final IOFile io = new IOFile(pth);
    String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null;
    ok = !pth.isEmpty();

    final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem());
    final OptionsOption<? extends Options> opts =
        mth == SerialMethod.JSON
            ? SerializerOptions.JSON
            : mth == SerialMethod.CSV ? SerializerOptions.CSV : null;
    final boolean showmparams = opts != null;
    mparams.setEnabled(showmparams);

    if (ok) {
      gui.gopts.set(GUIOptions.INPUTPATH, pth);
      try {
        if (comp == method) {
          if (showmparams) {
            final Options mopts = options(null).get(opts);
            mparams.setToolTipText(tooltip(mopts));
            mparams.setText(mopts.toString());
          } else {
            mparams.setToolTipText(null);
            mparams.setText("");
          }
        }
        Serializer.get(new ArrayOutput(), options(mth));
      } catch (final IOException ex) {
        ok = false;
        inf = ex.getMessage();
      }
    }

    info.setText(inf, ok ? Msg.WARN : Msg.ERROR);
    enableOK(buttons, B_OK, ok);
  }
 /**
  * Gets the jQuery statement.<br>
  * <b>Warning: </b> This method is *not* called by the behavior directly (only {@link #$()} is).
  *
  * @param options the {@link Options} to be supplied to the current method
  * @return the jQuery statement
  */
 public String $(Options options) {
   return this.$(options.toString());
 }