예제 #1
0
  public void saveImage() {

    // Store the image inot the database
    // This will prob have to have it's own function
    if (profileImg.getDrawable() != null) {
      Bitmap bImage = ((BitmapDrawable) profileImg.getDrawable()).getBitmap();
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bImage.compress(Bitmap.CompressFormat.PNG, 100, stream);

      byte[] byteArray = stream.toByteArray();
      final ParseFile pImg = new ParseFile("profile.png", byteArray);
      pImg.saveInBackground(
          new SaveCallback() {
            @Override
            public void done(ParseException e) {
              if (e == null) {
                // success
                ParseUser tempUser = ParseUser.getCurrentUser();
                tempUser.put("profileImg", pImg);
                tempUser.saveInBackground();
              } else {
                // failed
              }
            }
          }); // end of the saveinbackground
    }
  }
예제 #2
0
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      photoarraylist = new ArrayList<PhotoList>();
      try {
        // Locate the class table named "ImageUpload" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("ImageUpload");
        // Locate the column named "position" in Parse.com and order list
        // by descending order of created.
        query.orderByDescending("createdAt");
        query.setLimit(15);
        ob = query.find();
        for (ParseObject po : ob) {
          // retrieve objectID and Title
          String stringTitle = (String) po.get("Title");
          String stringObjectID = po.getObjectId();

          // retrieve the image file
          ParseFile image = (ParseFile) po.get("Photo");
          PhotoList map = new PhotoList();
          map.setPhoto(image.getUrl());
          map.setObjectID(stringObjectID);
          map.setTitle(stringTitle);
          photoarraylist.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
  public UpdateImage(Activity activity) {

    Bitmap bitmap =
        BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_action_name);
    // Convert it to byte
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    // Compress image to lower quality scale 1 - 100
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] image = stream.toByteArray();

    // Create the ParseFile
    ParseFile file = new ParseFile("androidbegin.png", image);
    // Upload the image into Parse Cloud
    file.saveInBackground();

    // Create a New Class called "ImageUpload" in Parse
    ParseObject imgupload = new ParseObject("ImageUpload");

    // Create a column named "ImageName" and set the string
    imgupload.put("ImageName", "AndroidBegin Logo");

    // Create a column named "ImageFile" and insert the image
    imgupload.put("ImageFile", file);

    // Create the class and the columns
    imgupload.saveInBackground();
  }
  private void uploadShirt() {
    final ParseObject newShirt = new ParseObject("Shirt");

    User currentUser = UserDataSource.getCurrentUser();
    final String username = (currentUser != null) ? currentUser.getFirstName() : "Jane";
    final String userID = (currentUser != null) ? currentUser.getId() : "Doe";

    final ParseFile imgFile = new ParseFile("shirtImage.jpeg", imageBytes);
    imgFile.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            newShirt.put("image", imgFile);
            newShirt.put("user", username);
            newShirt.put("userID", userID);
            newShirt.put("tag", shirtTag.getText().toString());
            newShirt.put("description", shirtDesc.getText().toString());
            newShirt.put("size", shirtSize.getSelectedItem().toString());
            newShirt.saveInBackground();

            ArrayList<Shirt> oldShirts = UserDataSource.getCurrentUserShirts();
            Shirt shirt = new Shirt();
            shirt.description = shirtDesc.getText().toString();
            shirt.size = shirtSize.getSelectedItem().toString();
            shirt.url = new Uri.Builder().path(imgFile.getUrl()).build();

            oldShirts.add(shirt);
            UserDataSource.setCurrentUserShirts(oldShirts);
            ((SellingFragment) parentFragment).notifyDataChanged();

            dismiss();
          }
        });
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      soaplist = new ArrayList<WorldPopulation>();
      try {
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Product");
        // query.orderByAscending("Product");
        ob = query.find();
        for (ParseObject Product : ob) {
          // Locate images in Picture column
          ParseFile image = (ParseFile) Product.get("Picture");

          WorldPopulation map = new WorldPopulation();
          if (Product.get("Category").equals("soaps and shampoos")) {
            map.setPrice((String) Product.get("Price"));
            map.setProduct((String) Product.get("Product"));
            map.setCategory((String) Product.get("Category"));
            map.setQuantity(Integer.parseInt(Product.get("qty").toString()));
            map.setPicture(image.getUrl());
            soaplist.add(map);
          }
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
예제 #6
0
 private void createNewFriend(final ParseUser parseUser) {
   final ParseFile parseFile = (ParseFile) parseUser.get("avatar");
   if (parseFile != null) {
     parseFile.getDataInBackground(
         new GetDataCallback() {
           @Override
           public void done(byte[] bytes, ParseException e) {
             if (e != null) {
               e.printStackTrace();
               return;
             }
             final Bitmap avatar = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
             final String id = parseUser.getObjectId();
             newFriend =
                 new FriendItem(
                     id, avatar, parseUser.getUsername(), parseUser.getString("fullName"));
             Intent intentAddFriend = new Intent();
             intentAddFriend.setAction(CommonValue.ACTION_ADD_FRIEND);
             boolean isOnline = parseUser.getBoolean("isOnline");
             intentAddFriend.putExtra("isOnline", isOnline);
             MainActivity.this.sendBroadcast(intentAddFriend);
           }
         });
   }
 }
예제 #7
0
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    ParseObject message = mMessages.get(position);
    String messageType = message.getString(ParseConstant.KEY_FILE_TYPE);
    ParseFile file = message.getParseFile(ParseConstant.KEY_FILE);
    Uri fileUri = Uri.parse(file.getUrl());

    if (messageType.equals(ParseConstant.TYPE_IMAGE)) {
      Intent intent = new Intent(getActivity(), ViewimageActivity.class);
      intent.setData(fileUri);
      startActivity(intent);
    } else {
      Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
      intent.setDataAndType(fileUri, "video/*");
      startActivity(intent);
    }

    // Delete it
    List<String> ids = message.getList(ParseConstant.KEY_RECIPIENT_IDS);
    if (ids.size() == 1) {
      // last recipients
      message.deleteInBackground();
    } else {
      ids.remove(ParseUser.getCurrentUser().getObjectId());
      ArrayList<String> idsToRemove = new ArrayList<String>();
      idsToRemove.add(ParseUser.getCurrentUser().getObjectId());

      message.removeAll(ParseConstant.KEY_RECIPIENT_IDS, idsToRemove);
      message.saveInBackground();
    }
  }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ((TextView) view.findViewById(R.id.property_title)).setText(mProperty.getString("title"));
    ((TextView) view.findViewById(R.id.property_category))
        .setText("Type: " + mProperty.getString("category"));
    ((TextView) view.findViewById(R.id.property_facing))
        .setText("Facing: " + mProperty.getString("facing_side"));
    ((TextView) view.findViewById(R.id.property_floors))
        .setText("Floors: " + mProperty.getInt("no_of_floors"));
    ((TextView) view.findViewById(R.id.property_description))
        .setText("Description: " + mProperty.getString("major_things_available"));
    ((TextView) view.findViewById(R.id.property_parking))
        .setText("Parking: " + (mProperty.getBoolean("parking") ? " Available" : "Not Available"));
    ((TextView) view.findViewById(R.id.property_price))
        .setText("Price: Rs." + mProperty.getInt("price") + "/-");
    ((TextView) view.findViewById(R.id.property_price_negotiable))
        .setText("Price Negotiable: " + (mProperty.getBoolean("price_negotiable") ? "Yes" : "No"));
    ((TextView) view.findViewById(R.id.property_location))
        .setText("Location: " + mProperty.getString("location"));
    ((TextView) view.findViewById(R.id.property_landmark))
        .setText("Landmark: " + mProperty.getString("landmark"));

    ParseFile image = mProperty.getParseFile("property_image");
    final ImageView imageView = (ImageView) view.findViewById(R.id.property_full_image);
    Glide.with(getActivity()).load(image.getUrl()).centerCrop().into(imageView);
  }
