public static void ShowInmobi(DrawingSurfaceBackgroundGrid DrawingSurfaceBackground) { //SDKUtility.LogLevel = LogLevels.IMLogLevelDebug; // SDKUtility.LogLevel = LogLevels.IMLogLevelDebug; if (AdView == null) { AdView = new IMAdView(); AdView.AdSize = IMAdView.INMOBI_AD_UNIT_468x60; //Subscribe for IMAdView events AdView.OnAdRequestFailed += AdView_AdRequestFailed; AdView.OnAdRequestLoaded += AdView_AdRequestLoaded; AdView.OnDismissAdScreen += new EventHandler(AdView_DismissFullAdScreen); AdView.OnLeaveApplication += new EventHandler(AdView_LeaveApplication); AdView.OnShowAdScreen += new EventHandler(AdView_ShowFullAdScreen); AdView.VerticalAlignment = VerticalAlignment.Bottom; //Set the AppId. Provide you AppId AdView.AppId = AdsManager.STR_PUBLISH_ID_INMOBI; AdView.RefreshInterval = 20; AdView.AnimationType = IMAdAnimationType.SLIDE_IN_LEFT; IMAdRequest imAdRequest = new IMAdRequest(); AdView.LoadNewAd(imAdRequest); //Add IMAdView to Container DrawingSurfaceBackground.Children.Add(AdView); } }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="drawingSurface">The XAML drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> static public T Create(string launchParameters, DrawingSurfaceBackgroundGrid drawingSurface) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (drawingSurface == null) { throw new NullReferenceException("The drawing surface cannot be null!"); } WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = drawingSurface.ActualWidth; WindowsPhoneGameWindow.Height = drawingSurface.ActualHeight; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } // Hookup the handlers for updates and touch. drawingSurface.SetBackgroundContentProvider(new SurfaceUpdateHandler(game)); drawingSurface.SetBackgroundManipulationHandler(new SurfaceTouchHandler()); // Return the constructed, but not initialized game. return(game); }
/// <summary> /// Creates a new VideoElement /// </summary> /// <param name="videoUrl">URL to the vidoe (from Windows Phone's point of view)</param> /// <param name="tapSkipsVideo">If true, a tap will stop & remove the Video playback</param> /// <param name="autoPlay">If true, the video will immediatly start playback</param> public VideoElement(string videoUrl, bool tapSkipsVideo, bool autoPlay) { #if WINDOWS_PHONE Deployment.Current.Dispatcher.BeginInvoke( (Action)(() => { var frame = Application.Current.RootVisual as PhoneApplicationFrame; var currentPage = frame.Content as PhoneApplicationPage; _drawingSurfaceBackgroundElement = (DrawingSurfaceBackgroundGrid)currentPage.FindName("DrawingSurfaceBackground"); _mediaElement = new MediaElement(); _mediaElement.Height = Double.NaN; _mediaElement.Width = Double.NaN; _mediaElement.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; _mediaElement.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; _mediaElement.Stretch = System.Windows.Media.Stretch.UniformToFill; _mediaElement.Source = new Uri(videoUrl, UriKind.RelativeOrAbsolute); _mediaElement.MediaEnded += _mediaElement_MediaEnded; _mediaElement.MediaOpened += _mediaElement_MediaOpened; if (tapSkipsVideo) { _mediaElement.Tap += _mediaElement_Tap; _mediaElement.Tap += delegate { _drawingSurfaceBackgroundElement.Children.Remove(_mediaElement); }; } })); if (autoPlay) { this.Play(); } #endif }
private DrawingSurfaceBackgroundGrid BuildGrid() { var grid = new DrawingSurfaceBackgroundGrid(); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); var label = new TextBlock { Text = "Count: " + (count++) }; var button = new Button { Content = "Switch" }; button.Click += HandleButtonClick; grid.Children.Add(label); grid.Children.Add(button); button.SetValue(Grid.RowProperty, 1); Content = grid; return(grid); }
/// <summary> /// Binds the corresponding event handler to the provided <see cref="DrawingSurfaceBackgroundGrid"/> /// </summary> /// <param name="grid">An instance of <see cref="DrawingSurfaceBackgroundGrid"/> whose events needs to be bound to</param> /// <exception cref="ArgumentNullException">Is thrown if <paramref name="grid"/> is null</exception> private void BindManipulationEvents(DrawingSurfaceBackgroundGrid grid) { if (grid == null) throw new ArgumentNullException("grid"); grid.SetBackgroundManipulationHandler(this); // TODO: review if we need to unbind the handlers to avoid memory leaks grid.Unloaded += (_, __) => grid.SetBackgroundManipulationHandler(null); Disposing += (_, __) => grid.SetBackgroundManipulationHandler(null); }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="page">The XAML page containing the drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> /// static public T Create(string launchParameters, PhoneApplicationPage page) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (page == null) { throw new NullReferenceException("The page parameter cannot be null!"); } if (!(page.Content is DrawingSurfaceBackgroundGrid)) { throw new NullReferenceException("The drawing surface could not be found!"); } DrawingSurfaceBackgroundGrid drawingSurface = (DrawingSurfaceBackgroundGrid)page.Content; MediaElement mediaElement = null; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(page.Content); i++) { var child = VisualTreeHelper.GetChild(page.Content, i); if (child is MediaElement) { mediaElement = (MediaElement)child; } } if (mediaElement == null) { throw new NullReferenceException("The media element could not be found! Add it to the GamePage."); } Microsoft.Xna.Framework.Media.MediaPlayer._mediaElement = mediaElement; WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = drawingSurface.ActualWidth; WindowsPhoneGameWindow.Height = drawingSurface.ActualHeight; WindowsPhoneGameWindow.Page = page; page.BackKeyPress += Microsoft.Xna.Framework.Input.GamePad.GamePageWP8_BackKeyPress; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } // Hookup the handlers for updates and touch. drawingSurface.SetBackgroundContentProvider(new SurfaceUpdateHandler(game)); drawingSurface.SetBackgroundManipulationHandler(new SurfaceTouchHandler()); // Return the constructed, but not initialized game. return(game); }
public void SetGrid(object grid) { #if WINDOWS_PHONE baseGrid = (DrawingSurfaceBackgroundGrid)grid; #elif NETFX_CORE Debug.WriteLine(grid); backPanel = (SwapChainBackgroundPanel)grid; #else //Unity or some such return; #endif }
/// <summary> /// Initializes a new instance of the <see cref="GameContext" /> class. /// </summary> /// <param name="control">The control.</param> /// <param name="requestedWidth">Width of the requested.</param> /// <param name="requestedHeight">Height of the requested.</param> public GameContext(DrawingSurfaceBackgroundGrid control, int requestedWidth = 0, int requestedHeight = 0) { if (control == null) { throw new ArgumentNullException("control"); } Control = control; RequestedWidth = requestedWidth; RequestedHeight = requestedHeight; ContextType = GameContextType.WindowsPhoneBackgroundXaml; }
internal override void Initialize(object windowContext) { nativeWindow = windowContext; drawingSurfaceBackgroundGrid = windowContext as DrawingSurfaceBackgroundGrid; if (windowContext == null) { throw new ArgumentNullException("windowContext cannot be null under WP8", "windowContext"); } if (drawingSurfaceBackgroundGrid == null) { throw new ArgumentException("Expecting a DrawingSurfaceBackgroundGrid as a window context under WP8", "windowContext"); } }
/// <summary> /// Binds the corresponding event handler to the provided <see cref="DrawingSurfaceBackgroundGrid"/> /// </summary> /// <param name="grid">An instance of <see cref="DrawingSurfaceBackgroundGrid"/> whose events needs to be bound to</param> /// <exception cref="ArgumentNullException">Is thrown if <paramref name="grid"/> is null</exception> private void BindManipulationEvents(DrawingSurfaceBackgroundGrid grid) { if (grid == null) { throw new ArgumentNullException("grid"); } grid.SetBackgroundManipulationHandler(this); // TODO: review if we need to unbind the handlers to avoid memory leaks grid.Unloaded += (_, __) => grid.SetBackgroundManipulationHandler(null); Disposing += (_, __) => grid.SetBackgroundManipulationHandler(null); }
public static void ShowMobfoxAds(DrawingSurfaceBackgroundGrid DrawingSurfaceBackground) { if (adview == null) { adview = new MobFox.Ads.AdControl(); // adview.Name = "mobFoxadControl"; adview.NewAd += mobFoxadControl_NewAd; adview.NoAd += noAdsMobfox; adview.PublisherID = AdsManager.STR_PUBLISH_ID_MOBFOX; adview.VerticalAlignment = VerticalAlignment.Bottom; // adview.TestMode = true; DrawingSurfaceBackground.Children.Add(adview); } }
public void BindToControl(DrawingSurfaceBackgroundGrid backgroundGrid) { this.ThrowIfDisposed(); this.ThrowIfBound(); this.contentProvider = new DrawingSurfaceBackgroundContentProvider(this); this.manipulationHandler.ManipulationHostChanged += OnManipulationHostChanged; backgroundGrid.SetBackgroundContentProvider(this.contentProvider); backgroundGrid.SetBackgroundManipulationHandler(this.manipulationHandler); this.IsBound = true; }
public static void ShowInnerActive(DrawingSurfaceBackgroundGrid DrawingSurfaceBackground) { string AppID =AdsManager.STR_PUBLISH_ID_INNER_ACTIVE; Dictionary<InneractiveAd.IaOptionalParams, string> optionalParams = new Dictionary<InneractiveAd.IaOptionalParams, string>(); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_Ad_Alignment, InneractiveAd.IaAdAlignment.BOTTOM_CENTER.ToString()); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdWidth, "480"); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdHeight, "50"); iaBanner = new InneractiveAd(AppID, InneractiveAd.IaAdType.IaAdType_Banner, 60, optionalParams); iaBanner.AdReceived += new InneractiveAd.IaAdReceived(InneractiveAd_AdReceived); iaBanner.AdFailed += new InneractiveAd.IaAdFailed(InneractiveAd_AdFailed); iaBanner.DefaultAdReceived += new InneractiveAd.IaDefaultAdReceived(InneractiveAd_DefaultAdReceived); iaBanner.AdClicked += new InneractiveAd.IaAdClicked(InneractiveAd_AdClicked); DrawingSurfaceBackground.Children.Add(iaBanner); }
public static void ShowInnerActive(DrawingSurfaceBackgroundGrid DrawingSurfaceBackground) { string AppID = AdsManager.STR_PUBLISH_ID_INNER_ACTIVE; Dictionary <InneractiveAd.IaOptionalParams, string> optionalParams = new Dictionary <InneractiveAd.IaOptionalParams, string>(); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_Ad_Alignment, InneractiveAd.IaAdAlignment.BOTTOM_CENTER.ToString()); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdWidth, "480"); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdHeight, "50"); iaBanner = new InneractiveAd(AppID, InneractiveAd.IaAdType.IaAdType_Banner, 60, optionalParams); iaBanner.AdReceived += new InneractiveAd.IaAdReceived(InneractiveAd_AdReceived); iaBanner.AdFailed += new InneractiveAd.IaAdFailed(InneractiveAd_AdFailed); iaBanner.DefaultAdReceived += new InneractiveAd.IaDefaultAdReceived(InneractiveAd_DefaultAdReceived); iaBanner.AdClicked += new InneractiveAd.IaAdClicked(InneractiveAd_AdClicked); DrawingSurfaceBackground.Children.Add(iaBanner); }
internal override void Switch(GameContext context) { isInitialized = false; drawingSurfaceBackgroundGrid.Loaded -= DrawingSurfaceBackgroundGridOnLoaded; drawingSurfaceBackgroundGrid.Unloaded -= drawingSurfaceBackgroundGrid_Unloaded; drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(null); drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)context.Control; BindDrawingSurfaceBackgroundGridEvents(); // TODO: check if this can cause issues as event "Loaded" never gets called drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(this); currentDevice = null; currentDeviceContext = null; }
private DrawingSurfaceBackgroundGrid BuildGrid() { var grid = new DrawingSurfaceBackgroundGrid(); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); var label = new TextBlock { Text = "Count: " + (count++) }; var button = new Button { Content = "Switch" }; button.Click += HandleButtonClick; grid.Children.Add(label); grid.Children.Add(button); button.SetValue(Grid.RowProperty, 1); Content = grid; return grid; }
public static void showAds(DrawingSurfaceBackgroundGrid _DrawingSurfaceBackground,int index) { DrawingSurfaceBackground = _DrawingSurfaceBackground; switch (index) { case INDEX_INMOBI: Ads.AdsInmobi.ShowInmobi(_DrawingSurfaceBackground); break; case INDEX_MOBFOX: Ads.AdsMobfox.ShowMobfoxAds(_DrawingSurfaceBackground); break; case INDEX_INNER_ACTIVE: Ads.AdsInnerActive.ShowInnerActive(_DrawingSurfaceBackground); break; // case INDEX_MILLENIAL_MEDIA: // Ads.AdsMillenialMedia.ShowMillenialMedia(_DrawingSurfaceBackground); // break; } }
public static void showAds(DrawingSurfaceBackgroundGrid _DrawingSurfaceBackground, int index) { DrawingSurfaceBackground = _DrawingSurfaceBackground; switch (index) { case INDEX_INMOBI: Ads.AdsInmobi.ShowInmobi(_DrawingSurfaceBackground); break; case INDEX_MOBFOX: Ads.AdsMobfox.ShowMobfoxAds(_DrawingSurfaceBackground); break; case INDEX_INNER_ACTIVE: Ads.AdsInnerActive.ShowInnerActive(_DrawingSurfaceBackground); break; // case INDEX_MILLENIAL_MEDIA: // Ads.AdsMillenialMedia.ShowMillenialMedia(_DrawingSurfaceBackground); // break; } }
/// <summary> /// Creates a native Windows Phone MediaElement and immediatly starts playback. /// </summary> /// <param name="videoUrl">URL to the vidoe (from Windows Phone's point of view)</param> /// <param name="tapSkipsVideo">If true, a tap will stop & remove the Video playback</param> private static void PlayVideoFullscreenOnUIThread(string videoUrl, bool tapSkipsVideo) { #if WINDOWS_PHONE var frame = Application.Current.RootVisual as PhoneApplicationFrame; var currentPage = frame.Content as PhoneApplicationPage; DrawingSurfaceBackgroundGrid drawingSurfaceBackgroundElement = (DrawingSurfaceBackgroundGrid)currentPage.FindName("DrawingSurfaceBackground"); MediaElement videoPlayBackElement = new MediaElement(); videoPlayBackElement.Height = Double.NaN; videoPlayBackElement.Width = Double.NaN; videoPlayBackElement.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; videoPlayBackElement.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; videoPlayBackElement.Stretch = System.Windows.Media.Stretch.UniformToFill; videoPlayBackElement.Source = new Uri(videoUrl, UriKind.RelativeOrAbsolute); if (tapSkipsVideo) { videoPlayBackElement.Tap += delegate { drawingSurfaceBackgroundElement.Children.Remove(videoPlayBackElement); }; } drawingSurfaceBackgroundElement.Children.Add(videoPlayBackElement); videoPlayBackElement.Play(); #endif }
/// <summary> /// Creates a new VideoElement /// </summary> /// <param name="videoUrl">URL to the vidoe (from Windows Phone's point of view)</param> /// <param name="tapSkipsVideo">If true, a tap will stop & remove the Video playback</param> /// <param name="autoPlay">If true, the video will immediatly start playback</param> public VideoElement(string videoUrl, bool tapSkipsVideo, bool autoPlay) { #if WINDOWS_PHONE Deployment.Current.Dispatcher.BeginInvoke( (Action)(() => { var frame = Application.Current.RootVisual as PhoneApplicationFrame; var currentPage = frame.Content as PhoneApplicationPage; _drawingSurfaceBackgroundElement = (DrawingSurfaceBackgroundGrid)currentPage.FindName("DrawingSurfaceBackground"); _mediaElement = new MediaElement(); _mediaElement.Height = Double.NaN; _mediaElement.Width = Double.NaN; _mediaElement.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; _mediaElement.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; _mediaElement.Stretch = System.Windows.Media.Stretch.UniformToFill; _mediaElement.Source = new Uri(videoUrl, UriKind.RelativeOrAbsolute); _mediaElement.MediaEnded += _mediaElement_MediaEnded; _mediaElement.MediaOpened +=_mediaElement_MediaOpened; if (tapSkipsVideo) { _mediaElement.Tap += _mediaElement_Tap; _mediaElement.Tap += delegate { _drawingSurfaceBackgroundElement.Children.Remove(_mediaElement); }; } })); if (autoPlay) { this.Play(); } #endif }
internal override void Initialize(GameContext gameContext) { drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid) gameContext.Control; }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="page">The XAML page containing the drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> /// static public T Create(string launchParameters, PhoneApplicationPage page) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (page == null) { throw new NullReferenceException("The page parameter cannot be null!"); } UIElement drawingSurface = page.Content as DrawingSurfaceBackgroundGrid; MediaElement mediaElement = null; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(page.Content); i++) { var child = VisualTreeHelper.GetChild(page.Content, i); if (child is MediaElement) { mediaElement = (MediaElement)child; } else if (drawingSurface == null && child is DrawingSurface) { drawingSurface = (DrawingSurface)child; } } if (!(drawingSurface is DrawingSurfaceBackgroundGrid) && !(drawingSurface is DrawingSurface)) { throw new NullReferenceException("The drawing surface could not be found!"); } if (mediaElement == null) { throw new NullReferenceException("The media element could not be found! Add it to the GamePage."); } Microsoft.Xna.Framework.Media.MediaPlayer._mediaElement = mediaElement; WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = ((FrameworkElement)drawingSurface).ActualWidth; WindowsPhoneGameWindow.Height = ((FrameworkElement)drawingSurface).ActualHeight; WindowsPhoneGameWindow.Page = page; Microsoft.Xna.Framework.Audio.SoundEffect.InitializeSoundEffect(); page.BackKeyPress += Microsoft.Xna.Framework.Input.GamePad.GamePageWP8_BackKeyPress; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } SurfaceTouchHandler surfaceTouchHandler = new SurfaceTouchHandler(); if (drawingSurface is DrawingSurfaceBackgroundGrid) { // Hookup the handlers for updates and touch. DrawingSurfaceBackgroundGrid drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)drawingSurface; drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(new DrawingSurfaceBackgroundContentProvider(game)); drawingSurfaceBackgroundGrid.SetBackgroundManipulationHandler(surfaceTouchHandler); } else { var drawingSurfaceUpdateHandler = new DrawingSurfaceUpdateHandler(game); DrawingSurface ds = (DrawingSurface)drawingSurface; RoutedEventHandler onLoadedHandler = (object sender, RoutedEventArgs e) => { if (sender != ds) { return; } if (initializedSurfaces.ContainsKey(ds) == false) { // Hook-up native component to DrawingSurface ds.SetContentProvider(drawingSurfaceUpdateHandler.ContentProvider); ds.SetManipulationHandler(surfaceTouchHandler); // Make sure surface is not initialized twice... initializedSurfaces.Add(ds, true); } }; // Don't wait for loaded event here since control might // be loaded already. onLoadedHandler(ds, null); ds.Unloaded += OnDrawingSurfaceUnloaded; ds.Loaded += onLoadedHandler; } // Return the constructed, but not initialized game. return(game); }
internal override void Initialize(GameContext gameContext) { drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)gameContext.Control; graphicsDeviceManager = (IGraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager)); }