Ejemplo n.º 1
0
        public override void Set(ImageLoaderTask task, UIImage image, bool isLocalOrFromCache, bool isLoadingPlaceholder)
        {
            var control = Control;

            if (control == null)
            {
                return;
            }

            var parameters = task.Parameters;

            bool isFadeAnimationEnabled          = parameters.FadeAnimationEnabled ?? ImageService.Instance.Config.FadeAnimationEnabled;
            bool isFadeAnimationEnabledForCached = isFadeAnimationEnabled && (parameters.FadeAnimationForCachedImages ?? ImageService.Instance.Config.FadeAnimationForCachedImages);

            if (!isLoadingPlaceholder && isFadeAnimationEnabled && (!isLocalOrFromCache || (isLocalOrFromCache && isFadeAnimationEnabledForCached)))
            {
                // fade animation
                double fadeDuration = (double)((parameters.FadeAnimationDuration.HasValue ?
                                                parameters.FadeAnimationDuration.Value : ImageService.Instance.Config.FadeAnimationDuration)) / 1000;

                UIView.Transition(control, fadeDuration,
                                  UIViewAnimationOptions.TransitionCrossDissolve
                                  | UIViewAnimationOptions.BeginFromCurrentState,
                                  () => { control.Image = image; },
                                  () => {  });
            }
            else
            {
                control.Image = image;
            }
        }
 private static IScheduledWork Into(this TaskParameter parameters, Func<Image> getNativeControl, Action<WriteableBitmap, bool> doWithImage)
 {
     var task = new ImageLoaderTask(ImageService.Config.DownloadCache, new MainThreadDispatcher(), ImageService.Config.Logger, parameters,
         getNativeControl, doWithImage);
     ImageService.LoadImage(task);
     return task;
 }
Ejemplo n.º 3
0
		public AsyncDrawable(Resources res, Bitmap bitmap, ImageLoaderTask imageLoaderTask)
			: base(res, bitmap)
		{
			if (imageLoaderTask == null)
				throw new ArgumentNullException("Parameter 'imageLoaderTask' cannot be null");
			
			_imageLoaderTaskReference = new WeakReference<ImageLoaderTask>(imageLoaderTask);
		}
Ejemplo n.º 4
0
		private bool UsesSameNativeControl(ImageLoaderTask task)
		{
			var currentControl = _getNativeControl();
			var control = task._getNativeControl();
			if (currentControl == null || control == null || currentControl.Handle == IntPtr.Zero || control.Handle == IntPtr.Zero)
				return false;

			return currentControl.Handle == control.Handle;
		}
Ejemplo n.º 5
0
        public override void Set(ImageLoaderTask task, UIImage image, bool isLocalOrFromCache, bool isLoadingPlaceholder)
        {
            var control = Control;

            if (control == null)
            {
                return;
            }
            control.SetImage(image, UIControlState.Normal);
        }
Ejemplo n.º 6
0
        private bool UsesSameNativeControl(ImageLoaderTask task)
        {
            var currentControl = _getNativeControl();
            var control = task._getNativeControl();

            if (currentControl == null || control == null)
                return false;

            return currentControl == control;
        }
Ejemplo n.º 7
0
        public override void SetAsEmpty(ImageLoaderTask task)
        {
            var control = Control;

            if (control == null)
            {
                return;
            }

            control.SetImage(null, UIControlState.Normal);
        }
Ejemplo n.º 8
0
        public override void SetAsEmpty(ImageLoaderTask task)
        {
            var control = Control;

            if (control == null)
            {
                return;
            }

            control.Image = null;
        }
Ejemplo n.º 9
0
        public override void Set(ImageLoaderTask task, UIImage image, bool isLocalOrFromCache, bool isLoadingPlaceholder)
        {
            var control = Control;

            if (control == null)
            {
                return;
            }

            control.Image = image;
        }
Ejemplo n.º 10
0
		private bool UsesSameNativeControl(ImageLoaderTask task)
		{
			ImageView currentControl;
			_imageWeakReference.TryGetTarget(out currentControl);

			ImageView control;
			task._imageWeakReference.TryGetTarget(out control);
			if (currentControl == null || control == null || currentControl.Handle == IntPtr.Zero || control.Handle == IntPtr.Zero)
				return false;

			return currentControl.Handle == control.Handle;
		}