예제 #9
0
  private void saveNewUser() {
    parseUser = ParseUser.getCurrentUser();
    parseUser.setUsername(name);
    parseUser.setEmail(email);

    //        Saving profile photo as a ParseFile
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Bitmap bitmap = ((BitmapDrawable) mProfileImage.getDrawable()).getBitmap();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream);
    byte[] data = stream.toByteArray();
    String thumbName = parseUser.getUsername().replaceAll("\\s+", "");
    final ParseFile parseFile = new ParseFile(thumbName + "_thumb.jpg", data);

    parseFile.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            parseUser.put("profileThumb", parseFile);

            // Finally save all the user details
            parseUser.saveInBackground(
                new SaveCallback() {
                  @Override
                  public void done(ParseException e) {
                    Toast.makeText(
                            MainActivity.this,
                            "New user:"******" Signed up",
                            Toast.LENGTH_SHORT)
                        .show();
                  }
                });
          }
        });
  }
예제 #10
0
 private void saveNewUser(Bitmap profileImageBitmap) {
   parseUser = ParseUser.getCurrentUser();
   parseUser.setUsername(name);
   parseUser.setEmail(email);
   parseUser.put("dob", birthday);
   //        Saving profile photo as a ParseFile
   ByteArrayOutputStream stream = new ByteArrayOutputStream();
   profileImageBitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream);
   byte[] data = stream.toByteArray();
   String thumbName = parseUser.getUsername().replaceAll("\\s+", "");
   final ParseFile parseFile = new ParseFile(thumbName + "_thumb.jpg", data);
   // we can use saveInBackground() in this method because this data is from Fb
   // so the user must have an internet connection
   parseFile.saveInBackground(
       new SaveCallback() {
         @Override
         public void done(ParseException e) {
           parseUser.put("profileThumb", parseFile);
           // Finally save all the user details
           parseUser.saveInBackground(
               new SaveCallback() {
                 @Override
                 public void done(ParseException e) {
                   Toast.makeText(
                           LoginActivity.this,
                           "New user: "******" Signed up",
                           Toast.LENGTH_SHORT)
                       .show();
                   // Only start the next activity after this one is done
                   startMainActivity();
                 }
               });
         }
       });
 }
