Esempio n. 1
0
        protected override void OnAttached()
        {
            // Gesture touches
            gesture                  = new GestureTouchSam(this, null, View);
            View.TouchDelegate       = gesture;
            View.Clickable           = true;
            View.LongClickable       = true;
            View.SoundEffectsEnabled = true;

            // Animation tap
            overlayAnimation = new FrameLayout(Container.Context)
            {
                LayoutParameters = new ViewGroup.LayoutParams(-1, -1),
                Clickable        = false,
                Focusable        = false,
            };

            Container.AddView(overlayAnimation);
            Container.LayoutChange += OnViewLayoutChanged;
            overlayAnimation.BringToFront();

            if (IsSdk21)
            {
                tapColor = Touch.GetColor(Element).ToAndroid();
                overlayAnimation.Background = CreateRipple(tapColor);
            }

            // Updates
            UpdateAnimationColor();
            UpdateLongTapCommand();
            UpdateLongTapLatency();
        }
Esempio n. 2
0
        protected override void OnDetached()
        {
            if (IsDisposed)
            {
                return;
            }

            Container.RemoveView(overlayAnimation);
            Container.LayoutChange -= OnViewLayoutChanged;

            overlayAnimation.Pressed    = false;
            overlayAnimation.Foreground = null;
            overlayAnimation.Dispose();

            TimerDispose();

            if (IsSdk21)
            {
                ripple?.Dispose();
            }

            gesture.Dispose();
            gesture = null;
        }
Esempio n. 3
0
 internal GView(View view, GestureTouchSam gesture)
 {
     View    = view;
     Gesture = gesture;
 }
Esempio n. 4
0
            public override bool OnTouchEvent(MotionEvent e)
            {
                float x         = e.RawX;
                float y         = e.RawY;
                float internalX = e.GetX();
                float internalY = e.GetY();

                host.currentX = x;
                host.currentY = y;

                // Detect nestered gesture
                if (nestedGesture != null)
                {
                    nestedGesture.OnTouchEvent(e);

                    // Detect END for nestered gesture
                    if (e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up)
                    {
                        nestedGesture = null;
                    }

                    return(true);
                }

                // START
                if (e.Action == MotionEventActions.Down)
                {
                    if (!host.IsEnabled || isGestureProcessed)
                    {
                        return(true);
                    }

                    // Detect nested TouchSam gestures
                    var childs = host.GetNestedTouchs(view);
                    foreach (var item in childs)
                    {
                        if (host.IsViewInBounds(item.View, (int)x, (int)y))
                        {
                            nestedGesture = item.Gesture;
                            nestedGesture.OnTouchEvent(e);
                            return(true);
                        }
                    }

                    isGestureProcessed = true;
                    host.startX        = x;
                    host.startY        = y;
                    host.StartTap();
                    host.AnimationStart(internalX, internalY);

                    // Try start long tap timer
                    if (Touch.GetLongTap(host.Element) != null)
                    {
                        host.timer?.Stop();
                        host.timer?.Start();
                    }
                }
                // MOVE
                else if (e.Action == MotionEventActions.Move || e.Action == MotionEventActions.Scroll)
                {
                    if (!isGestureProcessed)
                    {
                        return(true);
                    }

                    float deltaX = Math.Abs(host.startX - x);
                    float deltaY = Math.Abs(host.startY - y);

                    if (deltaX > touchSlop || deltaY > touchSlop || !host.IsEnabled)
                    {
                        host.FinishTap();
                        host.AnimationEnd();
                        host.timer?.Stop();
                        isGestureProcessed = false;
                    }
                }
                // UP
                else if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Cancel)
                {
                    if (host.IsDisposed || !isGestureProcessed)
                    {
                        return(true);
                    }

                    isGestureProcessed = false;
                    host.AnimationEnd();
                    host.FinishTap();

                    if (e.Action == MotionEventActions.Up && host.IsEnabled)
                    {
                        // Tap sound :)
                        view.PlaySoundEffect(SoundEffects.Click);

                        if (host.IsViewInBounds(view, (int)e.RawX, (int)e.RawY))
                        {
                            if (Touch.GetLongTap(host.Element) == null)
                            {
                                host.Tap();
                            }
                            else if (host.timer == null || host.timer.Enabled)
                            {
                                host.Tap();
                            }
                        }
                    }

                    host.timer?.Stop();
                }

                return(true);
            }
Esempio n. 5
0
 public static void Preserve()
 {
     Touch.Preserve();
     GestureTouchSam.Preserve();
     GView.Preserve();
 }
Esempio n. 6
0
 public static void Init()
 {
     GestureTouchSam.Preserve();
     GView.Preserve();
 }