public static AppMsg MakeText( string text, int duration) { var appMsg = new AppMsg(text,duration); return appMsg; }
public void ClearMsg(AppMsg appMsg) { if (msgQueue.Contains(appMsg)) { appMsg.State = MsgState.Removed; } }
private void AddMsgToView(AppMsg appMsg) { UIApplication.SharedApplication.InvokeOnMainThread(() => { const int paddingh = 15; const int paddingv = 8; var size = new NSString (appMsg.Text).StringSize (UIFont.BoldSystemFontOfSize (14f), UIScreen.MainScreen.Bounds.Width - 80, UILineBreakMode.WordWrap); var inner = new UILabel( new CoreGraphics.CGRect( (UIScreen.MainScreen.Bounds.Width-size.Width)/2, // (UIScreen.MainScreen.Bounds.Bottom - size.Height) / 2, (UIScreen.MainScreen.Bounds.Bottom - size.Height-80), size.Width, size.Height ) ) { Text = appMsg.Text, Lines=0, Font = UIFont.BoldSystemFontOfSize(14f), TextColor = UIColor.White, BackgroundColor=UIColor.FromWhiteAlpha(0,0), TextAlignment = UITextAlignment.Center, LineBreakMode=UILineBreakMode.WordWrap }; inner.SizeToFit(); var rect=inner.Frame; var outRect=new CGRect(rect.X-paddingh,rect.Y-paddingv,rect.Width+paddingh*2,rect.Height+paddingv*2); var layout=new UIView(outRect){ BackgroundColor = UIColor.FromRGBA(0,0,0,0) }; layout.Layer.CornerRadius=8; layout.Layer.MasksToBounds=true; layout.Layer.BorderWidth=0; inner.Frame=new CGRect(paddingh,paddingv,rect.Width,rect.Height); layout.AddSubview(inner); UIApplication.SharedApplication.KeyWindow.AddSubview(layout); UIView.AnimateAsync(0.2,()=>{ layout.BackgroundColor=UIColor.FromRGBA(0,0,0,200); }); appMsg.State = MsgState.IsShowing; Task.Delay(appMsg.Duration-700).ContinueWith(r => UIApplication.SharedApplication.InvokeOnMainThread(() => { UIView.AnimateAsync(.5,()=>{ layout.BackgroundColor=layout.BackgroundColor.ColorWithAlpha(0); }).ContinueWith(t=>{ InvokeOnMainThread (()=>{ layout.Hidden=true; layout.RemoveFromSuperview(); }); }); appMsg.State = MsgState.Display; if (msgQueue.Count == 0) { needGoon = false; } allDone.Set(); })); }); }
public void Add(AppMsg appMsg) { msgQueue.Enqueue (appMsg); needGoon = true; if (!IsRunning) { Start (); allDone.Set(); } }