예제 #11
0
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      menulista = new ArrayList<MenuSetGet>();
      try {
        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("computadoras");
        // Locate the column named "ranknum" in Parse.com and order list
        // by ascending
        query.orderByAscending("orden");
        ob = query.find();
        for (ParseObject country : ob) {
          // Locate images in flag column
          ParseFile image = (ParseFile) country.get("imagen");

          MenuSetGet map = new MenuSetGet();
          map.setNombre((String) country.get("nombre"));
          map.setDetalle((String) country.get("Detalle"));
          map.setPrecio((String) country.get("precio"));
          map.setImagen(image.getUrl());
          menulista.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
예제 #12
0
 public String uploadParseAvatar(byte[] data) {
   String username = EMChatManager.getInstance().getCurrentUser();
   ParseQuery<ParseObject> pQuery = ParseQuery.getQuery(CONFIG_TABLE_NAME);
   pQuery.whereEqualTo(CONFIG_USERNAME, username);
   ParseObject pUser = null;
   try {
     pUser = pQuery.getFirst();
     if (pUser == null) {
       pUser = new ParseObject(CONFIG_TABLE_NAME);
       pUser.put(CONFIG_USERNAME, username);
     }
     ParseFile pFile = new ParseFile(data);
     pUser.put(CONFIG_AVATAR, pFile);
     pUser.save();
     return pFile.getUrl();
   } catch (ParseException e) {
     if (e.getCode() == ParseException.OBJECT_NOT_FOUND) {
       try {
         pUser = new ParseObject(CONFIG_TABLE_NAME);
         pUser.put(CONFIG_USERNAME, username);
         ParseFile pFile = new ParseFile(data);
         pUser.put(CONFIG_AVATAR, pFile);
         pUser.save();
         return pFile.getUrl();
       } catch (ParseException e1) {
         e1.printStackTrace();
         EMLog.e(TAG, "parse error " + e1.getMessage());
       }
     } else {
       e.printStackTrace();
       EMLog.e(TAG, "parse error " + e.getMessage());
     }
   }
   return null;
 }
예제 #13
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
      Bundle extras = data.getExtras();
      Bitmap imageBitmap = (Bitmap) extras.get("data");
      mImageView = (ImageView) findViewById(R.id.imgView);

      // Saving in Parse server
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
      byte[] dataTostore = stream.toByteArray();

      final ParseFile imgFile = new ParseFile("img.png", dataTostore);
      imgFile.saveInBackground();

      GalleryObj tempPicObj = new GalleryObj();
      ParseObject obj = new ParseObject("Gallery");

      obj.put("pic", imgFile);
      obj.put("Apartment", ParseUser.getCurrentUser().getString("Apartment"));
      try {
        obj.save();
        tempPicObj.id = obj.getObjectId();
        tempPicObj.pic = imageBitmap;
        STgallery.getInstance().add(tempPicObj);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      adapter.notifyDataSetChanged();
    }
  }
예제 #14
0
  public String getVideoUrl() throws UnavailableVideoException {
    ParseFile video = getParseFile(KEY_VIDEO);
    if (video == null) {
      throw new UnavailableVideoException();
    }

    return video.getUrl();
  }
예제 #15
0
  public String getPictureUrl() throws UnavailablePictureException {
    ParseFile picture = getParseFile(KEY_PICTURE);
    if (picture == null) {
      throw new UnavailablePictureException();
    }

    return picture.getUrl();
  }
예제 #16
0
  public String getThumbnailUrl() throws UnavailableThumbnailException {
    ParseFile thumbnail = getParseFile(KEY_THUMBNAIL);
    if (thumbnail == null) {
      throw new UnavailableThumbnailException();
    }

    return thumbnail.getUrl();
  }
  private void updateUser() {

    // convert bitmapAvatar to byte[]
    Bitmap bitmap = ((BitmapDrawable) editAvatar.getDrawable()).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();

    // make parse file of avatar and save it
    final ParseFile avatar = new ParseFile("avatar.png", byteArray);
    avatar.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            if (e != null) {
              Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
            } else {

              // get intent
              Intent intent = getIntent();

              // new user
              final ParseUser user = ParseUser.getCurrentUser();
              // set other information

              user.put("name", editName.getText().toString().trim());
              user.put("gender", editGender.getSelectedItem().toString());
              user.put("date_of_birth", editDateOfBirth.getText().toString());
              user.put("phone", editPhone.getText().toString().trim());
              user.put("id_card_number", editIDCardNumber.getText().toString().trim());
              user.put("description", editDescription.getText().toString().trim());
              user.put("avatar", avatar);

              // Sign up user
              user.saveInBackground(
                  new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                      progressDialog.hide();
                      if (e == null) {
                        Toast.makeText(
                                EditProfileActivity.this, "Update completed", Toast.LENGTH_SHORT)
                            .show();

                        finish();
                      } else {
                        Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT)
                            .show();
                      }
                    }
                  });
            }
          }
        });
  }
