Git Product home page Git Product logo

lazylist's People

Contributors

thest1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lazylist's Issues

LazyList update(refresh) Listview

Hi,

I m trying to use searchView with LazyList. In my lazyAdapter I m updating my arraylist , this works smoothly but my listview doesn't update with arrayList. This is my filer method. I suppose notifyDataSetChanged does not work.Please help how can I refresh my listview?

public void filter(String charText) {

    charText = charText.toLowerCase(Locale.getDefault());
    //list.clear();
    list = new ArrayList<HashMap<String, String>>();
    if (charText.length() == 0) {
        list.addAll(arraylist);
    } 
    else 
    {
        for (HashMap<String, String> map : arraylist) 
        {
            if (map.get("radio").toString().toLowerCase(Locale.getDefault()).contains(charText)) 
            {
                list.add(map);
            }
        }
    }
    notifyDataSetChanged();
}

Clarify license -- BSD, MIT, Apache, GPL, etc?

I don't know if you've mentioned this anywhere, but it would be appropriate if you mentioned the license on a README.md so everyone that views your code knows what they're allowed to do with it.

File Cache not being used

Maybe i've missed something. It seems that the FileCache is never actually used. Its interface has two methods, getFile(String) and clear(). Where the save / put / cache methods?! I am planning to use an LRU cache here instead so not a problem...

Problem when retrieving images from sdcard

Hello I have downloaded this code n tried to retrieve saved images into list-view, but the problem is, it is not showing the way as it is inserted , images are displaying but are in shuffled.

Refresh Image

Hi,
I'm Using your Lazy Loading, But the Problem is

  1. when the image get changed on server it not get reflected on device..
  2. Also I'm setting alphabet If Image not present..

What are the solution for these problem..I need your help to make changes in LazyList..The first problem is having high priority..

When strictmode enabled, i get these error msj

10-18 14:26:14.988: E/StrictMode(16632): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
10-18 14:26:14.988: E/StrictMode(16632): java.lang.Throwable: Explicit termination method 'close' not called
10-18 14:26:14.988: E/StrictMode(16632): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
10-18 14:26:14.988: E/StrictMode(16632): at java.io.FileInputStream.(FileInputStream.java:80)
10-18 14:26:14.988: E/StrictMode(16632): at com.fedorvlasov.lazylist.ImageLoader.decodeFile(ImageLoader.java:94)
10-18 14:26:14.988: E/StrictMode(16632): at com.fedorvlasov.lazylist.ImageLoader.getBitmap(ImageLoader.java:62)
10-18 14:26:14.988: E/StrictMode(16632): at com.fedorvlasov.lazylist.ImageLoader.access$0(ImageLoader.java:57)
10-18 14:26:14.988: E/StrictMode(16632): at com.fedorvlasov.lazylist.ImageLoader$PhotosLoader.run(ImageLoader.java:136)
10-18 14:26:14.988: E/StrictMode(16632): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
10-18 14:26:14.988: E/StrictMode(16632): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-18 14:26:14.988: E/StrictMode(16632): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-18 14:26:14.988: E/StrictMode(16632): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-18 14:26:14.988: E/StrictMode(16632): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-18 14:26:14.988: E/StrictMode(16632): at java.lang.Thread.run(Thread.java:856)

Race condition in MemoryCache

Size isn't locked. Simultaneous puts will do weird things.

checkSize() or anything else with an iterator will also have undefined behavior.

Safest quick fix is to synchronize on the public methods, not the "cache" object. Shouldn't be all that different speed-wise, except when a cache resize happens.

imageView.getContext() can fail - is there another way to get the activity?

Hi

I love the lazylist and in particular the ImageLoader.
It worked fine for me until i tried something new :

I created a horizontal Scroller and loaded views into it within the oncreate code oh my activity.
After creating a such ImageView (which is in a layout which i add to the horizontal scroller) i used DisplayImage(img, iv) to get a picture from an url into it.

Well it never worked .. no exceptions, no result at all.
I analyzed all the ImageLoader code and used Logcat to find the command which caused the behavior.

The issue is in the run method of the PhotosLoader class which will try to get the activity the imageView lives in to let its UI Thread set the image bitmap:

(Activity)photoToLoad.imageView.getContext();

Based on Logcat outputs i think my view will return an application object in this case:

08-24 12:54:30.895: V/REPMKT(2430): android.app.Application@414626f0

