@Override
  public void onBackPressed() {
    ContactsSync app = ContactsSync.getInstance();

    if (!app.getDisableAds()) {
      AppBrain.getAds().maybeShowInterstitial(this);
      finish();
    } else {
      super.onBackPressed();
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AppBrain.init(this);
    AppBrain.getAds().setPopupBorder(Color.parseColor("#145214"), BorderSize.MEDIUM);
    // Say we know here that the user is male and is 35 years old, then we can pass this to
    // AppBrain:
    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.YEAR, -35);

    AppBrain.getAds()
        .setUserData(
            AppBrainUserData.create().setGender(Gender.MALE).setBirthDate(calendar.getTime()));

    setContentView(R.layout.main);

    final RemoteSettings settings = AppBrain.getSettings();

    new Handler()
        .postDelayed(
            new Runnable() {
              @Override
              public void run() {
                // fetch the welcome message from the remote settings
                String welcomeMessage =
                    settings.get("welcome_message", "Hello (this comes from the app)");
                // show as toast
                Toast.makeText(ExampleActivity.this, welcomeMessage, Toast.LENGTH_LONG).show();
              }
            },
            2500);

    final AdService ads = AppBrain.getAds();
    findViewById(R.id.maybe_show_interstitial)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                if (!ads.maybeShowInterstitial(ExampleActivity.this)) {
                  Toast.makeText(
                          ExampleActivity.this,
                          "not showing, since it was shown already recently",
                          Toast.LENGTH_LONG)
                      .show();
                }
              }
            });

    final AdOptions options = new AdOptions();
    options.setListener(
        new InterstitialListener() {
          @Override
          public void onPresented() {
            Toast.makeText(ExampleActivity.this, "Interstitial presented", Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onDismissed(boolean arg0) {
            Toast.makeText(
                    ExampleActivity.this, "Interstitial dismissed " + arg0, Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onClick() {
            Toast.makeText(ExampleActivity.this, "Interstitial clicked", Toast.LENGTH_SHORT).show();
          }
        });

    findViewById(R.id.show_interstitial)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                if (!ads.showInterstitial(ExampleActivity.this, options)) {
                  Toast.makeText(
                          ExampleActivity.this,
                          "Not showing, no internet connection?",
                          Toast.LENGTH_LONG)
                      .show();
                }
              }
            });

    ads.setOfferWallClickListener(this, findViewById(R.id.show_offerwall));

    findViewById(R.id.show_banners)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View arg0) {
                Intent intent = new Intent(ExampleActivity.this, BannerActivity.class);
                startActivity(intent);
              }
            });

    findViewById(R.id.show_listview)
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(ExampleActivity.this, ListAdsActivity.class));
              }
            });
  }
Ejemplo n.º 3
0
 // @Override
 @Override
 public void onBackPressed() {
   AppBrain.getAds().maybeShowInterstitial(this);
   finish();
 }