public ItemViewHolder(View itemView) : base(itemView) { icon = itemView.FindViewById <ImageView>(Resource.Id.icon); title = itemView.FindViewById <TextView>(Resource.Id.title); subTitle = itemView.FindViewById <TextView>(Resource.Id.subtitle); }
static async Task UpdateBitmap( this AImageView imageView, IImageElement newView, IImageElement previousView, ImageSource newImageSource, ImageSource previousImageSource) { IImageController imageController = newView as IImageController; newImageSource = newImageSource ?? newView?.Source; previousImageSource = previousImageSource ?? previousView?.Source; if (imageView.IsDisposed()) { return; } if (newImageSource != null && Equals(previousImageSource, newImageSource)) { return; } imageController?.SetIsLoading(true); (imageView as IImageRendererController)?.SkipInvalidate(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); try { if (newImageSource != null) { var imageViewHandler = Internals.Registrar.Registered.GetHandlerForObject <IImageViewHandler>(newImageSource); if (imageViewHandler != null) { await imageViewHandler.LoadImageAsync(newImageSource, imageView); } else { using (var drawable = await imageView.Context.GetFormsDrawableAsync(newImageSource)) { // only set the image if we are still on the same one if (!imageView.IsDisposed() && Equals(newView?.Source, newImageSource)) { imageView.SetImageDrawable(drawable); } } } } } finally { // only mark as finished if we are still working on the same image if (Equals(newView?.Source, newImageSource)) { imageController?.SetIsLoading(false); imageController?.NativeSizeChanged(); } } }
public static async void UpdateBitmap(this AImageView imageView, Image newImage, Image previousImage = null) { if (Device.IsInvokeRequired) { throw new InvalidOperationException("Image Bitmap must not be updated from background thread"); } if (previousImage != null && Equals(previousImage.Source, newImage.Source)) { return; } ((IImageController)newImage).SetIsLoading(true); (imageView as IImageRendererController).SkipInvalidate(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); ImageSource source = newImage.Source; Bitmap bitmap = null; IImageSourceHandler handler; if (source != null && (handler = Internals.Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null) { try { bitmap = await handler.LoadImageAsync(source, imageView.Context); } catch (TaskCanceledException) { } catch (IOException ex) { Internals.Log.Warning("Xamarin.Forms.Platform.Android.ImageRenderer", "Error updating bitmap: {0}", ex); } } if (newImage == null || !Equals(newImage.Source, source)) { bitmap?.Dispose(); return; } if (bitmap == null && source is FileImageSource) { imageView.SetImageResource(ResourceManager.GetDrawableByName(((FileImageSource)source).File)); } else { imageView.SetImageBitmap(bitmap); } bitmap?.Dispose(); ((IImageController)newImage).SetIsLoading(false); ((IVisualElementController)newImage).NativeSizeChanged(); }
static async Task SetImagePlaceholder(AImageView imageView, ImageSource placeholder) { using (var drawable = await imageView.Context.GetFormsDrawableAsync(placeholder)) { // only set the image if we are still on the same one if (!imageView.IsDisposed()) { imageView.SetImageDrawable(drawable); } } }
public static void Reset(this AImageView imageView) { if (!imageView.IsDisposed()) { if (imageView.Drawable is FormsAnimationDrawable animation) { imageView.SetImageDrawable(null); animation.Reset(); } imageView.SetImageResource(global::Android.Resource.Color.Transparent); } }
public virtual async Task <IImageSourceServiceResult?> LoadDrawableAsync( IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var realResult = await GetDrawableAsync(imageSource, imageView.Context !, cancellationToken); if (realResult is null) { imageView.SetImageDrawable(null); return(null); } imageView.SetImageDrawable(realResult.Value); var result = new ImageSourceServiceLoadResult( realResult.IsResolutionDependent, () => realResult.Dispose()); return(result); }
public virtual void SetImageView(ImageView imageView, ImageView imageCheck, SelectedUriCollection mCollection) { this.imageView = imageView; this.imageView.SetMinimumWidth(Width); this.imageView.SetMinimumHeight(Height); this.imageCheck = imageCheck; this.mCollection = mCollection; this.imageView.SetOnClickListener(new AnonymousOnClickListener(v => { var a = this.mCollection.IsCountOver(); var b = !this.mCollection.IsSelected(this.item.BuildContentUri()); if (a && b) { return; } if (this.item.Capture) { ((ImageSelectActivity)v.Context).ShowCameraAction(); return; } else if (this.mCollection.IsSingleChoose) { this.mCollection.Add(this.item.BuildContentUri()); ((ImageSelectActivity)v.Context).SetResult(); return; } if (this.mCollection.IsSelected(this.item.BuildContentUri())) { this.mCollection.Remove(this.item.BuildContentUri()); this.imageCheck.SetImageResource(Resource.Drawable.pick_photo_checkbox_normal); this.imageView.ClearColorFilter(); } else { this.mCollection.Add(this.item.BuildContentUri()); this.imageCheck.SetImageResource(Resource.Drawable.pick_photo_checkbox_check); this.imageView.SetColorFilter(Color.Gray, PorterDuff.Mode.Multiply); } })); }
void UpdateTitleIcon() { Page currentPage = CurrentPage; if (currentPage == null) { return; } ImageSource source = NavigationPage.GetTitleIconImageSource(currentPage); if (source == null || source.IsEmpty) { Toolbar.RemoveView(_titleIconView); _titleIconView?.Dispose(); _titleIconView = null; _imageSource = null; return; } if (_titleIconView == null) { _titleIconView = new Android.Widget.ImageView(NavigationLayout.Context); Toolbar.AddView(_titleIconView, 0); } if (_imageSource != source) { _imageSource = source; _titleIconView.SetImageResource(global::Android.Resource.Color.Transparent); ImageSourceLoader.LoadImage(source, MauiContext, (result) => { _titleIconView.SetImageDrawable(result.Value); AutomationPropertiesProvider.AccessibilitySettingsChanged(_titleIconView, source); }); } }
public Task <IImageSourceServiceResult> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { if (imageSource is not ICustomImageSourceStub imageSourceStub) { return(Task.FromResult <IImageSourceServiceResult>(new ImageSourceServiceLoadResult())); } var color = imageSourceStub.Color; var drawable = _cache.Get(color); imageView.SetImageDrawable(drawable); var result = new ImageSourceServiceLoadResult(() => _cache.Return(color)); return(Task.FromResult <IImageSourceServiceResult>(result)); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var uriImageSource = (IUriImageSource)imageSource; if (!uriImageSource.IsEmpty) { try { var callback = new ImageLoaderCallback(); PlatformInterop.LoadImageFromUri(imageView, uriImageSource.Uri.OriginalString, new Java.Lang.Boolean(uriImageSource.CachingEnabled), callback); return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image uri '{Uri}'.", uriImageSource.Uri.OriginalString); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
// TODO hartez 2017/04/07 09:33:03 Review this again, not sure it's handling the transition from previousImage to 'null' newImage correctly public static async Task UpdateBitmap(this AImageView imageView, Image newImage, Image previousImage = null) { if (imageView == null || imageView.IsDisposed()) { return; } if (Device.IsInvokeRequired) { throw new InvalidOperationException("Image Bitmap must not be updated from background thread"); } if (previousImage != null && Equals(previousImage.Source, newImage.Source)) { return; } var imageController = newImage as IImageController; imageController?.SetIsLoading(true); (imageView as IImageRendererController)?.SkipInvalidate(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); ImageSource source = newImage?.Source; Bitmap bitmap = null; Drawable drawable = null; IImageSourceHandler handler; if (source != null && (handler = Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(source)) != null) { if (handler is FileImageSourceHandler) { drawable = imageView.Context.GetDrawable((FileImageSource)source); } if (drawable == null) { try { bitmap = await handler.LoadImageAsync(source, imageView.Context); } catch (TaskCanceledException) { imageController?.SetIsLoading(false); } } } if (newImage == null || !Equals(newImage.Source, source)) { bitmap?.Dispose(); return; } if (!imageView.IsDisposed()) { if (bitmap == null && drawable != null) { imageView.SetImageDrawable(drawable); } else { imageView.SetImageBitmap(bitmap); } } bitmap?.Dispose(); imageController?.SetIsLoading(false); ((IVisualElementController)newImage).NativeSizeChanged(); }
public override void Set(Android.Widget.ImageView imageView, Android.Net.Uri uri, Android.Graphics.Drawables.Drawable placeholder) { Picasso.With(imageView.Context).Load(uri).Placeholder(placeholder).Into(imageView); }
public override void Cancel(Android.Widget.ImageView imageView) { Picasso.With(imageView.Context).CancelRequest(imageView); }
public static Task UpdateBitmap(this AImageView imageView, ImageSource newImageSource, ImageSource previousImageSourc) => imageView.UpdateBitmap(null, null, newImageSource, previousImageSourc);
public override void DisplayImage(string path, ImageView imageView) { ChargeInit(imageView.Context); Glide.With(imageView.Context).Load(path).CenterCrop().Error(img_loading).Placeholder(img_loading).DontAnimate().Into(imageView); }
internal static async void SetImage(this AImageView image, ImageSource source, Context context) { image.SetImageDrawable(await context.GetFormsDrawableAsync(source)); }
internal async Task <Bitmap> Open(CancellationToken ct, Android.Widget.ImageView targetImage = null, int?targetWidth = null, int?targetHeight = null) { IsImageLoadedToUiDirectly = false; BitmapFactory.Options options = new BitmapFactory.Options(); options.InJustDecodeBounds = true; var targetSize = UseTargetSize && targetWidth != null && targetHeight != null ? (global::System.Drawing.Size?) new global::System.Drawing.Size(targetWidth.Value, targetHeight.Value) : null; if (ResourceId.HasValue) { return(ImageData = await FetchResourceWithDownsampling(ct, ResourceId.Value, targetSize)); } if (Stream != null) { if (Stream.CanSeek) //For now if we can only validate the size of streams that are seekable { var emptyPadding = new Rect(); // Try to move position to beginning of the stream, if seekable. Stream.Position = 0; //Get the size of the image and validate await BitmapFactory.DecodeStreamAsync(Stream, emptyPadding, options); Stream.Position = 0; if (ValidateIfImageNeedsResize(options)) { options.InJustDecodeBounds = false; return(ImageData = await BitmapFactory.DecodeStreamAsync(Stream, emptyPadding, options)); } } return(ImageData = await BitmapFactory.DecodeStreamAsync(Stream)); } if (FilePath.HasValue()) { await BitmapFactory.DecodeFileAsync(FilePath, options); if (ValidateIfImageNeedsResize(options)) { options.InJustDecodeBounds = false; return(ImageData = await BitmapFactory.DecodeFileAsync(FilePath, options)); } return(ImageData = await BitmapFactory.DecodeFileAsync(FilePath)); } if (WebUri != null) { if (ImageLoader == null) { // The ContactsService returns the contact uri for compatibility with UniversalImageLoader - in order to obtain the corresponding photo we resolve using the service below. if (IsContactUri(WebUri)) { var stream = ContactsContract.Contacts.OpenContactPhotoInputStream(ContextHelper.Current.ContentResolver, Android.Net.Uri.Parse(WebUri.OriginalString)); return(ImageData = await BitmapFactory.DecodeStreamAsync(stream)); } var filePath = await Download(ct, WebUri); if (filePath == null) { return(null); } return(ImageData = await BitmapFactory.DecodeFileAsync(filePath.LocalPath)); } else { if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().DebugFormat("Using ImageLoader to get {0}", WebUri); } ImageData = await ImageLoader(ct, WebUri.OriginalString, targetImage, targetSize); if ( !ct.IsCancellationRequested && targetImage != null && targetSize == null ) { IsImageLoadedToUiDirectly = true; targetImage.SetImageBitmap(ImageData); } return(ImageData); } } return(null); }
public static Task UpdateBitmap(this AImageView imageView, IImageController newView, IImageController previousView) => imageView.UpdateBitmap(newView, previousView, null, null);
public GlideBitmapViewTarget(Android.Widget.ImageView imageView, Action loadAction) : base(imageView) { LoadAction = loadAction; }
public override void DisplayCameraItem(ImageView imageView) { ChargeInit(imageView.Context); Glide.With(imageView.Context).Load(img_camera).CenterCrop().Error(img_camera).Placeholder(img_camera).DontAnimate().Into(imageView); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var fontImageSource = (IFontImageSource)imageSource; if (!fontImageSource.IsEmpty) { var size = FontManager.GetFontSize(fontImageSource.Font); var unit = fontImageSource.Font.AutoScalingEnabled ? ComplexUnitType.Sp : ComplexUnitType.Dip; var textSize = TypedValue.ApplyDimension(unit, size.Value, imageView.Context?.Resources?.DisplayMetrics); var typeface = FontManager.GetTypeface(fontImageSource.Font); var color = (fontImageSource.Color ?? Graphics.Colors.White).ToPlatform(); var callback = new ImageLoaderCallback(); try { PlatformInterop.LoadImageFromFont( imageView, color, fontImageSource.Glyph, typeface, textSize, callback); return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to generate font image '{Glyph}'.", fontImageSource.Glyph); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
public override async Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var streamImageSource = (IStreamImageSource)imageSource; if (!streamImageSource.IsEmpty) { Stream?stream = null; try { stream = await streamImageSource.GetStreamAsync(cancellationToken).ConfigureAwait(false); var callback = new ImageLoaderCallback(); PlatformInterop.LoadImageFromStream(imageView, stream, callback); var result = await callback.Result; stream?.Dispose(); return(result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image stream."); throw; } finally { if (stream != null) { GC.KeepAlive(stream); } } } return(null); }
// TODO hartez 2017/04/07 09:33:03 Review this again, not sure it's handling the transition from previousImage to 'null' newImage correctly public static async Task UpdateBitmap(this AImageView imageView, Image newImage, ImageSource source, Image previousImage = null, ImageSource previousImageSource = null) { if (imageView == null || imageView.IsDisposed()) { return; } if (Device.IsInvokeRequired) { throw new InvalidOperationException("Image Bitmap must not be updated from background thread"); } source = source ?? newImage?.Source; previousImageSource = previousImageSource ?? previousImage?.Source; if (Equals(previousImageSource, source)) { return; } var imageController = newImage as IImageController; imageController?.SetIsLoading(true); (imageView as IImageRendererController)?.SkipInvalidate(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); bool setByImageViewHandler = false; Bitmap bitmap = null; if (source != null) { var imageViewHandler = Internals.Registrar.Registered.GetHandlerForObject <IImageViewHandler>(source); if (imageViewHandler != null) { try { await imageViewHandler.LoadImageAsync(source, imageView); setByImageViewHandler = true; } catch (TaskCanceledException) { imageController?.SetIsLoading(false); } } else { var imageSourceHandler = Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(source); try { bitmap = await imageSourceHandler.LoadImageAsync(source, imageView.Context); } catch (TaskCanceledException) { imageController?.SetIsLoading(false); } } } // Check if the source on the new image has changed since the image was loaded if (newImage != null && !Equals(newImage.Source, source)) { bitmap?.Dispose(); return; } if (!setByImageViewHandler && !imageView.IsDisposed()) { if (bitmap == null && source is FileImageSource) { imageView.SetImageResource(ResourceManager.GetDrawableByName(((FileImageSource)source).File)); } else { imageView.SetImageBitmap(bitmap); } } bitmap?.Dispose(); imageController?.SetIsLoading(false); ((IVisualElementController)newImage)?.NativeSizeChanged(); }
//functions private void BuildPageObjects() { var btnSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)); var lblSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)); var entrySize = Device.GetNamedSize(NamedSize.Large, typeof(Entry)); scrollView = new ScrollView(); stackLayout = new StackLayout(); buttonLayout = new StackLayout(); emailLayout = new StackLayout(); passwordLayout = new StackLayout(); innerStackLayout = new StackLayout(); innerStackLayout.Spacing = 50; //View objects innerGrid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength(7, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(2, GridUnitType.Star) } } }; outerGrid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } } }; buttonGrid = new Grid { ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; emailGrid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } }, ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) } } }; passwordGrid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } }, ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) } } }; mahechaLogo = new Image { Source = ImageSource.FromResource("mahechabjjlogo.png"), Aspect = Aspect.AspectFit }; emailImg = new Image { Source = "mail.png", Aspect = Aspect.AspectFit }; emailLbl = new Label { Text = "E-Mail Address", #if __IOS__ FontFamily = "AmericanTypewriter-Bold", FontSize = lblSize * 2, #endif #if __ANDROID__ FontFamily = "Roboto Bold", FontSize = lblSize, Margin = -5, #endif VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; emailEntry = new Entry { #if __IOS__ FontFamily = "AmericanTypewriter-Bold", #endif #if __ANDROID__ FontFamily = "Roboto Bold", Placeholder = "E-Mail Address", #endif FontSize = entrySize, HorizontalOptions = LayoutOptions.FillAndExpand }; passwordImg = new Image { Source = "password.png", Aspect = Aspect.AspectFit }; passwordLbl = new Label { Text = "Password", #if __IOS__ FontFamily = "AmericanTypewriter-Bold", FontSize = lblSize * 2, #endif #if __ANDROID__ FontFamily = "Roboto Bold", FontSize = lblSize, Margin = -5, #endif VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; passwordEntry = new Entry { IsPassword = true, #if __IOS__ FontFamily = "AmericanTypewriter-Bold", #endif #if __ANDROID__ FontFamily = "Roboto Bold", Placeholder = "Password", #endif FontSize = entrySize, HorizontalOptions = LayoutOptions.FillAndExpand }; loginBtn = new Button { Text = "Login", FontFamily = "AmericanTypewriter-Bold", FontSize = btnSize * 2, Style = (Style)Application.Current.Resources["common-blue-btn"], VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; backBtn = new Button { Image = "back.png", Style = (Style)Application.Current.Resources["common-red-btn"], VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; forgotPasswordBtn = new Button { Image = "forgotpassword.png", Style = (Style)Application.Current.Resources["common-blue-btn"], VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; #if __ANDROID__ var pd = new PaintDrawable(Android.Graphics.Color.Rgb(58, 93, 174)); pd.SetCornerRadius(100); var pdTwo = new PaintDrawable(Android.Graphics.Color.Rgb(124, 37, 41)); pdTwo.SetCornerRadius(100); androidLoginBtn = new Android.Widget.Button(MainApplication.ActivityContext); androidLoginBtn.Text = "Login"; androidLoginBtn.Typeface = Constants.COMMONFONT; androidLoginBtn.SetAutoSizeTextTypeWithDefaults(Android.Widget.AutoSizeTextType.Uniform); androidLoginBtn.SetBackground(pd); androidLoginBtn.SetTextColor(Android.Graphics.Color.Rgb(242, 253, 255)); androidLoginBtn.Gravity = Android.Views.GravityFlags.Center; androidLoginBtn.SetAllCaps(false); androidForgotPasswordBtn = new Android.Widget.Button(MainApplication.ActivityContext); androidForgotPasswordBtn.Text = "?"; androidForgotPasswordBtn.Typeface = Constants.COMMONFONT; androidForgotPasswordBtn.SetAutoSizeTextTypeWithDefaults(Android.Widget.AutoSizeTextType.Uniform); androidForgotPasswordBtn.SetBackground(pdTwo); androidForgotPasswordBtn.SetTextColor(Android.Graphics.Color.Rgb(242, 253, 255)); androidForgotPasswordBtn.Gravity = Android.Views.GravityFlags.Center; androidForgotPasswordBtn.SetAllCaps(false); androidForgetPasswordImgBtn = new Android.Widget.ImageButton(MainApplication.ActivityContext); androidForgetPasswordImgBtn.SetImageResource(2130837598); androidForgetPasswordImgBtn.SetAdjustViewBounds(true); androidForgetPasswordImgBtn.SetBackground(pdTwo); androidEmailEntry = new Android.Widget.EditText(MainApplication.ActivityContext); androidEmailEntry.Typeface = Constants.COMMONFONT; androidEmailEntry.SetTextSize(Android.Util.ComplexUnitType.Fraction, 75); androidEmailEntry.SetPadding(0, 10, 0, 10); androidEmailEntry.SetTextColor(Android.Graphics.Color.Black); androidEmailEntry.InputType = Android.Text.InputTypes.TextVariationEmailAddress; androidImageEmail = new Android.Widget.ImageView(MainApplication.ActivityContext); androidImageEmail.SetImageResource(2130837780); androidImageEmail.SetAdjustViewBounds(true); androidPasswordEntry = new Android.Widget.EditText(MainApplication.ActivityContext); androidPasswordEntry.Typeface = Constants.COMMONFONT; androidPasswordEntry.SetTextSize(Android.Util.ComplexUnitType.Fraction, 75); androidPasswordEntry.SetPadding(0, 0, 0, 0); androidPasswordEntry.SetTextColor(Android.Graphics.Color.Black); androidPasswordEntry.SetHighlightColor(Android.Graphics.Color.Transparent); androidPasswordEntry.InputType = Android.Text.InputTypes.TextVariationWebPassword; androidPasswordEntry.TransformationMethod = new PasswordTransformationMethod(); androidImagePassword = new Android.Widget.ImageView(MainApplication.ActivityContext); androidImagePassword.SetImageResource(2130837816); androidImagePassword.SetAdjustViewBounds(true); #endif //Events loginBtn.Clicked += async(object sender, EventArgs e) => { ToggleButtons(); await Validate(sender, e); ToggleButtons(); }; backBtn.Clicked += async(object sender, EventArgs e) => { ToggleButtons(); await Navigation.PopModalAsync(); ToggleButtons(); }; forgotPasswordBtn.Clicked += async(object sender, EventArgs e) => { ToggleButtons(); await Navigation.PushModalAsync(new ForgotPasswordPage()); ToggleButtons(); }; #if __ANDROID__ androidLoginBtn.Click += async(object sender, EventArgs e) => { ToggleButtons(); await Validate(sender, e); ToggleButtons(); }; androidForgetPasswordImgBtn.Click += async(object sender, EventArgs e) => { ToggleButtons(); await Navigation.PushModalAsync(new ForgotPasswordPage()); ToggleButtons(); }; #endif #if __IOS__ buttonLayout.Children.Add(backBtn); buttonLayout.Children.Add(loginBtn); buttonLayout.Children.Add(forgotPasswordBtn); buttonLayout.Orientation = StackOrientation.Horizontal; emailLayout.Children.Add(emailImg); emailLayout.Children.Add(emailEntry); emailLayout.Orientation = StackOrientation.Horizontal; passwordLayout.Children.Add(passwordImg); passwordLayout.Children.Add(passwordEntry); passwordLayout.Orientation = StackOrientation.Horizontal; innerStackLayout.Children.Add(emailLayout); innerStackLayout.Children.Add(passwordLayout); //innerStackLayout.Children.Add(emailImg); //innerStackLayout.Children.Add(emailEntry); //innerStackLayout.Children.Add(passwordImg); //innerStackLayout.Children.Add(passwordEntry); innerStackLayout.Children.Add(buttonLayout); stackLayout.Children.Add(mahechaLogo); stackLayout.Children.Add(innerStackLayout); stackLayout.Orientation = StackOrientation.Vertical; stackLayout.VerticalOptions = LayoutOptions.CenterAndExpand; stackLayout.HorizontalOptions = LayoutOptions.CenterAndExpand; scrollView.Content = stackLayout; Content = scrollView; #endif #if __ANDROID__ buttonGrid.Children.Add(androidLoginBtn.ToView(), 0, 0); buttonGrid.Children.Add(androidForgetPasswordImgBtn.ToView(), 1, 0); emailGrid.Children.Add(androidImageEmail.ToView(), 0, 0); emailGrid.Children.Add(androidEmailEntry.ToView(), 1, 0); emailGrid.Padding = new Thickness(10, 0); passwordGrid.Children.Add(androidImagePassword.ToView(), 0, 0); passwordGrid.Children.Add(androidPasswordEntry.ToView(), 1, 0); passwordGrid.Padding = new Thickness(10, 0); innerGrid.Children.Add(mahechaLogo, 0, 0); innerGrid.Children.Add(emailGrid, 0, 2); innerGrid.Children.Add(passwordGrid, 0, 4); innerGrid.Children.Add(buttonGrid, 0, 6); outerGrid.Children.Add(innerGrid, 0, 0); Content = outerGrid; #endif }
static async Task UpdateBitmap( this AImageView imageView, IImageElement newView, IImageElement previousView, ImageSource newImageSource, ImageSource previousImageSource) { IImageController imageController = newView as IImageController; newImageSource = newImageSource ?? newView?.Source; previousImageSource = previousImageSource ?? previousView?.Source; if (imageView.IsDisposed()) { return; } if (newImageSource != null && Equals(previousImageSource, newImageSource)) { return; } imageController?.SetIsLoading(true); (imageView as IImageRendererController)?.SkipInvalidate(); imageView.Reset(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); try { if (newImageSource != null) { // all this animation code will go away if/once we pull in GlideX IFormsAnimationDrawable animation = null; if (imageController.GetLoadAsAnimation()) { var animationHandler = Registrar.Registered.GetHandlerForObject <IAnimationSourceHandler>(newImageSource); if (animationHandler != null) { animation = await animationHandler.LoadImageAnimationAsync(newImageSource, imageView.Context); } } if (animation == null) { var imageViewHandler = Registrar.Registered.GetHandlerForObject <IImageViewHandler>(newImageSource); if (imageViewHandler != null) { await imageViewHandler.LoadImageAsync(newImageSource, imageView); } else { using (var drawable = await imageView.Context.GetFormsDrawableAsync(newImageSource)) { // only set the image if we are still on the same one if (!imageView.IsDisposed() && SourceIsNotChanged(newView, newImageSource)) { imageView.SetImageDrawable(drawable); } } } } else { if (!imageView.IsDisposed() && SourceIsNotChanged(newView, newImageSource)) { imageView.SetImageDrawable(animation.ImageDrawable); } else { animation?.Reset(); animation?.Dispose(); } } } else { imageView.SetImageBitmap(null); } } finally { // only mark as finished if we are still working on the same image if (SourceIsNotChanged(newView, newImageSource)) { imageController?.SetIsLoading(false); imageController?.NativeSizeChanged(); } } bool SourceIsNotChanged(IImageElement imageElement, ImageSource imageSource) { return((imageElement != null) ? imageElement.Source == imageSource : true); } }
public static async Task UpdateBitmap(this AImageView imageView, Image newImage, Image previousImage = null) { await UpdateBitmap(imageView, newImage, newImage?.Source, previousImage, previousImage?.Source); }
public static Task UpdateBitmap(this AImageView imageView, IImageElement newView, IImageElement previousView) => imageView.UpdateBitmap(newView, previousView, null, null);
public async Task <IImageSourceServiceResult> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { if (imageSource is not ICountedImageSourceStub imageSourceStub) { return(null); } try { Starting.Set(); // simulate actual work var drawable = await Task.Run(() => { if (imageSourceStub.Wait) { DoWork.WaitOne(); } var color = imageSourceStub.Color.ToPlatform(); return(new ColorDrawable(color)); }).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); imageView.SetImageDrawable(drawable); return(new ImageSourceServiceLoadResult(drawable.Dispose)); } finally { Finishing.Set(); } }
// TODO hartez 2017/04/07 09:33:03 Review this again, not sure it's handling the transition from previousImage to 'null' newImage correctly static async Task UpdateBitmap( this AImageView imageView, IImageElement newView, IImageElement previousView, ImageSource newImageSource, ImageSource previousImageSource) { IImageController imageController = newView as IImageController; newImageSource = newImageSource ?? newView?.Source; previousImageSource = previousImageSource ?? previousView?.Source; if (imageView.IsDisposed()) { return; } if (newImageSource != null && Equals(previousImageSource, newImageSource)) { return; } imageController?.SetIsLoading(true); (imageView as IImageRendererController)?.SkipInvalidate(); imageView.SetImageResource(global::Android.Resource.Color.Transparent); bool setByImageViewHandler = false; Bitmap bitmap = null; try { if (newImageSource != null) { var imageViewHandler = Internals.Registrar.Registered.GetHandlerForObject <IImageViewHandler>(newImageSource); if (imageViewHandler != null) { await imageViewHandler.LoadImageAsync(newImageSource, imageView); setByImageViewHandler = true; } else { var imageSourceHandler = Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(newImageSource); bitmap = await imageSourceHandler.LoadImageAsync(newImageSource, imageView.Context); } } } catch (TaskCanceledException) { imageController?.SetIsLoading(false); } // Check if the source on the new image has changed since the image was loaded if (!Equals(newView?.Source, newImageSource)) { bitmap?.Dispose(); return; } if (!setByImageViewHandler && !imageView.IsDisposed()) { if (bitmap == null && newImageSource is FileImageSource) { imageView.SetImageResource(ResourceManager.GetDrawableByName(((FileImageSource)newImageSource).File)); } else { imageView.SetImageBitmap(bitmap); } } bitmap?.Dispose(); imageController?.SetIsLoading(false); imageController?.NativeSizeChanged(); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var fileImageSource = (IFileImageSource)imageSource; if (!fileImageSource.IsEmpty) { var callback = new ImageLoaderCallback(); try { var id = imageView.Context?.GetDrawableId(fileImageSource.File) ?? -1; if (id > 0) { imageView.SetImageResource(id); return(Task.FromResult <IImageSourceServiceResult?>(new ImageSourceServiceLoadResult())); } else { PlatformInterop.LoadImageFromFile(imageView, fileImageSource.File, callback); } return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image file '{File}'.", fileImageSource.File); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }