async Task <Bitmap> PortableAsyncRenderer <Bitmap> .GetThumbnailAsync ( PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag, int viewWidth, int viewHeight//, //Bitmap reusedThumbnail ) { if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } Task <Bitmap> thumbnailTask = ThumbnailUtils.CreateVideoThumbnailAsync ( FilePath, ThumbnailKind.MicroKind ); if (thumbnailTask.Result == null) { throw new CorruptObjectException(FileName); } return(await thumbnailTask); }
private static async void RenderTextAsync ( this PortableAsyncRenderer <Bitmap> asyncRenderer, PortableCorrelatedEntity correlatedEntity, Action <Action> runOnUiThread, string initialText, TextView textView ) { if (correlatedEntity.CorrelationTag != textView.GetCorrelationTag()) { return; } IReadOnlyDictionary <string, object> objectAttributes; try { objectAttributes = await asyncRenderer.GetAttributesAsync ( correlatedEntity, () => textView.GetCorrelationTag() ); } catch (Exception exception) { AndroidCrapApplication.ApplicationLogger.LogError(exception); throw; } if (correlatedEntity.CorrelationTag != textView.GetCorrelationTag()) { return; } runOnUiThread ( () => { if (correlatedEntity.CorrelationTag != textView.GetCorrelationTag()) { return; } if (objectAttributes == null) { return; } textView.Text = initialText /* string.Join * ( * " * ", * objectAttributes.Value.Values * )*/; } ); }
async Task <IReadOnlyDictionary <string, object> > PortableAsyncRenderer <Bitmap> .GetAttributesAsync ( PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag ) { if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } IReadOnlyDictionary <string, string> imageAttributes = await AndroidExifHandler.GetPictureAttributesAsync ( FilePath, attributeTags : new[] { ExifInterface.TagOrientation, ExifInterface.TagModel, ExifInterface.TagDatetimeDigitized, ExifInterface.TagDatetime, ExifInterface.TagGpsAltitude, ExifInterface.TagGpsAltitudeRef, ExifInterface.TagGpsLatitude, ExifInterface.TagGpsLatitudeRef, ExifInterface.TagGpsLongitude, ExifInterface.TagGpsLongitudeRef } ); if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } var objectAttributes = new Dictionary <string, object> ( imageAttributes.Count ); foreach (KeyValuePair <string, string> imageAttribute in imageAttributes) { string attributeKey = imageAttribute.Key; object attributeValue = imageAttribute.Value; objectAttributes.Add(attributeKey, attributeValue); } return(objectAttributes); }
public static async Task <Bitmap> GetThumbnailAsync ( this PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag, int viewWidth, int viewHeight, //Bitmap reusedThumbnail, string thumbnailPath ) { if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } int pictureOrientation = await AndroidExifHandler.GetPictureOrientationAsync ( thumbnailPath ); if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } byte[] thumbnailData = await AndroidExifHandler.GetThumbnailDataAsync(thumbnailPath); if (correlatedEntity.CorrelationTag != correlationTag()) { return(null); } Bitmap thumbnailBitmap = await AndroidBitmapHandler.LoadAdjustedBitmapAsync ( thumbnailPath, viewWidth, viewHeight, pictureOrientation, //reusedThumbnail, thumbnailData ); if (correlatedEntity.CorrelationTag != correlationTag()) { thumbnailBitmap?.Dispose(); thumbnailBitmap = null; } return(thumbnailBitmap); }
async Task <Bitmap> PortableAsyncRenderer <Bitmap> .GetThumbnailAsync ( PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag, int viewWidth, int viewHeight//, //Bitmap reusedThumbnail ) { return(await correlatedEntity.GetThumbnailAsync(correlationTag, viewWidth, viewHeight, //reusedThumbnail, FilePath)); }
public static PortableBaseObject GetObjectByCorrelationTag ( string correlationTag ) { PortableBaseObject foundObject = _cachedObjects.FirstOrDefault ( cachedObject => { PortableCorrelatedEntity correlatedEntity = cachedObject; return(correlatedEntity.CorrelationTag == correlationTag); } ); return(foundObject); }
public static void FireParallelTextRendering ( this PortableAsyncRenderer <Bitmap> asyncRenderer, PortableCorrelatedEntity correlatedEntity, Action <Action> runOnUiThread, string initialText, TextView textView ) { Task.Run ( () => asyncRenderer.RenderTextAsync(correlatedEntity, runOnUiThread, initialText, textView) ); }
async Task <Bitmap> PortableAsyncRenderer <Bitmap> .GetThumbnailAsync ( PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag, int viewWidth, int viewHeight//, //Bitmap reusedThumbnail ) { string thumbnailPath = Path.Combine(DirectorySource.DirectoryPath, "AlbumArtSmall.jpg"); if (File.Exists(thumbnailPath) == false) { return(null); } return(await correlatedEntity.GetThumbnailAsync(correlationTag, viewWidth, viewHeight, //reusedThumbnail, thumbnailPath)); }
async Task <IReadOnlyDictionary <string, object> > PortableAsyncRenderer <Bitmap> .GetAttributesAsync ( PortableCorrelatedEntity correlatedEntity, Func <string> correlationTag ) { return(await Task.Run ( () => { IReadOnlyDictionary <string, object> objectAttributes = new Dictionary <string, object>(); return objectAttributes; } )); /* * * if (correlatedEntity.CorrelationTag != correlationTag()) * { * return null; * } * * IReadOnlyDictionary<string, string> imageAttributes * = await AndroidExifHandler.GetPictureAttributesAsync * ( * FilePath, * attributeTags : new[] * { * ExifInterface.TagOrientation, * ExifInterface.TagModel, * ExifInterface.TagDatetimeDigitized, * * ExifInterface.TagDatetime, * ExifInterface.TagGpsAltitude, * ExifInterface.TagGpsAltitudeRef, * ExifInterface.TagGpsLatitude, * ExifInterface.TagGpsLatitudeRef, * ExifInterface.TagGpsLongitude, * ExifInterface.TagGpsLongitudeRef * } * ); * * if (correlatedEntity.CorrelationTag != correlationTag()) * { * return null; * } * * var objectAttributes = new Dictionary<string, object> * ( * imageAttributes.Count * ); * * foreach(KeyValuePair<string, string> imageAttribute in imageAttributes) * { * string attributeKey = imageAttribute.Key; * * object attributeValue = imageAttribute.Value; * * objectAttributes.Add(attributeKey, * attributeValue); * } * * return objectAttributes;*/ }
public static void FireParallelThumbnailRendering ( this PortableAsyncRenderer <Bitmap> asyncRenderer, PortableCorrelatedEntity correlatedEntity, Action <Action> runOnUiThread, View itemView, AndroidCachingImageView thumbnailView, Resources activityResources, int?backgroundResource, Action <CorruptObjectException, ImageView> onCorrupt, Action <ImageView, Drawable, AnimationDrawable, bool> onFinished ) { Drawable originalBackground = itemView.Tag as Drawable; AnimationDrawable loadingAnimation = thumbnailView.Background as AnimationDrawable; bool isLoaded = false; if (correlatedEntity.CorrelationTag != thumbnailView.GetCorrelationTag()) { onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } if (backgroundResource != null) { thumbnailView.SetBackgroundResource(backgroundResource.Value); } loadingAnimation?.Start(); itemView.Post // to have image view measured size reliable ( async() => { int thumbnailWidth = thumbnailView.MeasuredWidth; int thumbnailHeight = thumbnailView.MeasuredHeight; if (thumbnailView.Visibility != ViewStates.Visible) { onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } try { await asyncRenderer.RenderThumbnailAsync(correlatedEntity, runOnUiThread, thumbnailView, thumbnailWidth, thumbnailHeight, activityResources, originalBackground, loadingAnimation, onCorrupt, onFinished); } catch (Exception exception) { AndroidCrapApplication.ApplicationLogger.LogError(exception); throw; } } ); }
private static async Task RenderThumbnailAsync ( this PortableAsyncRenderer <Bitmap> asyncRenderer, PortableCorrelatedEntity correlatedEntity, Action <Action> runOnUiThread, AndroidCachingImageView thumbnailView, int thumbnailWidth, int thumbnailHeight, Resources activityResources, Drawable originalBackground, AnimationDrawable loadingAnimation, Action <CorruptObjectException, ImageView> onCorrupt, Action <ImageView, Drawable, AnimationDrawable, bool> onFinished ) { bool isLoaded = false; if (correlatedEntity.CorrelationTag != thumbnailView.GetCorrelationTag()) { onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } Bitmap thumbnailBitmap = null; CorruptObjectException thumbnailException = null; BitmapDrawable thumbnailDrawable = AndroidCrapApplication.GetDrawableFromCache ( correlatedEntity.CorrelationTag ); if (thumbnailDrawable == null) { try { /*thumbnailDrawable = AndroidCrapApplication.GetReusableBitmapDrawable(thumbnailWidth, * thumbnailHeight);*/ thumbnailBitmap = await asyncRenderer.GetThumbnailAsync ( correlatedEntity, () => thumbnailView.GetCorrelationTag(), thumbnailWidth, thumbnailHeight//, //thumbnailDrawable.Bitmap ); } catch (Exception exception) { AndroidCrapApplication.ApplicationLogger.LogError(exception); thumbnailBitmap?.Dispose(); thumbnailException = exception as CorruptObjectException; if (thumbnailException == null) { throw; } else { runOnUiThread ( () => onCorrupt(thumbnailException, thumbnailView) ); } onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } if (correlatedEntity.CorrelationTag != thumbnailView.GetCorrelationTag()) { thumbnailBitmap?.Dispose(); onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } if (thumbnailBitmap == null) { onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); return; } thumbnailDrawable = AndroidCrapApplication.AddBitmapToCache ( correlatedEntity.CorrelationTag, thumbnailBitmap, activityResources ); } isLoaded = true; onFinished?.Invoke(thumbnailView, originalBackground, loadingAnimation, isLoaded); runOnUiThread ( () => { thumbnailView.SetImageDrawable(thumbnailDrawable); } ); /*AndroidCrapApplication.ApplicationLogger.LogDebug("{0} : {1}", * correlatedEntity.CorrelationTag, * GC.GetTotalMemory(false));*/ }