예제 #18
0
 private void savePic() {
   String fileName = Long.toString(System.currentTimeMillis()) + ".png";
   ParseFile file = new ParseFile(fileName, photoBytes);
   file.saveInBackground();
   ParseObject pictureSave = new ParseObject("Album");
   pictureSave.put("userName", UserInfo.username);
   pictureSave.put("picture", file);
   pictureSave.put("fileName", fileName);
   pictureSave.saveInBackground();
   Toast.makeText(getApplicationContext(), "Picture has been saved", Toast.LENGTH_SHORT).show();
 }
예제 #19
0
      @Override
      public void onClick(View v) {
        // TODO: Check flag
        final Album album = mAlbums.get(getAdapterPosition());
        mCountPhotos = mImageUris.size();
        if (mSendPhoto) {
          mProgressDialog.show();
          for (Uri imageUri : mImageUris) {
            try {
              final Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(
                      SearchableActivity.this.getContentResolver(), imageUri);

              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
              final byte[] data = stream.toByteArray();

              ParseFile file = new ParseFile("teste.jpg", data);

              file.saveInBackground(
                  new SaveCallback() {
                    public void done(ParseException e) {
                      // Handle success or failure here ...
                      mCountPhotos--;
                      if (mCountPhotos == 0) {
                        mProgressDialog.dismiss();
                      }
                    }
                  },
                  new ProgressCallback() {
                    public void done(Integer percentDone) {
                      // Update your progress spinner here. percentDone will be between 0 and 100.
                    }
                  });

              Photo photo = new Photo();
              photo.setImage(file);
              photo.setAlbum(album);
              photo.setAuthor(ParseUser.getCurrentUser());
              photo.saveInBackground();

            } catch (IOException e) {
              e.printStackTrace();
            }
            mSendPhoto = false;
          }

        } else {
          Intent intent = new Intent(SearchableActivity.this, AlbumDetailActivity.class);
          intent.putExtra(AlbumDetailActivity.ALBUM_ID_EXTRA, album.getObjectId());
          intent.putExtra(AlbumDetailActivity.ALBUM_NAME_EXTRA, album.getName());
          startActivity(intent);
        }
      }
