0

How can I add Crop Image Activity I have tried many times. I need crop images because the profile photos not displaying as full image cause of circular imageview. I need to use circular imageview also. :) I am trying to make a social-media app on Android-Studio platform. ( And also I am wondering how can I show unreaded messages on each chat group? I couldn't add seen feature to group chatting. ) Thanks already! My Activity Result:

@Override
        public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            if (resultCode == RESULT_OK  ) {
                if (requestCode == IMAGE_PICK_GALLERY_CODE) {
                    image_uri = data.getData();
                    uploadProfileCoverPhoto(image_uri);
                }
                else if (requestCode == IMAGE_PICK_CAMERA_CODE) {
                    uploadProfileCoverPhoto(image_uri);
                }
            }
            super.onActivityResult(requestCode, resultCode, data);
    
        }

and my uploadprofilecoverphoto method:

    private void uploadProfileCoverPhoto(Uri uri) {
        pd.show();

        String filePathAndName = storagePath+ ""+ profileOrCoverPhoto +"_"+ user.getUid();
        StorageReference storageReference2 = storageReference.child(filePathAndName);
        storageReference2.putFile(uri)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
                        while (!uriTask.isSuccessful());
                        Uri downloadUri = uriTask.getResult();

                        if (uriTask.isSuccessful()) {
                            HashMap<String, Object> results = new HashMap<>();
                            results.put(profileOrCoverPhoto, downloadUri.toString());

                            databaseReference.child(user.getUid()).updateChildren(results)
                                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                                        @Override
                                        public void onSuccess(Void aVoid) {
                                            pd.dismiss();
                                            Toast.makeText(getActivity(), "Görsel Güncellendi", Toast.LENGTH_SHORT).show();
                                        }
                                    })
                                    .addOnFailureListener(new OnFailureListener() {
                                        @Override
                                        public void onFailure(@NonNull Exception e) {
                                            pd.dismiss();
                                            Toast.makeText(getActivity(), "Güncelleme Hatası...", Toast.LENGTH_SHORT).show();
                                        }
                                    });
                            if  (profileOrCoverPhoto.equals("gorsel")) {
                                DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Gönderiler");
                                Query query = ref.orderByChild("Id").equalTo(Id);
                                query.addValueEventListener(new ValueEventListener() {
                                    @Override
                                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                                        for (DataSnapshot ds: snapshot.getChildren()){
                                            String child = ds.getKey();
                                            snapshot.getRef().child(child).child("Profilgorsel").setValue(downloadUri.toString());
                                        }
                                    }

                                    @Override
                                    public void onCancelled(@NonNull DatabaseError error) {

                                    }
                                });
                                ref.addListenerForSingleValueEvent(new ValueEventListener() {
                                    @Override
                                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                                        for (DataSnapshot ds: snapshot.getChildren()){
                                            String child = ds.getKey();
                                            if (snapshot.child(child).hasChild("Yorumlar")){
                                                String child1 = ""+snapshot.child(child).getKey();
                                                Query child2 = FirebaseDatabase.getInstance().getReference("Gönderiler").child(child1).child("Yorumlar").orderByChild("uId").equalTo(Id);
                                                child2.addValueEventListener(new ValueEventListener() {
                                                    @Override
                                                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                                                        for (DataSnapshot ds: snapshot.getChildren()){
                                                            String child = ds.getKey();
                                                            snapshot.getRef().child(child).child("Profilgorsel").setValue(downloadUri.toString());
                                                        }
                                                    }

                                                    
    }

1 Answers1

0

The question isn't clear without examples of what you want to achieve - I'm assuming you want to display your images in imageView as a circle? Glide is an amazing library for that, check out some of it's usage examples. Here and here.

Moreover, best not to ask multiple unrelated questions at once.

  • I don't want display my picture. Just crop it picture from gallery. I think it is clear already. (I know I cant ask multiple question. I just add words cause of your post containt too much code please add some details warning) – jwkserf kmjdfsvg Jan 14 '21 at 07:39