Exemple #1
0
        public ToastOverlay(CGRect frame, string LabelText) : base(frame)
        {
            // configurable bits
            BackgroundColor  = UIColor.Black;
            Alpha            = 0.75f;
            AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

            nfloat labelHeight = 22;
            nfloat labelWidth  = Frame.Width;

            // derive the center x and y
            //nfloat centerX = Frame.Width / 2;
            //nfloat centerY = Frame.Height / 2;

            // create and configure the "Loading Data" label
            loadingLabel = new UILabel(new CGRect(
                                           0f, 0f,
                                           labelWidth,
                                           labelHeight
                                           ));
            loadingLabel.BackgroundColor  = UIColor.Clear;
            loadingLabel.TextColor        = UIColor.White;
            loadingLabel.Font             = UIFont.FromName("Arial", 14f);
            loadingLabel.Text             = LabelText;
            loadingLabel.TextAlignment    = UITextAlignment.Center;
            loadingLabel.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
            AddSubview(loadingLabel);

            NSTimer fadeout = NSTimer.CreateTimer(2, timer => Hide());

            NSRunLoop.Main.AddTimer(fadeout, NSRunLoopMode.Common);
        }
Exemple #2
0
 public CustomAnnotationProvider(PSPDFDocument doc)
 {
     document = doc;
     // add timer in a way so it works while we're dragging pages
     timer = NSTimer.CreateTimer(1, this, new Selector("timerFired:"), null, true);
     NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
 }
Exemple #3
0
        public void CreateTimer_NewSignature()
        {
            bool result = false;
            var  evt    = new ManualResetEvent(false);

            NSTimer timer = null;

            using (timer = NSTimer.CreateTimer(0.1f, (NSTimer t) => {
                result = t != null && t.Handle == timer.Handle;
                evt.Set();
            })) {
                var thread = new Thread(() => {
                    NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Default);
                    NSRunLoop.Current.RunUntil(NSRunLoopMode.Default, NSDate.Now.AddSeconds(5));
                })
                {
                    IsBackground = true,
                };
                thread.Start();

                Assert.IsTrue(evt.WaitOne(TimeSpan.FromSeconds(5)), "WaitOne");
                Assert.IsTrue(result, "result");
                thread.Join();
            }
        }
Exemple #4
0
        private void StartTimer(long duration)
        {
//            PostDelayed(_dismissRunnable, duration);
            _timer = NSTimer.CreateTimer(duration, timer =>
            {
                _dismissRunnable();
            });
        }
Exemple #5
0
        void StartDismissTimer(TimeSpan duration)
        {
#if __UNIFIED__
            _fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker());
#else
            _fadeoutTimer = NSTimer.CreateTimer(duration, DismissWorker);
#endif
            NSRunLoop.Main.AddTimer(_fadeoutTimer, NSRunLoopMode.Common);
        }
Exemple #6
0
        private void HideToast()
        {
            UIView.BeginAnimations(null, IntPtr.Zero);
            this.view.Alpha = 0;
            UIView.CommitAnimations();
            var timer = NSTimer.CreateTimer(TimeSpan.FromSeconds(0.5), t => this.HideToast());

            NSRunLoop.Main.AddTimer(timer, 0);
        }
 void ScheduleReset()
 {
     if (timer != null)
     {
         timer.Invalidate();
     }
     timer = NSTimer.CreateTimer(TimeSpan.FromSeconds(1), ResetAllGroups);
     NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
 }
Exemple #8
0
        public void Scan(TimeSpan scanTime)
        {
            StartScan();

            NSTimer timer = NSTimer.CreateTimer(scanTime, () => {
                StopScan();
            });

            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Default);
        }
Exemple #9
0
 public void AnimationDidStart(CABasicAnimation anim)
 {
     if (_animationTimer == null)
     {
         const double timeInterval = 1.0f / 60.0f;
         _animationTimer = NSTimer.CreateTimer(timeInterval, this, new Selector("updateTimerFired:"), null, true);
         NSRunLoop.Main.AddTimer(_animationTimer, NSRunLoopMode.Common);
     }
     _animations.Add(anim);
 }
