Esempio n. 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 {

      }
    }
  }
Esempio n. 2
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();
    }
  }
Esempio n. 3
0
 private void save_weather(Weather weather) {
   Editor edit = prefs.edit();
   Conversor.saveWeather(edit, weather);
 }
Esempio n. 4
0
  private String genXml(CliGol cliGol) {

    return conversor.convierte("EntradaCalculadora", cliGol);
  }