-1
Guys I have a simple doubt basically, but I’m traveling on ideas.
I have a class called chamada
:
@Override
public boolean onLongPressClickListener(View view, int position) {
// opcional, utilize o valor que achar melhor
int **tamanhoPadraoCompartilhamento** = 395;
String imgPath = DataUrl.getUrlCustom(mList.get(position)
.getUrlPhoto(), tamanhoPadraoCompartilhamento);
Log.i("log", "Path img em Server: " + imgPath);
picassoDownloadImg(imgPath);
return true;
}
but I’m already in another class
I just want to call the method. (tamanhoPadraoCompartilhamento
) I think that’s it. Here follows the class I’m trying to do the method invocation.
@Override
public void onClick(View v) {
//campo onde vou chamar o método da outra class
}
Good as I do to call the method.
i have a class with a certain function to share an image by pressing a banner in the application.
So, I’m going to put that same function on button in a cardView.
this code is in a class with the name Carfragment.
/*
MÉTODO QUE COMPARTILHAR O BANNER.
*/
@Override
public boolean onLongPressClickListener(View view, int position) {
int tamanhoPadraoCompartilhamento = 395; // opcional, utilize o valor que achar melhor
String imgPath = DataUrl.getUrlCustom(mList.get(position).getUrlPhoto(), tamanhoPadraoCompartilhamento);
Log.i("log", "Path img em Server: " + imgPath);
picassoDownloadImg(imgPath);
return true;
}
private void picassoDownloadImg(String imgPath) {
Picasso.with(getActivity())
.load(imgPath)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/partiuapp");
boolean success = true;
// CRIANDO DIRETÓRIO CASO NÃO EXISTA
if (!myDir.exists()) {
success = myDir.mkdirs();
}
// CLÁUSULA DE GUARDA
if (!success) {
return;
}
String name = "shared_image_" + System.currentTimeMillis() + ".jpg";
myDir = new File(myDir, name);
FileOutputStream out = new FileOutputStream(myDir);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
shareEventImg(name); // CHAMA O CÓDIGO INTENT PARA COMPARTILHAR A IMG
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
}
);
}
private void shareEventImg(String imgName) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Melhor Aplicativo de Eventos de Maceió");
String imagePath = Environment.getExternalStorageDirectory().toString() + "/partiuapp";
File photoFile = new File(imagePath, imgName);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Compartilhar imagem"));
}
I have another class with the name Caradapter
where I want her to do the function of the first class that is to share, put in a button.
@Override
public void onClick(View view) {
Log.i("log", "passou aqui: ");
}
FOLLOWING THE FIRST-CLASS LOGIC WHAT CAN I DO TO MAKE THE CARADAPTER CLASS CALL THE FIRST-CLASS METHOD THAT IS SHARED???
thank you all.
OK Sorack I’ll validate.
– Anselmo Cardoso
because the method has to be Static?
– Italo Rodrigo
Because when you create the method as
static
it becomes class method and requires no instance to run– Sorack
@Italorodrigo take a look at this question here: Static blocks, heritage and constructors in Java. It’s not 100% what you asked but you can get an idea
– Sorack