使用毕加索将图像从Firebase加载到CircleImageView中

时间:2018-09-23 18:15:50

标签: android firebase picasso

我尝试使用毕加索将图像从Firebase加载到CircleImageView中 这是代码的一部分

 getUserDataRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                String name =dataSnapshot.child("UserName").getValue().toString();
                String status =dataSnapshot.child("Status").getValue().toString();
                String profile_image =dataSnapshot.child("ProfileImage").getValue().toString();
                String thumb_image =dataSnapshot.child("thumb_Profile").getValue().toString();
                UserName.setText(name);
                Status.setText(status);
                Picasso.with(Settings.this).load(profile_image).placeholder(R.drawable.profile_image).into(profile_imageCirc);

            }

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

            }
        });

Firebase中的每件事都可以,但是该图像不会出现在CircleImageView中 和这样的运行:

D/libc-netbsd: [getaddrinfo]: hostname=chatit-e11ac.firebaseio.com; servname=(null); netid=0; mark=0
D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
D/libc-netbsd: [getaddrinfo]: hostname=chatit-e11ac.firebaseio.com; servname=(null); netid=0; mark=0
D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
D/libc-netbsd: getaddrinfo: chatit-e11ac.firebaseio.com get result from proxy gai_error = 0
D/libc-netbsd: [getaddrinfo]: hostname=chatit-e11ac.firebaseio.com; servname=(null); netid=0; mark=0
D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
E/NativeCrypto: ssl=0x7f7712c900 cert_verify_callback x509_store_ctx=0x7f61cfd410 arg=0x0
E/NativeCrypto: ssl=0x7f7712c900 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
E/MultiWindowProxy: getServiceInstance failed!
Application terminated.

这是整个课程:

public class Settings extends AppCompatActivity {

    private TextView UserName,Status;
    private Button ChangUserName,ChangeStatus;
    private CircleImageView profile_imageCirc;
    private DatabaseReference getUserDataRef;
    private FirebaseAuth mFirebaseAuth;
    private final static int Gallary_Pick=1;
    private StorageReference storeProfileImageStorageRef;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        //initial firebase Refrence
        mFirebaseAuth=FirebaseAuth.getInstance();
        String UserId=mFirebaseAuth.getCurrentUser().getUid();
        getUserDataRef= FirebaseDatabase.getInstance().getReference().child("Users").child(UserId);
        storeProfileImageStorageRef= FirebaseStorage.getInstance().getReference().child("profile_images");
        FindView();
        //add Event Listener to  the reference to get the value from data base
        getUserDataRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                String name =dataSnapshot.child("UserName").getValue().toString();
                String status =dataSnapshot.child("Status").getValue().toString();
                String profile_image =dataSnapshot.child("ProfileImage").getValue().toString();
                String thumb_image =dataSnapshot.child("thumb_Profile").getValue().toString();
                UserName.setText(name);
                Status.setText(status);
                Picasso.with(Settings.this).load(profile_image).placeholder(R.drawable.profile_image).into(profile_imageCirc);

            }

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

            }
        });
        //let the user choose image from his phone images
        ChangUserName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                startActivityForResult(intent,Gallary_Pick);
            }
        });
    }

    private void FindView() {
        UserName=(TextView) findViewById(R.id.user_name);
        Status=(TextView) findViewById(R.id.status);
        ChangeStatus=(Button)findViewById(R.id.Change_status);
        ChangUserName=(Button)findViewById(R.id.Change_user_name);
        profile_imageCirc=(CircleImageView)findViewById(R.id.profile_image);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if(resultCode==RESULT_OK&&requestCode==Gallary_Pick&&data!=null){
            Uri image=data.getData();
            // start picker to get image for cropping and then use the image in cropping activity
            CropImage.activity()
                    .setGuidelines(CropImageView.Guidelines.ON).setAspectRatio(1,1)
                    .start(this);

        }
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                Uri resultUri = result.getUri();
                String Uid=mFirebaseAuth.getCurrentUser().getUid();
                StorageReference filePath=storeProfileImageStorageRef.child(Uid+".jpg");
                filePath.putFile(resultUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {

                       String downloadUrl= taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
                       getUserDataRef.child("ProfileImage").setValue(downloadUrl).addOnCompleteListener(new OnCompleteListener<Void>() {
                           @Override
                           public void onComplete(@NonNull Task<Void> task) {
                               Toast.makeText(Settings.this,"Image Update Successfully", Toast.LENGTH_SHORT).show();


                           }
                       });
                        Toast.makeText(Settings.this,"Saved", Toast.LENGTH_SHORT).show();


                    }
                })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {

                                Toast.makeText(Settings.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        });
            }
        }

        }}

0 个答案:

没有答案
相关问题