From dde4216100f9cee1882a355db9a5eef385a2559e Mon Sep 17 00:00:00 2001 From: Sang Ki Kwon Date: Fri, 17 Jul 2015 17:10:13 +0900 Subject: [PATCH] Fixed wp8 build error --- README.md | 2 + package.json | 2 +- plugin.xml | 25 +- .../AdMobOverlap.cs | 487 +++ .../AdMobPlugin.cs | 278 ++ .../AdMobPlugin_old.cs | 584 ++++ ...rrygame.Cordova.Plugin.Ad.DesktopAd.csproj | 125 + ...anberrygame.Cordova.Plugin.Ad.AdMob.csproj | 132 + ....Cranberrygame.Cordova.Plugin.Ad.AdMob.sln | 40 + ....Cranberrygame.Cordova.Plugin.Ad.AdMob.suo | Bin 0 -> 99328 bytes ...nberrygame.Cordova.Plugin.Ad.AdMob.v12.suo | Bin 0 -> 94720 bytes .../Lib/GoogleAds.XML | 2622 +++++++++++++++++ .../Lib/GoogleAds.dll | Bin 0 -> 165888 bytes .../Properties/AssemblyInfo.cs | 29 + .../bin/Debug/DesktopAd.winmd | Bin 0 -> 58368 bytes ...lugin.Ad.AdMob.csproj.FileListAbsolute.txt | 1 + ...n.Ad.DesktopAd.csproj.FileListAbsolute.txt | 21 + ...topAd.csprojResolveAssemblyReference.cache | Bin 0 -> 21482 bytes ...gnTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 12994 bytes ...le_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs | 0 ...le_5937a670-0e60-4077-877b-f7221da3dda1.cs | 0 ...le_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs | 0 .../obj/Debug/build.force | 0 src/windows/admobproxy.js | 125 + src/wp8/Admob.cs | 118 +- src/wp8/AdmobOverlap.cs | 80 +- src/wp8/AdmobSplit.cs | 5 +- 27 files changed, 4599 insertions(+), 77 deletions(-) create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobOverlap.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin_old.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Backup/Com.Cranberrygame.Cordova.Plugin.Ad.DesktopAd.csproj create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob.csproj create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob.sln create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob.suo create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob.v12.suo create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Lib/GoogleAds.XML create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Lib/GoogleAds.dll create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/Properties/AssemblyInfo.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/bin/Debug/DesktopAd.winmd create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob.csproj.FileListAbsolute.txt create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/Com.Cranberrygame.Cordova.Plugin.Ad.DesktopAd.csproj.FileListAbsolute.txt create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/Com.Cranberrygame.Cordova.Plugin.Ad.DesktopAd.csprojResolveAssemblyReference.cache create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs create mode 100755 src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/obj/Debug/build.force create mode 100755 src/windows/admobproxy.js diff --git a/README.md b/README.md index aff1dd1..fdf2b94 100755 --- a/README.md +++ b/README.md @@ -77,6 +77,8 @@ You can see Plugins For Cordova in one page: http://cranberrygame.github.io?refe Updated Admob SDK Windows Phone 8 - 6.5.13 Supports wp8 split mode +1.0.95 + Fixed wp8 build error To-Do: diff --git a/package.json b/package.json index 9d5febd..e07c17d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-ad-admob", - "version": "1.0.94", + "version": "1.0.95", "description": "Show admob banner and full screen ad", "cordova": { "id": "cordova-plugin-ad-admob", diff --git a/plugin.xml b/plugin.xml index ad0c3a5..6e16dd1 100755 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.95"> Cordova Admob plugin Show admob banner and full screen ad @@ -56,8 +56,7 @@ - - + @@ -72,4 +71,24 @@ + + + + + + + \ No newline at end of file diff --git a/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobOverlap.cs b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobOverlap.cs new file mode 100755 index 0000000..a0adbd7 --- /dev/null +++ b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobOverlap.cs @@ -0,0 +1,487 @@ +//Copyright (c) 2014 Sang Ki Kwon (Cranberrygame) +//Email: cranberrygame@yahoo.com +//Homepage: http://cranberrygame.github.io +//License: MIT (http://opensource.org/licenses/MIT) +using System; +using System.Windows; +using System.Runtime.Serialization; +////using WPCordovaClassLib; +////using WPCordovaClassLib.Cordova; +////using WPCordovaClassLib.Cordova.Commands; +////using WPCordovaClassLib.Cordova.JSON; +////using System.Windows.Controls; +////using Microsoft.Phone.Controls; +using System.Diagnostics; //Debug.WriteLine +// +using Windows.UI.Popups;// +// +using GoogleAds; + +namespace Test { + + public class Util + { + public static async void alert(string message) + { + var msgDlg = new Windows.UI.Popups.MessageDialog(message); + msgDlg.DefaultCommandIndex = 1; + await msgDlg.ShowAsync(); + } + } + + public class AdMobOverlap + { + protected string bannerAdUnit; + protected string fullScreenAdUnit; + protected bool isOverlap; + protected bool isTest; + // + protected string bannerPreviousPosition; + protected string bannerPreviousSize; + protected int lastOrientation; + // + protected bool bannerAdPreload; + protected bool fullScreenAdPreload; + //admob + protected AdView bannerView; + protected InterstitialAd interstitialView; + + public void _setLicenseKey(string email, string licenseKey) { + } + + public void _setUp(string bannerAdUnit, string fullScreenAdUnit, bool isOverlap, bool isTest) + { + this.bannerAdUnit = bannerAdUnit; + this.fullScreenAdUnit = fullScreenAdUnit; + this.isOverlap = isOverlap; + this.isTest = isTest; + } + + public void _preloadBannerAd() + { + bannerAdPreload = true; + + _hideBannerAd(); + + loadBannerAd(); + } + + private void loadBannerAd() + { + if (bannerView == null) + { + if (bannerPreviousSize == null) + { + //bannerPreviousSize = "SMART_BANNER"; + bannerPreviousSize = "BANNER"; + } + // + AdFormats format = AdFormats.Banner; + //https://developers.google.com/mobile-ads-sdk/docs/admob/wp/banner + if (bannerPreviousSize.Equals("BANNER")) + { + format = AdFormats.Banner;//Banner (320x50, Phones and Tablets) + } + else if (bannerPreviousSize.Equals("SMART_BANNER")) + { + format = AdFormats.SmartBanner;//Smart banner (Auto size, Phones and Tablets) //https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner#smart + } + else { + format = AdFormats.SmartBanner; + } +/* + // + bannerView = new AdView + { + //Format = AdFormats.Banner, + //Format = AdFormats.SmartBanner, + Format = format, + AdUnitID = this.bannerAdUnit + }; + bannerView.ReceivedAd += bannerView_ReceivedAd; + bannerView.FailedToReceiveAd += bannerView_FailedToReceiveAd; + bannerView.ShowingOverlay += bannerView_ShowingOverlay; + bannerView.LeavingApplication += bannerView_LeavingApplicationAd; + bannerView.DismissingOverlay += bannerView_DismissingOverlay; + */ + } + + AdRequest adRequest = new AdRequest(); + if(isTest) + { + adRequest.ForceTesting = true; + } + bannerView.LoadAd(adRequest); + } + + public void _showBannerAd(string position, string size) + { + if (bannerIsShowingOverlap() && position.Equals(this.bannerPreviousPosition) && size.Equals(this.bannerPreviousSize)) + { + return; + } + + this.bannerPreviousPosition = position; + this.bannerPreviousSize = size; + + if (bannerAdPreload) + { + bannerAdPreload = false; + } + else + { + _hideBannerAd(); + + loadBannerAd(); + } + + addBannerViewOverlap(position, size); + +/* + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdShown"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + */ + } + + protected virtual bool bannerIsShowingOverlap() + { + bool bannerIsShowing = false; + + if (bannerView != null) + { + PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; + PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage; + Grid rootGrid = rootPage.FindName("LayoutRoot") as Grid; + //rootGrid.ShowGridLines = true; + CordovaView rootView = rootPage.FindName("CordovaView") as CordovaView; + + if (rootGrid.Children.Contains(bannerView)) + bannerIsShowing = true; + } + + return bannerIsShowing; + } + + protected virtual void addBannerViewOverlap(String position, String size) + { +/* +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml + + + + + + + + + + +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml.cs +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Controls; +using System.IO; +using System.Windows.Media.Imaging; +using System.Windows.Resources; + +namespace com.cranberrygame.adrotatortest +{ + public partial class MainPage : PhoneApplicationPage + { + // Constructor + public MainPage() + { + InitializeComponent(); + this.CordovaView.Loaded += CordovaView_Loaded; + } + + private void CordovaView_Loaded(object sender, RoutedEventArgs e) + { + this.CordovaView.Loaded -= CordovaView_Loaded; + } + } +} + +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml + + + + + + + + + + + + +*/ + + if (position.Equals("top-left")) + { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("top-center")) + { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("top-right")) + { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else if (position.Equals("left")) + { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("center")) + { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("right")) + { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else if (position.Equals("bottom-left")) + { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("bottom-center")) + { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("bottom-right")) + { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else + { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + + PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; + PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage; + Grid rootGrid = rootPage.FindName("LayoutRoot") as Grid; + //rootGrid.ShowGridLines = true; + CordovaView rootView = rootPage.FindName("CordovaView") as CordovaView; + + rootGrid.Children.Add(bannerView); + } + + public void _reloadBannerAd() + { + loadBannerAd(); + } + + public void _hideBannerAd() + { + removeBannerViewOverlap(); + +/* + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdHidden"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + */ + } + + protected virtual void removeBannerViewOverlap() + { + if (bannerView == null) + return; + + PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; + PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage; + Grid rootGrid = rootPage.FindName("LayoutRoot") as Grid; + //rootGrid.ShowGridLines = true; + CordovaView rootView = rootPage.FindName("CordovaView") as CordovaView; + + if (rootGrid.Children.Contains(bannerView)) + { + rootGrid.Children.Remove(bannerView); + } + } + + public void _preloadFullScreenAd() + { + fullScreenAdPreload = true; + + loadFullScreenAd(); + } + + protected void loadFullScreenAd() + { + if (interstitialView == null) + { + //interstitialView = new InterstitialAd("ca-app-pub-4906074177432504/4879304879");//x cf) wp8 + //interstitialView = new InterstitialAd("ca-app-pub-4906074177432504/5150650074");//o cf) android + interstitialView = new InterstitialAd(this.fullScreenAdUnit); + //http://forums.xamarin.com/discussion/849/binding-library-for-inneractive-sdk + interstitialView.ReceivedAd += interstitialView_ReceivedAd; + interstitialView.FailedToReceiveAd += interstitialView_FailedToReceiveAd; + interstitialView.ShowingOverlay += interstitialView_ShowingOverlay; + interstitialView.DismissingOverlay += interstitialView_DismissingOverlay; + } + + AdRequest adRequest = new AdRequest(); + if(isTest) + { + adRequest.ForceTesting = true; + } + interstitialView.LoadAd(adRequest); + } + + public void _showFullScreenAd() + { + if (fullScreenAdPreload) + { + fullScreenAdPreload = false; + + //An exception of type 'System.NullReferenceException' occurred in GoogleAds.DLL and wasn't handled before a managed/native boundary + try + { + interstitialView.ShowAd(); + } + catch (Exception ex) + { + } + } + else + { + loadFullScreenAd(); + } + } + + protected void bannerView_ReceivedAd(object sender, AdEventArgs e) + { + Debug.WriteLine("BannerView_ReceivedAd"); + +/* + PluginResult pr; + if (bannerAdPreload) + { + pr = new PluginResult(PluginResult.Status.OK, "onBannerAdPreloaded"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + } + + pr = new PluginResult(PluginResult.Status.OK, "onBannerAdLoaded"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + */ + } + + protected void bannerView_FailedToReceiveAd(object sender, AdErrorEventArgs errorCode) + { + Debug.WriteLine("BannerView_FailedToReceiveAd " + errorCode.ErrorCode); + } + + protected void bannerView_ShowingOverlay(object sender, AdEventArgs e) + { + Debug.WriteLine("BannerView_ShowingOverlay");//click and ad opened //onBannerAdShown x + } + + protected void bannerView_LeavingApplicationAd(object sender, AdEventArgs args) + { + Debug.WriteLine("bannerView_LeavingApplicationAd"); + } + + protected void bannerView_DismissingOverlay(object sender, AdEventArgs e) + { + Debug.WriteLine("BannerView_DismissingOverlay");//onBannerAdHidden x + } + + protected void interstitialView_ReceivedAd(object sender, AdEventArgs e) + { + Debug.WriteLine("interstitialView_ReceivedAd"); + +/* + PluginResult pr; + if (fullScreenAdPreload) + { + pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdPreloaded"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + } + + pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdLoaded"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); +*/ + + if (!fullScreenAdPreload) + { + interstitialView.ShowAd(); + } + } + + protected void interstitialView_FailedToReceiveAd(object sender, AdErrorEventArgs errorCode) + { + Debug.WriteLine("interstitialView_FailedToReceiveAd " + errorCode.ErrorCode); + } + + protected void interstitialView_ShowingOverlay(object sender, AdEventArgs e) + { + Debug.WriteLine("OnInterstitialViewPresentScreen"); + +/* + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdShown"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + */ + } + + protected void interstitialView_DismissingOverlay(object sender, AdEventArgs e) + { + Debug.WriteLine("interstitialView_DismissingOverlay"); + +/* + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdHidden"); + pr.KeepCallback = true; + plugin.DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //plugin.DispatchCommandResult(pr); + */ + } + } +} \ No newline at end of file diff --git a/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin.cs b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin.cs new file mode 100755 index 0000000..a0670f7 --- /dev/null +++ b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin.cs @@ -0,0 +1,278 @@ +//Copyright (c) 2014 Sang Ki Kwon (Cranberrygame) +//Email: cranberrygame@yahoo.com +//Homepage: http://cranberrygame.github.io +//License: MIT (http://opensource.org/licenses/MIT) +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Diagnostics; //Debug.WriteLine +using Windows.UI.Core;//CoreDispatcher.RunAsync +////using Windows.UI.Xaml; +////using Windows.UI.Xaml.Controls; +////using Windows.UI.Xaml.Controls.Primitives; +// + + +namespace Com.Cranberrygame.Cordova.Plugin.Ad.AdMob +{ + public sealed class AdMobPlugin + { + + } + +} + +//////////////////////// + +/* + private void _preloadBannerAd() { + bannerAdPreload = true; + + _hideBannerAd(); + + loadBannerAd(); + } + + private void loadBannerAd() { + if (bannerView == null) { + if(size == null) { + size = "SMART_BANNER"; + } + // + AdFormats format = AdFormats.Banner; + //https://developers.google.com/mobile-ads-sdk/docs/admob/wp/banner + if (size.Equals("BANNER")) { + format = AdFormats.Banner;//Banner (320x50, Phones and Tablets) + } + else if (size.Equals("SMART_BANNER")) { + format = AdFormats.SmartBanner;//Smart banner (Auto size, Phones and Tablets) //https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner#smart + } + else { + format = AdFormats.SmartBanner; + } + // + bannerView = new AdView + { + //Format = AdFormats.Banner, + //Format = AdFormats.SmartBanner, + Format = format, + AdUnitID = this.bannerAdUnit + }; + bannerView.ReceivedAd += OnBannerViewReceivedAd; + bannerView.FailedToReceiveAd += OnBannerViewFailedToReceiveAd; + bannerView.ShowingOverlay += OnBannerViewShowingOverlay; + bannerView.DismissingOverlay += OnBannerViewDismissingOverlay; + } + + AdRequest adRequest = new AdRequest(); + if(isTest) { + adRequest.ForceTesting = true; + } + bannerView.LoadAd(adRequest); + } + + private void _showBannerAd(string position, string size) { + + if (bannerIsShowing() && position.Equals(this.previousBannerPosition) && size.Equals(this.previousBannerSize)) { + return; + } + + this.previousBannerPosition = position; + this.previousBannerSize = size; + + if(bannerAdPreload) { + bannerAdPreload = false; + } + else{ + _hideBannerAd(); + + loadBannerAd(); + } +*/ + +/* +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml + + + + + + + + + + +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml.cs +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Controls; +using System.IO; +using System.Windows.Media.Imaging; +using System.Windows.Resources; + +namespace com.cranberrygame.adrotatortest +{ + public partial class MainPage : PhoneApplicationPage + { + // Constructor + public MainPage() + { + InitializeComponent(); + this.CordovaView.Loaded += CordovaView_Loaded; + } + + private void CordovaView_Loaded(object sender, RoutedEventArgs e) + { + this.CordovaView.Loaded -= CordovaView_Loaded; + } + } +} + +//D:\share\cordova_test\testapp\platforms\wp8\MainPage.xaml + + + + + + + + + + + + +*/ + +/* + if (isOverlap) { + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + if (page != null) { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) { + if (position.Equals("top-left")) { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("top-center")) { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("top-right")) { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else if (position.Equals("left")) { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("center")) { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("right")) { + bannerView.VerticalAlignment = VerticalAlignment.Center; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else if (position.Equals("bottom-left")) { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (position.Equals("bottom-center")) { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (position.Equals("bottom-right")) { + bannerView.VerticalAlignment = VerticalAlignment.Bottom; + bannerView.HorizontalAlignment = HorizontalAlignment.Right; + } + else { + bannerView.VerticalAlignment = VerticalAlignment.Top; + bannerView.HorizontalAlignment = HorizontalAlignment.Center; + } + + grid.Children.Add(bannerView); + } + } + } + } + else { + + } + + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdShown"); + pr.KeepCallback = true; + DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //DispatchCommandResult(pr); + } + + protected boolean bannerIsShowingOverlap() { + bool bannerIsShowing = false; + //if banner is showing + if (bannerView != null) { + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + if (page != null) { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) { + if (grid.Children.Contains(bannerView)) { + bannerIsShowing = true; + } + } + } + } + } + + return bannerIsShowing; + } + + private void _reloadBannerAd() { + loadBannerAd(); + } + + private void _hideBannerAd() { + removeBannerViewOverlap(); + + PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdHidden"); + pr.KeepCallback = true; + DispatchCommandResult(pr); + //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); + //pr.KeepCallback = true; + //DispatchCommandResult(pr); + } + + private void removeBannerViewOverlap() { + if (bannerView == null) + return + + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + if (page != null) { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) { + if (grid.Children.Contains(bannerView)) { + grid.Children.Remove(bannerView); + } + } + } + } + } +*/ diff --git a/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin_old.cs b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin_old.cs new file mode 100755 index 0000000..4448276 --- /dev/null +++ b/src/windows/Com.Cranberrygame.Cordova.Plugin.Ad.AdMob/AdMobPlugin_old.cs @@ -0,0 +1,584 @@ +//Copyright (c) 2014 Sang Ki Kwon (Cranberrygame) +//Email: cranberrygame@yahoo.com +//Homepage: http://cranberrygame.github.io +//License: MIT (http://opensource.org/licenses/MIT) +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Diagnostics; //Debug.WriteLine +using Windows.UI.Core;//CoreDispatcher.RunAsync +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +// + + +namespace Com.Cranberrygame.Cordova.Plugin.Ad.AdMob +{ + public sealed class AdMobPlugin + { + + // + private static string appKey; + private static string appSecret; + //desktopad + private static Banner bannerView; + + public static string echo(string str) + { + return str+"echo"; + } + + ////////////////////// + + public static void setLicenseKey(string email, string licenseKey) + { + Debug.WriteLine("email: " + email); + Debug.WriteLine("licenseKey: " + licenseKey); + + // Your UI update code goes here! + //http://stackoverflow.com/questions/19341591/the-application-called-an-interface-that-was-marshalled-for-a-different-thread + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _setLicenseKey(email, licenseKey); + }); + } + + public static void setUp(string appKey, string appSecret, bool isOverlap, bool isTest) + { + //Debug.WriteLine("appKey: " + appKey); + //Debug.WriteLine("appSecret: " + appSecret); + //Debug.WriteLine("isOverlap: " + isOverlap); + //Debug.WriteLine("isTest: " + isTest); + Debug.WriteLine("appKey: " + appKey); + Debug.WriteLine("appSecret: " + appSecret); + Debug.WriteLine("isOverlap: " + isOverlap); + Debug.WriteLine("isTest: " + isTest); + + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _setUp(appKey, appSecret, isOverlap, isTest); + }); + } + + // + public static void preloadBannerAd() + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _preloadBannerAd(); + }); + } + + public static void showBannerAd(string position, int size) + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _showBannerAd(position, size); + }); + } + + public static void reloadBannerAd() + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _reloadBannerAd(); + }); + } + + public static void hideBannerAd() + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _hideBannerAd(); + }); + } + + public static void preloadPopupAd() + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _preloadPopupAd(); + }); + } + + public static void showPopupAd() + { + Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, + () => + { + _showPopupAd(); + }); + } + + // + public static void _setLicenseKey(string email, string licenseKey) + { + + } + + public static void _setUp(string appKey, string appSecret, bool isOverlap, bool isTest) + { + AdMobPlugin.appKey = appKey; + AdMobPlugin.appSecret = appSecret; + } + + public static void _preloadBannerAd() + { + loadBannerAd(); + } + + + private static void loadBannerAd() + { +/* +//MainPage.xaml + + + + + + +//MainPage.xaml.cs +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace App1 +{ + public sealed partial class MainPage : Page + { + public MainPage() + { + this.InitializeComponent(); + } + } +} +//MainPage.xaml + + + +