Exemple #1
0
        private async void MDraggableView_Touch(object sender, View.TouchEventArgs e)
        {
            float x = e.Event.RawX;
            float y = e.Event.RawY;

            View touchedView = sender as View;

            switch (e.Event.Action)
            {
            case MotionEventActions.Down:
                mXInit = touchedView.GetX() - x;
                mYInit = touchedView.GetY() - y;
                break;

            case MotionEventActions.Move:
                touchedView.Animate()
                .X(e.Event.RawX + mXInit)
                .Y(e.Event.RawY + mYInit)
                .SetDuration(0)
                .Start();

                break;

            default:
                break;
            }

            mRoot.Invalidate();

            await mChatHubProxy.Invoke("DragView", new object[] { e.Event.RawX, mXInit, e.Event.RawY, mYInit });
        }
        public void Move(object sender, ElapsedEventArgs e)
        {
            Activity.RunOnUiThread(() =>
            {
                for (int i = 0; i < _lBalls.Count; i++)
                {
                    int w   = _lBalls[i].Width;
                    float x = _lBalls[i].GetX();
                    float y = _lBalls[i].GetY();
                    if (x < 0 || x > _maxX - w)
                    {
                        _dx[i] = -_dx[i];
                    }
                    if (y < 0 || y > _maxY - w)
                    {
                        _dy[i] = -_dy[i];
                    }
                    x += _dx[i];
                    y += _dy[i];

                    _lBalls[i].SetX(x);
                    _lBalls[i].SetY(y);
                    _ball.Invalidate();
                }
            });
        }
Exemple #3
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mRoot          = FindViewById <FrameLayout>(Resource.Id.root);
            mDraggableView = FindViewById(Resource.Id.draggableView);

            mDraggableView.Touch += MDraggableView_Touch;

            HubConnection hubConnection = new HubConnection("http://cforbeginners.com:901");

            mChatHubProxy = hubConnection.CreateHubProxy("ChatHub");

            try
            {
                await hubConnection.Start();
            }
            catch (Exception)
            {
                //handle errors
            }

            mChatHubProxy.On <float, float, float, float>("UpdateView", (rawX, initX, rawY, initY) =>
            {
                RunOnUiThread(() =>
                {
                    mDraggableView.Animate()
                    .X(rawX + initX)
                    .Y(rawY + initY)
                    .SetDuration(0)
                    .Start();

                    mRoot.Invalidate();
                });
            });
        }