I fixxed the issue by passing my activity into the ImageLoader via constructor and from there pass it into the PhotosLoader.
I don't hink that's a clever approach but it works.

Any ideas how to fix this ?

Nik

Threads not closed

Hi,

According to the DDMS tool, the ImageLoader doesn't close the threads in the thread pool for the executorService.

This is a rather large memory issue is it not?

Image sometimes fails to correctly decode

I've noticed that sometimes the image can fail to correctly decode.

EXAMPLE: http://i44.tinypic.com/vzcxg2.png (I cut off the top half of the image)

As you can see the bottom half does not show correctly.

I've noticed that in ImageLoader.java if you change

            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
            conn.setConnectTimeout(30000);
            conn.setReadTimeout(30000);
            conn.setInstanceFollowRedirects(true);
            InputStream is=conn.getInputStream();

to this:

            HttpGet httpRequest = null;
            httpRequest = new HttpGet(imageUrl.toURI());

            HttpClient httpClient = new DefaultHttpClient();
            HttpResponse response = (HttpResponse) httpClient.execute(httpRequest);

            HttpEntity entity = response.getEntity();
            BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
            InputStream is = bufHttpEntity.getContent();

the problem goes away.

Bitmaps from sdcard

Hi, I was trying to change this code to show bitmaps from sdcard instead of the internet. I've changed this part of the code:

private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);

    //from SD cache
    Bitmap b = decodeFile(f);
    if(b!=null)
        return b;

    //from web
    try {
        Bitmap bitmap=null;
        URL imageUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
        conn.setConnectTimeout(30000);
        conn.setReadTimeout(30000);
        conn.setInstanceFollowRedirects(true);
        InputStream is=conn.getInputStream();
        OutputStream os = new FileOutputStream(f);
        Utils.CopyStream(is, os);
        os.close();
        bitmap = decodeFile(f);
        return bitmap;
    } catch (Throwable ex){
       ex.printStackTrace();
       if(ex instanceof OutOfMemoryError)
           memoryCache.clear();
       return null;
    }
}

to this:

private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);

    //from SD cache
    Bitmap b = decodeFile(f);
    if(b!=null)
        return b;

    //from sdcard
    try {
        Bitmap bitmap=null;
        InputStream is=new FileInputStream(url);
        OutputStream os = new FileOutputStream(f);
        Utils.CopyStream(is, os);
        os.close();
        bitmap = decodeFile(f);
        return bitmap;
    } catch (Throwable ex){
       ex.printStackTrace();
       if(ex instanceof OutOfMemoryError)
           memoryCache.clear();
       return null;
    }
}

And I've used my ArrayAdapter:

public class AdapterFiles extends ArrayAdapter{
private int resource;

private String item;
private ViewHolder viewHolder;

public ImageLoader imageLoader;

public AdapterFiles(Context context, int textViewResourceId, int label, List<String> objects) {
        super(context, textViewResourceId, objects);
        …
        resource = textViewResourceId;
        imageLoader=new ImageLoader(getContext());



}

static class ViewHolder {
    TextView label;
    ImageView ikonka;
    …

}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RelativeLayout RowView;
        item = getItem(position);



        if(convertView == null) {
        RowView = new RelativeLayout(getContext());
        LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(resource, RowView, true);
        viewHolder = new ViewHolder();
        viewHolder.label = (TextView)RowView.findViewById(R.id.label);
        viewHolder.ikonka = (ImageView)RowView.findViewById(R.id.icon);
        …
        RowView.setTag(viewHolder);
        } else {
            RowView = (RelativeLayout)convertView;
            viewHolder = (ViewHolder) RowView.getTag();
        }


            …

        File file = new File(item);
        if (file.isDirectory()){
            if(file.canRead()){
            viewHolder.ikonka.setImageResource(R.drawable.folder);
            }
            else{
            viewHolder.ikonka.setImageResource(R.drawable.foldernoway); 
            }
        …

        else if(item.endsWith(".jpg") || item.endsWith(".JPG") || item.endsWith(".png") || item.endsWith(".jpeg")){



            if(thumbnails == false){
            viewHolder.ikonka.setImageResource(R.drawable.image);   
            }else{


                imageLoader.DisplayImage(item, viewHolder.ikonka);


            }
            }           
        …



        viewHolder.label.setText(file.getName());

        …          

        return RowView;

}

And now, I have two problems..

