Ejemplo n.º 1
0
        public static AgentCoordinateMapper Create(AgentIdentity agentIdentity, Window window)
        {
            if (agentIdentity == null)
            {
                throw new ArgumentNullException(nameof(agentIdentity));
            }

            var agentType = agentIdentity.AgentType;

            switch (agentType)
            {
            case AgentType.Android:
                return(new WindowsAndroidCoordinateMapper(agentIdentity, window));

            case AgentType.WPF:
                return(new WpfCoordinateMapper(window));

            case AgentType.iOS:
                return(new iOSCoordinateMapper(agentIdentity, window));

            default:
                throw new NotSupportedException(
                          String.Format("AgentType {0} not supported", agentType));
            }
        }
        public WindowsAndroidCoordinateMapper(AgentIdentity agentIdentity, Window window)
        {
            // Sometimes, we fail to find the top-level XAP window in the UIAutomation tree. In practice,
            // a single retry appears to fix it. I've rounded up to 3 total tries. --SA
            var tries = 3;

            do
            {
                if (agentIdentity.DeviceManufacturer == "Xamarin")
                {
                    xapRect = GetXapBoundingRect();
                }
                else if (agentIdentity.DeviceManufacturer == "VS Emulator")
                {
                    xapRect = GetVsEmulatorBoundingRect();
                }
                else
                {
                    xapRect = GetGoogleEmulatorBoundingRect();
                }
                tries--;
            } while (xapRect.IsEmpty && tries > 0);

            // TODO: Better to throw? Or have some IsValid flag that gets set to false? Client shouldn't
            //       proceed with highlight if this happens. Use should be notified that something's up.
            if (xapRect.IsEmpty)
            {
                Log.Warning(TAG, "XAP screen rect not found. Coordinate mapping will fail.");
            }

            scale = agentIdentity.ScreenWidth / xapRect.Width;
            hostRectScaleFactor =
                PresentationSource.FromVisual(window).CompositionTarget.TransformToDevice.M11;
        }
Ejemplo n.º 3
0
        public iOSCoordinateMapper(AgentIdentity agentIdentity, Window window)
        {
            // Sometimes, we fail to find the top-level window in the UIAutomation tree. In practice,
            // a single retry appears to fix it. I've rounded up to 3 total tries. --SA
            var tries = 3;

            do
            {
                simRect = GetSimulatorRect();
                tries--;
            } while (simRect.IsEmpty && tries > 0);

            // TODO: Better to throw? Or have some IsValid flag that gets set to false? Client shouldn't
            //       proceed with highlight if this happens. Use should be notified that something's up.
            if (simRect.IsEmpty)
            {
                Log.Warning(TAG, "iOS Simulator screen rect not found. Coordinate mapping will fail.");
            }

            hostRectScaleFactor =
                PresentationSource.FromVisual(window).CompositionTarget.TransformToDevice.M11;
            scale = agentIdentity.ScreenWidth / simRect.Width;
        }