protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); var adMobElement = Element as AdmobBannerView; if (null != adMobElement) { adView = new GADBannerView(GADAdSizeCons.Banner) { AdUnitID = adMobElement.AdUnitID, RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController }; adView.AdReceived += (sender, args) => { if (!viewOnScreen) { AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); SetNativeControl(adView); } }
void AddToTableView() { if (adViewTableView == null) { // Setup your GADBannerView, review GADAdSizeCons class for more Ad sizes. adViewTableView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(-10, 0)) { AdUnitID = admobId, RootViewController = navController }; // Wire DidReceiveAd event to know when the Ad is ready to be displayed adViewTableView.DidReceiveAd += (object sender, EventArgs e) => { if (!adOnTable) { dvcDialog.Root.Add(new Section(caption: "Ad Section") { new UIViewElement(caption: "Ad", view: adViewTableView, transparent: true) }); adOnTable = true; } }; } adViewTableView.LoadRequest(GADRequest.Request); }
public void createBannerAds() { CGRect xxy = new CGRect(0, View.Frame.Height - 50, View.Frame.Width, 100f); iAdBanner = new ADBannerView (xxy); iAdBanner.Hidden = false; iAdBanner.AdLoaded += HandleAdLoaded; iAdBanner.FailedToReceiveAd += HandleFailedToReceiveAd; View.AddSubview(iAdBanner); adView = new GADBannerView( new CGRect(0, View.Frame.Height - GADAdSizeCons.Banner.Size.Height, View.Frame.Width, GADAdSizeCons.Banner.Size.Height)) { AdUnitID = AdmobID, RootViewController = this, }; adView.AdReceived += gadAdHandle; GADRequest request = GADRequest.Request; //= GADRequest ; request.TestDevices = new string[1] { "2cf5064e1aa0d8a637761a3665b96475" }; adView.LoadRequest(GADRequest.Request); View.AddSubview(adView); }
/// <summary> /// reload the view and hit up google admob /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); //convert the element to the control we want var adMobElement = Element as AdMobBuddyControl; if (null != adMobElement) //TODO: does need this check here? { adView = new GADBannerView(size: GADAdSizeCons.Banner) { AdUnitID = adMobElement.AdUnitId, RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController }; adView.DidReceiveAd += (sender, args) => { if (!viewOnScreen) { this.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); base.SetNativeControl(adView); } }
void SetUpGoogle() { try { if (iAdView != null) { iAdView.RemoveFromSuperview(); } if (googleAdView == null) { googleAdView = new GADBannerView(size: GADAdSizeCons.SmartBannerLandscape, origin: new PointF(0, 0)) { AdUnitID = AdmobID, RootViewController = this }; googleAdView.DidReceiveAd += (object sender, EventArgs e) => { if (adView == null) { return; } if (adView.Superview != View) { View.AddSubview(adView); } adView.Hidden = false; Resize(); }; googleAdView.DidFailToReceiveAd += (object sender, GADBannerViewErrorEventArgs e) => { Console.WriteLine(e.Error); if (adView == null) { return; } adView.Hidden = true; ; Resize(); SetupiAd(); }; View.AddSubview(googleAdView); } adView = googleAdView; googleAdView.LoadRequest(GADRequest.Request); } catch (Exception ex) { Console.WriteLine(ex); Resize(); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { vc = new UIViewController(); window = new UIWindow(UIScreen.MainScreen.Bounds); window.RootViewController = vc; window.MakeKeyAndVisible(); bannerView = new GADBannerView(new RectangleF(new PointF(0, vc.View.Frame.Height - GADBannerView.GAD_SIZE_320x50.Height), GADBannerView.GAD_SIZE_320x50)); bannerView.AdUnitID = "MY_BANNER_UNIT_ID"; bannerView.RootViewController = vc; vc.View.AddSubview(bannerView); bannerView.LoadRequest(new GADRequest()); return(true); }
void getAdmob() { base.OnElementChanged(e); adView = new GADBannerView(size: GADAdSizeCons.Banner) //, origin: new PointF(0, 0)) { AdUnitID = "ca-app-pub-3940256099942544/2934735716", RootViewController = this.ViewController }; adView.DidReceiveAd += (sender, args) => { if (!viewOnScreen) { this.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); base.SetNativeControl(adView); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); adView = new GADBannerView(size: GADAdSizeCons.Banner)//, origin: new PointF(0, 0)) { AdUnitID = ApiConstants.GoogleAds.iOSKey, RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController }; adView.AdReceived += (sender, args) => { if (!viewOnScreen) { this.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); base.SetNativeControl(adView); }
/// <summary> /// reload the view and hit up google admob /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); //convert the element to the control we want var adMobElement = Element as AdMobBuddyControl; if (null != adMobElement) { adView = new GADBannerView(size: GADAdSizeCons.Banner) { AdUnitID = adMobElement.AdUnitId, RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController }; adView.AdReceived += (sender, args) => { if (!viewOnScreen) { this.AddSubview(adView); } viewOnScreen = true; }; var request = GADRequest.Request; #if DEBUG var identifier = UIDevice.CurrentDevice.IdentifierForVendor.ToString(); var currentDevice = MD5.GetMd5String(identifier); if (!ApiConstants.GoogleAds.Devices.Contains(currentDevice)) { ApiConstants.GoogleAds.Devices.Add(currentDevice); } request.TestDevices = ApiConstants.GoogleAds.Devices?.ToArray(); #endif adView.LoadRequest(request); base.SetNativeControl(adView); } }
void AddToWindow() { if (adViewWindow == null) { // Setup your GADBannerView, review GADAdSizeCons class for more Ad sizes. adViewWindow = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, window.Bounds.Size.Height - GADAdSizeCons.Banner.size.Height)) { AdUnitID = admobId, RootViewController = navController }; // Wire DidReceiveAd event to know when the Ad is ready to be displayed adViewWindow.DidReceiveAd += (object sender, EventArgs e) => { if (!adOnWindow) { navController.View.Subviews.First().Frame = new RectangleF(0, 0, 320, UIScreen.MainScreen.Bounds.Height - 50); navController.View.AddSubview(adViewWindow); adOnWindow = true; } }; } adViewWindow.LoadRequest(GADRequest.Request); }
public override void ViewDidLoad() { base.ViewDidLoad(); //set share button image btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal); if (Reachability.IsHostReachable("www.laftrip.com")) { this.ParentViewController.ParentViewController.NavigationItem.SetRightBarButtonItem( new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) => { this.TabBarController.NavigationController.PushViewController(new AddJokeView(), true); }) , true); //get liked jokes from db likedJokes = LikeProvider.GetLikedJokes(); // btnShare.TouchUpInside += (object sender, EventArgs e) => { this.TabBarController.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Joke, currentJokeTitle, currentJokeDesc, currentJokeId), true); }; btnLike.TouchUpInside += (object sender, EventArgs e) => { if (!isLiked) { int success = -1; Downloader downloader = new Downloader(); DisplayProgress("Liking Joke"); Task.Factory.StartNew(() => { success = downloader.LikeJoke(currentJokeId); }).ContinueWith(task3 => { HideProgress(); View.BackgroundColor = UIColor.White; //save liked joke to db LikeProvider.SaveLikedJoke(currentJokeId); //add jokeid to array btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal); likedJokes.Add(currentJokeId); isLiked = true; return(success); }, TaskScheduler.FromCurrentSynchronizationContext()); } else //already liked. dislike. //remove from db { LikeProvider.DeleteLikedPhoto(currentJokeId); btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal); likedJokes.Remove(currentJokeId); isLiked = false; } }; //INITIAL DOWNLOAD DisplayProgress("Getting Jokes"); Download(); // previous swipeRight.AddTarget(() => { jokeIndex--; internalPage--; swipeLeft.Enabled = true; //if this is the first element in the internal list, download previous external page if (internalPage == -1 && jokeIndex > 0) { DisplayProgress("Getting Jokes"); Download(); externalPage--; } else { txtJokeDesc.Text = filteredJokesBatch[internalPage].JokeDesc; lblTitle.Text = filteredJokesBatch[internalPage].Title; currentJokeId = filteredJokesBatch[internalPage].JokeID; currentJokeTitle = filteredJokesBatch[internalPage].Title; currentJokeDesc = filteredJokesBatch[internalPage].JokeDesc; checkLiked(); } if (jokeIndex == 0) { swipeRight.Enabled = false; } lblPage.Text = (jokeIndex + 1) + " of " + jokeCount; }); //next swipeLeft.AddTarget(() => { jokeIndex++; internalPage++; swipeRight.Enabled = true; //if this is the last element in the internal list, download next external page if (internalPage == filteredJokesBatch.Count) { externalPage++; DisplayProgress("Getting Jokes"); Download(); } else { txtJokeDesc.Text = filteredJokesBatch [internalPage].JokeDesc; lblTitle.Text = filteredJokesBatch[internalPage].Title; currentJokeId = filteredJokesBatch[internalPage].JokeID; currentJokeTitle = filteredJokesBatch[internalPage].Title; currentJokeDesc = filteredJokesBatch[internalPage].JokeDesc; checkLiked(); } if ((jokeIndex + 1) == jokeCount) { swipeLeft.Enabled = false; } lblPage.Text = (jokeIndex + 1) + " of " + jokeCount; }); View.AddGestureRecognizer(swipeRight); View.AddGestureRecognizer(swipeLeft); NavigationController.SetNavigationBarHidden(true, true); //admob adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0)) { AdUnitID = AdmobID, RootViewController = this }; adView.DidReceiveAd += (sender, args) => { if (!viewOnScreen) { View.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); } else { connDelegate = new NoConnectionDelegate(this.NavigationController); new UIAlertView("No Internet Detected", "Internet Connection is required." , connDelegate, "ok", null).Show(); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // set share icon btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal); if (Reachability.IsHostReachable("www.laftrip.com")) { //get liked jokes from db likedPhotos = LikeProvider.GetLikedPhotos(); // btnShare.TouchUpInside += (object sender, EventArgs e) => { this.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Photo, currentphotoTitle, currentphotoDesc, currentphotoId), true); }; btnLike.TouchUpInside += (object sender, EventArgs e) => { if (!isLiked) { int success = -1; Downloader downloader = new Downloader(); DisplayProgress("Liking Photo"); Task.Factory.StartNew(() => { success = downloader.LikePhoto(currentphotoId); }).ContinueWith(task3 => { HideProgress(); //save liked joke to db LikeProvider.SaveLikedPhoto(currentphotoId); //add photoid to array btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal); isLiked = true; likedPhotos.Add(currentphotoId); return(success); }, TaskScheduler.FromCurrentSynchronizationContext()); } else { //remove from db LikeProvider.DeleteLikedPhoto(currentphotoId); btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal); isLiked = false; likedPhotos.Remove(currentphotoId); } }; //INITIAL DOWNLOAD DisplayProgress("Getting Photo"); Download(); NavigationController.SetNavigationBarHidden(true, true); //admob adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0)) { AdUnitID = AdmobID, RootViewController = this }; adView.DidReceiveAd += (sender, args) => { if (!viewOnScreen) { View.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); } else { connDelegate = new NoConnectionDelegate(this.NavigationController); new UIAlertView("No Internet Detected", "Internet Connection is required." , connDelegate, "ok", null).Show(); } }
public override void ViewDidLoad() { base.ViewDidLoad(); //set share button image btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal); if (Reachability.IsHostReachable("www.laftrip.com")) { // Perform any additional setup after loading the view, typically from a nib. View.BackgroundColor = UIColor.Black; progressBar.Hidden = true; lblPercent.Hidden = true; this.ParentViewController.ParentViewController.NavigationItem.SetRightBarButtonItem( new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) => { this.TabBarController.NavigationController.PushViewController(new AddPhotoView(), true); }) , true); //get liked jokes from db likedPhotos = LikeProvider.GetLikedPhotos(); // btnShare.TouchUpInside += (object sender, EventArgs e) => { this.TabBarController.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Photo, currentphotoTitle, currentphotoDesc, currentphotoId), true); }; btnLike.TouchUpInside += (object sender, EventArgs e) => { if (!isLiked) { int success = -1; Downloader downloader = new Downloader(); DisplayProgress("Liking Photo"); Task.Factory.StartNew(() => { success = downloader.LikePhoto(currentphotoId); }).ContinueWith(task3 => { HideProgress(); //save liked joke to db LikeProvider.SaveLikedPhoto(currentphotoId); //add photoid to array btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal); isLiked = true; likedPhotos.Add(currentphotoId); return(success); }, TaskScheduler.FromCurrentSynchronizationContext()); } else { //remove from db LikeProvider.DeleteLikedPhoto(currentphotoId); btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal); isLiked = false; likedPhotos.Remove(currentphotoId); } }; //INITIAL DOWNLOAD DisplayProgress("Getting Photos"); Download(); // previous swipeRight.AddTarget(() => { photoIndex--; internalPage--; swipeLeft.Enabled = true; //if this is the first element in the internal list, download previous external page if (internalPage == -1 && photoIndex > 0) { DisplayProgress("Getting Photos"); Download(); externalPage--; } else { lblDescription.Text = filteredphotosBatch [internalPage].Description; currentphotoId = filteredphotosBatch [internalPage].PhotoId; currentphotoTitle = filteredphotosBatch [internalPage].Title; currentphotoDesc = filteredphotosBatch [internalPage].Description; checkLiked(); ImageUrl = new NSUrl(filteredphotosBatch [internalPage].Url); if (ImageUrl != null) { progressBar.Hidden = false; lblPercent.Hidden = false; imgPhoto.SetImage(ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler); } } if (photoIndex == 0) { swipeRight.Enabled = false; } lblPage.Text = (photoIndex + 1) + " of " + photoCount; }); //next swipeLeft.AddTarget(() => { photoIndex++; internalPage++; swipeRight.Enabled = true; //if this is the last element in the internal list, download next external page if (internalPage == filteredphotosBatch.Count) { externalPage++; DisplayProgress("Getting Photos"); Download(); } else { lblDescription.Text = filteredphotosBatch [internalPage].Description; ImageUrl = new NSUrl(filteredphotosBatch [internalPage].Url); if (ImageUrl != null) { progressBar.Hidden = false; lblPercent.Hidden = false; imgPhoto.SetImage(ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler); } currentphotoId = filteredphotosBatch [internalPage].PhotoId; currentphotoTitle = filteredphotosBatch [internalPage].Title; currentphotoDesc = filteredphotosBatch [internalPage].Description; checkLiked(); } if ((photoIndex + 1) == photoCount) { swipeLeft.Enabled = false; } lblPage.Text = (photoIndex + 1) + " of " + photoCount; }); View.AddGestureRecognizer(swipeRight); View.AddGestureRecognizer(swipeLeft); NavigationController.SetNavigationBarHidden(true, true); //admob adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0)) { AdUnitID = AdmobID, RootViewController = this }; adView.DidReceiveAd += (sender, args) => { if (!viewOnScreen) { View.AddSubview(adView); } viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); } else { connDelegate = new NoConnectionDelegate(this.NavigationController); new UIAlertView("No Internet Detected", "Internet Connection is required." , connDelegate, "ok", null).Show(); } }