public override void ViewWillDisappear(bool animated)
 {
     _unloadedCount++;
     _receiver?.Stop();
     base.ViewWillDisappear(animated);
 }
Esempio n. 2
0
        private static void RunAsMobileEnd()
        {
            Console.Title = "Walterlv Cloud Keyboard - Mobile";
            var inScreenCount = 0;

            // 模拟构造函数。
            var receiver = new CloudKeyboardReceiver(HostInfo.BaseUrl, "0");

            receiver.Typing    += OnReceived;
            receiver.Confirmed += OnConfirmed;
            receiver.Start();

            // 模拟消息循环。
            ConsoleKeyInfo key;

            do
            {
                key = Console.ReadKey(true);
            } while (key.Key != ConsoleKey.Escape);

            receiver.Stop();

            void OnReceived(object sender, TypingTextEventArgs e)
            {
                ClearCurrentDocument();
                SetDocument(e.Typing);
            }

            void OnConfirmed(object sender, TypingTextEventArgs e)
            {
                ClearCurrentDocument();

                inScreenCount++;
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("[上屏] ");
                Console.Write(e.Typing.Text);
                Console.ResetColor();
                Console.WriteLine();
            }

            void SetDocument(TypingText typing)
            {
                for (var i = 0; i < typing.Text.Length; i++)
                {
                    var c = typing.Text[i];
                    if (typing.CaretStartIndex <= i && typing.CaretEndIndex > i)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(c);
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.Write(c);
                    }
                }
            }

            void ClearCurrentDocument()
            {
                Console.CursorTop  = inScreenCount;
                Console.CursorLeft = 0;
                for (var i = 0; i < 320; i++)
                {
                    Console.Write(' ');
                }

                Console.CursorTop  = inScreenCount;
                Console.CursorLeft = 0;
            }
        }