Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CuentaFragment extends Fragment {
- private Button btnagregarfoto;
- private StorageReference storage;
- private ImageView logoempresa;
- private Uri descargarfoto;
- private ProgressDialog progressDialog;
- private static final int GALLERY_INTENT = 1;
- private EditText newPassword;
- private ProgressBar progressBar;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View vista = inflater.inflate(R.layout.fragment_cuenta, container, false);
- storage = FirebaseStorage.getInstance().getReference();
- btnagregarfoto = (Button) vista.findViewById(R.id.btnagregarfoto);
- logoempresa = (ImageView) vista.findViewById(R.id.logoempresa);
- progressDialog = new ProgressDialog(getActivity());
- btnagregarfoto.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(Intent.ACTION_PICK);
- intent.setType("image/*");
- startActivityForResult(intent, GALLERY_INTENT);
- }
- return vista;
- }
- //ESTO PARA SUBIR Y SELECCIONAR LA IMAGEN
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK);
- progressDialog.setTitle("Cargando...");
- progressDialog.setMessage("Subiendo foto");
- progressDialog.setCancelable(false);
- progressDialog.show();
- Uri uri = data.getData();
- StorageReference filepath = storage.child("fotos").child(uri.getLastPathSegment());
- filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
- @Override
- public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
- progressDialog.dismiss();
- descargarfoto = taskSnapshot.getDownloadUrl();
- Glide.with(getActivity()) // .load(descargarfoto).fitCenter().centerCrop().into(logoempresa);
- .load(descargarfoto)
- .apply(new RequestOptions()
- .placeholder(R.mipmap.ic_launcher)
- .centerCrop()
- .dontAnimate()
- .dontTransform())
- .into(logoempresa);
- Toast.makeText(getActivity(), "La foto ha sido cargada exitosamente.", Toast.LENGTH_SHORT).show();
- }
- });
- }
- //ESTO PARA SUBIR Y SELECCIONAR LA IMAGEN
Add Comment
Please, Sign In to add comment