private void sendEmail() { /* * Create attachment files * then attach files to email and send */ File file = null; String message = ""; /* * Update the comments field members from the textbox */ storeAddressFields(); // change based on date String file_name = "graffiti_" + System.currentTimeMillis() + ".csv"; String dir_name = "/Graffiti Files"; /* message = String.format( "COMMENTS: \n\n\nLat: %1$s\nLong: %2$s\nBuilding: %3$s\nStreet: %4$s\nCity: %5$s\nState: %6$s\nZip: %7$s\n", m_latitude, m_longitude, m_bldg_num, m_street, m_city, m_state, m_zip); */ // Create attachment to send with email message = generateCsvFile(); if (message == "") { message = "Error"; displayMessage("ERROR"); } file = createLocationFile(file_name, dir_name, message); m_loc_file_location = file.getAbsolutePath(); String pic_attachment = m_camera_tool.getPictureLocation(); /* * Set up email activity */ Intent email_intent = m_email_tool.sendEmail(m_loc_file_location, pic_attachment); /* * Send email, or catch no email client */ try { startActivityForResult( Intent.createChooser(email_intent, "Send mail..."), EMAIL_ACTIVITY_KEY); } catch (android.content.ActivityNotFoundException ex) { displayMessage("There are no email clients installed."); } // displayMessage(full_path); }
/* * functions called when app is ending */ private void deleteTempFiles() { File file = null; boolean deleted = false; String pic_file_name = m_camera_tool.getPictureLocation(); if (pic_file_name != "") { file = new File(pic_file_name); deleted = file.delete(); if (deleted == false) { displayMessage("Could not delete pic"); } } if (m_loc_file_location != "") { file = new File(m_loc_file_location); deleted = file.delete(); if (deleted == false) { displayMessage("Could not delete text file"); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case SETTINGS_ACTIVITY_KEY: // user possibly changed GPS location updateLocation(); break; case CAMERA_ACTIVITY_KEY: // check if picture received if (resultCode == 0) { break; } // TODO: move to own function ImageController image_control = new ImageController(); Bitmap m_bmap = null; String path = m_camera_tool.getPictureLocation(); BitmapFactory m_bmap_factory = new BitmapFactory(); m_bmap = m_bmap_factory.decodeFile(path); Float width = new Float(m_bmap.getWidth()); Float height = new Float(m_bmap.getHeight()); Float ratio = width / height; m_bmap = Bitmap.createScaledBitmap( m_bmap, (int) (THUMBNAIL_HEIGHT * ratio), THUMBNAIL_WIDTH, false); int padding = (THUMBNAIL_WIDTH - m_bmap.getWidth()) / 2; iv_user_pic.setPadding(padding, 0, padding, 0); iv_user_pic.setImageBitmap(m_bmap); break; case EMAIL_ACTIVITY_KEY: String message = ""; if (resultCode == RESULT_CANCELED) { message = String.format("Email failed: %1$s", resultCode); } else { message = String.format("Email succeeded: %1$s", resultCode); shutdownApp(); } finish(); // displayMessage(message); break; case COMMENTS_ACTIVITY_KEY: // store comments if (data != null) { m_comments = data.getExtras().getString(COMMENTS); } if (resultCode == 1) { // displayMessage("Time to send email..." + m_comments); sendEmail(); } else { // displayMessage("Continue Editing" + m_comments); } default: // UNKNOWN Activity started break; } }