Exemplo n.º 1
0
        private Picasso(Context context, ICache <Bitmap> cache, IRequestTransformer <Bitmap> requestTransformer, List <RequestHandler> extraRequestHandlers, IExecutorService service, Dispatcher dispatcher, IListener listener)
        {
            m_Context            = context;
            m_Cache              = cache;
            m_RequestTransformer = requestTransformer;

            const int builtInHandlersCount = 3;
            int       extraHandlersCount   = extraRequestHandlers != null ? extraRequestHandlers.Count : 0;
            var       allRequestHandlers   = new List <IRequestHandler <Bitmap> >(builtInHandlersCount + extraHandlersCount);

            // ResourceRequestHandler needs to be the first in the list to avoid
            // forcing other RequestHandlers to perform null checks on request.uri
            // to cover the (request.resourceId != 0) case.
            allRequestHandlers.Add(new ResourceRequestHandler(context));
            if (extraRequestHandlers != null)
            {
                allRequestHandlers.AddRange(allRequestHandlers);
            }
            allRequestHandlers.Add(new ContentStreamRequestHandler(context));
            allRequestHandlers.Add(new FileRequestHandler(context));
            allRequestHandlers.Add(new NetworkRequestHandler(dispatcher.Downloader));
            m_RequestHandlers = new ReadOnlyCollection <IRequestHandler <Bitmap> >(allRequestHandlers);

            m_Service        = service;
            m_Dispatcher     = dispatcher;
            m_Listener       = listener;
            m_TargetToAction = new WeakHashtable <object, Action <Bitmap, Drawable> >();
            m_TargetToDeferredRequestCreator = new WeakHashtable <ImageView, DeferredRequestCreator>();
        }
Exemplo n.º 2
0
            public Picasso Build()
            {
                if (m_Cache == null)
                {
                    int cacheSize = AndroidUtils.CalculateMemoryCacheSize(m_Context);
                    m_Cache = new LruCache <Bitmap>(cacheSize, AndroidUtils.SizeOfBitmap);
                }

                if (m_Service == null)
                {
                    m_Service = new PicassoExecutorService();
                }

                if (m_Downloader == null)
                {
                    m_Downloader = AndroidUtils.CreateDefaultDownloader(m_Context);
                }

                if (m_RequestTransformer == null)
                {
                    m_RequestTransformer = new DummyRequestTransformer();
                }

                var dispatcher = new Dispatcher(m_Context, Handler, m_Service, m_Cache, m_Downloader);

                return(new Picasso(m_Context, m_Cache, m_RequestTransformer, m_RequestHandlers, m_Service, dispatcher, m_Listener));
            }
Exemplo n.º 3
0
 public Builder RequestTransformer(IRequestTransformer <UIImage> requestTransformer)
 {
     if (requestTransformer == null)
     {
         throw new ArgumentNullException("requestTransformer");
     }
     if (m_RequestTransformer != null)
     {
         throw new InvalidOperationException("Request transformer already set");
     }
     m_RequestTransformer = requestTransformer;
     return(this);
 }
Exemplo n.º 4
0
        private Picasso(ICache <UIImage> cache, IRequestTransformer <UIImage> requestTransformer, List <RequestHandler> extraRequestHandlers, Dispatcher dispatcher)
        {
            m_Cache          = cache;
            m_Dispatcher     = dispatcher;
            m_TargetToAction = new ConditionalWeakTable <Object, Action <UIImage, UIImage> >();

            const int builtInHandlersCount = 3;
            int       extraHandlersCount   = extraRequestHandlers != null ? extraRequestHandlers.Count : 0;
            var       allRequestHandlers   = new List <IRequestHandler <UIImage> >(builtInHandlersCount + extraHandlersCount);

            if (extraRequestHandlers != null)
            {
                allRequestHandlers.AddRange(allRequestHandlers);
            }
            allRequestHandlers.Add(new FileRequestHandler());
            allRequestHandlers.Add(new NetworkRequestHandler(dispatcher.Downloader));
            m_RequestHandlers = new ReadOnlyCollection <IRequestHandler <UIImage> >(allRequestHandlers);
        }
Exemplo n.º 5
0
            public Picasso Build()
            {
                if (m_Cache == null)
                {
                    int cacheSize = IOSUtils.CalculateCacheSize();
                    m_Cache = new LruCache <UIImage>(cacheSize, IOSUtils.SizeOfImage);
                }

                if (m_Downloader == null)
                {
                    m_Downloader = new NSUrlDownloader();
                }

                if (m_RequestTransformer == null)
                {
                    m_RequestTransformer = new DummyRequestTransformer();
                }

                var dispatcher = new Dispatcher(m_Cache, m_Downloader);

                return(new Picasso(m_Cache, m_RequestTransformer, m_RequestHandlers, dispatcher));
            }