Пример #1
0
        public void TransitionOptionsBackwardAnimationSet()
        {
            tlog.Debug(tag, $"TransitionOptionsBackwardAnimationSet START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            View view = new View()
            {
                Size  = new Size(150, 300),
                Color = Color.Green
            };

            testingTarget.AnimatedTarget   = view;
            testingTarget.EnableTransition = true;

            TransitionAnimation backwordAnimation = new TransitionAnimation(300);

            testingTarget.BackwardAnimation = backwordAnimation;

            var result = testingTarget.BackwardAnimation;

            Assert.AreEqual(300, result.DurationMilliSeconds, "should be equal!");

            view.Dispose();
            backwordAnimation.Dispose();
            testingTarget.Dispose();
            tlog.Debug(tag, $"TransitionOptionsBackwardAnimationSet END (OK)");
        }
Пример #2
0
        public void NUIApplicationSendLaunchRequest()
        {
            tlog.Debug(tag, $"NUIApplicationSendLaunchRequest START");

            var testingTarget = new NUIApplication();

            Assert.IsNotNull(testingTarget, "Should be not null.");
            Assert.IsInstanceOf <NUIApplication>(testingTarget, "Should be an instance of Window type.");

            TransitionOptions transitionOption = new TransitionOptions(Window.Instance);

            testingTarget.TransitionOptions   = transitionOption;
            transitionOption.EnableTransition = true;

            var appControl = new Applications.AppControl(true);

            try
            {
                testingTarget.SendLaunchRequest(appControl);
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            transitionOption.Dispose();
            testingTarget.Dispose();
            tlog.Debug(tag, $"NUIApplicationSendLaunchRequest END (OK)");
        }
        public override void Apply(CstTransition cstTransition)
        {
            var transitionOptions = new TransitionOptions();

            if (cstTransition.IsEpsilon)
            {
                cstTransition.StartStateName.Visit(this);
                cstTransition.EndStateName.Visit(this);

                transitionOptions.IsEpsilon  = true;
                transitionOptions.EndState   = (string)_buffer.Pop();
                transitionOptions.StartState = (string)_buffer.Pop();
            }

            else
            {
                cstTransition.StartStateName.Visit(this);
                cstTransition.Token.Visit(this);
                cstTransition.EndStateName.Visit(this);

                transitionOptions.IsEpsilon  = false;
                transitionOptions.EndState   = (string)_buffer.Pop();
                transitionOptions.Token      = (string)_buffer.Pop();
                transitionOptions.StartState = (string)_buffer.Pop();
            }

            _buffer.Push(transitionOptions);
        }
Пример #4
0
        void Initialize()
        {
            Window.Instance.KeyEvent += OnKeyEvent;
            uiCreator = new UICreator();
            uiCreator.CreateUI();

            TransitionOptions = new TransitionOptions(GetDefaultWindow());
            TransitionOptions.EnableTransition = true;
        }
Пример #5
0
        private IEnumerator CoTransitToNewState(StateMapping newState, TransitionOptions options)
        {
            // Cache this so that we can overwrite it and hijack a transition.
            _destinationState = newState;

            if (_currentState != null)
            {
                if (_currentState.layout.hasExitCoroutine)
                {
                    _exitCoroutine = _currentState.exitCoroutine();

                    // Don't wait for exit if we are overwriting
                    if (_exitCoroutine != null && (options & TransitionOptions.Overwrite) == 0)
                    {
                        yield return(_runner.StartCoroutine(_exitCoroutine));
                    }

                    _exitCoroutine = null;
                }
                else
                {
                    _currentState.exitCall();
                }

                _currentState.finallyCall();
            }

            _lastState      = _currentState;
            _currentState   = _destinationState;
            _stateChangedAt = Time.time;

            if (_currentState != null)
            {
                if (_currentState.layout.hasEnterCoroutine)
                {
                    _enterCoroutine = _currentState.enterCoroutine();

                    if (_enterCoroutine != null)
                    {
                        yield return(_runner.StartCoroutine(_enterCoroutine));
                    }

                    _enterCoroutine = null;
                }
                else
                {
                    _currentState.enterCall();
                }

                // Broadcast change only after enter transition has begun.
                Changed?.Invoke(_lastState.state != null ? (T)_lastState.state : default(T), (T)_currentState.state);
            }

            _isInTransition = false;
        }
Пример #6
0
        public void TransitionOptionsConstructorWithWindowInstance()
        {
            tlog.Debug(tag, $"TransitionOptionsConstructorWithWindowInstance START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            testingTarget.Dispose();
            tlog.Debug(tag, $"TransitionOptionsConstructorWithWindowInstance END (OK)");
        }
Пример #7
0
 public TransitionEntry(
     TransitionKind kind,
     NextTileHandler nextTile,
     CreateTransitionHandler createTransition,
     TransitionOptions options,
     TransitionDesaturationMode desaturationMode)
 {
     Kind             = kind;
     NextTile         = nextTile;
     CreateTransition = createTransition;
     Options          = options;
     DesaturationMode = desaturationMode;
     IsEnabled        = true;
 }
Пример #8
0
        public void TransitionOptionsEnableTransitionSet()
        {
            tlog.Debug(tag, $"TransitionOptionsEnableTransitionSet START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            testingTarget.EnableTransition = true;
            Assert.IsTrue(testingTarget.EnableTransition);

            testingTarget.Dispose();
            tlog.Debug(tag, $"TransitionOptionsEnableTransitionSet END (OK)");
        }
Пример #9
0
        public void TransitionOptionsTransitionWithChildGet()
        {
            tlog.Debug(tag, $"TransitionOptionsTransitionWithChildGet START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            var result = testingTarget.TransitionWithChild;

            Assert.IsFalse(result);

            testingTarget.Dispose();
            tlog.Debug(tag, $"TransitionOptionsTransitionWithChildGet END (OK)");
        }
Пример #10
0
        void Initialize()
        {
            Window.Instance.KeyEvent   += OnKeyEvent;
            Window.Instance.TouchEvent += OnTouchEvent;

            TextLabel text = new TextLabel("Callee");

            text.HorizontalAlignment = HorizontalAlignment.Center;
            text.VerticalAlignment   = VerticalAlignment.Center;
            text.TextColor           = Color.Red;
            text.PointSize           = 12.0f;
            text.HeightResizePolicy  = ResizePolicyType.FillToParent;
            text.WidthResizePolicy   = ResizePolicyType.FillToParent;
            Window.Instance.GetDefaultLayer().Add(text);

            TransitionOptions = new TransitionOptions(GetDefaultWindow());
            TransitionOptions.EnableTransition = true;
        }
Пример #11
0
        protected override void OnCreate()
        {
            base.OnCreate();
            window           = GetDefaultWindow();
            window.KeyEvent += OnKeyEvent;

            page = new XamlPage();
            page.PositionUsesPivotPoint = true;
            page.ParentOrigin           = ParentOrigin.TopLeft;
            page.PivotPoint             = PivotPoint.TopLeft;
            page.BackgroundColor        = Color.Black;
            page.Size = window.WindowSize;
            window.Add(page);

            TransitionOptions = new TransitionOptions(window);
            TransitionOptions.EnableTransition    = true;
            TransitionOptions.CallerScreenHidden += TransitionOptions_CallerScreenHidden;
            TransitionOptions.CallerScreenShown  += TransitionOptions_CallerScreenShown;
        }
Пример #12
0
        void Initialize()
        {
            Window.Instance.KeyEvent       += OnKeyEvent;
            Window.Instance.BackgroundColor = new Color(0.9f, 0.9f, 0.9f, 1.0f);

            uiCreator = new UICreator(this);
            uiCreator.CreateUI();

            TransitionOptions = new TransitionOptions(GetDefaultWindow());
            TransitionOptions.EnableTransition = true;

            fAnimation = new SeamlessForwardAnimation(uiCreator, 600);
            bAnimation = new SeamlessBackwardAnimation(uiCreator, 600);
            TransitionOptions.ForwardAnimation = fAnimation;
            //TransitionOptions.BackwardAnimation = bAnimation;

            TransitionOptions.AnimationInitialized += TransitionOptions_AnimationInitialized;
            //(launchBroker as SeamlessAnimator)?.SetUICreator(uiCreator);
        }
Пример #13
0
 public ChartConfiguration(ChartData data,
                           ChartAxis axis                 = null,
                           SizeOptions size               = null,
                           PaddingOptions padding         = null,
                           ColorOptions color             = null,
                           InteractionOptions interaction = null,
                           TransitionOptions transition   = null,
                           SubchartOptions subchart       = null,
                           ZoomOptions zoom               = null)
 {
     Data        = data;
     Axis        = axis;
     Size        = size;
     Padding     = padding;
     Color       = color;
     Interaction = interaction;
     Transition  = transition;
     Subchart    = subchart;
     Zoom        = zoom;
 }
Пример #14
0
        private void EnableAppTransition(bool isCustomAnimation = true)
        {
            TransitionOptions = new TransitionOptions(window);
            TransitionOptions.AnimatedTarget   = animationView;
            TransitionOptions.EnableTransition = true;

            if (isCustomAnimation)
            {
                //Set Custom Animation
                TransitionOptions.ForwardAnimation      = new SeamlessForward(400);
                TransitionOptions.BackwardAnimation     = new SeamlessBackward(400);
                TransitionOptions.AnimationInitialized += TransitionOptions_AnimationInitialized;
            }
            else
            {
                //Set Default Animation
                TransitionOptions.ForwardAnimation  = new SlideIn(600);
                TransitionOptions.BackwardAnimation = new SlideOut(600);
            }
        }
Пример #15
0
        public void TransitionOptionsDispose()
        {
            tlog.Debug(tag, $"TransitionOptionsDispose START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            try
            {
                testingTarget.Dispose();
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"TransitionOptionsDispose END (OK)");
        }
Пример #16
0
        public void NUIApplicationTransitionOptions()
        {
            tlog.Debug(tag, $"NUIApplicationTransitionOptions START");

            var testingTarget = new NUIApplication();

            Assert.IsNotNull(testingTarget, "Should be not null.");
            Assert.IsInstanceOf <NUIApplication>(testingTarget, "Should be an instance of Window type.");

            TransitionOptions transitionOption = new TransitionOptions(Window.Instance);

            testingTarget.TransitionOptions = transitionOption;

            var result = testingTarget.TransitionOptions;

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <TransitionOptions>(result, "Should be an instance of TransitionOptions type.");

            result.Dispose();
            transitionOption.Dispose();
            tlog.Debug(tag, $"NUIApplicationTransitionOptions END (OK)");
        }
Пример #17
0
        void Initialize()
        {
            Window.Instance.KeyEvent   += OnKeyEvent;
            Window.Instance.TouchEvent += OnTouchEvent;

            TextLabel text = new TextLabel("NUI Simple Caller Sample");

            text.HorizontalAlignment = HorizontalAlignment.Center;
            text.VerticalAlignment   = VerticalAlignment.Center;
            text.TextColor           = Color.Blue;
            text.PointSize           = 12.0f;
            text.HeightResizePolicy  = ResizePolicyType.FillToParent;
            text.WidthResizePolicy   = ResizePolicyType.FillToParent;
            Window.Instance.GetDefaultLayer().Add(text);


            TransitionOptions = new TransitionOptions(GetDefaultWindow());
            TransitionOptions.EnableTransition  = true;
            TransitionOptions.ForwardAnimation  = new SlideIn(300);
            TransitionOptions.BackwardAnimation = new SlideOut(300);

            ////TransitionOptions.AnimationStart += TransitionOptions_AnimationStart;
            ////TransitionOptions.AnimationFinished += TransitionOptions_AnimationFinished;
        }
Пример #18
0
        public void TransitionOptionsAnimatedTargetGet()
        {
            tlog.Debug(tag, $"TransitionOptionsAnimatedTargetGet START");

            var testingTarget = new TransitionOptions(Window.Instance);

            Assert.IsNotNull(testingTarget, "should not be null.");
            Assert.IsInstanceOf <TransitionOptions>(testingTarget, "should be an instance of TransitionOptions class!");

            View view = new View()
            {
                Size = new Size(30, 50)
            };

            testingTarget.AnimatedTarget = view;

            var result = testingTarget.AnimatedTarget;

            Assert.AreEqual(30, result.SizeWidth, "should be equal!");
            Assert.AreEqual(50, result.SizeHeight, "should be equal!");

            testingTarget.Dispose();
            tlog.Debug(tag, $"TransitionOptionsAnimatedTargetGet END (OK)");
        }
Пример #19
0
        public void slide(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize <string[]>(options)[0];
                transitionOptions = JsonHelper.Deserialize <TransitionOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // grab a screenshot
                WriteableBitmap bmp = new WriteableBitmap(browser, null);
                var width           = (int)bmp.PixelWidth;
                var height          = (int)bmp.PixelHeight;

                img.Source = bmp;

                img2        = new Image();
                img2.Source = bmp;

                // image animation
                img2.RenderTransform         = new TranslateTransform();
                DoubleAnimation imgAnimation = new DoubleAnimation();
                imgAnimation.Duration        = TimeSpan.FromMilliseconds(transitionOptions.duration);

                string animationAxis         = "X";
                double webviewAnimationFrom  = 0;
                int screenshotSlowdownFactor = 1;
                int webviewSlowdownFactor    = 1;
                int imgOrdering = 0;

                if (transitionOptions.direction == "left")
                {
                    screenshotSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom     = width;
                    imgAnimation.To          = -width / screenshotSlowdownFactor; // Application.Current.Host.Content.ActualWidth;
                }
                else if (transitionOptions.direction == "right")
                {
                    webviewSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom  = -width;
                    imgAnimation.To       = width; // Application.Current.Host.Content.ActualWidth;
                    imgOrdering           = 1;
                }
                else if (transitionOptions.direction == "up")
                {
                    animationAxis            = "Y";
                    screenshotSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom     = height;
                    imgAnimation.To          = -height / screenshotSlowdownFactor; // Application.Current.Host.Content.ActualHeight;
                }
                else if (transitionOptions.direction == "down")
                {
                    animationAxis         = "Y";
                    webviewSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom  = -height;
                    imgAnimation.To       = height; // Application.Current.Host.Content.ActualHeight;
                    imgOrdering           = 1;
                }

                // inserting the image at index 0 makes it appear below the webview,
                // but we need to set it to 1 first so the webview is hidden and can be updated
                cView.LayoutRoot.Children.Insert(1, img);
                cView.LayoutRoot.Children.Insert(imgOrdering, img2);


                // now load the new content
                if (transitionOptions.href != null && transitionOptions.href != "" && transitionOptions.href != "null")
                {
                    String to      = transitionOptions.href;
                    Uri currenturi = browser.Source;
                    string path    = currenturi.OriginalString;
                    if (to.StartsWith("#"))
                    {
                        if (path.StartsWith("//"))
                        {
                            path = path.Substring(2);
                        }
                                                if (path.Contains("#"))
                        {
                            path = path.Substring(0, path.IndexOf("#"));
                        }
                        to = path + to;
                    }
                    else
                    {
                        to = "www/" + to;
                    }
                    browser.Navigate(new Uri(to, UriKind.RelativeOrAbsolute));
                }

                Storyboard.SetTarget(imgAnimation, img2);
                Storyboard.SetTargetProperty(imgAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform." + animationAxis + ")"));


                browser.RenderTransform          = new TranslateTransform();
                DoubleAnimation webviewAnimation = new DoubleAnimation();
                webviewAnimation.Duration        = TimeSpan.FromMilliseconds(transitionOptions.duration);
                webviewAnimation.From            = webviewAnimationFrom / webviewSlowdownFactor;
                webviewAnimation.To = 0;
                Storyboard.SetTarget(webviewAnimation, browser);
                Storyboard.SetTargetProperty(webviewAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform." + animationAxis + ")"));


                Storyboard storyboard = new Storyboard();
                storyboard.Completed += slideAnimationCompleted;
                storyboard.Children.Add(imgAnimation);
                storyboard.Children.Add(webviewAnimation);

                this.Perform(delegate()
                {
                    cView.LayoutRoot.Children.Remove(img);
                    storyboard.Begin();
                }, transitionOptions.winphonedelay);
            });
        }
Пример #20
0
        public void flip(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize <string[]>(options)[0];
                transitionOptions = JsonHelper.Deserialize <TransitionOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // grab a screenshot
                WriteableBitmap bmp = new WriteableBitmap(browser, null);

                img2        = new Image();
                img2.Source = bmp;

                int direction = 1;
                DependencyProperty property = PlaneProjection.RotationYProperty;

                if (transitionOptions.direction == "right")
                {
                    direction = -1;
                }
                else if (transitionOptions.direction == "up")
                {
                    property  = PlaneProjection.RotationXProperty;
                    direction = -1;
                }
                else if (transitionOptions.direction == "down")
                {
                    property = PlaneProjection.RotationXProperty;
                }

                // Insert the screenshot above the webview (index 1)
                cView.LayoutRoot.Children.Insert(1, img2);

                // now load the new content
                if (transitionOptions.href != null && transitionOptions.href != "" && transitionOptions.href != "null")
                {
                    String to      = transitionOptions.href;
                    Uri currenturi = browser.Source;
                    string path    = currenturi.OriginalString;
                    if (to.StartsWith("#"))
                    {
                        if (path.StartsWith("//"))
                        {
                            path = path.Substring(2);
                        }
                                                if (path.Contains("#"))
                        {
                            path = path.Substring(0, path.IndexOf("#"));
                        }
                        to = path + to;
                        //Debug.WriteLine("browser will navigate to (a): " + to);
                    }
                    else
                    {
                        to = "www/" + to;
                        //Debug.WriteLine("browser will navigate to (b): " + to);
                    }
                    browser.Navigate(new Uri(to, UriKind.RelativeOrAbsolute));
                }

                TimeSpan duration = TimeSpan.FromMilliseconds(transitionOptions.duration);
                Storyboard sb     = new Storyboard();

                // animation for the screenshot
                DoubleAnimation imgAnimation = new DoubleAnimation()
                {
                    From     = 0,
                    To       = direction * 180,
                    Duration = new Duration(duration)
                };
                Storyboard.SetTargetProperty(imgAnimation, new PropertyPath(property));
                img2.Projection = new PlaneProjection();
                Storyboard.SetTarget(imgAnimation, img2.Projection);
                sb.Children.Add(imgAnimation);

                // animation for the webview
                DoubleAnimation webviewAnimation = new DoubleAnimation()
                {
                    From     = direction * -180,
                    To       = 0,
                    Duration = new Duration(duration)
                };
                Storyboard.SetTargetProperty(webviewAnimation, new PropertyPath(property));
                browser.Projection = new PlaneProjection();
                Storyboard.SetTarget(webviewAnimation, browser.Projection);
                sb.Children.Add(webviewAnimation);

                // perform the transition after the specified delay
                this.Perform(delegate()
                {
                    // remove the image halfway down the transition so we don't see the back of the image instead of the webview
                    this.Perform(delegate()
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            CordovaView cView2 = getCordovaView();
                            cView2.LayoutRoot.Children.Remove(img2);
                        });
                    }, transitionOptions.duration / 2);

                    sb.Begin();
                }, transitionOptions.winphonedelay);
            });
        }
