예제 #1
0
파일: AddVue.java 프로젝트: onepix/BelleVue
  private void saveVue(String name, String description, int categorie, List<File> files) {
    int cptrPicture = 0;
    byte[] pictureTmp;

    // Create the LocationPoint
    ParseGeoPoint point =
        new ParseGeoPoint(
            MapFragment.mCurrentLocation.getLatitude(),
            MapFragment.mCurrentLocation.getLongitude());

    // Set Permission ACCESS CONTROL LISTS
    ParseACL acl = new ParseACL();
    acl.setPublicReadAccess(true);

    // Create the BelleVue
    ParseObject newVue = new ParseObject("BelleVue");
    newVue.setACL(acl);
    newVue.put("name", name);
    newVue.put("description", description);
    newVue.put("categorie", categorie);
    newVue.put("star", 5.0);
    newVue.put("location", point);

    // Create the Pictures
    ParseObject pictures = new ParseObject("Pictures");
    pictures.setACL(acl);
    // nbPicture incr at each photo taken <=> nbPhoto
    pictures.put("nbPicture", nbPicture);

    for (cptrPicture = 0; cptrPicture < nbPicture; cptrPicture++) {
      try {
        pictureTmp = Files.toByteArray(files.get(cptrPicture));
        // pictureList.add(new ParseFile("resume.txt", pictureTmp));
        pictures.put(
            "picture" + String.valueOf(cptrPicture),
            new ParseFile(files.get(cptrPicture).getName(), pictureTmp));
      } catch (IOException e) {
        Log.d("Convert Picture", "FAILED AT LIST INDEX " + String.valueOf(cptrPicture));
      }
    }

    // Add a relation between the BelleVue and Pictures
    newVue.put("Pictures", pictures);

    // This will save both BelleVue and Pictures
    newVue.saveInBackground();
    nbPicture = 0;
    finish();
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
   super.onActivityResult(requestCode, resultCode, intent);
   Bundle extras = intent.getExtras();
   switch (requestCode) {
     case ACTIVITY_FRIEND_LIST_SHOW:
       ArrayList<String> flist;
       Log.d("BuganizerParseEdit", "onActivityResult:ACTIVITY_FRIEND_LIST_SHOW");
       flist = extras.getStringArrayList(BuganizerParseConstants.friendslist);
       for (String f : flist) {
         Log.d("BuganizerParseEdit", "Adding user to ACL " + f);
         if (acl == null) {
           Log.d("BuganizerParseEdit", "Creating ACL");
           acl = new ParseACL();
         }
         acl.setWriteAccess(f, true);
         acl.setReadAccess(f, true);
       }
       if ((acl != null) && (flist.size() > 0)) {
         Log.d("BuganizerParseEdit", "Saving object with ACL in background");
         pObject.setACL(acl);
         pObject.saveInBackground();
       }
       break;
   }
 }