示例#1
0
        protected override void OnAttached()
        {
            // Get the Android View corresponding to the Element that the effect is attached to
            view = Control == null ? Container : Control;

            // Get access to the TouchEffect class in the .NET Standard library
            UITestDemo.TouchEffect touchEffect =
                (UITestDemo.TouchEffect)Element.Effects.
                FirstOrDefault(e => e is UITestDemo.TouchEffect);

            if (touchEffect != null && view != null)
            {
                viewDictionary.Add(view, this);

                formsElement = Element;

                libTouchEffect = touchEffect;

                // Save fromPixels function
                fromPixels = view.Context.FromPixels;

                // Set event handler on View
                view.Touch += OnTouch;
            }
        }
示例#2
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            btnClear.Clicked += BtnClear_Clicked;
            //btnInput.Clicked += BtnInput_Clicked;
            TouchEffect touchEffect = new TouchEffect();

            touchEffect.TouchAction += TouchEffect_TouchAction;
            bvTarget.Effects.Add(touchEffect);
        }
示例#3
0
        private void TouchEffect_TouchAction(object sender, TouchActionEventArgs args)
        {
            BoxView box = sender as BoxView;

            switch (args.Type)
            {
            case TouchActionType.Pressed:
                if (!dragDictionary.ContainsKey(box))
                {
                    dragDictionary.Add(box, new DragInfo(args.Id, args.Location));

                    TouchEffect touchEffect = (TouchEffect)box.Effects.FirstOrDefault(e => e is TouchEffect);
                    touchEffect.Capture = true;
                }
                break;

            case TouchActionType.Moved:
                if (dragDictionary.ContainsKey(box) && dragDictionary[box].Id == args.Id)
                {
                    Rectangle rect            = AbsoluteLayout.GetLayoutBounds(box);
                    Point     initialLocation = dragDictionary[box].PressPoint;
                    rect.X += args.Location.X - initialLocation.X;
                    rect.Y += args.Location.Y - initialLocation.Y;
                    AbsoluteLayout.SetLayoutBounds(box, rect);
                }
                break;

            case TouchActionType.Released:
                if (dragDictionary.ContainsKey(box) && dragDictionary[box].Id == args.Id)
                {
                    dragDictionary.Remove(box);
                    //show the result on the label
                    txtResult.Text += string.Format(" ({0},{1}) ", Math.Round(box.X, 2), Math.Round(box.Y, 2));
                }
                break;
            }
        }