Esempio n. 1
0
        /// <summary>
        /// Returns display orientation given its display number.
        /// </summary>
        /// <param name="displayNumber">Display number.</param>
        /// <returns>Display orientation, or default (portrait) if displayNumber does not match any display.</returns>
        public DisplayOrientation GetOrientation(int displayNumber)
        {
            DisplayInfo di = GetDisplayInfo(displayNumber);

            if (di != null)
            {
                return(di.DisplayOrientation);
            }

            return(DisplayOrientation.Portrait);
        }
Esempio n. 2
0
        /// <summary>
        ///  Get Display Information for the given display number.
        /// </summary>
        /// <param name="displayNumber">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <returns>
        /// A <see cref="DisplayInfo"/>
        /// </returns>
        public override DisplayInfo GetDisplayInfo(int displayNumber)
        {
            DisplayInfo displayInfo = null;

            if(displayNumber<=GetDisplays()) {
                // Display number is a valid number.
                displayInfo = new DisplayInfo();
                displayInfo.DisplayNumber = displayNumber;
                displayInfo.DisplayBitDepth = DisplayBitDepth.Bpp24; // default bit depth for iphone/ipad.
                displayInfo.DisplayType = DisplayType.Primary;

                // Default is MainScreen
                UIScreen screen = UIScreen.MainScreen;

                // display orientation is by default the device orientation.
                displayInfo.DisplayOrientation = GetDeviceOrientation();

                if(GetOSHardwareInfo().Version.IndexOf("iPad")>=0) {
                    UIScreen[] screens = UIScreen.Screens;
                    screen = screens[displayNumber-1];

                    // TODO how to get orientation from external display, if case.
                    // DisplayOrientation ??
                    // DisplayType.External ??
                }

                displayInfo.DisplayY = (int) screen.Bounds.Height;
                displayInfo.DisplayX = (int) screen.Bounds.Width;

                if(displayInfo.DisplayOrientation==DisplayOrientation.Landscape) {
                    displayInfo.DisplayY = (int) screen.Bounds.Width;
                    displayInfo.DisplayX = (int) screen.Bounds.Height;
                }
            }

            return displayInfo;
        }
Esempio n. 3
0
        /// <summary>
        /// Provides information of screens connected to the device. Display 1 is the primary.
        /// </summary>
        /// <returns>Display info array.</returns>
        private DisplayInfo[] GetDisplayInfoList()
        {
            List<DisplayInfo> list = new List<DisplayInfo>();
            int i = 1;
            foreach (var screen in Screen.AllScreens)
            {
                DisplayInfo di = new DisplayInfo();

                di.DisplayNumber = i;
                di.DisplayX = screen.WorkingArea.Width;
                di.DisplayY = screen.WorkingArea.Height;

                if (screen.Primary)
                {
                    di.DisplayType = DisplayType.Primary;
                }
                else
                {
                    di.DisplayType = DisplayType.External;
                }

                switch(screen.BitsPerPixel) {
                    case -1:
                        di.DisplayBitDepth = DisplayBitDepth.Unknown;
                        break; 
                    case 32:
                         di.DisplayBitDepth = DisplayBitDepth.Bpp32;
                         break;
                    case 24:
                        di.DisplayBitDepth = DisplayBitDepth.Bpp24;
                        break;
                    case 16:
                        di.DisplayBitDepth = DisplayBitDepth.Bpp16;
                        break;
                    default:
                        di.DisplayBitDepth = DisplayBitDepth.Bpp8;
                        break;
                }

                //Compare height and width of screen and act accordingly.
                if (di.DisplayY > di.DisplayX)
                {
                    di.DisplayOrientation = DisplayOrientation.Portrait;
                }
                else
                {
                    di.DisplayOrientation = DisplayOrientation.Landscape;
                }

                list.Add(di);
                i++;
            }

            return list.ToArray();
        }