Пример #1
0
        public bool Click(int x, int y)
        {
            var data = new Bundle();

            data.AddItem("command", "click");
            data.AddItem("x", x.ToString());
            data.AddItem("y", y.ToString());

            try
            {
                return(_connection.SendAsync(data).Result);
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #2
0
        public bool TouchDown(int x, int y)
        {
            var data = new Bundle();

            data.AddItem("command", "down");
            data.AddItem("x", x.ToString());
            data.AddItem("y", y.ToString());

            try
            {
                var ret = _connection.SendAsync(data).Result;
                if (ret)
                {
                    _touchTriggered = true;
                    _x = x;
                    _y = y;

                    return(ret);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #3
0
        public bool PressKey(string key)
        {
            var data = new Bundle();

            data.AddItem("command", "presskey");
            data.AddItem("key", key);

            try
            {
                var ret = _connection.SendAsync(data).Result;
                if (ret)
                {
                    _key        = key;
                    _keyPressed = true;
                    return(ret);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #4
0
        public void SendMessage(string value, string time, string direction)
        {
            //string remoteAppId = "AndroidAPS.Tizen.Companion";
            //string remotePort = "bg_reading_port";

            //Log.Debug(TAG, "Create");
            //MessagePort _msgPort = new MessagePort("bg_reading_port", false);
            //Log.Debug(TAG, "MessagePort Create: " + _msgPort.PortName + "Trusted: " + _msgPort.Trusted);

            //Log.Debug(TAG, "sending message");
            //_msgPort.Listen();
            //var bundle = new Bundle();
            //bundle.AddItem("message", "144");
            //bundle.AddItem("value", value);
            //bundle.AddItem("time", time);
            //bundle.AddItem("direction", direction);
            try
            {
                MessagePort messagePort = new MessagePort("SenderPort", true);
                using (var message = new Bundle())
                {
                    message.AddItem("value", "144");
                    message.AddItem("time", "1585393739");
                    messagePort.Listen();
                    messagePort.Send(message, "org.tizen.example.AndroidAPS_CompanionXAML.Tizen.Watchface", "receiverPort");
                }
            }
            catch (Exception e)
            {
                Log.Debug(TAG, e.ToString());
            }
        }
Пример #5
0
        public App()
        {
            try
            {
                MessagePort messagePort = null;
                messagePort = new MessagePort(uiAppPortName, true);
                // You need to first call Listen even you need to send a message.
                messagePort.Listen();
                // Register MessageReceived event callback
                messagePort.MessageReceived += (s, e) => {
                    Console.WriteLine("UI application received a message");
                    if (e.Message.Contains("greetingReturn"))
                    {
                        Toast.DisplayText("Received:" + e.Message.GetItem("greetingReturn") + ", Array: " + BitConverter.ToInt32((byte[])e.Message.GetItem("intByteArray"), 0));
                    }
                };

                // The root page of your application
                MainPage = new CirclePage
                {
                    Content = new StackLayout
                    {
                        VerticalOptions = LayoutOptions.Center,
                        Children        =
                        {
                            new Label
                            {
                                HorizontalTextAlignment = TextAlignment.Center,
                                Text = "Talk over message port APIs"
                            },
                            new Button
                            {
                                Text    = "Send a message",
                                Command = new Command(() =>
                                {
                                    Bundle bundleToSend = new Bundle();
                                    bundleToSend.AddItem("greeting", "hello");
                                    bundleToSend.AddItem("intByteArray", BitConverter.GetBytes(1024 * 1024));

                                    try
                                    {
                                        // Need to call Listen() before calling Send
                                        messagePort.Send(bundleToSend, "org.tizen.example.ServiceApp", serviceAppPortName, false);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("Exception: " + e.Message + ", " + e);
                                        Toast.DisplayText("An exception occurs!!   " + e.Message + ",   " + e, 10000);
                                    }
                                })
                            }
                        }
                    }
                };
            } catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
Пример #6
0
            internal override void Make(Notification notification)
            {
                string replyKey = "__PARENT_INDEX__";

                if (Button != null)
                {
                    Interop.Notification.SetText(notification.Handle, NotificationText.InputButton, Button.Text, null, -1);
                    Interop.Notification.SetImage(notification.Handle, NotificationImage.TextInputButton, Button.ImagePath);

                    if (this.Button.Action != null && this.Button.Action.SafeAppControlHandle.IsInvalid == false)
                    {
                        Interop.Notification.SetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, this.Button.Action.SafeAppControlHandle);

                        if (this.ParentIndex != ButtonIndex.None)
                        {
                            Interop.Notification.SetEventHandler(notification.Handle, (int)this.ParentIndex, this.Button.Action.SafeAppControlHandle);
                        }
                    }
                }

                Bundle bundle = new Bundle();

                bundle.AddItem(replyKey, ((int)this.ParentIndex).ToString());
                Interop.Notification.SetExtensionData(notification.Handle, replyKey, bundle.SafeBundleHandle);

                Interop.Notification.SetPlaceHolderLength(notification.Handle, this.ReplyMax);
                Interop.Notification.SetText(notification.Handle, NotificationText.PlaceHolder, PlaceHolderText, null, -1);
            }
Пример #7
0
        public bool Drag(int xDown, int yDown, int xUp, int yUp)
        {
#if WATCH
            _steps = 100;
#endif
            var data = new Bundle();

            data.AddItem("command", "drag");
            data.AddItem("xDown", xDown.ToString());
            data.AddItem("yDown", yDown.ToString());
            data.AddItem("xUp", xUp.ToString());
            data.AddItem("yUp", yUp.ToString());
            data.AddItem("steps", _steps.ToString());

            try
            {
                return(_connection.SendAsync(data).Result);
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #8
0
        public bool TouchMove(int xDown, int yDown, int xUp, int yUp, int steps)
        {
            var data = new Bundle();

            data.AddItem("command", "move");
            data.AddItem("xDown", xDown.ToString());
            data.AddItem("yDown", yDown.ToString());
            data.AddItem("xUp", xUp.ToString());
            data.AddItem("yUp", yUp.ToString());
            data.AddItem("steps", steps.ToString());

            try
            {
                return(_connection.SendAsync(data).Result);
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #9
0
        public bool TouchUp(int x, int y)
        {
            var data = new Bundle();

            data.AddItem("command", "up");

            try
            {
                if (_touchTriggered)
                {
                    data.AddItem("x", _x.ToString());
                    data.AddItem("y", _y.ToString());
                    var ret = _connection.SendAsync(data).Result;
                    if (ret)
                    {
                        _touchTriggered = false;
                        return(ret);
                    }
                }
                else
                {
                    data.AddItem("x", x.ToString());
                    data.AddItem("y", y.ToString());
                    return(_connection.SendAsync(data).Result);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #10
0
 private void MakeRequest(string cmd, string sentence, int requestid)
 {
     if (_connectionState == ConnectedState.Connected)
     {
         using (Bundle b = new Bundle())
         {
             b.AddItem("command", cmd);
             b.AddItem("info", sentence);
             b.AddItem("request_id", requestid.ToString());
             _msg.Send(b);
             b.Dispose();
         }
     }
     else if (_connectionState == ConnectedState.Connecting)
     {
         throw new InvalidOperationException("natural language service is connecting");
     }
     else
     {
         throw new InvalidOperationException("disconnected from natural language service");
     }
 }
Пример #11
0
        protected override void OnCreate()
        {
            // Start this service.
            base.OnCreate();
            // Create a MessagePort object.
            messagePort = new MessagePort(serviceAppPortName, false);
            // Register an event handler for MessagePort
            messagePort.MessageReceived += (s, e) => {
                if (e.Message.Contains("greeting"))
                {
                    // Create a bundle to send with the message port message
                    Bundle bundleToSend = new Bundle();
                    // Add a string type bundle message
                    bundleToSend.AddItem("greetingReturn", e.Message.GetItem("greeting") + " world");
                    // Add a byte array type bundle message
                    bundleToSend.AddItem("intByteArray", (byte[])e.Message.GetItem("intByteArray"));

                    messagePort.Send(bundleToSend, "org.tizen.example.MessagePortSampleApp", uiAppPortName, true); // last argument should match type of receiver port(trusted or not).
                }
            };
            // Listen regiser this local message port so this must be called to Send
            messagePort.Listen();
        }
Пример #12
0
        public bool ReleaseKey(string key)
        {
            var data = new Bundle();

            data.AddItem("command", "releasekey");

            try
            {
                if (_keyPressed)
                {
                    data.AddItem("key", _key);
                    var ret = _connection.SendAsync(data).Result;
                    if (ret)
                    {
                        _keyPressed = false;
                        return(ret);
                    }
                }
                else
                {
                    data.AddItem("key", key);
                    return(_connection.SendAsync(data).Result);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #13
0
        public bool SendKeys(string[] keys)
        {
            var data = new Bundle();

            data.AddItem("command", "sendkeys");
            data.AddItem("keys", keys);

            try
            {
                return(_connection.SendAsync(data).Result);
            }
            catch (AggregateException ae)
            {
                ae.Handle(e => {
                    if (e is TimeoutException)
                    {
                        throw e;
                    }
                    return(e is TimeoutException);
                });
            }

            return(false);
        }
Пример #14
0
 private bool OnViewTouched(object sender, View.TouchEventArgs e)
 {
     if (e.Touch.GetState(0) == PointStateType.Down)
     {
         PointStateType state = e.Touch.GetState(0);
         if (state == PointStateType.Down)
         {
             Bundle bundle = new Bundle();
             bundle.AddItem("COUNT", "" + mCount);
             String encodedBundle = bundle.Encode();
             SetContentInfo(encodedBundle);
             mCount++;
         }
     }
     return(true);
 }
Пример #15
0
        void Initialize()
        {
            Window window = GetDefaultWindow();

            window.KeyEvent   += OnKeyEvent;
            window.TouchEvent += OnTouchEvent;

            rootView = new View();
            rootView.BackgroundColor = Color.White;
            rootView.Size            = Window.Instance.Size;
            rootView.PivotPoint      = PivotPoint.Center;
            window.GetDefaultLayer().Add(rootView);

            TextLabel sampleLabel = new TextLabel("Widget Viewer ");

            sampleLabel.FontFamily = "SamsungOneUI 500";
            sampleLabel.PointSize  = 8;
            sampleLabel.TextColor  = Color.Black;
            sampleLabel.SizeWidth  = 300;
            sampleLabel.PivotPoint = PivotPoint.Center;
            rootView.Add(sampleLabel);

            Bundle bundle = new Bundle();

            bundle.AddItem("COUNT", "1");
            String encodedBundle = bundle.Encode();

            widgetWidth          = 500;
            widgetHeight         = 500;
            mWidgetView          = WidgetViewManager.Instance.AddWidget("*****@*****.**", encodedBundle, widgetWidth, widgetHeight, 0.0f);
            mWidgetView.Position = new Position(100, 100);
            window.GetDefaultLayer().Add(mWidgetView);

            mWidgetView2          = WidgetViewManager.Instance.AddWidget("*****@*****.**", encodedBundle, widgetWidth, widgetHeight, 0.0f);
            mWidgetView2.Position = new Position(100, widgetHeight + 110);
            window.GetDefaultLayer().Add(mWidgetView2);
        }
Пример #16
0
        void Initialize()
        {
            Window window = GetDefaultWindow();

            window.KeyEvent   += OnKeyEvent;
            window.TouchEvent += OnTouchEvent;

            rootView = new View();
            rootView.BackgroundColor = Color.White;
            rootView.Size            = Window.Instance.Size;
            rootView.PivotPoint      = PivotPoint.Center;
            window.GetDefaultLayer().Add(rootView);

            TextLabel sampleLabel = new TextLabel("Widget Viewer ");

            sampleLabel.FontFamily = "SamsungOneUI 500";
            sampleLabel.PointSize  = 8;
            sampleLabel.TextColor  = Color.Black;
            sampleLabel.SizeWidth  = 300;
            sampleLabel.PivotPoint = PivotPoint.Center;
            rootView.Add(sampleLabel);

            Bundle bundle = new Bundle();

            bundle.AddItem("COUNT", "1");
            String encodedBundle = bundle.Encode();

            WidgetViewManager widgetViewManager = new WidgetViewManager(this, this.ApplicationInfo.ApplicationId);

            WidgetView myWidgetView = widgetViewManager.AddWidget("*****@*****.**", encodedBundle, 600, 600, 3.0f);

            myWidgetView.Position = new Position(50, 100);
            window.GetDefaultLayer().Add(myWidgetView);

            myWidgetView.WidgetContentUpdated += OnWidgetContentUpdatedCB;
        }
Пример #17
0
        public static Bundle ToBundle(this IPersistedState?state)
        {
            var userInfo = new Bundle();

            var keyset = userInfo.Keys;

            if (keyset != null)
            {
                foreach (var k in keyset)
                {
                    userInfo?.GetItem <string>(k);
                }
            }

            if (state is not null)
            {
                foreach (var pair in state)
                {
                    userInfo.AddItem(pair.Key, pair.Value);
                }
            }

            return(userInfo);
        }