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
- Glide.with(getActivity())
- .load(descargarfoto)
- .apply(new RequestOptions()
- .placeholder(R.mipmap.ic_launcher)
- .centerCrop()
- .dontAnimate()
- .dontTransform().diskCacheStrategy(DiskCacheStrategy.RESOURCE))
- .thumbnail(.5f)
- .into(logoempresa);
- public class IntegerVersionSignature implements Key {
- private int currentVersion;
- public IntegerVersionSignature(int currentVersion) {
- this.currentVersion = currentVersion;
- }
- @Override
- public boolean equals(Object o) {
- if (o instanceof IntegerVersionSignature) {
- IntegerVersionSignature other = (IntegerVersionSignature) o;
- return currentVersion = other.currentVersion;
- }
- return false;
- }
- @Override
- public int hashCode() {
- return currentVersion;
- }
- @Override
- public void updateDiskCacheKey(MessageDigest md) {
- messageDigest.update(ByteBuffer.allocate(Integer.SIZE).putInt(signature).array());
- }
- }
- public static class GlideOptions {
- public static RequestOptions LOGO_OPTION = new RequestOptions().placeholder(R.mipmap.ic_launcher).centerCrop()
- .dontAnimate().dontTransform().diskCacheStrategy(DiskCacheStrategy.RESOURCE);
- public static void updateSignatureOptions(int version){
- LOGO_OPTION = LOGO_OPTION.signature(new IntegerVersionSignature(version));
- }
- }
- GlideOptions.updateSignatureOptions(/*valor desde firebase indicando la version*/);
- Glide.with(getActivity())
- .load(url)
- .apply(GlideOptions.LOGO_OPTION);
- .thumbnail(.5f)
- .into(imageView);
- Glide.with(getActivity())
- .load(url)
- .apply(GlideOptions.LOGO_OPTION);
- .into(imageView);
Add Comment
Please, Sign In to add comment