예제 #20
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();
   }
 }
예제 #21
0
  public void siginUp(User user, SunshineLoginCallback callback) {

    this.callback = callback;

    parseUser = new ParseUser();
    parseUser.setEmail(user.getEmail());
    parseUser.setUsername(user.getUserName());
    parseUser.setPassword(user.getPassword());
    // prepareParseUser(parseUser, user);
    parseUser.put("name", user.getName());

    if (user.getImgPath() != null) {
      File file = new File(user.getImgPath());
      parseFile = new ParseFile(file);
      parseFile.saveInBackground(
          new SaveCallback() {
            @Override
            public void done(ParseException e) {
              if (e != null) e.printStackTrace();
              parseUser.put("img", parseFile);
              parseUser.signUpInBackground(SunshineLogin.this);
            }
          });
    } else {
      parseUser.signUpInBackground(SunshineLogin.this);
    }
  }
예제 #22
0
  public void post() {
    buffer = new ByteArrayOutputStream();
    scaledTakenImage.compress(Bitmap.CompressFormat.JPEG, 100, buffer);
    photoFile = new ParseFile(buffer.toByteArray());
    photoFile.saveInBackground();

    if (etFoodDesc.getText() == null
        || etFeedCap.getText() == null
        || etExp.getText() == null
        || location == null
        || photoFile == null) {
      Toast.makeText(this, "Please provide all the information", Toast.LENGTH_SHORT).show();
      return;
    }

    ParseObject parseObject = new ParseObject("FoodData");
    parseObject.put("fooddesc", etFoodDesc.getText().toString());
    parseObject.put("feedcap", etFeedCap.getText().toString());
    parseObject.put("timeexp", etExp.getText().toString());
    parseObject.put("lat", location.getLatitude());
    parseObject.put("lon", location.getLongitude());
    parseObject.put("photo", photoFile);
    parseObject.put("ownerid", ParseUser.getCurrentUser().getObjectId());
    parseObject.put("ownername", ParseUser.getCurrentUser().getUsername());
    parseObject.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            if (e == null)
              Toast.makeText(PostActivity.this, "Posted Sucessfully", Toast.LENGTH_SHORT).show();
          }
        });
  }
예제 #23
0
  public static void updateUserProfile(final String nickName, Bitmap profilePic) {
    final ParseUser user = ParseUser.getCurrentUser();

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    profilePic.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bytearray = stream.toByteArray();
    final ParseFile imgFile = new ParseFile(user.getUsername() + "_profile.jpg", bytearray);
    imgFile.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            user.put(Common.OBJECT_USER_NICK, nickName);
            user.put(Common.OBJECT_USER_PROFILE_PIC, imgFile);
            user.saveInBackground();
          }
        });
  }
예제 #24
0
 /** Sets the photo of the group. */
 private void setPhoto() {
   if (TheGroupUtil.getCurrentGroup().get(TheGroupUtil.GROUP_PHOTO) != null) {
     ParseFile picFile = (ParseFile) TheGroupUtil.getCurrentGroup().get(TheGroupUtil.GROUP_PHOTO);
     picFile.getDataInBackground(
         new GetDataCallback() {
           @Override
           public void done(byte[] bytes, ParseException e) {
             if (e == null) {
               Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
               myPhoto.setImageBitmap(bitmap);
               myPhoto.setBackgroundColor(0xFFffffff);
             } else {
               // unable to load image. //TODO
             }
           }
         });
   }
 }
 private void savePhoto(String _id) {
   final String id = _id;
   for (Galleryitem g : lists) {
     Bitmap bitmap = g.getBitmap();
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
     byte[] data = stream.toByteArray();
     final ParseFile file = new ParseFile(System.currentTimeMillis() + ".png", data);
     file.saveInBackground(
         new SaveCallback() {
           @Override
           public void done(ParseException e) {
             if (e == null) savePhotoObject(file, id);
             Log.d("DENYSYUK", "done image");
           }
         });
   }
   mActivity.getFragmentNavigator().replaceFragment(new GalleryFragment());
 }