  1. Images don't appear when I scroll listview down. I have to scroll down, up and again down to view images. How can I fix it?
  2. How to resize bitmaps in the cache folder?

how to return bitmap

hello
thank you for lazy list
how to change your code for return bitmap ?
(return bitmap default image when downloading image then return bitmap image downloaded.)
please show in you code thank you

Change the scaling/resizing of the images being loaded

First of all i want to say thank you very much for this great solution for lazy loading images. I integrated your way succesfully in my already existing arrrayadapter. What i was not able to achieve yet is changing the scaling of the images before they are cached. it seems as if the images always have the same resolution. i can resize them afterwards without problems but this messes up the original resolution.
So my question: how to change scaling/resizing to exactly the size the picture should appear in the UI afterwards?

Images only loads when i scroll in ListView

Today, I was testing my application that uses a custom layout (with imageview inside) and I found out as soon as I scroll in listview, the listview lags then the image appears. Why? Is this an expected behaviour from imageloader when i'm loading images from a database? I am using almost the same code from LazyList.
Here is my code:

SamsungListView offlineadapter = new SamsungListView(ctx, c);
listview.setAdapter(offlineadapter);
SamsungListView Class:

public class SamsungListView extends CursorAdapter {

public com.androidarabia.lazylist.ImageLoader imageLoader;
LayoutInflater mLayoutInflater;
Cursor curs;
LebanonDatabase DbHelper;
ViewHolder holder;

public SamsungListView(Context context, Cursor c) {
    super(context, c);
    curs = c;
    mLayoutInflater = LayoutInflater.from(context);
    imageLoader = new com.androidarabia.lazylist.ImageLoader(
            context.getApplicationContext());
    DbHelper = new LebanonDatabase(context).open();
    holder = new ViewHolder();

}

static class ViewHolder {
    TextView title_text;
    TextView date_text;
    ImageView item_image;
    TextView del_image;
}

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View v = mLayoutInflater.inflate(R.layout.pricelist, parent, false);
    return v;
}

@Override
public void bindView(View v, Context context, Cursor c) {
    holder.title_text = (TextView) v.findViewById(R.id.title);
    holder.date_text = (TextView) v.findViewById(R.id.modelnumber);
    holder.item_image = (ImageView) v.findViewById(R.id.list_image);
    holder.del_image = (TextView) v.findViewById(R.id.details);

    final String title = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_PHONENAME));
    final String date = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_MODELNUMBER));

    final String imagePath = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_PRICE));

    final String deletion = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_URL));
    imageLoader.DisplayImage(deletion, holder.item_image);
    holder.title_text.setText(title);
    holder.del_image.setText(imagePath + " $");
    holder.date_text.setText(date);

}

Any suggestions? the listview sees some hiccups when i'm scrolling first time, but at second time everything is smooth.
i posted a topic on Stackoverflow http://goo.gl/T46dQO
Thank you for your time! this is the best repository for Android ever!

Issue with android M

Images are not loading while working with android M, And I have already checked that image url is valid and permissions are taken from the user

clear() in FileCache.java throws NullPointerException

When you do not have permissions setup for external storage and you clear the cache of the application, then reload it and try and clear the cache onload using 'clear()'. It has a null value for 'files' variable and crashes. So I put this null pointer check in here just in case it is ever null again :)

FileCache.java

public void clear(){
    File[] files=cacheDir.listFiles();
    if (files != null)
    {
        for(File f:files)
            f.delete();
    }
}

Some image failed to load.

Hi,

i just implement lazylist to my application,but it doesn't work well, some of the image not loaded to the image view, it will load if i scroll the listview to the bottom. is there any fix for this ?, or is this known issue ?

thanks

images fail to load after a while

Hi, I've been using your LazyList and it really works well. However, every now and then, images fail to load into my listview using your lazy loading technique. Restarting my app does not fix the issue, but rebooting the phone fixes it. Have you seen this issue or do you know what could be causing this behavior?

I have not been able to reproduce this issue, so I'm not sure where or how to start debugging. Any helpful tips that you can provide would be greatly appreciated.

Thank you

Argument is needless?

Thanks for your code — it's a pure beauty!

I just wonder if method


has a needless argument activity which is passed to queuePhoto and never used there at all.

scroll issue

