Issue
i am using this gif library https://github.com/koral--/android-gif-drawable to display gif in xml and gifImageView as view , i was using ImageRequest in volley to download gif from url . but the gif is shown as still image in app. cant figure out what happened ?pls help me with my code or pls tell me how to download gif via volley.
variables defined:-
SwipeDeck cardSwipe;
String url = "";
ImageView iv;
RequestQueue que;
RequestQueue que2;
SwipeCardAdapter adapter;
ArrayList<Bitmap> urls = new ArrayList<>();
this is stringRequest function block to fetch Json
public StringRequest strReq(){
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray dataObject = jsonObject.getJSONArray("data");
for(int i = 0 ; i < dataObject.length() ; i++){
JSONObject thisObject = dataObject.getJSONObject(i);
JSONObject image = thisObject.getJSONObject("images");
JSONObject imageType = image.getJSONObject("original");
String imageUrl = imageType.getString("url");
Log.d("TAG", imageUrl);
URL url = new URL(imageUrl);
que2.add(imageReq(imageUrl));
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("TAG","error occured in try and catch");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error.getCause() != null){
error.getCause().printStackTrace();
}
if(error.networkResponse != null){
Toast.makeText(MainActivity.this, "Network Response is " + error.networkResponse , Toast.LENGTH_SHORT).show();
}
}
});
return stringRequest;
}
and this is the imageRequest function block to download gif from the url:-
public ImageRequest imageReq(String url){
ImageRequest imageRequest = new ImageRequest(url, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
urls.add(response);
adapter.notifyDataSetChanged();
}
}, 0, 0, null, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error.getCause() != null){
error.getCause().printStackTrace();
}
if(error.networkResponse != null){
Toast.makeText(MainActivity.this, "Network Response is " + error.networkResponse , Toast.LENGTH_SHORT).show();
}
}
});
return imageRequest;
}
and this inside the adapter class to set gifImageView:-
GifImageView gifImageView = (GifImageView) convertView.findViewById(R.id.gifIV);
Bitmap thisGif = getItem(position);
gifImageView.setImageBitmap(thisGif);
Solution
I am not exactly sure why you are using the GifDrawable Library the Glide Library is so much better. https://github.com/bumptech/glide
Glide.with(mContext).load(image.getMedium())
.thumbnail(0.5f)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.thumbnail);
Answered By - dominicd Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.