public bool RemoveContainerAndCancelIfNecessary(ImageContainer container)
 {
     mContainers.Remove(container);
     if (mContainers.Count == 0)
     {
         mRequest.Cancel();
         return(true);
     }
     return(false);
 }
 public bool RemoveContainerAndCancelIfNecessary(ImageContainer container)
 {
     mContainers.Remove(container);
     if (mContainers.Count == 0)
     {
         mRequest.Cancel();
         return true;
     }
     return false;
 }
 protected override void OnDetachedFromWindow()
 {
     if (mImageContainer != null)
     {
         mImageContainer.CancelRequest();
         SetImageBitmap(null);
         mImageContainer = null;
     }
     base.OnDetachedFromWindow();
 }
        private void LoadImageIfNecessary(bool isInLayoutPass)
        {
            int       width     = Width;
            int       height    = Height;
            ScaleType scaleType = GetScaleType();

            bool wrapWidth = false, wrapHeight = false;

            if (LayoutParameters != null)
            {
                wrapWidth  = LayoutParameters.Width == ViewGroup.LayoutParams.WrapContent;
                wrapHeight = LayoutParameters.Height == ViewGroup.LayoutParams.WrapContent;
            }

            bool isFullWrapContent = wrapWidth && wrapHeight;

            if (width == 0 && height == 0 && !isFullWrapContent)
            {
                return;
            }

            if (String.IsNullOrEmpty(mUrl))
            {
                if (mImageContainer != null)
                {
                    mImageContainer.CancelRequest();
                    mImageContainer = null;
                }
                SetDefaultImageOrNull();
                return;
            }

            if (mImageContainer != null && mImageContainer.GetRequestUrl() != null)
            {
                if (mImageContainer.GetRequestUrl() == mUrl)
                {
                    return;
                }
                else
                {
                    mImageContainer.CancelRequest();
                    SetDefaultImageOrNull();
                }
            }

            int maxWidth  = wrapWidth ? 0 : width;
            int maxHeight = wrapHeight ? 0 : height;

            ImageContainer newContainer = mImageLoader.Get(mUrl, new DefaultImageListener(), maxWidth, maxHeight, scaleType);

            mImageContainer = newContainer;
        }
