Esempio n. 1
0
        public void ReleaseAllTouchesTest(bool testBetween)
        {
            //Create multiple touches in different states

            //Start a touch
            var pos  = new Vector2(1);
            var pos2 = new Vector2(2);

            _tps.AddEvent(1, TouchLocationState.Pressed, pos);

            var state = _tps.GetState();

            Assert.AreEqual(1, state.Count);

            var initialTouch = state[0];

            Assert.AreEqual(TouchLocationState.Pressed, initialTouch.State);
            Assert.AreEqual(pos, initialTouch.Position);

            _tps.AddEvent(2, TouchLocationState.Pressed, pos2);

            if (testBetween)
            {
                state = _tps.GetState();
                Assert.AreEqual(2, state.Count);
                var touch  = state.First(x => x.Id == initialTouch.Id);
                var touch2 = state.First(x => x.Id != initialTouch.Id);

                Assert.AreEqual(TouchLocationState.Moved, touch.State);
                Assert.AreEqual(TouchLocationState.Pressed, touch2.State);
            }

            //Call ReleaseAllTouches
            _tps.ReleaseAllTouches();

            //If we saw the second touch happen then we should see it be released, otherwise it will be in pressed, then in released next time
            state = _tps.GetState();
            Assert.AreEqual(2, state.Count);

            Assert.AreEqual(testBetween ? TouchLocationState.Released : TouchLocationState.Pressed, state.Single(p => p.Id != initialTouch.Id).State);
            Assert.AreEqual(TouchLocationState.Released, state.Single(p => p.Id == initialTouch.Id).State);

            if (!testBetween)
            {
                state = _tps.GetState();
                Assert.AreEqual(1, state.Count);

                Assert.AreEqual(TouchLocationState.Released, state[0].State);
            }

            //Then it should be empty
            state = _tps.GetState();
            Assert.AreEqual(0, state.Count);
        }
Esempio n. 2
0
        private void SetDisplayOrientation(DisplayOrientation value)
        {
            if (value != _currentOrientation)
            {
                DisplayOrientation supported            = GetEffectiveSupportedOrientations();
                ScreenOrientation  requestedOrientation = ScreenOrientation.Unspecified;
                bool wasPortrait     = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitDown;
                bool requestPortrait = false;

                bool didOrientationChange = false;
                // Android 2.3 and above support reverse orientations
                int sdkVer = (int)Android.OS.Build.VERSION.SdkInt;
                if (sdkVer >= 10)
                {
                    // Check if the requested orientation is supported. Default means all are supported.
                    if ((supported & value) != 0)
                    {
                        didOrientationChange = true;
                        _currentOrientation  = value;
                        switch (value)
                        {
                        case DisplayOrientation.LandscapeLeft:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Landscape;
                            requestPortrait      = false;
                            break;

                        case DisplayOrientation.LandscapeRight:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReverseLandscape;
                            requestPortrait      = false;
                            break;

                        case DisplayOrientation.Portrait:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Portrait;
                            requestPortrait      = true;
                            break;

                        case DisplayOrientation.PortraitDown:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReversePortrait;
                            requestPortrait      = true;
                            break;
                        }
                    }
                }
                else
                {
                    // Check if the requested orientation is either of the landscape orientations and any landscape orientation is supported.
                    if ((value == DisplayOrientation.LandscapeLeft || value == DisplayOrientation.LandscapeRight) &&
                        ((supported & (DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight)) != 0))
                    {
                        didOrientationChange = true;
                        _currentOrientation  = DisplayOrientation.LandscapeLeft;
                        requestedOrientation = ScreenOrientation.Landscape;
                        requestPortrait      = false;
                    }
                    // Check if the requested orientation is either of the portrain orientations and any portrait orientation is supported.
                    else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitDown) &&
                             ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitDown)) != 0))
                    {
                        didOrientationChange = true;
                        _currentOrientation  = DisplayOrientation.Portrait;
                        requestedOrientation = ScreenOrientation.Portrait;
                        requestPortrait      = true;
                    }
                }

                if (didOrientationChange)
                {
                    // Android doesn't fire Released events for existing touches
                    // so we need to clear them out.
                    if (wasPortrait != requestPortrait)
                    {
                        TouchPanelState.ReleaseAllTouches();
                    }

                    OnOrientationChanged();
                }
            }
        }