Example #1
0
  private static File zipImages(AlarmManager.Alarm alarm) {

    StringBuffer output = new StringBuffer();

    try {
      final String cmd =
          "zip -r " + alarm.getPictureLocation() + ".zip " + alarm.getPictureLocation() + "/";
      Logger.Log(cmd);

      Process p = Runtime.getRuntime().exec(cmd);
      p.waitFor();

      InputStreamReader is = new InputStreamReader(p.getInputStream());
      StringBuilder sb = new StringBuilder();
      BufferedReader br = new BufferedReader(is);
      String read = br.readLine();

      while (read != null) {
        // System.out.println(read);
        sb.append(read);
        read = br.readLine();
      }

      Logger.Log(sb.toString());
    } catch (Exception e) {
      Logger.Log(e.getMessage());
    }

    return new File(alarm.getPictureLocation() + ".zip");
  }
Example #2
0
  public void setPrices(String priceFileName) {
    BufferedReader buffer;
    try {
      buffer = new BufferedReader(new FileReader(priceFileName));
      String line;
      while ((line = buffer.readLine()) != null) {
        String[] tokens = line.split(":");

        if (tokens.length == 4) {
          Double singlePrice = Double.parseDouble(tokens[1]);
          Double volumePrice = Double.parseDouble(tokens[3]);
          Integer volumeQuantity = Integer.parseInt(tokens[2]);
          items.put(tokens[0], new Item(tokens[0], singlePrice, volumePrice, volumeQuantity));
        } else if (tokens.length == 2) {
          Double singlePrice = Double.parseDouble(tokens[1]);
          items.put(tokens[0], new Item(tokens[0], singlePrice, singlePrice, 1));
        }
      }
    } catch (FileNotFoundException e) {
      logger.Log(e.getMessage());
    } catch (IOException e) {
      logger.Log(e.getMessage());
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
    Logger.Log(getApplicationContext(), TAG, "Started...");
  }
Example #4
0
  public static void send(AlarmManager.Alarm alarm) {

    String to = Settings.GetSettingForKey(Setting.EMAIL_ADDR);

    // ***** smtp login details *****
    // Dont save these details in a file
    // Strongly recommended to generate a single application access key from google
    // Dont use your actual password!
    String from = "@gmail.com";
    final String username = "******";
    final String password = "";

    Properties props = new Properties();
    props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.ssl.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "465");

    Session session =
        Session.getInstance(
            props,
            new Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });
    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
      message.setSubject("PiSec Alarm Notice");

      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setText(alarm.toString());

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);

      try {
        if (!alarm.getPictureLocation().equals("")) {
          File zippedImages = zipImages(alarm);
          String filename = zippedImages.getAbsolutePath();
          DataSource source = new FileDataSource(filename);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(filename);
          multipart.addBodyPart(messageBodyPart);
        }
      } catch (Exception e) {
        Logger.Log("Unable to attach zipped images!");
      }

      message.setContent(multipart);

      Transport.send(message);
      Logger.Log("Email Sent!");

    } catch (MessagingException e) {
      e.printStackTrace();
      Logger.Log("Unable to send email! " + e.getMessage());
    }
  }
 public void onClickStatus(View view) {
   Logger.Log(getApplicationContext(), TAG, "User clicks status button...");
   Intent intent = new Intent(this, Status.class);
   startActivity(intent);
 }
 public void onClickMisc(View view) {
   Logger.Log(getApplicationContext(), TAG, "User clicks miscellaneous button...");
   Intent intent = new Intent(this, Misc.class);
   startActivity(intent);
 }
 public void onClickDegree(View view) {
   Logger.Log(getApplicationContext(), TAG, "User clicks degree button...");
   Intent intent = new Intent(this, Degree.class);
   startActivity(intent);
 }
 public void onClickMyAcc(View view) {
   Logger.Log(getApplicationContext(), TAG, "User clicks my acc button...");
   Intent intent = new Intent(this, MyAcc.class);
   startActivity(intent);
 }