A simple Android library (currently in early stage) to cross promote your apps, sites!
This is modified version of https://github.com/ItzNotABug/HouseAds.
Currently includes a Dialog & Interstitial Ad fetched from a json stored on a site/server.
Add JitPack in your root build.gradle at the end of repositories:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Add it as a dependency in your app's build.gradle file:
dependencies {
implementation 'com.github.mkaflowski:HouseAds:1.x' //CHANGE X TO CURRENT VERSION!!!
}
Json Array Schema that you'll have to put on a server:
{
"apps":
[{
"app_title": "App Name (Dialog)",
"app_desc": "Your App's description",
"app_icon": "https:// URL to Icon",
"app_header_image": "https:// URL to Header Image",
"app_uri": "http:// URL or Package Name - com.package.name",
"app_rating": "4.5",
"app_cta_text": "Install",
"app_price": "Free",
"app_adType": "dialog"
},
{
"app_title": "App Name 2 (Interstitial)",
"app_desc": "Your App's Description",
"app_icon": "https:// URL to Icon",
"app_header_image": "https:// URL to Header Image",
"app_uri": "http:// URL or Package Name - com.package.name",
"app_rating": "4.5",
"app_cta_text": "Install",
"app_price": "Free",
"app_adType": "interstitial"
},
{
"app_title": "App Name 3 (Native Ad)",
"app_desc": "Your App's Description",
"app_icon": "https:// URL to Icon",
"app_header_image": "https:// URL to Header Image",
"app_uri": "http:// URL or Package Name - com.package.name",
"app_rating": "4.5",
"app_cta_text": "Install",
"app_price": "Free",
"app_adType": "native"
}]
}
Some of the Assets like App Title, App Description, Icons & call to Action Text & Package Name are necessary!
HouseAdsDialog is a beautifully Styled Dialog which shows your Ad Assets like Header Image, App Icon, App Title & Description, Call to Action Button, Star Ratings & Price of the App. "Don't remind" button will stop showing ads for given package or URL.
The library internally uses Palette API
to color the CTA Button by fetching the Dominant Color
from Icon or Header Bitmap, whichever available.
Following is an example of HouseAdsDialog -
HouseAdsDialog houseAds = new HouseAdsDialog(MainActivity.this);
houseAds.setUrl(adURL); //URL to Json File
houseAds.hideIfAppInstalled(false); //An App's Ad will be shown if it is Installed on the Device.
houseAds.setUsePaletteColor(false);
houseAds.setThemeId(R.style.AppTheme);
houseAds.setThemeId(android.R.style.Theme_Dialog);
houseAds.setCardCorners(100); // Set CardView's corner radius.
houseAds.setCtaCorner(100); //Set CTA Button's background radius.
houseAds.setForceLoadFresh(false); //Fetch Json everytime loadAds() is called, true by default, if set to false, Json File's Response is kept untill App is closed!
houseAds.showHeaderIfAvailable(false); //Show Header Image if available, true by default
houseAds.loadAds();
You can check if the Ad is loaded via -
houseAds.isAdLoaded();
//returns true if loaded, false otherwise!
You can also add a Listener to HouseAdsDialog,
houseAds.setAdListener(new AdListener() {
@Override
public void onAdLoadFailed() {}
@Override
public void onAdLoaded() {
//Show AdDialog as soon as it is loaded.
houseAds.showAd();
}
@Override
public void onAdClosed() {}
@Override
public void onAdShown() {}
@Override
public void onAdClicked {}
});
NOTE: You cannot Customize the Dialog except for the CardView's Corner Radius & CTA Button's Background Radius!
Use HouseAdsNative
instead :)
HouseAds also supports Interstitial Ad support just like AdMob has one!
HouseAdsInterstitial shows an Image fetched from your Json & navigates the User to Google Play if you specified a Package Name or the Website otherwise.
Following is an example of HouseAdsInterstitial -
final HouseAdsInterstitial interstitial = new HouseAdsInterstitial(MainActivity.this);
interstitial.setUrl(adURL);
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoadFailed() {}
@Override
public void onAdLoaded() {}
@Override
public void onAdClosed() {}
@Override
public void onAdShown() {}
@Override
public void onAdClicked() {}
});
interstitial.loadAd();
Just like the HouseAdsDialog, you can check if the Interstitial is Loaded in the same way - interstitial.isAdLoaded();
And show Interstitial like - interstitial.show();
HouseAdsNative is the type of Ad where you can pass your own views which includes Ad Assets just like AdMob's NativeAdvancedUnified
.
The setNativeAdView()
method in HouseAdsNative
accepts two types of object to specify your View containing Ad Assets.
- HouseAdsNativeAdView Object,
- View Object containing Ad Assets.
If you use a HouseAdsNativeView
, you'll need to pass the ids of the Assets (Icon, Call to Action View, Header Image etc) in a HouseAdsNativeView
in their respective setter methods
and then set that object to the HouseAdsNative's setNativeView()
.
Following is an example of HouseAdsNativeView
-
final Relativelayout adLayout = findViewById(R.id.adLayout); //Ad Assets inside a ViewGroup
adlayout.setVisibility(View.GONE):
HouseAdsNativeView nativeView = new HouseAdsNativeView();
nativeView.setTitleView((TextView) findViewById(R.id.appinstall_headline));
nativeView.setDescriptionView((TextView) findViewById(R.id.appinstall_body));
nativeView.setIconView((ImageView) findViewById(R.id.appinstall_app_icon));
nativeView.setHeaderImageView((ImageView) findViewById(R.id.large));
nativeView.setCallToActionView(findViewById(R.id.appinstall_call_to_action));
nativeView.setPriceView((TextView) findViewById(R.id.price));
nativeView.setRatingsView((RatingBar) findViewById(R.id.rating));
You can also pass a View in the setNativeAdView()
, however there are some rules you'll need to follow!
You'll need to use the same IDs
for your Ad Assets mentioned below -
Ad Assets | IDs |
---|---|
Header Image | houseAds_header_image |
App Icon | houseAds_app_icon |
Title | houseAds_title |
Description | houseAds_description |
Price | houseAds_price |
RatingBar | houseAds_rating |
HouseAdsNative houseAdsNative = new HouseAdsNative(NativeAdActivity.this);
houseAdsNative.setNativeAdView(nativeView); //HouseAdsNativeView Object
houseAdsNative.setNativeNativeView(adLayout); //View Object
houseAdsNative.setUrl(adUrl);
houseAdsNative.setNativeAdListener(new NativeAdListener() {
@Override
public void onAdLoaded() {
adLayout.setVisibility(View.VISIBLE);
}
@Override
public void onAdLoadFailed() {
Toast.makeText(NativeAdActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
});
houseAdsNative.loadAds();
Check if NativeAd is loaded - houseAdsNative.isAdLoaded();
Additionally, you can define your own 'Call to Action' Button's action by using a CallToActionListener
, for e.g.
houseAdsNative.setCallToActionListener(new NativeAdListener.CallToActionListener() {
@Override
public void onCallToActionClicked(View view) {
//Do your Stuff!
}
});
Note: If you don't implement the CTAListener, default implementation is used which navigates the user to PlayStore or Website depending on the passed argument to the "app_uri" object in json, when clicked.
HouseAds uses Glide for Image Loading and Caching, therefore you should clear its cache periodically by calling the following method -
HouseAdsHelper.clearGlideCache(MainActivity.this);