Пример #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);
                }
            });
        }
Пример #2
0
        bool DisplayLoadingImage(Image image, DisplayOption option)
        {
            if (!DisplayFromResource(image, option.loadingImagePath, option))
            {
                DisplayTransparent(image);
            }

            return(true);
        }
Пример #3
0
 DisplayOption GetOptionFromParams(params DisplayOption[] option)
 {
     if (option == null || option.Length <= 0)
     {
         return(DisplayOption.GetDefaultDisplayOption());
     }
     else
     {
         return(option[0]);
     }
 }
Пример #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));
        }
Пример #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);
        }
Пример #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);
         }
     }
 }
Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #10
0
 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();
     }
 }
Пример #11
0
        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);
                }
            }
        }
Пример #12
0
 bool DisplayErrorImage(Image image, DisplayOption option)
 {
     return(DisplayFromResource(image, option.loadErrorImagePath, option));
 }