Пример #1
0
  private void showBannerAd(final String adId, final String adPosition) {
    removeBannerAd();
    if (adId.length() > 0) {
      bannerAd = new AdView(context, adId);
    } else {
      bannerAd = new AdView(context);
    }
    bannerAd.setPublisherId(appId);

    if (adPosition.compareToIgnoreCase("bottom") == 0) {
      RelativeLayout relativeLayout = new RelativeLayout(context);
      RelativeLayout.LayoutParams relativeParams =
          new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      relativeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      context.addContentView(
          relativeLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
      relativeLayout.addView(bannerAd, relativeParams);
      relativeLayout.setFocusable(false);
    } else {
      LinearLayout bannerAdLayout = new LinearLayout(context);
      bannerAdLayout.setOrientation(LinearLayout.VERTICAL);
      context.addContentView(
          bannerAdLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
      bannerAdLayout.addView(bannerAd);
      bannerAdLayout.setFocusable(false);
    }

    ViewGroup group = (ViewGroup) bannerAd.getParent().getParent();
    group.findViewById(Cocos2dxActivity.GLVIEW_ID).requestFocus();

    bannerAd.setFocusable(false);
    bannerAd.setAdListener(this);
    bannerAd.loadAd(new AdRequest());
  }
Пример #2
0
 private void removeBannerAd() {
   if (bannerAd != null) {
     bannerAd.setAdListener(null);
     ViewGroup bannerAdParent = (ViewGroup) bannerAd.getParent();
     ViewGroup group = (ViewGroup) bannerAdParent.getParent();
     group.removeView(bannerAdParent);
     bannerAd = null;
     listener.onDismissScreen();
   }
 }
Пример #3
0
  @Override
  public void onPresentScreen() {
    Log.d("PunchBoxAd", "AdHandler.onPresentScreen");

    if (adType.compareToIgnoreCase("banner") == 0) {
      ViewGroup group = (ViewGroup) bannerAd.getParent().getParent();
      group.findViewById(Cocos2dxActivity.GLVIEW_ID).requestFocus();
    }

    listener.onPresentScreen();
  }