Пример #5
0
        public ImageContainer Get(String requestUrl, int maxWidth, int maxHeight, Android.Widget.ImageView.ScaleType scaleType,
                                  Action <ImageContainer, bool> successResponse, Action <VolleyError> errorResponse)
        {
            ThrowIfNotOnMainThread();
            if (successResponse == null)
            {
                throw new ArgumentNullException("successResponse不能为null,必须提供请求成功的委托。");
            }

            String cacheKey = GetCacheKey(requestUrl, maxWidth, maxHeight, scaleType);

            //缓存命中直接响应请求
            Bitmap cachedBitmap = mCache.GetBitmap(cacheKey);

            if (cachedBitmap != null)
            {
                ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, mInFlightRequests,
                                                              mBatchedResponses);
                successResponse(container, true);
                return(container);
            }

            //缓存未命中添加到请求中
            ImageContainer imageContainer = new ImageContainer(null, requestUrl, cacheKey, mInFlightRequests,
                                                               mBatchedResponses);

            imageContainer.ErrorResponse   += errorResponse;
            imageContainer.SuccessResponse += successResponse;

            successResponse(imageContainer, true);

            //是否存在相同的请求,存在则添加该请求,否则创建
            BatchedImageRequest request = null;

            mInFlightRequests.TryGetValue(cacheKey, out request);
            if (request != null)
            {
                request.AddContainer(imageContainer);
                return(imageContainer);
            }

            Request newRequest = MakeImageRequest(requestUrl, maxWidth, maxHeight, scaleType, cacheKey);

            mRequestQueue.Add(newRequest);
            mInFlightRequests.Add(cacheKey, new BatchedImageRequest(newRequest, imageContainer));
            return(imageContainer);
        }
            public void OnResponse(ImageContainer response, bool isImmediate)
            {
                if (isImmediate && isInLayoutPass)
                {
                    Post(() =>
                    {
                        OnResponse(response, false);
                    });
                    return;
                }

                if (response.GetBitmap() != null)
                {
                    SetImageBitmap(response.GetBitmap());
                }
                else if (mDefaultImageId != 0)
                {
                    SetImageResource(mDefaultImageId);
                }
            }
 /// <summary>
 /// ���һ���µ�ͼƬ����
 /// </summary>
 /// <param name="container"></param>
 public void AddContainer(ImageContainer container)
 {
     mContainers.Add(container);
 }
 public BatchedImageRequest(Request request, ImageContainer container)
 {
     mRequest = request;
     mContainers.Add(container);
 }
 /// <summary>
 /// 添加一个新的图片请求
 /// </summary>
 /// <param name="container"></param>
 public void AddContainer(ImageContainer container)
 {
     mContainers.Add(container);
 }
 public BatchedImageRequest(Request request, ImageContainer container)
 {
     mRequest = request;
     mContainers.Add(container);
 }
 protected override void OnDetachedFromWindow()
 {
     if (mImageContainer != null)
     {
         mImageContainer.CancelRequest();
         SetImageBitmap(null);
         mImageContainer = null;
     }
     base.OnDetachedFromWindow();
 }
            public void OnResponse(ImageContainer response, bool isImmediate)
            {
                if (isImmediate && isInLayoutPass)
                {
                    Post(() =>
                        {
                            OnResponse(response, false);
                        });
                    return;
                }

                if (response.GetBitmap() != null)
                {
                    SetImageBitmap(response.GetBitmap());
                }
                else if (mDefaultImageId != 0)
                {
                    SetImageResource(mDefaultImageId);
                }
            }
        private void LoadImageIfNecessary(bool isInLayoutPass)
        {
            int width = Width;
            int height = Height;
            ScaleType scaleType = GetScaleType();

            bool wrapWidth = false, wrapHeight = false;
            if (LayoutParameters != null)
            {
                wrapWidth = LayoutParameters.Width == ViewGroup.LayoutParams.WrapContent;
                wrapHeight = LayoutParameters.Height == ViewGroup.LayoutParams.WrapContent;
            }

            bool isFullWrapContent = wrapWidth && wrapHeight;
            if (width == 0 && height == 0 && !isFullWrapContent)
            {
                return;
            }

            if (String.IsNullOrEmpty(mUrl))
            {
                if (mImageContainer != null)
                {
                    mImageContainer.CancelRequest();
                    mImageContainer = null;
                }
                SetDefaultImageOrNull();
                return;
            }

            if (mImageContainer != null && mImageContainer.GetRequestUrl() != null)
            {
                if (mImageContainer.GetRequestUrl() == mUrl)
                {
                    return;
                }
                else
                {
                    mImageContainer.CancelRequest();
                    SetDefaultImageOrNull();
                }
            }

            int maxWidth = wrapWidth ? 0 : width;
            int maxHeight = wrapHeight ? 0 : height;

            ImageContainer newContainer = mImageLoader.Get(mUrl, new DefaultImageListener(), maxWidth, maxHeight, scaleType);
            mImageContainer = newContainer;
        }
        public ImageContainer Get(String requestUrl, int maxWidth, int maxHeight, Android.Widget.ImageView.ScaleType scaleType,
            Action<ImageContainer, bool> successResponse, Action<VolleyError> errorResponse)
        {
            ThrowIfNotOnMainThread();
            if (successResponse == null)
            {
                throw new ArgumentNullException("successResponse����Ϊnull�������ṩ����ɹ���ί�С�");
            }

            String cacheKey = GetCacheKey(requestUrl, maxWidth, maxHeight, scaleType);

            //��������ֱ����Ӧ����
            Bitmap cachedBitmap = mCache.GetBitmap(cacheKey);
            if (cachedBitmap != null)
            {
                ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, mInFlightRequests,
                    mBatchedResponses);
                successResponse(container, true);
                return container;
            }

            //����δ������ӵ�������
            ImageContainer imageContainer = new ImageContainer(null, requestUrl, cacheKey, mInFlightRequests,
                mBatchedResponses);

            imageContainer.ErrorResponse += errorResponse;
            imageContainer.SuccessResponse += successResponse;

            successResponse(imageContainer, true);

            //�Ƿ������ͬ�����󣬴�������Ӹ����󣬷��򴴽�
            BatchedImageRequest request = null;
            mInFlightRequests.TryGetValue(cacheKey, out request);
            if (request != null)
            {
                request.AddContainer(imageContainer);
                return imageContainer;
            }

            Request newRequest = MakeImageRequest(requestUrl, maxWidth, maxHeight, scaleType, cacheKey);

            mRequestQueue.Add(newRequest);
            mInFlightRequests.Add(cacheKey, new BatchedImageRequest(newRequest, imageContainer));
            return imageContainer;
        }