2

I created a app. Which display images as carousel when click three buttons. Which are event, shows & home. These images are downloaded from internet. these images are saved in cache. For that I used three cache directories. But it doesn't work. Also I want to access these images separately from directories.

Here is my code

 public class FileCache
    {
        private File                cacheDir;
        private File                cacheDirEvent;
        private File                cacheDirPromotion;
        Context context;

        public FileCache(Context context,int i)
        {

            if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)&& i==3)
                    cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"TNLRadio/res/shows");
                else if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)&& i==2)
                    cacheDirEvent=new File(android.os.Environment.getExternalStorageDirectory(),"TNLRadio/res/events");
                else if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) && i==1)
                    cacheDirPromotion=new File(android.os.Environment.getExternalStorageDirectory(),"TNLRadio/res/home");
                else
                    cacheDir=context.getCacheDir();
                    cacheDirEvent=context.getCacheDir();
                    cacheDirPromotion=context.getCacheDir();
                if(!cacheDir.exists())
                    cacheDir.mkdirs();
                else if (!cacheDirPromotion.exists())
                    cacheDirPromotion.mkdirs();
                else if  (!cacheDirEvent.exists())
                    cacheDirEvent.mkdirs();
            }

            public File getFile( final String url) throws FileNotFoundException
            {
                // retrieve filename/location from shared preferences based on the the url
                final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
                String filename = settings.getString(url, null);

                if (url == null)
                {
                    throw new FileNotFoundException();
                }

    //            final File f = new File(this.cacheDir, filename);
    //            return f;
                if(url.substring(0, 26).equals("http://tnlradio/promotions")){
                    File f = new File(cacheDirPromotion, filename);
                    return f;
                    }
                    else if(url.substring(0, 26).equals("http://tnlradio/promotions")){
                        File f = new File(cacheDirEvent, filename);
                        return f;
                        }
                    else{
                        File f = new File(cacheDir, filename);
                        return f;
                    }
            }

Here I used to select the directory using integer value. It means when those buttons are clicked the integer is passed to the FileCash. So how to load exact images seperatly. Now any images are not loaded.

pls help me.thanks

madu243
  • 243
  • 2
  • 7
  • 18

0 Answers0