mirror of https://github.com/M66B/NetGuard.git
Added ad margin and divider
https://support.google.com/admob/answer/6128877
This commit is contained in:
parent
2027736e10
commit
82dfd13c2e
|
@ -843,10 +843,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
// https://developers.google.com/android/reference/com/google/android/gms/ads/package-summary
|
||||
MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id));
|
||||
|
||||
RelativeLayout rlAd = (RelativeLayout) findViewById(R.id.rlAd);
|
||||
final TextView tvAd = (TextView) findViewById(R.id.tvAd);
|
||||
final AdView adView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
rlAd.setVisibility(View.VISIBLE);
|
||||
tvAd.setVisibility(View.VISIBLE);
|
||||
adView.setVisibility(View.VISIBLE);
|
||||
|
||||
SpannableString content = new SpannableString(getString(R.string.title_pro_ads));
|
||||
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
|
||||
|
@ -903,14 +905,22 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
});
|
||||
|
||||
requestAds(adView);
|
||||
requestAds();
|
||||
}
|
||||
|
||||
private void reloadAds() {
|
||||
RelativeLayout rlAd = (RelativeLayout) findViewById(R.id.rlAd);
|
||||
TextView tvAd = (TextView) findViewById(R.id.tvAd);
|
||||
AdView adView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
rlAd.setVisibility(View.VISIBLE);
|
||||
tvAd.setVisibility(View.VISIBLE);
|
||||
adView.setVisibility(View.VISIBLE);
|
||||
|
||||
recreateAds();
|
||||
requestAds();
|
||||
}
|
||||
|
||||
private void recreateAds() {
|
||||
AdView adView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) adView.getLayoutParams();
|
||||
RelativeLayout parent = (RelativeLayout) adView.getParent();
|
||||
|
@ -923,11 +933,11 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
adView.setId(R.id.adView);
|
||||
adView.setLayoutParams(params);
|
||||
parent.addView(adView);
|
||||
|
||||
requestAds(adView);
|
||||
}
|
||||
|
||||
private void requestAds(final AdView adView) {
|
||||
private void requestAds() {
|
||||
final AdView adView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
|
@ -941,17 +951,9 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
|
||||
private void disableAds() {
|
||||
TextView tvAd = (TextView) findViewById(R.id.tvAd);
|
||||
AdView adView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
if (adView != null) {
|
||||
RelativeLayout parent = (RelativeLayout) adView.getParent();
|
||||
parent.removeView(tvAd);
|
||||
parent.removeView(adView);
|
||||
|
||||
tvAd.setVisibility(View.GONE);
|
||||
adView.destroy();
|
||||
}
|
||||
RelativeLayout rlAd = (RelativeLayout) findViewById(R.id.rlAd);
|
||||
rlAd.setVisibility(View.GONE);
|
||||
recreateAds();
|
||||
}
|
||||
|
||||
private void checkExtras(Intent intent) {
|
||||
|
|
|
@ -150,25 +150,38 @@
|
|||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rlAd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAd"
|
||||
<View
|
||||
android:id="@+id/tvDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginTop="8dip"
|
||||
android:background="@android:color/darker_gray" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:textAppearance="@style/TextSmall"
|
||||
android:textColor="?attr/colorOff" />
|
||||
android:layout_below="@id/tvDivider">
|
||||
|
||||
<com.google.android.gms.ads.AdView
|
||||
android:id="@+id/adView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:visibility="gone"
|
||||
ads:adSize="SMART_BANNER"
|
||||
ads:adUnitId="@string/ad_banner_unit_id" />
|
||||
<TextView
|
||||
android:id="@+id/tvAd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:textAppearance="@style/TextSmall"
|
||||
android:textColor="?attr/colorOff" />
|
||||
|
||||
<com.google.android.gms.ads.AdView
|
||||
android:id="@+id/adView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
ads:adSize="SMART_BANNER"
|
||||
ads:adUnitId="@string/ad_banner_unit_id" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue