Exemple #1
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);
           }
         });
   }
 }
Exemple #2
0
 public static void displayImage(ParseFile img, final ImageView imgView) {
   img.getDataInBackground(
       new GetDataCallback() {
         @Override
         public void done(byte[] bytes, ParseException e) {
           if (e == null) {
             Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
             if (bmp != null) {
               imgView.setImageBitmap(bmp);
             }
           }
         }
       });
 }
 /** 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 displayImage(ParseFile thumbnail, final ImageView img) {

    if (thumbnail != null) {
      thumbnail.getDataInBackground(
          new GetDataCallback() {

            @Override
            public void done(byte[] data, ParseException e) {
              if (e == null) {
                Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                if (bmp != null) {
                  img.setImageBitmap(bmp);
                }
              } else {
                Log.e("paser after downloade", " null");
              }
            }
          });
    }
  }
Exemple #5
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);
              }
            }
          });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    setupToolbar();

    // Connect views
    editName = (EditText) findViewById(R.id.edit_name);
    editDateOfBirth = (EditText) findViewById(R.id.edit_date_of_birth);
    editPhone = (EditText) findViewById(R.id.edit_phone_number);
    editIDCardNumber = (EditText) findViewById(R.id.edit_id_card_number);
    editDescription = (EditText) findViewById(R.id.edit_description);
    editAvatar = (ImageView) findViewById(R.id.edit_avatar);
    editGender = (Spinner) findViewById(R.id.edit_gender);
    buttonChangeAvatar = (Button) findViewById(R.id.button_change_avatar);

    // Set up button change avatar
    buttonChangeAvatar.setOnClickListener(this);

    // set up date of birth input field
    editDateOfBirth.setFocusable(false);
    editDateOfBirth.setClickable(true);
    editDateOfBirth.setOnClickListener(this);

    // Determine whether the current user is an anonymous user
    if (!ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {

      // If current user is not anonymous user
      // Get current user data from Parse.com
      ParseUser currentUser = ParseUser.getCurrentUser();
      if (currentUser != null) {

        // get user information
        editName.setText(currentUser.getString("name"));
        editDateOfBirth.setText(currentUser.getString("date_of_birth"));
        if (currentUser.getString("gender").equals("Male")) {
          editGender.setSelection(1);
        } else {
          editGender.setSelection(2);
        }
        editPhone.setText(currentUser.getString("phone"));
        editDescription.setText(currentUser.getString("description"));
        editIDCardNumber.setText(currentUser.getString("id_card_number"));

        // get avatar
        ParseFile file = currentUser.getParseFile("avatar");
        file.getDataInBackground(
            new GetDataCallback() {
              @Override
              public void done(byte[] bytes, ParseException e) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                editAvatar.setImageBitmap(bitmap);
              }
            });
      }
    }

    // Set up gender spinner
    List<String> list = new ArrayList<String>();
    list.add("Male");
    list.add("Female");
    ArrayAdapter<String> dataAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    editGender.setAdapter(dataAdapter);

    // Set up progress dialog
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(this.getResources().getString(R.string.wait));
    progressDialog.setCanceledOnTouchOutside(false);
  }