void Initialize() { OnceInitializeAction = null; ContentView.SetBackgroundColor(_loadingView.OverlayColor.ToAndroid()); ContentView.Alpha = 1f; ContentView.SetPadding(0, (int)Dialogs.Context.ToPixels(24), 0, 0); // Statusbar _loadingView.Parent = XF.Application.Current.MainPage; _renderer = Dialogs.CreateNativeView(_loadingView); if (_loadingView.CornerRadius > 0) { var nativeView = _renderer.View as ViewGroup; var border = new GradientDrawable(); border.SetCornerRadius(Dialogs.Context.ToPixels(_loadingView.CornerRadius)); if (!_loadingView.BackgroundColor.IsDefault) { border.SetColor(_loadingView.BackgroundColor.ToAndroid()); } nativeView.ClipToOutline = true; nativeView.SetBackground(border); } var measure = Dialogs.Measure(_loadingView); _loadingView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height)); var width = (int)Dialogs.Context.ToPixels(_loadingView.Bounds.Width); var height = (int)Dialogs.Context.ToPixels(_loadingView.Bounds.Height); using (var param = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ) { Width = width, Height = height, Gravity = Dialogs.GetGravity(_loadingView) }) { Dialogs.SetOffsetMargin(param, _loadingView); ContentView.AddView(_renderer.View, 0, param); } }
void Initialize() { _dlgView.Parent = XF.Application.Current.MainPage; _renderer = Dialogs.CreateNativeView(_dlgView); var measure = Dialogs.Measure(_dlgView); _dlgView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height)); _container = Dialogs.SetViewAppearance(_dlgView, _renderer.View as ViewGroup); _contentView = new FrameLayout(Dialogs.Context); using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)) { _contentView.LayoutParameters = param; } var fixPaddingTop = _dlgView.OverlayColor.IsTransparentOrDefault() ? Dialogs.StatusBarHeight : 0; if (_dlgView.UseCurrentPageLocation) { var padding = Dialogs.CalcWindowPadding(); _contentView.SetPadding(0, padding.top - fixPaddingTop, 0, padding.bottom); } else { _contentView.SetPadding(0, Dialogs.StatusBarHeight - fixPaddingTop, 0, 0); } _contentView.SetBackgroundColor(_dlgView.OverlayColor.ToAndroid()); _contentView.SetClipChildren(false); _contentView.SetClipToPadding(false); _contentView.FocusableInTouchMode = true; _contentView.Touch += _contentView_Touch; var width = Dialogs.Context.ToPixels(_dlgView.Bounds.Width); var height = Dialogs.Context.ToPixels(_dlgView.Bounds.Height); using (var param = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Width = (int)width, Height = (int)height, Gravity = Dialogs.GetGravity(_dlgView), }) { Dialogs.SetOffsetMargin(param, _dlgView); _contentView.AddView(_container, 0, param); }; // For now, Dynamic resizing is gaven to only Dialog. _dlgView.LayoutNative = () => { if (_renderer == null || _renderer.View.IsDisposed()) { return; } var p = _renderer.View.LayoutParameters as FrameLayout.LayoutParams; var w = (int)Dialogs.Context.ToPixels(_dlgView.Bounds.Width); var h = (int)Dialogs.Context.ToPixels(_dlgView.Bounds.Height); using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Width = w, Height = h, Gravity = p.Gravity }) { Dialogs.SetOffsetMargin(param, _dlgView); _renderer.View.LayoutParameters = param; }; }; OnceInitializeAction = null; }
void Initialize() { _dlgView.Parent = XF.Application.Current.MainPage; _renderer = Dialogs.CreateNativeView(_dlgView); var measure = Dialogs.Measure(_dlgView); _dlgView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height)); if (_dlgView.CornerRadius > 0) { var nativeView = _renderer.View as ViewGroup; var border = new GradientDrawable(); border.SetCornerRadius(Dialogs.Context.ToPixels(_dlgView.CornerRadius)); if (!_dlgView.BackgroundColor.IsDefault) { border.SetColor(_dlgView.BackgroundColor.ToAndroid()); } nativeView.ClipToOutline = true; nativeView.SetBackground(border); } _contentView = new FrameLayout(Dialogs.Context); using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)) { _contentView.LayoutParameters = param; } if (_dlgView.UseCurrentPageLocation) { var padding = Dialogs.CalcWindowPadding(); _contentView.SetPadding(0, padding.top, 0, padding.bottom); } else { _contentView.SetPadding(0, (int)Dialogs.Context.ToPixels(24), 0, 0); // Statusbar } _contentView.SetBackgroundColor(_dlgView.OverlayColor.ToAndroid()); _contentView.SetClipChildren(false); _contentView.SetClipToPadding(false); _contentView.SetOnKeyListener(this); _contentView.FocusableInTouchMode = true; _contentView.Touch += _contentView_Touch; var width = Dialogs.Context.ToPixels(_dlgView.Bounds.Width); var height = Dialogs.Context.ToPixels(_dlgView.Bounds.Height); using (var param = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Width = (int)width, Height = (int)height, Gravity = Dialogs.GetGravity(_dlgView), }) { Dialogs.SetOffsetMargin(param, _dlgView); _contentView.AddView(_renderer.View, 0, param); }; OnceInitializeAction = null; }
public void Show(ToastView view, object viewModel = null) { view.Parent = XF.Application.Current.MainPage; view.BindingContext = viewModel; var toast = new Android.Widget.Toast(Dialogs.Context); var offsetX = (int)Dialogs.Context.ToPixels(view.OffsetX); var offsetY = (int)Dialogs.Context.ToPixels(view.OffsetY); // HACK: For some reason, the offset direction is reversed when GravityFlags contains Left or Bottom. if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.End) { offsetX *= -1; } if (view.VerticalLayoutAlignment == XF.LayoutAlignment.End) { offsetY *= -1; } toast.SetGravity(Dialogs.GetGravity(view), offsetX, offsetY); toast.Duration = Android.Widget.ToastLength.Long; var renderer = Dialogs.CreateNativeView(view); var measure = Dialogs.Measure(view); view.Layout(new XF.Rectangle(new XF.Point(0, 0), measure)); var realW = (int)Dialogs.Context.ToPixels(measure.Width); var realH = (int)Dialogs.Context.ToPixels(measure.Height); var layout = new LinearLayout(Dialogs.Context); using (var param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) { Width = realW, Height = realH }){ layout.LayoutParameters = param; } using (var param = new LinearLayout.LayoutParams(realW, realH) { Width = realW, Height = realH }){ layout.AddView(renderer.View, param); } if (view.CornerRadius > 0) { var border = new GradientDrawable(); border.SetCornerRadius(Dialogs.Context.ToPixels(view.CornerRadius)); if (!view.BackgroundColor.IsDefault) { border.SetColor(view.BackgroundColor.ToAndroid()); border.Alpha = (int)(view.Opacity * 255); } layout.ClipToOutline = true; layout.SetBackground(border); } toast.View = layout; view.RunPresentationAnimation(); toast.Show(); var duration = Math.Max(Math.Min(view.Duration - 260, 3500), 0); // give a bit millisecond margin var handler = new Handler(); handler.PostDelayed(new Runnable(view.RunDismissalAnimation), duration); handler.PostDelayed(new Runnable(() => { //view.RunDismissalAnimation(); //await Task.Delay(250); toast?.Cancel(); view.Parent = null; if (!renderer.View.IsDisposed()) { renderer.View.RemoveFromParent(); renderer.View.Dispose(); } layout.Dispose(); // I coudn't reproduce https://github.com/muak/AiForms.Dialogs/issues/2. // But I let this code disabled because it has no influent even if it is disabled. //toast.View = null; renderer.Dispose(); renderer = null; toast?.Dispose(); toast = null; view.Destroy(); view.BindingContext = null; }), view.Duration); }