private void TouchEffect_TouchAction(object sender, TouchActionEventArgs e)
        {
            // We don't care if Middle or Right Mouse button is used.
            if ((e.MouseButton == TouchMouseButton.Middle) ||
                (e.MouseButton == TouchMouseButton.Right))
            {
                return;
            }

            Boolean cancelLongPress = false;
            Boolean startLongPress  = false;

            switch (e.Type)
            {
            case TouchActionType.Cancelled:
            case TouchActionType.Entered:
            case TouchActionType.Exited:
            case TouchActionType.Released:
                if (longPressStarted)
                {
                    cancelLongPress = true;
                }
                break;

            case TouchActionType.Moved:
                if (longPressStarted)
                {
                    cancelLongPress = (Math.Abs(e.Location.X - longPressInitialLocation.X) > 15) ||
                                      (Math.Abs(e.Location.Y - longPressInitialLocation.Y) > 15);
                }
                break;

            case TouchActionType.Pressed:
                cancelLongPress = true;
                startLongPress  = true;
                break;
            }

            if (cancelLongPress)
            {
                longPressStarted = false;
                if (cancelableDelayForLongPress != null)
                {
                    cancelableDelayForLongPress.Cancel();
                    cancelableDelayForLongPress = null;
                }
            }

            if (startLongPress)
            {
                longPressStarted            = true;
                longPressInitialLocation    = e.Location; // Here e.Location get the press Location relatively to the MessageContext UI Component
                cancelableDelayForLongPress = CancelableDelay.StartAfter(Helper.DELAY_FOR_LONG_PRESS, () => NeedToDisplayActionMenu(sender, longPressInitialLocation));
            }
        }
Esempio n. 2
0
        private void CheckIfUpdateModelForDateTimePurpose(DateTime dt)
        {
            int delay;

            // do we have a DateTime more recent ?
            if (dt.ToUniversalTime() > mostRecentDateTimeMessage.ToUniversalTime())
            {
                delay = Helper.GetRefreshDelay(dt);
                mostRecentDateTimeMessage = dt;

                // If there is not already a delay in progress, we ask a new one
                if (delayUpdateForDateTimePurpose == null)
                {
                    log.LogDebug("[CheckIfUpdateModelForDateTimePurpose] - Start Delay:[{0}] - DateTime:[{1}] - CASE MORE RECENT", delay, dt.ToString("o"));
                    delayUpdateForDateTimePurpose = CancelableDelay.StartAfter(delay * 1000, () => UpdateModelForDateTimePurpose());
                }
                // There is already a delay running. So we need to cancel it and update display now
                else
                {
                    log.LogDebug("[CheckIfUpdateModelForDateTimePurpose] - Stop current delay and ask update now - DateTime:[{0}]", dt.ToString("o"));

                    // We stop the current "update delay"
                    delayUpdateForDateTimePurpose.Cancel();

                    // We ask the update now
                    //TO DO - must be a UI THREAD TO YPDATE THE MODEL !!!
                    UpdateModelForDateTimePurpose();
                }
            }
            // We have not a more recent DateTime
            else
            {
                delay = Helper.GetRefreshDelay(mostRecentDateTimeMessage);
                // If there is not already a delay in progress, we ask a new one
                if ((delayUpdateForDateTimePurpose == null) || (!delayUpdateForDateTimePurpose.IsRunning()))
                {
                    log.LogDebug("[CheckIfUpdateModelForDateTimePurpose] - Start Delay:[{0}] - DateTime:[{1}] - CASE OLDER", delay, dt.ToString("o"));
                    delayUpdateForDateTimePurpose = CancelableDelay.StartAfter(delay * 1000, () => UpdateModelForDateTimePurpose());
                }
            }
        }