示例#1
0
  @Override
  public void onReceive(Context appContext, Intent intent) {
    context = appContext;
    loc = Localizator.geoLocate(context);
    if (loc != null) {
      URLForecast = Conversor.getUrlForecast(loc);

      /*
       * Toast.makeText(context,
       * "¡Vibration Mode On porque el tiempo se ha terminado!",
       * Toast.LENGTH_LONG).show();
       */

      // Define la vibracion del telefono

      /*
       * Vibrator vibrator = (Vibrator) context
       * .getSystemService(Context.VIBRATOR_SERVICE);
       * vibrator.vibrate(1000);
       */
      prefs = context.getSharedPreferences(Values.getPrefs(), Context.MODE_PRIVATE);
      prefs.edit().putBoolean("active", true).commit();
      check_server();
    } else {
      Log.e(LogDavid, "LOC NULL");
      if (!Localizator.isProviderEnabled(appContext)) {
        Notifications notif = new Notifications(appContext);
        notif.providerDisabled();
      } else {

      }
    }
  }
    public static void setSuggested_Temp_Basal(JSONObject openAPSSuggest, Context c) {
      try {
        Suggested_Temp_Basal = new TempBasal();
        Notifications.clear(MainActivity.activity); // Clears any open notifications
        if (openAPSSuggest.has("rate")) { // Temp Basal suggested
          Suggested_Temp_Basal.rate = openAPSSuggest.getDouble("rate");
          Suggested_Temp_Basal.ratePercent = openAPSSuggest.getInt("ratePercent");
          Suggested_Temp_Basal.duration = openAPSSuggest.getInt("duration");
          Suggested_Temp_Basal.basal_type = openAPSSuggest.getString("temp");
          Suggested_Temp_Basal.basal_adjustemnt = openAPSSuggest.getString("basal_adjustemnt");

          if (openAPSSuggest
              .getString("openaps_mode")
              .equals("closed")) { // OpenAPS mode is closed, send command direct to pump
            pumpAction.setTempBasal(
                openAPSFragment.getSuggested_Temp_Basal(), MainActivity.activity);
          } else { // Make notification (Wear & Phone)
            Notifications.newTemp(openAPSSuggest, c);
          }
        }
      } catch (Exception e) {
        Crashlytics.logException(e);
        Toast.makeText(
                MainActivity.activity, "Crash in setSuggested_Temp_Basal", Toast.LENGTH_SHORT)
            .show();
      }
      currentOpenAPSSuggest = openAPSSuggest;
      update();
    }
  /** Marshall the given parameter object, and output to a JSONWriter */
  public void marshall(Notifications notifications, JSONWriter jsonWriter) {
    if (notifications == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonWriter.object();

      if (notifications.getProgressing() != null) {
        jsonWriter.key("Progressing").value(notifications.getProgressing());
      }

      if (notifications.getCompleted() != null) {
        jsonWriter.key("Completed").value(notifications.getCompleted());
      }

      if (notifications.getWarning() != null) {
        jsonWriter.key("Warning").value(notifications.getWarning());
      }

      if (notifications.getError() != null) {
        jsonWriter.key("Error").value(notifications.getError());
      }

      jsonWriter.endObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
示例#4
0
  private DownloadSubmissionListener getDSLForDownloadBatch(
      final long totalSize, String barCaption) {
    final ProgressMonitor progressBar =
        new ProgressMonitor(frame, barCaption, "Starting...", 0, 10000);
    Notifications.fixupPM(progressBar, true);

    final ProgressTracker tracker = new ProgressTracker();
    tracker.setExpectedMaximum(totalSize);
    return new DownloadSubmissionListener() {
      @Override
      public void fileSubmitted(FileSystemEntry file) {
        tracker.progress(file.getSize());
        progressBar.setProgress((int) (tracker.percentComplete() * 100f));
        progressBar.setNote(tracker.describe());
      }

      @Override
      public boolean isCancelled() {
        return progressBar.isCanceled();
      }

      @Override
      public void complete() {
        progressBar.close();
      }
    };
  }
示例#5
0
  private void check_server() {
    JsonParser jsonParser = new JsonParser(URLForecast);
    WeatherAsyncTask weatherAsyncTask = new WeatherAsyncTask();
    Editor edit;
    try {
      if (necesaryUpdate()) {
        Log.d(LogDavid, "NECESITO ACTUALIZAR");
        Weather weathers[] = weatherAsyncTask.execute(jsonParser).get();
        int n = Conversor.getNextWeather(weathers);
        Weather weather = weathers[n];
        if (n > 0) save_weather(weathers[n - 1]);
        else save_weather(weathers[0]);

        /*
         * Toast toast2 = Toast.makeText(context, R.string.success,
         * Toast.LENGTH_SHORT); toast2.show();
         */

        // if (weather.getRain_threehours() > 0 || weather.getSnow_threehours() > 0) {
        if (notificationNeeded(weather)) {
          Log.d(LogDavid, "NECESITO AVISAR");
          if (Conversor.ifNotificationAllowed(prefs)) {
            Log.d(LogDavid, "PUEDO AVISAR");
            Notifications notif = new Notifications(context);
            notif.notify(weather);
          } else {
            Log.d(LogDavid, "NO PUEDO AVISAR");
          }
        } else {
          Log.d(LogDavid, "NO NECESITO AVISAR - PREVIOUS FALSE");
          edit = prefs.edit();
          edit.putBoolean(Values.getPrevNotif(), false);
          edit.commit();
        }
      } else {
        Log.d(LogDavid, "NO ACTUALIZO");
      }
    } catch (Exception e) {
      Log.e(LogDavid, "Error Refresh: " + e.toString());
      e.printStackTrace();
    }
  }
 public void setListNotification(Notifications notification) {
   this.notifications = notification.getListNotification();
 }
 public NotificationAdapter(Context context, Notifications notifications) {
   inflater = LayoutInflater.from(context);
   this.notifications = notifications.getListNotification();
   this.context = context;
 }