Skip to content

Commit

Permalink
Rectangle Native
Browse files Browse the repository at this point in the history
  • Loading branch information
rysasahrial-99 committed Apr 8, 2022
1 parent 01837d6 commit cdc6235
Show file tree
Hide file tree
Showing 5 changed files with 534 additions and 3 deletions.
212 changes: 212 additions & 0 deletions AlienAdsV2/src/main/java/com/aliendroid/alienads/AliendroidNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,114 @@ public void onNativeAdClicked(final MaxAd ad) {

}

public static void SmallNativeAdmobRectangle(Activity activity, RelativeLayout layNative, String selectAdsBackup, String nativeId, String idNativeBackup, String Hpk1,
String Hpk2, String Hpk3, String Hpk4, String Hpk5) {

AdLoader.Builder builder = new AdLoader.Builder(activity, nativeId);
builder.forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(@NonNull NativeAd nativeAds) {

if (nativeAd != null) {
nativeAd.destroy();
}
if ("APPLOVIN-M".equals(selectAdsBackup)) {
if (nativeAdMax != null) {
nativeAdLoader.destroy(nativeAdMax);
}
}
nativeAd = nativeAds;
NativeAdView adView = (NativeAdView) activity.getLayoutInflater()
.inflate(R.layout.admob_small_native_rectangle, null);
populateNativeAdView(nativeAds, adView);
layNative.removeAllViews();
layNative.addView(adView);
}

});

VideoOptions videoOptions = new VideoOptions.Builder()
.build();

NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();

builder.withNativeAdOptions(adOptions);


Bundle extras = new FacebookExtras()
.setNativeBanner(true)
.build();
AdRequest request = new AdRequest.Builder().addKeyword(Hpk1).addKeyword(Hpk2)
.addKeyword(Hpk3).addKeyword(Hpk4).addKeyword(Hpk5)
.addNetworkExtrasBundle(FacebookAdapter.class, extras)
.build();
AdLoader adLoader =
builder
.withAdListener(
new AdListener() {
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
if ("APPLOVIN-M".equals(selectAdsBackup)) {
MaxNativeAdViewBinder binder = new MaxNativeAdViewBinder.Builder(R.layout.max_small_native_rectangle)
.setTitleTextViewId(R.id.title_text_view)
.setBodyTextViewId(R.id.body_text_view)
.setAdvertiserTextViewId(R.id.advertiser_textView)
.setIconImageViewId(R.id.icon_image_view)
.setMediaContentViewGroupId(R.id.media_view_container)
.setOptionsContentViewGroupId(R.id.ad_options_view)
.setCallToActionButtonId(R.id.cta_button)
.build();
nativeAdView = new MaxNativeAdView(binder, activity);

nativeAdLoader = new MaxNativeAdLoader(idNativeBackup, activity);
nativeAdLoader.setRevenueListener(new MaxAdRevenueListener() {
@Override
public void onAdRevenuePaid(MaxAd ad) {

}
});
nativeAdLoader.setNativeAdListener(new MaxNativeAdListener() {
@Override
public void onNativeAdLoaded(final MaxNativeAdView nativeAdView, final MaxAd ad) {

if (nativeAd != null) {
nativeAd.destroy();
}
// Cleanup any pre-existing native ad to prevent memory leaks.
if (nativeAdMax != null) {
nativeAdLoader.destroy(nativeAdMax);
}

// Save ad for cleanup.
nativeAdMax = ad;

// Add ad view to view.
layNative.removeAllViews();
layNative.addView(nativeAdView);
}

@Override
public void onNativeAdLoadFailed(final String adUnitId, final MaxError error) {

}

@Override
public void onNativeAdClicked(final MaxAd ad) {

}
});

nativeAdLoader.loadAd(nativeAdView);
}
}
})
.build();
adLoader.loadAd(request);

}

