前往主控台

firebase::admob::BannerView

#include <banner_view.h>

Loads and displays AdMob banner ads.

Summary

Each BannerView object corresponds to a single AdMob banner placement. There are methods to load an ad, move it, show it and hide it, and retrieve the bounds of the ad onscreen.

BannerView objects maintain a presentation state that indicates whether or not they're currently onscreen, as well as a set of bounds (stored in a BoundingBox struct), but otherwise provide information about their current state through Futures. Methods like Initialize, LoadAd, and Hide each have a corresponding Future from which the result of the last call can be determined. The two variants of MoveTo share a single result Future, since they're essentially the same action.

In addition, applications can create their own subclasses of BannerView::Listener, pass an instance to the SetListener method, and receive callbacks whenever the presentation state or bounding box of the ad changes.

For example, you could initialize, load, and show a banner view while checking the result of the previous action at each step as follows:

namespace admob = ::firebase::admob;
admob::BannerView* banner_view = new admob::BannerView();
banner_view->Initialize(ad_parent, "YOUR_AD_UNIT_ID", desired_ad_size)

Then, later:

if (banner_view->InitializeLastResult().status() ==
    ::firebase::kFutureStatusComplete &&
    banner_view->InitializeLastResult().error() ==
    firebase::admob::kAdMobErrorNone) {
  banner_view->LoadAd(your_ad_request);
}

Constructors and Destructors

BannerView()
Creates an uninitialized BannerView object.
~BannerView()

Public types

Position{
  kPositionTop = 0,
  kPositionBottom,
  kPositionTopLeft,
  kPositionTopRight,
  kPositionBottomLeft,
  kPositionBottomRight
}
enum
The possible screen positions for a BannerView.
PresentationState{
  kPresentationStateHidden = 0,
  kPresentationStateVisibleWithoutAd,
  kPresentationStateVisibleWithAd,
  kPresentationStateOpenedPartialOverlay,
  kPresentationStateCoveringUI
}
enum
The presentation state of a BannerView.

Public functions

Destroy()
Future< void >
Cleans up and deallocates any resources used by the BannerView.
DestroyLastResult() const
Future< void >
Returns a Future containing the status of the last call to Destroy.
Hide()
Future< void >
Hides the BannerView.
HideLastResult() const
Future< void >
Returns a Future containing the status of the last call to Hide.
Initialize(AdParent parent, const char *ad_unit_id, AdSize size)
Future< void >
Initializes the BannerView object.
InitializeLastResult() const
Future< void >
Returns a Future that has the status of the last call to Initialize.
LoadAd(const AdRequest & request)
Future< void >
Begins an asynchronous request for an ad.
LoadAdLastResult() const
Future< void >
Returns a Future containing the status of the last call to LoadAd.
MoveTo(int x, int y)
Future< void >
Moves the BannerView so that its top-left corner is located at (x, y).
MoveTo(Position position)
Future< void >
Moves the BannerView so that it's located at the given pre-defined position.
MoveToLastResult() const
Future< void >
Returns a Future containing the status of the last call to either version of MoveTo.
Pause()
Future< void >
Pauses the BannerView.
PauseLastResult() const
Future< void >
Returns a Future containing the status of the last call to Pause.
Resume()
Future< void >
Resumes the BannerView after pausing.
ResumeLastResult() const
Future< void >
Returns a Future containing the status of the last call to Resume.
SetListener(Listener *listener)
void
Sets the Listener for this object.
Show()
Future< void >
Shows the BannerView.
ShowLastResult() const
Future< void >
Returns a Future containing the status of the last call to Show.
bounding_box() const
Retrieves the BannerView's current onscreen size and location.
presentation_state() const
Returns the current presentation state of the BannerView.

Classes

firebase::admob::BannerView::Listener

A listener class that developers can extend and pass to a BannerView object's SetListener method to be notified of changes to the presentation state and bounding box.

Public types

Position

 Position

The possible screen positions for a BannerView.

Properties
kPositionBottom

Bottom of the screen, horizontally centered.

kPositionBottomLeft

Bottom-left corner of the screen.

kPositionBottomRight

Bottom-right corner of the screen.

kPositionTop

Top of the screen, horizontally centered.

kPositionTopLeft

Top-left corner of the screen.

kPositionTopRight

Top-right corner of the screen.

PresentationState

 PresentationState

The presentation state of a BannerView.

Properties
kPresentationStateCoveringUI

BannerView is completely covering the screen or has caused focus to leave the application (for example, when opening an external browser during a clickthrough).

kPresentationStateHidden

BannerView is currently hidden.

kPresentationStateOpenedPartialOverlay

BannerView is visible and has opened a partial overlay on the screen.

kPresentationStateVisibleWithAd

BannerView is visible and contains an ad.

kPresentationStateVisibleWithoutAd

BannerView is visible, but does not contain an ad.

Public functions

BannerView

 BannerView()

Creates an uninitialized BannerView object.