Ejemplo n.º 11
0
        private bool UsesSameNativeControl(ImageLoaderTask task)
        {
            var currentControl = _getNativeControl();
            var control        = task._getNativeControl();

            if (currentControl == null || control == null)
            {
                return(false);
            }

            return(currentControl == control);
        }
Ejemplo n.º 12
0
        private bool UsesSameNativeControl(ImageLoaderTask task)
        {
            var currentControl = _getNativeControl();
            var control        = task._getNativeControl();

            if (currentControl == null || control == null || currentControl.Handle == IntPtr.Zero || control.Handle == IntPtr.Zero)
            {
                return(false);
            }

            return(currentControl.Handle == control.Handle);
        }
Ejemplo n.º 13
0
        private bool UsesSameNativeControl(ImageLoaderTask task)
        {
            ImageView currentControl;

            _imageWeakReference.TryGetTarget(out currentControl);

            ImageView control;

            task._imageWeakReference.TryGetTarget(out control);
            if (currentControl == null || control == null || currentControl.Handle == IntPtr.Zero || control.Handle == IntPtr.Zero)
            {
                return(false);
            }

            return(currentControl.Handle == control.Handle);
        }
Ejemplo n.º 14
0
        public override bool UsesSameNativeControl(ImageLoaderTask task)
        {
            var otherTarget = task._target as IUIViewTarget <TControl>;

            if (otherTarget == null)
            {
                return(false);
            }

            var control      = Control;
            var otherControl = otherTarget.Control;

            if (control == null || otherControl == null)
            {
                return(false);
            }

            return(control.Handle == otherControl.Handle);
        }
Ejemplo n.º 15
0
		public AsyncDrawable(Resources res, Bitmap bitmap, ImageLoaderTask imageLoaderTask)
			: base(res, bitmap)
		{
			_imageLoaderTaskReference = new WeakReference<ImageLoaderTask>(imageLoaderTask);
		}
 /// <summary>
 /// Loads the image into given imageView using defined parameters.
 /// </summary>
 /// <param name="parameters">Parameters for loading the image.</param>
 /// <param name="imageView">Image view that should receive the image.</param>
 public static IScheduledWork Into(this TaskParameter parameters, ImageViewAsync imageView)
 {
     var task = new ImageLoaderTask(ImageService.Config.DownloadCache, new MainThreadDispatcher(), ImageService.Config.Logger, parameters, imageView);
     ImageService.LoadImage(task);
     return task;
 }
 private static IScheduledWork Into(this TaskParameter parameters, Func<UIView> getNativeControl, Action<UIImage, bool> doWithImage, float imageScale = -1f)
 {
     var task = new ImageLoaderTask(ImageService.Config.DownloadCache, new MainThreadDispatcher(), ImageService.Config.Logger, parameters,
         getNativeControl, doWithImage, imageScale);
     ImageService.LoadImage(task);
     return task;
 }
		/// <summary>
		/// Invalidate the image corresponding to given parameters from given caches.
		/// </summary>
		/// <param name="parameters">Image parameters.</param>
		/// <param name="cacheType">Cache type.</param>
		public static void Invalidate(this TaskParameter parameters, CacheType cacheType)
		{
			using (var task = new ImageLoaderTask(ImageService.Config.DownloadCache, new MainThreadDispatcher(), ImageService.Config.Logger, parameters, null, null, 1))
			{
				var key = task.GetKey();
				ImageService.Invalidate(key, cacheType);
			}
		}
Ejemplo n.º 19
0
 public override bool IsTaskValid(ImageLoaderTask task)
 {
     return(IsValid);
 }
Ejemplo n.º 20
0
 public AsyncDrawable(Resources res, Bitmap bitmap, ImageLoaderTask imageLoaderTask)
     : base(res, bitmap)
 {
     _imageLoaderTaskReference = new WeakReference <ImageLoaderTask>(imageLoaderTask);
 }
		private static ImageLoaderTask CreateTask(this TaskParameter parameters, ImageViewAsync imageView)
		{
			var task = new ImageLoaderTask(ImageService.Config.DownloadCache, new MainThreadDispatcher(), ImageService.Config.Logger, parameters, imageView);
			return task;
		}