How to set image to Google Play Books API thumbnail using Fresco? - android

I am trying to load in a Google Play books image thumbnail from a URL using Fresco (I've also tried using Glide and Picasso) 1.10.0. I am able to load in another image (such as this https://i.imgur.com/6zDqjm8.jpg), but only the placeholder image shows when I use the Google Play Books thumbnail link (e.g. http://books.google.com/books/content?id=F1wgqlNi8AMC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api).
I've also tried adding ".jpeg" on to the end of the link (since in a web browser the image still shows) in the Uri.parse code, but it doesn't make a difference.
Do you know why this is and/or what I am doing wrong?
I have got the INTERNET permission in my manifest. I also have the Fresco namespace in my XML file.
My Fresco code (taken from Getting Started with Fresco guide):
Uri uri = Uri.parse("http://books.google.com/books/content?id=F1wgqlNi8AMC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api");
SimpleDraweeView draweeView = findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
XML code for the SimpleDraweeView:
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/my_image_view"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
fresco:placeholderImage="#drawable/search_white_24dp" />
JSON I'm working with (for more Google Play Books thumbnails): https://pastebin.com/hq4AFMRb
Please let me know if you need any more information (e.g. XML). I don't mind using a different third-party library (including Glide or Picasso) if that works.

Looks like, that unprotected traffic is no longer available for making requests to the Google Books servers (Pay attention at the piece of the Glide's log below):
08-09 22:31:06.428 7606-7606/com.sandbox.test W/Glide: Load failed for
http://books.google.com/books/content?id=F1wgqlNi8AMC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api
with size [2392x2392]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 2 causes:
java.io.IOException(Cleartext HTTP traffic to books.google.com not permitted)
java.io.FileNotFoundException(No content provider: http://books.google.com/books/content?id=F1wgqlNi8AMC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Fetching data failed,
class java.io.InputStream, REMOTE
There was 1 cause:
So, you can just add the "S" letter to pictures url protocol from the API and make a request through HTTPS.
In my case, this did the trick.

Related

Using placeholder in Coil when the url is null

I get some data from database and push it to reciclerview. I use Coil to show images. But there are some urls that are null and I need to use some placeholder in such cases.
I tried all the option I saw in the internet but nothing helped.
binding.posterIv.load(UtilsUi.BASE_URL + recyclerViewItem.poster_path){
placeholder(R.drawable.placeholder_male)
error(R.drawable.placeholder_male)
fallback(R.drawable.placeholder_male)
}
When the url is null I just get empty black space.
ImageView looks like this:
<ImageView
android:id="#+id/actorImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/keanuriives" />
Do you have any idea how to fix it?
P.S. Coil needs to be used, not Glide or Picasso.

How to show SVG string as an Image in Xamarin?

So the simple idea is that I have SVG data as a string that I fetch from Internet.
I would like to show that as an icon in my app. Is there any way I can do this?
I have seen countless examples where SVG data is in a file located in the app's directory that is then showed but this is not what I am looking for. I literally have the data in XML format after http request and I only need to transform that to a Image or something else visible on the screen.
I have been trying to find a solution to this for hours now, so I would really appreciate some help :S
Android doesn't support svg with ImageView directly,you could display SVG with some commonly used third-party controls.
Like FFImageLoading.
Add Xamarin.FFImageLoading.Svg nuget package to platform project. Use ImageService with svg data resolver for displaying svg images.
For Android:
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
then use like:
var svgString = #"<svg><rect width=""30"" height=""30"" style=""fill:blue"" /></svg>";
ImageView imageView = FindViewById<ImageView>(Resource.Id.image_view);
ImageService.Instance
.LoadString(svgString)
.LoadingPlaceholder(placeHolderPath)
.WithCustomDataResolver(new SvgDataResolver(64, 0, true))
.WithCustomLoadingPlaceholderDataResolver(new SvgDataResolver(64, 0, true))
.Into(imageView);

"No content provider: /storage/emulated/0/Pictures/Reddit/d8326aa.jpg" thrown for no reason

I am using the https://github.com/davemorrissey/subsampling-scale-image-view/ library to load one image of mine by just passing the correct (existing) path
like:
setImage(path)
and the "No content provider: /storage/emulated/0/Pictures/Reddit/d8326aa.jpg" is a message from exception. However if loading the image like:
setImage(Uri.fromFile(File(path)).toString())
that works but the image is blurry for some reason. Other apps that use this library and load the same image are not blurry and all functionality works.

Glide image load mysteriously fails

I am using Glide in my Android app to crop and cache a bitmap that I then post to my API. I handle the threading with Anko. This is my code:
val bitmap=preview_image_view.drawable as BitmapDrawable //I previously used `preview_image_view.setDrawable` to set this image. It shows properly in the debugger!
doAsync{ //an Anko specific thing
val file= Glide.with(applicationContext).asFile().load(bitmap).apply(RequestOptions().apply{
diskCacheStrategy(DiskCacheStrategy.RESOURCE)
centerCrop()
override()
}).submit().get() //Mysterious failure on submit()
uiThread{ //another Anko specific thing
Fuel.upload(.....
I get the following error whenever I hit the submit() function
W/Glide: Load failed for android.graphics.drawable.BitmapDrawable#fb798b8 with size [400x400]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Glide gives me no causes, stack trace, etc. to help me find why this error is occuring. Any ideas as to what is causing it to fail?
I later discovered the reason for the Glide image load failure. The image I was attempting to cache exceeded the size of the Android application cache, but did not provide an informative error. Later, Glide tried to load the corrupted data (an image that had size 0), but could not.
Downsizing the image before caching it (making sure it was under the Android application cache size limit) solved the issue.

How to load Image and other content in UI from server

Taking example of viewpager or recyclerview in android we know that they can contain images as well.What i want to know is that how we can load images from database from server and put that images in view pager or recycler view.Upto know my understanding is that i have to make a database in server and put images in it ,now during splash screen download that images and after that put that images into view.Am i going right? Basically what i want to achieve is like shopping app which shows images which changes time to time ? how i can do same ?Do i should go with Rest API to download that images from server and then put in view also do i need to make sure that every time user opens app then it download image?
You can simply fetch .jpg URL from API and then load that image in your app by using Fresco library.
Check this out: Display images with Fresco
First add Fresco to your dependencies in app/build.gradle.
dependencies {
implementation 'com.facebook.fresco:fresco:1.10.0'
}
Don't forget to add in your AndroidManifest.xml proper permission:
<uses-permission android:name="android.permission.INTERNET"/>
Initialize Fresco in class that extend Application class. You can do it in Activity, but it's better to do it just once in Application class.
Fresco.initialize(context);
Instead of ImageView use SimpleDraweeView like this:
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdvImage"
android:layout_width="130dp"
android:layout_height="130dp"
fresco:placeholderImage="#drawable/myPlaceholderImage" />
Then just init your SimpleDraweeView object in Activity/ViewHolder/Fragment, parse Url string to Uri like this:
Uri imageUri = Uri.parse("https://i.imgur.com/tGbaZCY.jpg");
And you can set Uri to your SimpelDraweeView object this way:
draweeView.setImageURI(imageUri);
You can use Glide or Picasso as well. Find one that suit your needs by read this post:
Picasso v/s Imageloader v/s Fresco vs Glide

Categories

Resources