Exemple #10
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            sfImageEditor       = new SfImageEditor(new CGRect(View.Frame.Location.X, 60, View.Frame.Size.Width, View.Frame.Size.Height - 60));
            sfImageEditor.Image = UIImage.FromBundle("Images/ImageEditor/WhiteImage.png");
            var sampleTimer = NSTimer.CreateTimer(TimeSpan.FromSeconds(3.0), delegate
            {
                ReadFile();
                Dispose();
            });

            sampleTimer.Fire();
            sfImageEditor.ImageSaving += (sender, e) =>
            {
                e.Cancel = true;
                var    stream    = e.Stream;
                var    byteArray = ReadFully(stream);
                NSData data      = NSData.FromArray(byteArray);

                if (_model.Name == "Create New")
                {
                    var count = _collectionView.DataSource.Count;
                    SerializationModel item = new SerializationModel()
                    {
                        Name                 = itemName != "" ? itemName : ValidateName(),
                        ImageAlignment       = UIViewContentMode.Center,
                        ImageBackgroundColor = UIColor.FromRGB(255, 255, 255),
                        id        = count - 1,
                        EditsStrm = null
                    };
                    item.EditsStrm      = sfImageEditor.SaveEdits();
                    item.Image          = UIImage.LoadFromData(data);
                    item.ImageAlignment = UIViewContentMode.ScaleAspectFit;
                    _serializationViewModel.ModelCollection.Add(item);
                    EditsViewModel.EditsCollection.Add(new EditsModel()
                    {
                        Name = item.Name
                    });
                }
                else
                {
                    _model.EditsStrm      = sfImageEditor.SaveEdits();
                    _model.Image          = UIImage.LoadFromData(data);
                    _model.ImageAlignment = UIViewContentMode.ScaleAspectFit;
                }


                _collectionView.DataSource = _serializationViewModel.ModelCollection;
            };

            this.View.Add(sfImageEditor);
        }
        private void ShowCopiedView()
        {
            NSTimer timer;

            TagCopiedView.Hidden = false;

            //Some action
            UIPasteboard.General.String = HashText.Text;

            timer = NSTimer.CreateTimer(2, delegate
            {
                TagCopiedView.Hidden = true;
            });
            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
        }
Exemple #12
0
        //        private bool IsNavigationBarHidden(ViewGroup root)
        //        {
        //            if (Build.VERSION.SdkInt < BuildVersionCodes.JellyBean)
        //                return false;
        //
        //            var viewFlags = (int) root.WindowSystemUiVisibility;
        //            return (viewFlags & (int) SystemUiFlags.LayoutHideNavigation) ==
        //                (int) SystemUiFlags.LayoutHideNavigation;
        //        }

        private void StartTimer()
        {
//            PostDelayed(_dismissRunnable, GetDuration());
            _timer = NSTimer.CreateTimer(GetDuration(), timer =>
            {
                _dismissRunnable();
            });

//            #if __UNIFIED__
//            _fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker ());
//            #else
//            _fadeoutTimer = NSTimer.CreateTimer (duration, DismissWorker);
//            #endif

            NSRunLoop.Main.AddTimer(_timer, NSRunLoopMode.Common);
        }
Exemple #13
0
        public IDisposable StartTimer(TimeSpan interval, Action callback)
        {
            NSTimer timer = NSTimer.CreateTimer(interval, t =>
            {
                if (t.IsValid)
                {
                    callback();
                }
            });

            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
            return(Disposable.Create(() =>
            {
                timer.Invalidate();
                timer.Dispose();
            }));
        }
Exemple #14
0
        public void ShowSingleWithTimeout(string message, int seconds)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                var alert = new UIAlertView()
                {
                    Message = message,
                    Alpha   = 1.0f
                };
                NSTimer tmr;
                alert.Show();

                tmr = NSTimer.CreateTimer(seconds, delegate
                {
                    alert.DismissWithClickedButtonIndex(0, true);
                    alert = null;
                });
                NSRunLoop.Main.AddTimer(tmr, NSRunLoopMode.Common);
            });
        }
Exemple #15
0
        public void ShowToast(string message)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                var alert = new UIAlertView()
                {
                    Message = message,
                    Alpha   = 1.0f
                };
                alert.Frame = new CoreGraphics.CGRect(alert.Frame.X, UIScreen.MainScreen.Bounds.Y * 0.7f, alert.Frame.Width, alert.Frame.Height);
                NSTimer tmr;
                alert.Show();

                tmr = NSTimer.CreateTimer(1.5, delegate
                {
                    alert.DismissWithClickedButtonIndex(0, true);
                    alert = null;
                });
                NSRunLoop.Main.AddTimer(tmr, NSRunLoopMode.Common);
            });
        }
