Guest User

Untitled

a guest
May 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public class CuentaFragment extends Fragment {
  2.  
  3. private Button btnagregarfoto;
  4. private StorageReference storage;
  5. private ImageView logoempresa;
  6. private Uri descargarfoto;
  7. private ProgressDialog progressDialog;
  8. private static final int GALLERY_INTENT = 1;
  9. private EditText newPassword;
  10. private ProgressBar progressBar;
  11.  
  12. @Override
  13. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  14. Bundle savedInstanceState) {
  15. // Inflate the layout for this fragment
  16. View vista = inflater.inflate(R.layout.fragment_cuenta, container, false);
  17.  
  18. storage = FirebaseStorage.getInstance().getReference();
  19. btnagregarfoto = (Button) vista.findViewById(R.id.btnagregarfoto);
  20. logoempresa = (ImageView) vista.findViewById(R.id.logoempresa);
  21. progressDialog = new ProgressDialog(getActivity());
  22.  
  23.  
  24. btnagregarfoto.setOnClickListener(new View.OnClickListener() {
  25. @Override
  26. public void onClick(View view) {
  27. Intent intent = new Intent(Intent.ACTION_PICK);
  28. intent.setType("image/*");
  29. startActivityForResult(intent, GALLERY_INTENT);
  30. }
  31. return vista;
  32. }
  33.  
  34. //ESTO PARA SUBIR Y SELECCIONAR LA IMAGEN
  35.  
  36. @Override
  37. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  38. super.onActivityResult(requestCode, resultCode, data);
  39.  
  40. if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK);
  41.  
  42. progressDialog.setTitle("Cargando...");
  43. progressDialog.setMessage("Subiendo foto");
  44. progressDialog.setCancelable(false);
  45. progressDialog.show();
  46.  
  47. Uri uri = data.getData();
  48.  
  49. StorageReference filepath = storage.child("fotos").child(uri.getLastPathSegment());
  50.  
  51. filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
  52. @Override
  53. public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  54.  
  55. progressDialog.dismiss();
  56.  
  57. descargarfoto = taskSnapshot.getDownloadUrl();
  58. Glide.with(getActivity()) // .load(descargarfoto).fitCenter().centerCrop().into(logoempresa);
  59. .load(descargarfoto)
  60. .apply(new RequestOptions()
  61. .placeholder(R.mipmap.ic_launcher)
  62. .centerCrop()
  63. .dontAnimate()
  64. .dontTransform())
  65. .into(logoempresa);
  66.  
  67. Toast.makeText(getActivity(), "La foto ha sido cargada exitosamente.", Toast.LENGTH_SHORT).show();
  68. }
  69. });
  70. }
  71. //ESTO PARA SUBIR Y SELECCIONAR LA IMAGEN
Add Comment
Please, Sign In to add comment