public static void SmallNativeAdmobWhite(Activity activity, RelativeLayout layNative, String selectAdsBackup, String nativeId, String idNativeBackup, String Hpk1,
String Hpk2, String Hpk3, String Hpk4, String Hpk5) {

Expand Down Expand Up @@ -737,6 +845,110 @@ public void onNativeAdClicked(final MaxAd ad) {
nativeAdLoader.loadAd(nativeAdView);
}

public static void SmallNativeMaxRectangle(Activity activity, RelativeLayout layNative, String selectAdsBackup, String nativeId, String idNativeBackup) {

MaxNativeAdViewBinder binder = new MaxNativeAdViewBinder.Builder(R.layout.max_small_native_rectangle)
.setTitleTextViewId(R.id.title_text_view)
.setBodyTextViewId(R.id.body_text_view)
.setAdvertiserTextViewId(R.id.advertiser_textView)
.setIconImageViewId(R.id.icon_image_view)
.setMediaContentViewGroupId(R.id.media_view_container)
.setOptionsContentViewGroupId(R.id.ad_options_view)
.setCallToActionButtonId(R.id.cta_button)
.build();
nativeAdView = new MaxNativeAdView(binder, activity);

nativeAdLoader = new MaxNativeAdLoader(nativeId, activity);
nativeAdLoader.setRevenueListener(new MaxAdRevenueListener() {
@Override
public void onAdRevenuePaid(MaxAd ad) {

}
});
nativeAdLoader.setNativeAdListener(new MaxNativeAdListener() {
@Override
public void onNativeAdLoaded(final MaxNativeAdView nativeAdView, final MaxAd ad) {


if ("ADMOB".equals(selectAdsBackup)) {
if (nativeAd != null) {
nativeAd.destroy();
}
}
// Cleanup any pre-existing native ad to prevent memory leaks.
if (nativeAdMax != null) {
nativeAdLoader.destroy(nativeAdMax);
}

// Save ad for cleanup.
nativeAdMax = ad;

// Add ad view to view.
layNative.removeAllViews();
layNative.addView(nativeAdView);
}

@Override
public void onNativeAdLoadFailed(final String adUnitId, final MaxError error) {
if ("ADMOB".equals(selectAdsBackup)) {
AdLoader.Builder builder2 = new AdLoader.Builder(activity, idNativeBackup);
builder2.forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(@NonNull NativeAd nativeAds) {

if (nativeAd != null) {
nativeAd.destroy();
}

nativeAd = nativeAds;
NativeAdView adView = (NativeAdView) activity.getLayoutInflater()
.inflate(R.layout.admob_small_native_rectangle, null);
populateNativeAdView(nativeAds, adView);
layNative.removeAllViews();
layNative.addView(adView);
}

});

VideoOptions videoOptions = new VideoOptions.Builder()
.build();

NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();

builder2.withNativeAdOptions(adOptions);


Bundle extras = new FacebookExtras()
.setNativeBanner(true)
.build();
AdRequest request = new AdRequest.Builder()
.addNetworkExtrasBundle(FacebookAdapter.class, extras)
.build();
AdLoader adLoader =
builder2
.withAdListener(
new AdListener() {
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {

}
})
.build();
adLoader.loadAd(request);
}
}

@Override
public void onNativeAdClicked(final MaxAd ad) {

}
});

nativeAdLoader.loadAd(nativeAdView);
}

public static void SmallNativeMaxWhite(Activity activity, RelativeLayout layNative, String selectAdsBackup, String nativeId, String idNativeBackup) {

MaxNativeAdViewBinder binder = new MaxNativeAdViewBinder.Builder(R.layout.max_small_native_white)
Expand Down
170 changes: 170 additions & 0 deletions AlienAdsV2/src/main/res/layout/admob_small_native_rectangle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="24dp"
android:layout_height="wrap_content"
android:background="#e74c3c"
android:gravity="center"
android:text="Ads"
android:textColor="#ffffff"
android:textSize="10sp" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical">

<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="75dp"
android:layout_height="75dp"

android:layout_gravity="center"
android:layout_marginTop="5dp"
android:adjustViewBounds="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:lines="1"
android:text="Reskin Aliendroid"
android:textAlignment="center"
android:textColor="#222f3e"
android:textSize="10sp"
android:textStyle="bold" />

<TextView
android:id="@+id/ad_advertiser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textAlignment="center"
android:textColor="#222f3e"
android:textSize="10sp"
android:textStyle="bold"
android:visibility="gone" />

<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="1st - The Big Marketplace Source Code for Monetize Mobile Application on Indonesia"
android:textAlignment="center"
android:textColor="#222f3e"
android:textSize="10sp" />

<RatingBar
android:id="@+id/ad_stars"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.5"
android:visibility="gone" />

</LinearLayout>

</LinearLayout>

<Button
android:id="@+id/ad_call_to_action"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:background="@drawable/round_black"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="8sp"
app:backgroundTint="#e74c3c"
tools:text="Install" />
</LinearLayout>
</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">

<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:visibility="visible" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">

<TextView
android:id="@+id/ad_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:textColor="#222f3e"
android:textSize="12sp" />

<TextView
android:id="@+id/ad_store"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:textColor="#222f3e"
android:textSize="12sp" />

</LinearLayout>
</LinearLayout>

</LinearLayout>

</com.google.android.gms.ads.nativead.NativeAdView>
Loading

0 comments on commit cdc6235

Please sign in to comment.