예제 #26
0
  private void getUserDetailsFromParse() {
    parseUser = ParseUser.getCurrentUser();

    // Fetch profile photo
    try {
      ParseFile parseFile = parseUser.getParseFile("profileThumb");
      byte[] data = parseFile.getData();
      Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
      mProfileImage.setImageBitmap(bitmap);
    } catch (Exception e) {
      e.printStackTrace();
    }

    mEmailID.setText(parseUser.getEmail());
    mUsername.setText(parseUser.getUsername());

    Toast.makeText(
            MainActivity.this, "Welcome back " + mUsername.getText().toString(), Toast.LENGTH_SHORT)
        .show();
  }
예제 #27
0
 public byte[] getUserPhotoByteArray() {
   if (mUserPhotoFile == null) {
     return null;
   }
   byte[] iconByteData = new byte[0];
   try {
     iconByteData = mUserPhotoFile.getData();
   } catch (ParseException e) {
     Log.e(TAG, "error getting byte[] " + e.getMessage());
   }
   return iconByteData;
 }
예제 #28
0
  private void setImage(Uri theUri) {
    Log.d("ProfileFragment", "Here in setImage with uri: " + theUri);
    try {
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), theUri);
      Log.d("ProfileFragment", "bitmap is: " + bitmap.toString());
      myPhoto.setImageBitmap(bitmap);

      // send to parse
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
      byte[] array = stream.toByteArray();
      ParseFile file = new ParseFile("profilePic.jpeg", array);
      file.saveInBackground();
      TheGroupUtil.getCurrentGroup().put(TheGroupUtil.GROUP_PHOTO, file);
      TheGroupUtil.getCurrentGroup().saveInBackground();

    } catch (FileNotFoundException e) {
      Log.e("ProfileFragment", "Error: " + e);
    } catch (IOException e) {
      Log.e("ProfileFragment", "Error: " + e);
    }
  }
예제 #29
0
  public void addItem(View view) {
    Number price = Double.parseDouble(etEditItemPrice.getText().toString().replace("$", ""));
    String description = String.valueOf(etEditItemDescription.getText());
    ParseFile imageParseFile;
    if (image != null) imageParseFile = new ParseFile(getBytesFromBitmap(image));
    else imageParseFile = item.getParseFile("photo");
    imageParseFile.saveInBackground();
    client.updateItem(
        getSupportFragmentManager(),
        item.getObjectId(),
        description,
        price,
        imageParseFile,
        item.getYardSale());

    Intent data = new Intent();
    data.putExtra("price", String.valueOf(etEditItemPrice.getText()));
    data.putExtra("desc", String.valueOf(etEditItemDescription.getText()));
    data.putExtra("obj_id", item.getObjectId());
    setResult(143, data);
    finish();
  }
예제 #30
0
  private void initializeProfileInformation() {
    imgAvatar = (CircleImageView) findViewById(R.id.imgAvatar);
    imgAvatar.setOnClickListener(this);
    final TextView txtName = (TextView) findViewById(R.id.txtName);
    final TextView txtEmail = (TextView) findViewById(R.id.txtEmail);

    if (((GlobalApplication) getApplication()).getAvatar() != null) {
      imgAvatar.setImageBitmap(((GlobalApplication) getApplication()).getAvatar());
      txtName.setText(((GlobalApplication) getApplication()).getFullName());
      txtEmail.setText(((GlobalApplication) getApplication()).getEmail());
      Log.i(TAG, "Get Profile Information from GlobalApplication");
      return;
    }

    Log.i(TAG, "Get Profile Information from Server");
    ParseFile parseFile = (ParseFile) currentUser.get("avatar");
    if (parseFile != null) {
      parseFile.getDataInBackground(
          new GetDataCallback() {
            @Override
            public void done(byte[] bytes, ParseException e) {
              if (e == null) {
                String fullName = currentUser.getString("fullName");
                String email = currentUser.getEmail();

                userAvatar = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                imgAvatar.setImageBitmap(userAvatar);
                txtName.setText(fullName);
                txtEmail.setText(email);

                ((GlobalApplication) getApplication()).setAvatar(userAvatar);
                ((GlobalApplication) getApplication()).setFullName(fullName);
                ((GlobalApplication) getApplication()).setPhoneNumber(currentUser.getUsername());
                ((GlobalApplication) getApplication()).setEmail(email);
              }
            }
          });
    }
  }