Exemple #1
0
 public static void savePictureToPostSync(ParseObject mPost, Bitmap picture) {
   ByteArrayOutputStream stream = new ByteArrayOutputStream();
   picture.compress(Bitmap.CompressFormat.JPEG, 100, stream);
   byte[] bytearray = stream.toByteArray();
   ParseFile questionPicture = new ParseFile(mPost.getObjectId() + "_picture.jpg", bytearray);
   try {
     questionPicture.save();
     mPost.put(Common.OBJECT_POST_PICTURE, questionPicture);
     mPost.save();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void saveNewBikeSpot() {

    SessionManager sessionManager = new SessionManager(getApplicationContext());
    HashMap<String, String> userSession = sessionManager.getUserDetails();
    String userCredential = userSession.get(sessionManager.KEY_REGISTRATION);
    String pwdVerified = userSession.get(sessionManager.KEY_PASSWORD);
    String emailCredential = userSession.get(sessionManager.KEY_EMAIL);
    if (pwdVerified.equalsIgnoreCase("FBPWD")) {
      saveFacebookUser(userCredential, pwdVerified, emailCredential);
    }
    final String fullAddressNewBikeSpot =
        edtTextAddressName
            .getText()
            .toString()
            .trim()
            .concat(", ")
            .concat(edtTextNumber.getText().toString().trim().concat(" - ").concat(cityState));
    BikeSpot bikeSpot = new BikeSpot();
    Date date = new Date();
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    FORMAT.format(date);
    parseGeoPoint = new ParseGeoPoint();
    parseGeoPoint.setLatitude(location.getLatitude());
    parseGeoPoint.setLongitude(location.getLongitude());
    bikeSpot.setLocation(parseGeoPoint);
    bikeSpot.setName(edtTextReference.getText().toString().trim());
    bikeSpot.setLocation(parseGeoPoint);
    bikeSpot.setDescription(edtTextReference.getText().toString().trim());
    bikeSpot.setFullAddress(fullAddressNewBikeSpot);
    bikeSpot.setAddressNumber(edtTextNumber.getText().toString().trim());
    bikeSpot.setUsername(userCredential);
    bikeSpot.setLocalDate(FORMAT.format(date));
    bikeSpot.setPlattaform("ANDROID");
    bikeSpot.setStatus(true);
    bikeSpot.setRate(0);
    bikeSpot.setCathegory(transformCathegoryToChar(spnrCathegory.getSelectedItem().toString()));
    bikeSpot.setCapacity(capacity = (capacity > 0) ? capacity : 0);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    if (bitmap != null) {
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
      byte[] bitmapBytes = stream.toByteArray();
      StringBuilder strBuilder = new StringBuilder();
      String fileName =
          strBuilder.replaceSpecialCharacters(edtTextReference.getText().toString().trim());
      ParseFile pic = new ParseFile(strBuilder.removeAllSpaces(fileName), bitmapBytes);
      try {
        pic.save();
      } catch (ParseException e) {
        e.printStackTrace();
      }
      bikeSpot.setPicture(pic);
    }
    final ProgressDialog dialog = new ProgressDialog(NewBikeSpotActivity.this);
    dialog.setMessage(getString(R.string.progress_new_bikespot));
    dialog.show();
    bikeSpot.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException p) {
            dialog.dismiss();
            Toast.makeText(
                    getApplicationContext(), MESSAGE_OF_SUCCESS.toString(), Toast.LENGTH_SHORT)
                .show();
          }
        });
  }