Git Product home page Git Product logo

adcontainerview's Introduction

AdContainerView

Codacy Badge

AdContainerView is a simple, lifecycle aware wrapper over Google AdMob's AdView (Banner Ad) for a plug & play use-case.

For the simplest use:
You just need to add AdContainerView in your layout, define adUnitId, adSize & that's it!
AdContainerView hooks to your Activity's lifecycle process & handles AdView's lifecycle (Resume, Pause, Destroy Ad).
This is most helpful when you just want to add a simple Banner Ad without any boilerplate.

Adding in your project

AdContainerView is now on mavenCentral(),
Make sure to add that to your repositories block.

Gradle

implementation 'com.lazygeniouz:acv:$latest_version'

Maven

<dependency>
    <groupId>com.lazygeniouz</groupId>
    <artifactId>acv</artifactId>
    <version>$latest_version</version>
    <type>aar</type>
</dependency>

Using AdContainerView

The same old XML Way

<com.lazygeniouz.acv.AdContainerView 
    android:id="@+id/adContainerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:acv_autoLoad="true"
    app:acv_adSize="ADAPTIVE"
    app:acv_adUnitId="@string/test_ad"/>

The attributes are as follows:

  • acv_autoLoad: Default Value is false
    If true, the AdView will be loaded as soon as the Activity is created.

  • acv_adSize: Default Value is ADAPTIVE which equals to AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize().
    Define an AdSize for the the AdView, check AdSize.

  • acv_adUnitId: Define an adUnitId for the Banner AdView from your AdMob dashboard.

Programmatically

val adContainerView = AdContainerView(this@MainActivity)
adContainerView.loadAdView(adUnitId, adSize, adRequest)
parentLayout.addView(adContainerView)

Loading the Ad:

fun loadAdView(
    adUnitId: String,
    adSize: AdSize,
    adRequest: AdRequest,
    parentHasListView: Boolean,
    showOnCondition: (() -> Boolean)? = null
)
  1. The arguments adSize & adRequest are optional\
  2. The default value of parameter adSize is ADAPTIVE.\
  3. Pass your AdRequest if you have a customized request.\
  4. Pass true if AdContainerView is added inside a list (RecyclerView, List / GridView).
    If you don't do this & the parent view group is a List, it will be destroyed.
  5. Pass you condition to evaluate whether to show the Ad or not (Default is Null).

All other methods:

  • @Nullable getAdView(): Returns the underlying AdView, can be @null if called before loadAdView().

  • isLoading(): Boolean: Returns true if the Ad is currently loading, false otherwise.

  • isAdLoaded(): Boolean: Returns true if the Ad is loaded, false otherwise.

  • isVisible(): Boolean: Returns true if the Ad is loaded, not null & visible, false otherwise.

  • getAdSize(): Returns current adSize.

  • getAdUnitId(): Returns current adUnitId.

  • setAdListener(listener: AdListener): Use the AdView's AdListener.

  • @Nullable getAdListener(): Returns the Listener if set, null otherwise.

  • removeAd(): Removes the AdView. Make sure to call loadAdView() to re-add AdView.

  • resumeAd(): Resumes AdView (Handled automatically)

  • pauseAd(): Pauses AdView (Handled automatically)

  • destroyAd(): Destroys AdView (Handled automatically)

adcontainerview's People

Contributors

codacy-badger avatar itznotabug avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

rxqbi mahir101

adcontainerview's Issues

Multiple `AdListener`s

Instead of adding a singular AdListener to the AdContainerView, we should be able to add/append multiple listeners.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.