I was very excited about Picasso android library . I have an android application that i want to use picasso but i have one problem in a place inside my application
I have a listview (endless) that display images in each item beside some text , now i don't have the Url for each item in the list ( I am using a stupid api ) , I have to hit the server with specific id ,then the server sent me image url(s) that i can use in Picasso .
example :
http://url/id/342
and the response look like
{
"images":["url_large":"http://........","url_medium":"http://........"]
}
I can't pre-load image url . because i have an endless list and for each item i need to call the web service to get it image url .
Can picasso handle this ?
Related
I can publish video with description using RestFB. I want to add thumbnail picture to video. How can I do that?
I tried to add some Parameter when publish as
Parameter.with("thumb", BinaryAttachment.with(fileName, fetchBytesFromImage(fileName)))
Parameter.with("picture", BinaryAttachment.with(fileName, fetchBytesFromImage(fileName)))
If publishing more than one BinaryAttachment, you have to add the fieldname to the BinaryAttachment.with method , put both BinaryAttachments in a List and use it in the publish method.
It looks like this:
fbClient.publish("me/videos", GraphResponse.class,
Arrays.asList(
BinaryAttachment.with("source","1.mp4",inputstream),
BinaryAttachment.with("thumb", "bla.jpg", fetchBytesFromImage("bla.jpg"))),
Parameter.with("description", "Test Thumb"));
I want to create an app in Android and I want to share text with a picture to telegram but I do not want the pictures and the text to be separated. I don't know how to do this.
Hopefully it works fine, I tried same.
$.sendPhoto(image_url,{caption : 'i am attached text with image'});
//bot.sendPhoto(chatId,image_url,{caption : 'i am attached text with image'}); /* TRY these according to you.
Or, if you want to send it from Telegram rest api, then call this api:
API URL : 'https://api.telegram.org/bot'+token+'/sendPhoto?
chat_id='+chatID+'&photo='+imageSrc+'&caption='+(message ?message : '');
METHOD : GET
I am building my application using Android Studio, this app can upload an image from raspberry to my emulator. It works fine. What I want to do now is uploading this image and showing it directly to the user without searching it in the gallery. I thought about creating another class and setting this image as a background image in my xml file, but this is too much like I have to create another class every time I want to upload an image from my raspberry.
Can someone help me please. Thank you
If I'm understanding your question correctly, you'd like to load an image from the Android filesystem into your app and display it to the user.
Drawable, Android's generalized image class, allows you to load from file via Drawable#createFromPath.
This SO question suggests Drawable#createFromPath doesn't work on paths beginning with file://, so depending on your use case you may want to precede that with Uri#parse/Uri#getPath.
Once you have a Drawable, you can display it in one of two ways: put an ImageView in your app and call its setImageDrawable method, or set the Drawable as your background image via View#setBackground (note that setBackground was only added in API 16 - in prior versions, you should call View#setBackgroundDrawable).
Putting all of this together, we end up with the following (untested):
private void loadImage(String imagePath) {
Uri imageUri;
String fullImagePath;
Drawable image;
ImageView imageDisplay;
imageUri = Uri.parse(imagePath);
fullImagePath = imageUri.getPath();
image = Drawable.createFromPath(fullImagePath);
imageDisplay = (ImageView) findViewById(R.id.imageDisplay);
/*if image is null after Drawable.createFromPath, this will simply
clear the ImageView's background */
imageDisplay.setImageDrawable(image);
/*if you want the image in the background instead of the foreground,
comment the line above and uncomment this bit instead */
//imageDisplay.setBackground(image);
}
You should be able to modify this to work with any View just by replacing imageDisplay's declared type with the appropriate View type and changing the cast on findViewById. Just make sure you're calling setBackground, not setImageDrawable, for a non-ImageView View.
I'm making this netflix style app in which images are loaded into different categories. Let's say Dog videos (has 15 images), Cat videos (15 images), etc... All the images are loaded from a URL, it kind of takes a while for all to load. I was wondering if there was anything I could do to speed up the process? Or maybe show an empty container then fill it as the images load (that would be cool).
This is what I have done:
I have multiple async calls in one Activity, (1 async call per category)
JSONTask1 dogTask = new JSONTask1();
JSONTask2 catTask = new JSONTask2();
JSONTask3 pigTask = new JSONTask3();
JSONTask4 horseTask = new JSONTask4();
dogTask.execute("");
catTask.execute("");
pigTask.execute("");
horseTask.execute("");
I have all of those in a row in my actual code. Thanks.
I would use the "proxy pattern". Basically, you need to create a class that contains the minimal informations required for the display. In which, you have a preview image.
When ever you load everything you start by showing the preview content, ie : a loading gif for everypicture with the title of the movie or whatever. and basically the proxy would have a "loadImage" method that would make an ajax call or async call and the photos would load one by one. Plus, to make the loading easier, make sure the photos are not oversized.
You can see Picasso answers , in picasso i suggest you this way :
Picasso.with(getApplicationContext()).load("your url").placeholder(R.drawable.your_place_holder).error(R.drawable.showing_when_error_occured)
.into(imageView, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
}
});
Also another suggestion from me : convert your thumb images to base64 format in backend, then firstly retrieve your thumbs and show them. Then start an async task and change images when successfull.
Like whatsapp. In whatsapp you have thumb images they have so low resolution and super fast. When you click image if you have internet connection they load actual thumb images, and click again they load larger image.
Picasso website :http://square.github.io/picasso/
Load them asynchronously with Picasso, you can even show a placeholder image until the real one is loaded
I state that I have already read all the other questions but none is right for me.My app retrieves data from a database. If I put in the database in the app does not display the image, while the other tag html yes because i put:
Text = (TextView) this.findViewById(R.article.text);
String formattedText = db.getText();
Text.setText(Html.fromHtml(formattedText));
For images I would like something that the download so that they are always available. I tried to put ImageGetter but with the loading time of an article in the app increased a lot and very often said that Android is not responding (ANR). I also need something that resizes images depending on the display. Any ideas?
Take a look at AQuery download the latest jar add it in your project
and use it like following
AQuerymAQuery;
mAquery=new AQuery(context);
mAquery.id(ImageView).auth(handle).image(ImagePath,true,true,400,0,null,0,0.0f);