Beispiel #1
0
        void DisplayFromHttp(Image image, string uri, DisplayOption option)
        {
            if (httpImpl == null)
            {
                httpImpl = new BestHttpImpl();
            }

            httpImpl.Get(uri, delegate(byte[] response, int statusCode, bool isSuccess) {
                //LogUtils.Log("image load from net");
                if (isSuccess)
                {
                    if (discCache != null && option.isDiscCache)
                    {
                        discCache.Set(uri, response);
                    }

                    Sprite sprite = Display(image, response);
                    if (sprite != null && option.isMemoryCache)
                    {
                        memoryCache.Set(uri, sprite);
                    }
                }
                else
                {
                    DisplayErrorImage(image, option);
                }
            });
        }
Beispiel #2
0
        bool DisplayLoadingImage(Image image, DisplayOption option)
        {
            if (!DisplayFromResource(image, option.loadingImagePath, option))
            {
                DisplayTransparent(image);
            }

            return(true);
        }
Beispiel #3
0
 DisplayOption GetOptionFromParams(params DisplayOption[] option)
 {
     if (option == null || option.Length <= 0)
     {
         return(DisplayOption.GetDefaultDisplayOption());
     }
     else
     {
         return(option[0]);
     }
 }
Beispiel #4
0
        public bool Display(byte[] data, Image image, string uri, params DisplayOption[] option)
        {
            DisplayOption opt = GetOptionFromParams(option);

            if (DisplayFromMemory(image, uri, option))
            {
                return(true);
            }

            return(DisplayFromBytes(data, image, uri, opt));
        }
Beispiel #5
0
        public bool DisplayFromMemory(Image image, string uri, params DisplayOption[] option)
        {
            DisplayOption opt = GetOptionFromParams(option);

            Sprite sprite = memoryCache.Get(uri);

            if (opt.isMemoryCache && sprite != null)
            {
                //LogUtils.Log("image load from memory cache");
                Display(image, sprite);
                return(true);
            }

            return(false);
        }
Beispiel #6
0
 void DisplayFromDiscCache(Image image, string uri, DisplayOption option)
 {
     if (discCache != null)
     {
         byte[] data = discCache.Get(uri);
         if (DisplayFromBytes(data, image, uri, option))
         {
             //LogUtils.Log("image load from disc cache");
             Debug.Log("image load from disc cache:" + uri);
         }
         else
         {
             DisplayFromHttp(image, uri, option);
         }
     }
 }
Beispiel #7
0
        bool DisplayFromBytes(byte[] data, Image image, string uri, DisplayOption option)
        {
            Sprite sprite = Display(image, data);

            if (sprite == null)
            {
                DisplayErrorImage(image, option);

                return(false);
            }
            else
            {
                if (option.isMemoryCache)
                {
                    memoryCache.Set(uri, sprite);
                }

                return(true);
            }
        }
Beispiel #8
0
        //Not consider to memory cache,just display from file immediately
        public void DisplayFromFile(Image image, string path, params DisplayOption[] option)
        {
            DisplayOption opt = GetOptionFromParams(option);

            DisplayLoadingImage(image, opt);

            if (File.Exists(path))
            {
                AsyncTask.GetInstance()
                .SetDoInBackground(delegate {
                    byte[] data = File.ReadAllBytes(path);
                    return(data);
                }).SetOnPostExecute(result => DisplayFromBytes((byte[])result, image, path, opt))
                .Excute();
            }
            else
            {
                DisplayErrorImage(image, opt);
            }
        }
Beispiel #9
0
        bool DisplayFromResource(Image image, string resourcePath, DisplayOption option)
        {
            if (string.IsNullOrEmpty(resourcePath))
            {
                return(false);
            }

            if (DisplayFromMemory(image, resourcePath, option))
            {
                return(true);
            }

            Sprite sprite = Display(image, Resources.Load <Texture2D>(resourcePath));

            if (sprite != null && option.isMemoryCache)
            {
                memoryCache.Set(resourcePath, sprite);
            }

            return(true);
        }
 void DisplayFromDiscCache(Image image, string uri, DisplayOption option)
 {
     if (discCache != null)
     {
         AsyncTask.GetInstance()
         .SetDoInBackground(delegate
         {
             return(discCache.Get(uri));
         }).SetOnPostExecute(delegate(object result)
         {
             byte[] data = (byte[])result;
             if (DisplayFromBytes(data, image, uri, option))
             {
                 //LogUtils.Log("image load from disc cache");
             }
             else
             {
                 DisplayFromHttp(image, uri, option);
             }
         }).Excute();
     }
 }
        public void Display(Image image, string uri, params DisplayOption[] option)
        {
            DisplayOption opt = GetOptionFromParams(option);

            if (string.IsNullOrEmpty(uri))
            {
                DisplayErrorImage(image, opt);

                return;
            }

            if (DisplayFromMemory(image, uri, option))
            {
                return;
            }

            Uri _uri = new Uri(uri);

            if (_uri.IsFile)
            {
                DisplayFromFile(image, uri, option);
            }
            else
            {
                DisplayLoadingImage(image, opt);

                if (opt.isDiscCache)
                {
                    discCache.Access(uri);

                    DisplayFromDiscCache(image, uri, opt);
                }
                else
                {
                    DisplayFromHttp(image, uri, opt);
                }
            }
        }
Beispiel #12
0
 bool DisplayErrorImage(Image image, DisplayOption option)
 {
     return(DisplayFromResource(image, option.loadErrorImagePath, option));
 }