Пример #21
0
        public void Transit(T newState, TransitionOptions options)
        {
            if (_stateLookup == null)
            {
                throw new Exception("States have not been configured, please call initialized before trying to set state");
            }

            StateMapping nextState = null;

            if (!_stateLookup.TryGetValue(newState, out nextState))
            {
                throw new Exception("No state with the name " + newState.ToString() + " can be found. Please make sure you are called the correct type the statemachine was initialized with");
            }

            // Self transition.
            if ((options & TransitionOptions.AllowSelfTransition) == 0)
            {
                if (_currentState == nextState)
                {
                    return;
                }
            }

            // Cancel any queued changes.
            if (_queuedChange != null)
            {
                _runner.StopCoroutine(_queuedChange);
                _queuedChange = null;
            }

            if ((options & TransitionOptions.Overwrite) == 0)
            {
                if (_isInTransition)
                {
                    // We are already exiting current state on our way to our previous target state
                    if (_exitCoroutine != null)
                    {
                        // Overwrite with our new target
                        _destinationState = nextState;
                        return;
                    }

                    // We are already entering our previous target state.
                    // Need to wait for that to finish and call the exit routine.
                    if (_enterCoroutine != null)
                    {
                        // Damn, I need to test this hard
                        _queuedChange = CoWaitForPreviousTranstionAndTransitToNext(nextState);
                        _runner.StartCoroutine(_queuedChange);
                        return;
                    }
                }
            }
            else
            {
                if (_currentTransition != null)
                {
                    _runner.StopCoroutine(_currentTransition);
                }

                if (_exitCoroutine != null)
                {
                    _runner.StopCoroutine(_exitCoroutine);
                }

                if (_enterCoroutine != null)
                {
                    _runner.StopCoroutine(_enterCoroutine);
                }
            }

            if ((_currentState != null && _currentState.layout.hasExitCoroutine) || nextState.layout.hasEnterCoroutine)
            {
                _isInTransition    = true;
                _currentTransition = CoTransitToNewState(nextState, options);
                _runner.StartCoroutine(_currentTransition);
            }
            else //Same frame transition, no coroutines are present
            {
                if (_currentState != null)
                {
                    _currentState.exitCall();
                    _currentState.finallyCall();
                }

                _lastState      = _currentState;
                _currentState   = nextState;
                _stateChangedAt = Time.time;

                if (_currentState != null)
                {
                    _currentState.enterCall();

                    Changed?.Invoke(_lastState.state != null ? (T)_lastState.state : default(T), (T)_currentState.state);
                }

                _isInTransition = false;
            }
        }
        public void flip(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize<string[]>(options)[0];
                transitionOptions = JsonHelper.Deserialize<TransitionOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // grab a screenshot
                WriteableBitmap bmp = new WriteableBitmap(browser, null);

                img2 = new Image();
                img2.Source = bmp;

                int direction = 1;
                DependencyProperty property = PlaneProjection.RotationYProperty;

                if (transitionOptions.direction == "right")
                {
                    direction = -1;
                }
                else if (transitionOptions.direction == "up")
                {
                    property = PlaneProjection.RotationXProperty;
                    direction = -1;
                }
                else if (transitionOptions.direction == "down")
                {
                    property = PlaneProjection.RotationXProperty;
                }

                // Insert the screenshot above the webview (index 1)
                cView.LayoutRoot.Children.Insert(1, img2);

                // now load the new content
                if (transitionOptions.href != null && transitionOptions.href != "" && transitionOptions.href != "null")
                {
                    String to = transitionOptions.href;
                    Uri currenturi = browser.Source;
                    string path = currenturi.OriginalString;
                    if (to.StartsWith("#"))
                    {
                        if (path.StartsWith("//"))
                        {
                            path = path.Substring(2);
                        }
                        if (path.Contains("#"))
                         {
                             path = path.Substring(0, path.IndexOf("#"));
                         }
                         to = path + to;
                    }
                    else
                    {
                      	to = path.Substring(0, path.LastIndexOf('/')+1) + to;
                    }
                    browser.Navigate(new Uri(to, UriKind.RelativeOrAbsolute));
                }

                TimeSpan duration = TimeSpan.FromMilliseconds(transitionOptions.duration);
                Storyboard sb = new Storyboard();
                sb.Completed += flipAnimationCompleted;

                // animation for the screenshot
                DoubleAnimation imgAnimation = new DoubleAnimation()
                {
                    From = 0,
                    To = direction * 180,
                    Duration = new Duration(duration)
                };
                Storyboard.SetTargetProperty(imgAnimation, new PropertyPath(property));
                img2.Projection = new PlaneProjection();
                Storyboard.SetTarget(imgAnimation, img2.Projection);
                sb.Children.Add(imgAnimation);

                // animation for the webview
                DoubleAnimation webviewAnimation = new DoubleAnimation()
                {
                    From = direction * -180,
                    To = 0,
                    Duration = new Duration(duration)
                };
                Storyboard.SetTargetProperty(webviewAnimation, new PropertyPath(property));
                browser.Projection = new PlaneProjection();
                Storyboard.SetTarget(webviewAnimation, browser.Projection);
                sb.Children.Add(webviewAnimation);

                // perform the transition after the specified delay
                this.Perform(delegate()
                {
                    // remove the image halfway down the transition so we don't see the back of the image instead of the webview
                    this.Perform(delegate()
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            CordovaView cView2 = getCordovaView();
                            cView2.LayoutRoot.Children.Remove(img2);
                        });
                    }, transitionOptions.duration / 2);

                    sb.Begin();
                }, transitionOptions.winphonedelay);
            });
        }
        public void slide(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize<string[]>(options)[0];
                transitionOptions = JsonHelper.Deserialize<TransitionOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // grab a screenshot
                WriteableBitmap bmp = new WriteableBitmap(browser, null);
                var width = (int)bmp.PixelWidth;
                var height = (int)bmp.PixelHeight;

                img.Source = bmp;

                img2 = new Image();
                img2.Source = bmp;

                // image animation
                img2.RenderTransform = new TranslateTransform();
                DoubleAnimation imgAnimation = new DoubleAnimation();
                imgAnimation.Duration = TimeSpan.FromMilliseconds(transitionOptions.duration);

                string animationAxis = "X";
                double webviewAnimationFrom = 0;
                int screenshotSlowdownFactor = 1;
                int webviewSlowdownFactor = 1;
                int imgOrdering = 0;

                if (transitionOptions.direction == "left")
                {
                    screenshotSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom = width;
                    imgAnimation.To = -width / screenshotSlowdownFactor; // Application.Current.Host.Content.ActualWidth;
                }
                else if (transitionOptions.direction == "right")
                {
                    webviewSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom = -width;
                    imgAnimation.To = width; // Application.Current.Host.Content.ActualWidth;
                    imgOrdering = 1;
                }
                else if (transitionOptions.direction == "up")
                {
                    animationAxis = "Y";
                    screenshotSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom = height;
                    imgAnimation.To = -height / screenshotSlowdownFactor; // Application.Current.Host.Content.ActualHeight;
                }
                else if (transitionOptions.direction == "down")
                {
                    animationAxis = "Y";
                    webviewSlowdownFactor = transitionOptions.slowdownfactor;
                    webviewAnimationFrom = -height;
                    imgAnimation.To = height; // Application.Current.Host.Content.ActualHeight;
                    imgOrdering = 1;
                }

                // inserting the image at index 0 makes it appear below the webview,
                // but we need to set it to 1 first so the webview is hidden and can be updated
                cView.LayoutRoot.Children.Insert(1, img);
                cView.LayoutRoot.Children.Insert(imgOrdering, img2);


                // now load the new content
                if (transitionOptions.href != null && transitionOptions.href != "" && transitionOptions.href != "null")
                {
                    String to = transitionOptions.href;
                    Uri currenturi = browser.Source;
                    string path = currenturi.OriginalString;
                    if (to.StartsWith("#"))
                    {
                        if (path.StartsWith("//"))
                        {
                            path = path.Substring(2);
                        }
                        if (path.Contains("#"))
                         {
                             path = path.Substring(0, path.IndexOf("#"));
                         }
                         to = path + to;
                    }
                    else
                    {
                      	to = path.Substring(0, path.LastIndexOf('/')+1) + to;
                    }
                    browser.Navigate(new Uri(to, UriKind.RelativeOrAbsolute));
                }

                Storyboard.SetTarget(imgAnimation, img2);
                Storyboard.SetTargetProperty(imgAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform." + animationAxis + ")"));


                browser.RenderTransform = new TranslateTransform();
                DoubleAnimation webviewAnimation = new DoubleAnimation();
                webviewAnimation.Duration = TimeSpan.FromMilliseconds(transitionOptions.duration);
                webviewAnimation.From = webviewAnimationFrom / webviewSlowdownFactor;
                webviewAnimation.To = 0;
                Storyboard.SetTarget(webviewAnimation, browser);
                Storyboard.SetTargetProperty(webviewAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform." + animationAxis + ")"));


                Storyboard storyboard = new Storyboard();
                storyboard.Completed += slideAnimationCompleted;
                storyboard.Children.Add(imgAnimation);
                storyboard.Children.Add(webviewAnimation);

                this.Perform(delegate()
                {
                    cView.LayoutRoot.Children.Remove(img);
                    storyboard.Begin();
                }, transitionOptions.winphonedelay);
            });
        }
Пример #24
0
 public TransitionEntry(
     TransitionKind kind,
     NextTileHandler nextTile, 
     CreateTransitionHandler createTransition, 
     TransitionOptions options, 
     TransitionDesaturationMode desaturationMode)
 {
     Kind = kind;
     NextTile = nextTile;
     CreateTransition = createTransition;
     Options = options;
     DesaturationMode = desaturationMode;
     IsEnabled = true;
 }