when i useing in grid view , it will be a little bit lag when i am scrolling ?? is it come from setimagebitmap whe n scrolling is too hard working for gridview or anything else ??

it is smooth , but not so smooth that i want .

Not really an issue, but a question

I am somewhat new to git hib and was trying to figure out how to just post a question. Your read me file says "Can also be used for GridView and just to display images into an ImageView." I am curious as to whether or not you have some example code of the. I am trying to do what your code does but with horizontal scrolling instead of vertical scrolling. Is that possiible and is that what the portion of your read me file means?

Application get slow/hang when change your code

Hi,
Thanks for your code. I needed Lazy Loader to load image from Internal Storage. So I change your code as per my need, My list is in TabHost. At first it works fine, But when I switch from one tab to another application gets slow and may times get Hang.
Why so?

In your getBitmap() I changed code to get Image from Internal Storage.

Suddenly stop working

Hi,

I've been using this since time ago, but suddenly has stop working. I've added permissions on execution time, but i'm still reciving the following error:

java.io.FileNotFoundException: /storage/emulated/0/LazyList/-44270421 (Permission denied)

The only thing has changed is the app.iml file, could be here the error?

Any help is apreciated! Thank you!

[Question] Callback for finished load image?

Hi Fedor,
Thank for your project, it's simple but awesome.
I have small question that:
How can I show a Toast or do somethings else when finished load image from internet or cache?

Not call to Bitmap.recycle();

Hi!
I am implementing this LazyList into my app and I realize that in the library never call to Bitmap.recycle() to free some memory.
Is this correct?? Thanks in advance!

Cheers,
Nicolas

Bitmap exceeds VM budget: potential issue

Hi,
While this is not your issue per se, I was wondering if you could comment on this. I have a listview which contains textviews and imageview which are both loaded from the network. After continuous opening and closing the listview activity, but retrieving different data sets, I run into this error message and the app then closes. I've tried such things like:

a) forcing a gc on the OnDestroy, OnPause events
b) nulling out references to the imageviews on the OnDestroy and OnPause events
c) using decodeFileDescription instead of decodeStream (see Comment 94 on the link below)
d) forcing a bitmap recycle when doing the gc and nulling references (see Comment 90)

None of these seem to be helping any.

There is a long thread about this problem which Google is well aware. Just wondering if you had any thoughts to this:
Btw, your code works great. Thanks for your help.

http://code.google.com/p/android/issues/detail?id=8488

Own object

Hi,

Can i use my own object with your lib? I mean, i have my object Scores, can i give LazyList an ArrayList ?
Of course, i'll have to modify your lib after that but LazyList doesnt recognize Scores (which is normal actually).

Thanks,

Out of Memory Error : Recycle?

Please forgive me for my noob-ness in Android programming. Just learnt Java weeks ago.

I've been using Lazylist to load images from website. However, I've been getting OOM error.
I searched it up on Stackoverflow and realized that recycle is needed so that space can be allocated for more images.
I looked it up on ImageLoader and this (recycle) wasn't implemented. I tried to code it myself yet faced with lots of error [bitmap.recycle()]. May I ask if this is possible?
Furthermore, in the listview, one image doesn't cause an error, yet when I add textview etc, it caused the OOM error too.
Thanks!

Please change decodeFile

If I use your code quality of image corrupted .
private Bitmap decodeFile(File f) {
final int MAX_SIZE = 400;
try {

        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > MAX_SIZE || o.outWidth > MAX_SIZE) {
            scale = (int) Math.pow(
                    2,
                    (int) Math.round(Math.log(MAX_SIZE / (double) Math.max(
                            o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(f);
        Bitmap b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
        return b;


    } catch (IOException e) {

    } catch (OutOfMemoryError e) {
        this.clearCache();
    }

    return null;
}

Query

Hello I have one query about this library.
If i am loading images into the listview and the images are downloaded then shown . But I in my next activity i repeat the same process. Does the images will be again download or it will apear from memory.

And if i close the application and internet is turned off then the listview will be populated from Local DB and the image path will be the same . Will it show the image from local cache or NOT ??

ImageLoader with fragments

Several people have reported me that ImageLoader doesn't display bitmaps correctly if used inside fragments. Unfortunately I can't reproduce this problem - it works just fine for me. It would be great if someone could attach a demo project with the problem inside. Have some ideas how to fix it. But before applying the fix need to be able to reproduce the problem and test it well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.