Ejemplo n.º 1
0
        private void createAds(AndroidGameWindow window)
        {
            var frameLayout  = new FrameLayout(this);
            var linearLayout = new LinearLayout(this);

            linearLayout.Orientation = Orientation.Horizontal;
            linearLayout.SetGravity(Android.Views.GravityFlags.Right | Android.Views.GravityFlags.Bottom);

            frameLayout.AddView(window);

            adView          = new AdView(this);
            adView.AdUnitId = AD_UNIT_ID;
            adView.AdSize   = AdSize.Banner;

            linearLayout.AddView(adView);
            frameLayout.AddView(linearLayout);
            SetContentView(frameLayout);

            try
            {
                // Initiate a generic request.
                var adRequest = new AdRequest.Builder()
                                .AddTestDevice(AdRequest.DeviceIdEmulator)
                                .AddTestDevice(TEST_DEVICE_ID)
                                .Build();

                // Load the adView with the ad request.
                adView.LoadAd(adRequest);
            }
            catch (Exception ex)
            {
                // your error logging goes here
            }
        }
Ejemplo n.º 2
0
        public override bool Initialize(GameHost host)
        {
            if (!base.Initialize(host))
            {
                return(false);
            }

            if (!(host.Window is AndroidGameWindow androidWindow))
            {
                return(false);
            }

            window = androidWindow;

            window.CursorStateChanged += updatePointerCapture;

            // it's possible that Android forcefully released capture if we were unfocused.
            // so we update here when we get focus again.
            View.FocusChange += (sender, args) =>
            {
                if (args.HasFocus)
                {
                    updatePointerCapture();
                }
            };

            UseRelativeMode.BindValueChanged(_ => updatePointerCapture());

            Enabled.BindValueChanged(enabled =>
            {
                if (enabled.NewValue)
                {
                    View.CapturedPointer += HandleCapturedPointer;
                    View.GenericMotion   += HandleGenericMotion;
                    View.Hover           += HandleHover;
                    View.KeyDown         += HandleKeyDown;
                    View.KeyUp           += HandleKeyUp;
                    View.Touch           += HandleTouch;
                }
                else
                {
                    View.CapturedPointer -= HandleCapturedPointer;
                    View.GenericMotion   -= HandleGenericMotion;
                    View.Hover           -= HandleHover;
                    View.KeyDown         -= HandleKeyDown;
                    View.KeyUp           -= HandleKeyUp;
                    View.Touch           -= HandleTouch;
                }

                updatePointerCapture();
            }, true);

            return(true);
        }
Ejemplo n.º 3
0
 internal TouchPanelState(GameWindow window)
 {
     Window = window;
 }
Ejemplo n.º 4
0
 internal TouchPanelState(AndroidGameWindow window)
 {
     Window = window;
 }
Ejemplo n.º 5
0
 public AndroidTouchEventManager(AndroidGameWindow androidGameWindow)
 {
     _gameWindow = androidGameWindow;
 }
Ejemplo n.º 6
0
 public MonoGameView(Context context, AndroidGameWindow window, Game game) : base(context)
 {
     _touchManager = new AndroidTouchEventManager(window);
     _gameWindow   = window;
     _game         = game;
 }
Ejemplo n.º 7
0
 public AndroidTouchEventManager(AndroidGameWindow androidGameWindow)
 {
     _gameWindow = androidGameWindow;
 }