public void Show(TopAlert alert) { if (_Layout != null) { _Layout.Dispose (); _Layout = null; } var window = UIApplication.SharedApplication.KeyWindow.RootViewController; _Layout = new MyToast (alert); window.Add (_Layout); UIApplication.SharedApplication.KeyWindow.BringSubviewToFront (_Layout); }
public void Show(TopAlert alert) { if (_Layout != null) { _Layout.Dispose(); _Layout = null; } var window = UIApplication.SharedApplication.KeyWindow.RootViewController; _Layout = new MyToast(alert); window.Add(_Layout); UIApplication.SharedApplication.KeyWindow.BringSubviewToFront(_Layout); }
public MyToast(TopAlert alert) : base(RectangleF.Empty) { this._Alert = alert; BackgroundColor = this._Alert.BackgroundColor.ToUIColor(); ClipsToBounds = false; UserInteractionEnabled = true; _Label = new UILabel { Text = this._Alert.Text, LineBreakMode = UILineBreakMode.TailTruncation, TextColor = this._Alert.TextColor.ToUIColor() }; if (this._Alert.TextSize > 0) { this._Label.Font = UIFont.SystemFontOfSize(this._Alert.TextSize); } this.AddSubview(this._Label); var w = UIApplication.SharedApplication.KeyWindow.Frame; var intent = alert.Intent; this.Frame = new CGRect(intent, TopBarSize() + alert.TopOffset, w.Width - intent * 2, (this._Alert.AlertHeight < 0 ? 40 : this._Alert.AlertHeight)); NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OrientationChanged); this._Gest1 = new UITapGestureRecognizer(MessageTapped); this._Gest2 = new UISwipeGestureRecognizer(MessageTapped); this.AddGestureRecognizer(this._Gest1); this.AddGestureRecognizer(this._Gest2); this.PerformSelector(new ObjCRuntime.Selector("TimerElaspsed:"), null, this._Alert.Duration); }
public MyToast(TopAlert alert) : base(RectangleF.Empty) { this._Alert = alert; BackgroundColor = this._Alert.BackgroundColor.ToUIColor (); ClipsToBounds = false; UserInteractionEnabled = true; _Label = new UILabel { Text = this._Alert.Text, LineBreakMode = UILineBreakMode.TailTruncation, TextColor = this._Alert.TextColor.ToUIColor() }; if (this._Alert.TextSize > 0) { this._Label.Font = UIFont.SystemFontOfSize (this._Alert.TextSize); } this.AddSubview (this._Label); var w = UIApplication.SharedApplication.KeyWindow.Frame; var intent = alert.Intent; this.Frame = new CGRect (intent, TopBarSize() + alert.TopOffset, w.Width - intent * 2, (this._Alert.AlertHeight < 0 ? 40 : this._Alert.AlertHeight)); NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OrientationChanged); this._Gest1 = new UITapGestureRecognizer(MessageTapped); this._Gest2 = new UISwipeGestureRecognizer (MessageTapped); this.AddGestureRecognizer(this._Gest1); this.AddGestureRecognizer(this._Gest2); this.PerformSelector (new ObjCRuntime.Selector ("TimerElaspsed:"), null, this._Alert.Duration); }
public void Show(TopAlert alert) { _Instance.Value.Show (alert); }
public async Task Show(TopAlert alert) { await Stop (); this._Token = new CancellationTokenSource (); this._Delay = alert.Duration; var activity = Xamarin.Forms.Forms.Context as Android.App.Activity; IWindowManager windowManager = Xamarin.Forms.Forms.Context.GetSystemService(Android.App.Service.WindowService).JavaCast<IWindowManager>(); this._Layout = (LinearLayout)activity.LayoutInflater.Inflate(Resource.Layout.AlertBox, null, false); this._Layout.LayoutParameters = new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); var submain = this._Layout.FindViewById<LinearLayout> (Resource.Id.linearLayout3); submain.SetBackgroundColor (alert.BackgroundColor.ToAndroid()); var main = _Layout.FindViewById<LinearLayout> (Resource.Id.linearLayout1); var id = Xamarin.Forms.Forms.Context.Resources.GetIdentifier ("alertborder", "drawable", Xamarin.Forms.Forms.Context.PackageName); Android.Graphics.Drawables.GradientDrawable drawable = Xamarin.Forms.Forms.Context.Resources.GetDrawable (id).JavaCast<Android.Graphics.Drawables.GradientDrawable>(); var text = submain.FindViewById<TextView> (Resource.Id.textView1); text.SetTextColor (alert.TextColor.ToAndroid ()); text.Text = alert.Text; if (alert.TextSize > 0) { text.TextSize = alert.TextSize; } drawable.SetColor (alert.BorderColor.ToAndroid ()); drawable.SetCornerRadius (alert.BorderWidth); main.SetBackground (drawable); //activity.ActionBar.Hide (); var actionBarHeight = activity.ActionBar.Height; var intent = alert.Intent; var p = new WindowManagerLayoutParams ( windowManager.DefaultDisplay.Width - intent * 2, (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight), WindowManagerTypes.SystemAlert, 0 | WindowManagerFlags.NotFocusable, Android.Graphics.Format.Translucent); var yOffset = alert.TopOffset; p.Gravity = GravityFlags.Top | GravityFlags.Left; p.X = intent; p.Y = alert.TopOffset + yOffset + (activity.ActionBar.IsShowing ? actionBarHeight : 0); p.Height = (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight); windowManager.AddView (_Layout, p); this._Layout.Touch += LayoutTouched; Task.Run (async() => { await Task.Delay(alert.Duration, this._Token.Token); if (this._Token != null && this._Token.IsCancellationRequested == false) { if(alert.FadeOut) { Xamarin.Forms.Device.BeginInvokeOnMainThread( () => { // this works this._fadeOut = ObjectAnimator.OfFloat(_Layout, "alpha", 1f, 0f); this._fadeOut.SetDuration(1000); this._fadeOut.AnimationEnd += _fadeOut_AnimationEnd; this._Set = new AnimatorSet(); this._Set.Play(_fadeOut); this._Set.Start(); }); } else { Stop(); } } }); }
public async Task Show(TopAlert alert) { await Stop(); this._Token = new CancellationTokenSource(); this._Delay = alert.Duration; var activity = Xamarin.Forms.Forms.Context as Android.App.Activity; IWindowManager windowManager = Xamarin.Forms.Forms.Context.GetSystemService(Android.App.Service.WindowService).JavaCast <IWindowManager>(); this._Layout = (LinearLayout)activity.LayoutInflater.Inflate(Resource.Layout.AlertBox, null, false); this._Layout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); var submain = this._Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout3); submain.SetBackgroundColor(alert.BackgroundColor.ToAndroid()); var main = _Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout1); var id = Xamarin.Forms.Forms.Context.Resources.GetIdentifier("alertborder", "drawable", Xamarin.Forms.Forms.Context.PackageName); Android.Graphics.Drawables.GradientDrawable drawable = Xamarin.Forms.Forms.Context.Resources.GetDrawable(id).JavaCast <Android.Graphics.Drawables.GradientDrawable>(); var text = submain.FindViewById <TextView> (Resource.Id.textView1); text.SetTextColor(alert.TextColor.ToAndroid()); text.Text = alert.Text; if (alert.TextSize > 0) { text.TextSize = alert.TextSize; } drawable.SetColor(alert.BorderColor.ToAndroid()); drawable.SetCornerRadius(alert.BorderWidth); main.SetBackground(drawable); //activity.ActionBar.Hide (); var actionBarHeight = activity.ActionBar.Height; var intent = alert.Intent; var p = new WindowManagerLayoutParams( windowManager.DefaultDisplay.Width - intent * 2, (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight), WindowManagerTypes.SystemAlert, 0 | WindowManagerFlags.NotFocusable, Android.Graphics.Format.Translucent); var yOffset = alert.TopOffset; p.Gravity = GravityFlags.Top | GravityFlags.Left; p.X = intent; p.Y = alert.TopOffset + yOffset + (activity.ActionBar.IsShowing ? actionBarHeight : 0); p.Height = (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight); windowManager.AddView(_Layout, p); this._Layout.Touch += LayoutTouched; Task.Run(async() => { await Task.Delay(alert.Duration, this._Token.Token); if (this._Token != null && this._Token.IsCancellationRequested == false) { if (alert.FadeOut) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { // this works this._fadeOut = ObjectAnimator.OfFloat(_Layout, "alpha", 1f, 0f); this._fadeOut.SetDuration(1000); this._fadeOut.AnimationEnd += _fadeOut_AnimationEnd; this._Set = new AnimatorSet(); this._Set.Play(_fadeOut); this._Set.Start(); }); } else { Stop(); } } }); }
public void Show(TopAlert alert) { _Instance.Value.Show(alert); }