Example #1
0
        public static void LoadBitmap(ImageView imageView, double d, int w, int h)
        {
            int direction = (int)d;

            // Check, if there is another image creation is running
            if (CancelPotentialWork(direction, imageView))
            {
                // Create task for image creation
                AsyncImageFromDirection asyncImageTask = new AsyncImageFromDirection(imageView, 0, w, h);
                // Has the ImageView an existing AsyncDrawable
                if (imageView.Drawable == null || !(imageView.Drawable is AsyncDrawable))
                {
                    // No, than create one
                    AsyncDrawable asyncDrawable = new AsyncDrawable(imageView.Context.Resources, BitmapFactory.DecodeResource(imageView.Context.Resources, Android.Resource.Drawable.IcMenuGallery), asyncImageTask);
                    // Set it as bitmap for the ImageView until the correct image is ready
                    imageView.SetImageDrawable(asyncDrawable);
                }
                asyncImageTask.Execute(direction);
            }
        }
Example #2
0
        /// <summary>
        /// Determines if there is another task for this ImageView, with the same direction.
        /// </summary>
        /// <returns><c>true</c> if no task is associated with this ImageView with the same direction; otherwise, <c>false</c>.</returns>
        /// <param name="direction">Direction in degrees.</param>
        /// <param name="imageView">ImageView to check.</param>
        public static Boolean CancelPotentialWork(int direction, ImageView imageView)
        {
            AsyncImageFromDirection asyncImageTask = GetAsyncImageTask(imageView) as AsyncImageFromDirection;

            if (asyncImageTask != null)
            {
                int?bitmapDirection = asyncImageTask.Direction;
                // If bitmapDirection is not yet set or it differs from the new direction
                if (bitmapDirection == null || bitmapDirection != direction)
                {
                    // Cancel previous task, because it is not longer needed
                    asyncImageTask.Cancel(true);
                }
                else
                {
                    // The same work is already in progress
                    return(false);
                }
            }
            // No task associated with the ImageView, or an existing task was cancelled
            return(true);
        }
		public static void LoadBitmap(ImageView imageView, double d, int w, int h)
		{
			int direction = (int)d;

			// Check, if there is another image creation is running
			if(CancelPotentialWork(direction, imageView)) {
				// Create task for image creation
				AsyncImageFromDirection asyncImageTask = new AsyncImageFromDirection(imageView, 0, w, h);
				// Has the ImageView an existing AsyncDrawable
				if(imageView.Drawable == null || !(imageView.Drawable is AsyncDrawable)) {
					// No, than create one
					AsyncDrawable asyncDrawable = new AsyncDrawable(imageView.Context.Resources, BitmapFactory.DecodeResource(imageView.Context.Resources, Android.Resource.Drawable.IcMenuGallery), asyncImageTask);
					// Set it as bitmap for the ImageView until the correct image is ready
					imageView.SetImageDrawable(asyncDrawable);
				}
				asyncImageTask.Execute(direction);
			}
		}