Exemple #16
0
        /// <summary>
        /// Expands an item. This automatically collapses a previously opened item.
        /// </summary>
        /// <param name="id">Identifier of the item to expand.</param>
        /// <param name="animated">If set to <c>true</c>, animate.</param>
        public void ExpandItem(string id, bool animated)
        {
            if (string.Compare(id, this.ExpandedItemId, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return;
            }

            if (this.timer != null)
            {
                this.timer.Invalidate();
                this.timer = null;
            }

            // Collapse current open item before expanding another one.
            this.Collapse(animated);

            KSMenuItemHostView hostView = null;

            foreach (KSMenuItemHostView subview in this.Subviews)
            {
                if (string.Compare(id, subview.ItemId, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    hostView = subview;
                    break;
                }
            }

            if (hostView == null)
            {
                return;
            }
            ;

            this.ExpandedItemId = id;

            if (animated)
            {
                UIView.Animate(ANIMATION_EXPAND_SECONDS, 0f, UIViewAnimationOptions.CurveEaseOut, delegate
                {
                    hostView.ExpandSubElements();
                },
                               delegate
                {
                    float newWidth = hostView.Bounds.Width;
                    if (this.Mode == STAPLEMENU_MODE.Right)
                    {
                        this.Frame = new RectangleF(this.Superview.Bounds.Width - newWidth, this.Frame.Y, newWidth, this.Bounds.Height);
                    }
                    else
                    {
                        this.Frame = new RectangleF(0, this.Frame.X, newWidth, this.Bounds.Height);
                    }
                });
            }
            else
            {
                hostView.ExpandSubElements();
                float newWidth = hostView.Bounds.Width;
                if (this.Mode == STAPLEMENU_MODE.Right)
                {
                    this.Frame = new RectangleF(this.Superview.Bounds.Width - newWidth, this.Frame.Y, newWidth, this.Bounds.Height);
                }
                else
                {
                    this.Frame = new RectangleF(0, this.Frame.X, newWidth, this.Bounds.Height);
                }
            }

            // Create a timer that collapses the expanded item after a while.
            this.timer = NSTimer.CreateTimer(AUTO_CLOSE_TIMEOUT_SECS, () => this.Collapse(animated));
            NSRunLoop.Current.AddTimer(this.timer, NSRunLoopMode.Default);
        }
 void StartDismissTimer(TimeSpan duration)
 {
     _fadeoutTimer = NSTimer.CreateTimer(duration, DismissWorker);
     NSRunLoop.Main.AddTimer(_fadeoutTimer, NSRunLoopMode.Common);
 }
Exemple #18
0
        public void Show(ToastType type)
        {
            var image    = this.theSettings().images[type];
            var font     = UIFont.SystemFontOfSize(this.theSettings().fontSize);
            var str      = new NSAttributedString(this.text, font);
            var textSize = str.GetBoundingRect(new CGSize(260, 50), NSStringDrawingOptions.UsesLineFragmentOrigin, null).Size;

            textSize.Width = textSize.Width + 5;

            var label =
                new UILabel(new CGRect(0, 0, textSize.Width + this.LeftAndRightPadding,
                                       textSize.Height + this.TopAndBottomPadding))
            {
                BackgroundColor = UIColor.Clear,
                TextColor       = UIColor.White,
                TextAlignment   = UITextAlignment.Left,
                Text            = this.text,
                Lines           = 0,
                Font            = UIFont.SystemFontOfSize(this.theSettings().fontSize)
            };

            if (this.theSettings().useShadow)
            {
                label.ShadowColor  = UIColor.DarkGray;
                label.ShadowOffset = new CGSize(1, 1);
            }

            var button = new UIButton(UIButtonType.Custom);

            if (image != null)
            {
                button.Frame = this.ToastFrameForImageSize(image.Size, textSize);

                /*switch (this.theSettings().imageLocation)
                 * {
                 *  case ToastImageLocation.Left:*/
                label.TextAlignment = UITextAlignment.Left;
                label.Center        = new CGPoint(image.Size.Width + (this.LeftAndRightPadding * 2) + (((button.Frame.Size.Width - image.Size.Width) - (this.LeftAndRightPadding * 2)) / 2), button.Frame.Size.Height / 2);

                /*       break;
                 *
                 * case ToastImageLocation.Top:
                 *     label.TextAlignment = UITextAlignment.Center;
                 *     label.Center = new CGPoint(button.Frame.Size.Width / 2, (image.Size.Height + (this.TopAndBottomPadding * 2)) + (((button.Frame.Size.Height - image.Size.Height) - (this.TopAndBottomPadding * 2)) / 2));
                 *     break;
                 * }*/
            }
            else
            {
                button.Frame = new CGRect(0, 0, textSize.Width + (this.LeftAndRightPadding * 2), textSize.Height + (this.TopAndBottomPadding * 2));
                label.Center = new CGPoint(button.Frame.Size.Width / 2, button.Frame.Size.Height / 2);
            }

            var rect8 = label.Frame;

            rect8.X     = (nfloat)Math.Ceiling((double)rect8.X);
            rect8.Y     = (nfloat)Math.Ceiling((double)rect8.Y);
            label.Frame = rect8;
            button.AddSubview(label);

            if (image != null)
            {
                var view = new UIImageView(image);
                view.Frame = this.FrameForImage(type, button.Frame);
                button.AddSubview(view);
            }

            button.BackgroundColor    = UIColor.FromRGBA(this.theSettings().bgRed, this.theSettings().bgGreen, this.theSettings().bgBlue, this.theSettings().bgAlpha);
            button.Layer.CornerRadius = this.theSettings().cornerRadius;

            var window      = UIApplication.SharedApplication.Windows[0];
            var empty       = CGPoint.Empty;
            var orientation = UIApplication.SharedApplication.StatusBarOrientation;

            switch (this.theSettings().gravity)
            {
            case ToastGravity.Top:
                empty = new CGPoint(window.Frame.Size.Width / 2, 0x2d);
                break;

            case ToastGravity.Bottom:
                empty = new CGPoint(window.Frame.Size.Width / 2, window.Frame.Size.Height - 0x2d);
                break;

            case ToastGravity.Center:
                empty = new CGPoint(window.Frame.Size.Width / 2, window.Frame.Size.Height / 2);
                break;
            }

            empty         = new CGPoint(empty.X + this.theSettings().offsetLeft, empty.Y + this.theSettings().offsetTop);
            button.Center = empty;
            button.Frame  = RectangleFExtensions.Integral(button.Frame);

            var timer = NSTimer.CreateTimer(TimeSpan.FromSeconds(this.theSettings().duration / 1000), t => this.HideToast());

            NSRunLoop.Main.AddTimer(timer, 0);
            button.Tag = (nint)CURRENT_TOAST_TAG;

            var view2 = window.ViewWithTag((nint)CURRENT_TOAST_TAG);

            if (view2 != null)
            {
                view2.RemoveFromSuperview();
            }

            button.Alpha = 0;
            window.AddSubview(button);
            UIView.BeginAnimations(null, IntPtr.Zero);
            button.Alpha = 1;
            UIView.CommitAnimations();
            this.view = button;
            button.AddTarget(new EventHandler(this.HideToastEventHandler), UIControlEvent.TouchDown);
            ToastSetting.SharedSettings = null;
        }
Exemple #19
0
        public void PerformCalibration(EventHandler <CalibrationProgressEventArgs> handler)
        {
            if (!isCalibrating)
            {
                isCalibrating = true;
                rangedBeacons.Clear();
                percentComplete = 0.0f;

                ProgressHandler = handler;

                locationManager.StartRangingBeacons(region);
                timer = NSTimer.CreateTimer(20.0f, (r) => {
                    locationManager.StopRangingBeacons(region);

                    DispatchQueue.DefaultGlobalQueue.DispatchAsync(new Action(delegate {
                        NSError error = null;
                        List <CLBeacon> allBeacons = new List <CLBeacon> ();
                        int measuredPower          = 0;
                        if (!isCalibrating)
                        {
                            error = new CalibrationCancelledError();
                        }
                        else
                        {
                            foreach (CLBeacon[] beacons in rangedBeacons)
                            {
                                if (beacons.Length > 1)
                                {
                                    error = new CalibrationCancelledError();
                                    break;
                                }
                                else
                                {
                                    allBeacons.AddRange(beacons);
                                }
                            }

                            if (allBeacons.Count == 0)
                            {
                                error = new CalibrationCancelledError();
                            }
                            else
                            {
                                allBeacons.Sort(delegate(CLBeacon x, CLBeacon y) {
                                    return((x.ValueForKey(Rssi) as NSNumber).CompareTo(y.ValueForKey(Rssi)));
                                });
                                float power        = 0;
                                int number         = 0;
                                int outlierPadding = (int)(allBeacons.Count * 0.1f);
                                for (int k = outlierPadding; k < allBeacons.Count - (outlierPadding * 2); k++)
                                {
                                    power += ((NSNumber)allBeacons [k].ValueForKey(Rssi)).FloatValue;
                                    number++;
                                }
                                measuredPower = (int)power / number;
                            }
                        }

                        DispatchQueue.MainQueue.DispatchAsync(delegate {
                            CalibrationCompletionHandler(this, new CalibrationCompletedEventArgs()
                            {
                                MeasurePower = measuredPower,
                                Error        = error
                            });
                        });

                        isCalibrating = false;
                        rangedBeacons.Clear();
                    }));
                });
                NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Default);
            }
        }