我目前正在使用Firebase处理聊天应用。对于Firebase身份验证,我使用getImageUrl()
从Firebase用户获取图片Uri,
但毕加索图书馆没有加载任何图像以显示也没有出现任何错误,但是当我使用直接链接时,它完美无缺。
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private FirebaseUser User;
private ImageView profileImg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
User = mAuth.getCurrentUser();
profileImg= (ImageView) findViewById(R.id.profileImage);
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
TextView name = (TextView) findViewById(R.id.profilenameTv);
name.setText(user.getDisplayName());
profileImg = (ImageView) findViewById(R.id.profileImage);
Picasso.with(getApplicationContext()).load(user.getPhotoUrl()).fit().centerCrop().into(profileImg);
}else{
// User is signed out
startActivity(new Intent(getApplicationContext(),Signup.class));
}
}
};
}
这是我的EditProfile类:
public class editProfile extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private FirebaseDatabase mDatabase;
private DatabaseReference mRef;
private StorageReference mStorage;
private FirebaseUser User;
private Button submitBtn, changePassBtn, deleteBtn;
private ImageButton addProImage;
private EditText UsernameEt, currentPassEt, newPassEt ;
int REQUEST_CODE = 1;
private Uri PhotoDownloadUri ;
private Uri photoUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
//firebase initilation
mAuth = FirebaseAuth.getInstance();
mStorage = FirebaseStorage.getInstance().getReference();
mDatabase = FirebaseDatabase.getInstance();
mRef = mDatabase.getReference();
User = mAuth.getCurrentUser();
//View initialization
//EditText
UsernameEt= (EditText) findViewById(R.id.usernameEt);
currentPassEt = (EditText) findViewById(R.id.curentPass);
newPassEt = (EditText) findViewById(R.id.newPass);
//Button
submitBtn = (Button) findViewById(R.id.sumitBtn);
changePassBtn = (Button) findViewById(R.id.ChangePassBtn);
deleteBtn = (Button) findViewById(R.id.deleteBtn);
//imageButton
addProImage = (ImageButton) findViewById(R.id.addProImg);
//add photo on start
Picasso.with(getApplicationContext()).load(User.getPhotoUrl()).fit().centerCrop().into(addProImage);
// request permission
requestPermission();
// open gallery
openGallery();
// delete mStorage data
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(User.getPhotoUrl() == PhotoDownloadUri){
mStorage.child("UserPhoto").child(photoUri.getLastPathSegment()).delete().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
//photo replaced with default photo
addProImage.setImageDrawable(getDrawable(R.mipmap.ic_launcher));
Toast.makeText(getApplicationContext(), " Photo deleted Successfully ", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
// Add update user profile info
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String Name =UsernameEt.getText().toString().trim();
String Photouri = PhotoDownloadUri.toString();
// Calling method
updateUserProfileInfo(Name,Photouri);
}
});
}//onCreate end here
@Override
protected void onStart() {
super.onStart();
}
//method for open gallery
private void openGallery(){
//image Button getting gallery intent
addProImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent galleryPickIntent = new Intent(Intent.ACTION_PICK);
galleryPickIntent.setType("image/*");
startActivityForResult(galleryPickIntent,REQUEST_CODE);
}
});
}
//request permittion
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
} else {
openGallery();
}
}
//on Activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_CODE || requestCode ==RESULT_OK){
photoUri = data.getData();
// add photo to imageView
addProImage.setImageURI(photoUri);
//
//upload photo in firebase database
//
mStorage.child("UserPhoto").child(photoUri.getLastPathSegment()).putFile(photoUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
PhotoDownloadUri = taskSnapshot.getDownloadUrl();
Toast.makeText(getApplicationContext(), "successfully uploaded ", Toast.LENGTH_SHORT).show();
}
});
mStorage.child("UserPhoto").child(photoUri.getLastPathSegment()).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//PhotoDownloadUri = uri;
}
});
}
}
//checking gallery permission
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
openGallery();
}
}
//update user profile info name and photo
public void updateUserProfileInfo(String name, String photoUri){
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(name)
.setPhotoUri(Uri.parse(photoUri))
.build();
User.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
//setting user profile data to firebase database
mRef.child("Users").child(User.getUid()).child("username").setValue(User.getDisplayName());
mRef.child("Users").child(User.getUid()).child("photouri").setValue(User.getPhotoUrl());
mRef.child("Users").child(User.getUid()).child("uid").setValue(User.getUid());
Toast.makeText(getApplicationContext(), " Profile Update Successful ", Toast.LENGTH_SHORT).show();
// add photo to edit
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
}
});
}
}
我的结果截图:
答案 0 :(得分:0)
尝试
// Camera.js
import { Euler } from 'three'
const euler = new Euler( 0, 0, 0, 'YXZ' )
export const updateCamera = (camera, motion) => {
euler.x = motion.rotation.x
euler.y = motion.rotation.y
camera.quaternion.setFromEuler( euler )
camera.position.copy( motion.position )
camera.position.y += 10.0
}