Esempio n. 1
0
 private Date load() {
   try {
     return FORMAT.parse(getDateString());
   } catch (ParseException e) {
     return ERROR;
   }
 }
 /**
  * Protected constructor.
  *
  * @param percentile The percentile value to compute.
  */
 protected TPStatistic(final double percentile) {
   _percentile = percentile;
   _defaultName = "tp" + FORMAT.format(_percentile);
   _aliases = Sets.newHashSet();
   _aliases.add(_defaultName);
   _aliases.add(_defaultName.substring(1));
   _aliases.add(_defaultName.replace(".", "p"));
   _aliases.add(_defaultName.substring(1).replace(".", "p"));
 }
  public void savePhoto() {

    final FloatingActionButton save = (FloatingActionButton) findViewById(R.id.save);
    save.setEnabled(false);
    save.setIndeterminate(true);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String file_path = prefs.getString("path", null);

    String format = prefs.getString("image_format", "0");

    class FORMAT {
      public String ext;
      public Bitmap.CompressFormat bitmap_format;
      public Integer q;

      public void setString(String x) {
        this.ext = x;
      }

      public void setBitmapFormat(Bitmap.CompressFormat x) {
        this.bitmap_format = x;
      }

      public void setQuality(Integer x) {
        this.q = x;
      }
    }

    final FORMAT f = new FORMAT();

    if (format.equals("0")) {
      f.setString(".png");
      f.setBitmapFormat(Bitmap.CompressFormat.PNG);
      f.setQuality(100);
    } else {
      f.setString(".jpeg");
      f.setBitmapFormat(Bitmap.CompressFormat.JPEG);
      f.setQuality(80);
    }

    assert file_path != null;
    final File dir = new File(file_path);
    if (!dir.exists()) {
      dir.mkdirs();
    }

    Thread normal_save =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                pushObjectToSP();

                String modifiedTitle = gagTitle.replaceAll(" ", "-");
                File file = new File(dir, modifiedTitle + f.ext);

                FileOutputStream outo = null;
                try {
                  outo = new FileOutputStream(file);
                  bp.getBitmap(true).compress(f.bitmap_format, f.q, outo);
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  try {
                    if (outo != null) {
                      outo.close();
                    }
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                File directory_gags =
                    new File(
                        getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                            + File.separator
                            + "gags");
                if (!directory_gags.exists()) {
                  directory_gags.mkdirs();
                }
                File dir_app = new File(directory_gags + File.separator + photo_id);
                FileOutputStream outi = null;

                try {
                  outi = new FileOutputStream(dir_app);
                  bp.getBitmap(true).compress(f.bitmap_format, f.q, outi);
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  try {
                    if (outi != null) {
                      outi.close();
                    }
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                intent.setData(Uri.fromFile(file));
                sendBroadcast(intent);

                runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        save.setIndeterminate(false);
                        Toast.makeText(
                                getApplicationContext(),
                                "Gag saved successfully",
                                Toast.LENGTH_LONG)
                            .show();
                      }
                    });
              }
            });

    normal_save.start();
  }
Esempio n. 4
0
 /** @return the time */
 public String getTime() {
   return FORMAT.format(time);
 }
Esempio n. 5
0
  @Override
  public Collection<Throwable> call() throws Exception {

    if (this.formatString != null) {
      try {
        this.format = FORMAT.valueOf(this.formatString.toUpperCase());
      } catch (Exception e) {
        return wrapException(e);
      }
    }
    try {
      this.script = super.compileJavascript();
    } catch (Exception err) {
      return wrapException(err);
    }

    final List<String> args = getInputFiles();

    try {
      this.bindings = this.script.getEngine().createBindings();
      if (getOutputFile() == null) {
        this.writer = new PrintWriter(stdout());
      } else {
        this.writer = new PrintWriter(getOutputFile());
      }
      this.bindings.put("out", this.writer);

      if (args.isEmpty()) {
        if (this.format == null) {
          return wrapException("Format must be specified when reading from stdin");
        }
        return execute(this.format, null);
      }
      for (String filename : IOUtils.unrollFiles(args)) {
        this.bindings.put("FILENAME", filename);
        FORMAT fmt = this.format;
        if (fmt == null) {
          for (FORMAT t : FORMAT.values()) {
            if (t.canAs(filename)) {
              fmt = t;
              break;
            }
          }
        }
        if (fmt == null) {
          return wrapException("Cannot get file format for " + filename);
        }
        Collection<Throwable> errors = execute(fmt, filename);
        if (!errors.isEmpty()) {
          return errors;
        }
      }

      this.writer.flush();
      return RETURN_OK;
    } catch (Exception err) {
      return wrapException(err);
    } finally {
      if (this.writer != null) this.writer.flush();
      if (getOutputFile() != null) {
        CloserUtil.close(this.writer);
      }
      this.writer = null;
      bindings = null;
      this.bindings = null;
      this.format = null;
    }
  }
 private String getShowValue(double value) {
   return FORMAT.format(value);
 }