Android Open Source - plus1-android-sdk Bart Activity






From Project

Back to project page plus1-android-sdk.

License

The source code is released under:

Copyright (c) 2012, WapStart All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Red...

If you think the Android project plus1-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.wapstart.plus1.bart;
//  w w w. j av  a2s .co m
import android.app.Activity;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.KeyEvent;
import android.widget.ImageView;

import java.util.Random;
import java.util.Date;

// Uncomment the following line if you want to use Plus1 WapStart Conversion SDK
// import ru.wapstart.plus1.conversion.sdk.Plus1ConversionTracker;
import ru.wapstart.plus1.sdk.Plus1BannerView;
import ru.wapstart.plus1.sdk.Plus1Request;
import ru.wapstart.plus1.sdk.Plus1BannerAsker;

public class BartActivity extends Activity implements View.OnClickListener
{
  private MediaPlayer mp;
  private Plus1BannerAsker mAsker;
  private Plus1BannerView mBannerView;

    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    Log.d("BartActivity", "onCreate fired");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView imageView = (ImageView) findViewById(R.id.background);
    Random random = new Random(new Date().getTime());

    imageView.setBackgroundColor(
      Color.rgb(
        random.nextInt(256),
        random.nextInt(256),
        random.nextInt(256))
    );

    imageView.setImageResource(R.drawable.bartsimpson);

    imageView.setOnClickListener(this);

    mBannerView =
      (Plus1BannerView) findViewById(R.id.plus1BannerView);

    mAsker =
      new Plus1BannerAsker(
        new Plus1Request()
          .setApplicationId(/* Place your WapStart Plus1 application id here */),
        mBannerView
          .enableAnimationFromTop()
          .enableCloseButton()
      )
      .setCallbackUrl("wsp1bart://ru.wapstart.plus1.bart")
      .setRefreshDelay(10); // default value

    mBannerView
      .addListener(new Plus1BannerView.OnShowListener() {
        public void onShow(Plus1BannerView pbv) {
          Log.d("BartActivity", "OnShowListener was touched");
        }
      })
      .addListener(new Plus1BannerView.OnHideListener() {
        public void onHide(Plus1BannerView pbv) {
          Log.d("BartActivity", "OnHideListener was touched");
        }
      })
      .addListener(new Plus1BannerView.OnCloseButtonListener() {
        public void onCloseButton(Plus1BannerView pbv) {
          Log.d("BartActivity", "OnCloseButtonListener was touched");
        }
      })
      .addListener(new Plus1BannerView.OnImpressionListener() {
        public void onImpression(Plus1BannerView pbv) {
          Log.d("BartActivity", "OnImpressionListener was touched");
        }
      })
      .addListener(new Plus1BannerView.OnTrackClickListener() {
        public void onTrackClick(Plus1BannerView pbv) {
          Log.d("BartActivity", "OnTrackClickListener was touched");
        }
      });
    }

  public void onClick(View view) {
    if (mp == null)
      this.mp = MediaPlayer.create(getApplicationContext(), R.raw.laugh);

    mp.start();
    mAsker.refreshBanner();
  }

  @Override
  protected void onResume() {
    Log.d("BartActivity", "onResume fired");

    super.onResume();

    // Uncomment the block bellow if you want to use Plus1 WapStart Conversion SDK
    /**
    try {
      new Plus1ConversionTracker(this)
        .setTrackId(Place your WapStart Plus1 conversion track id here)
        .setCallbackUrl("wsp1hc://ru.wapstart.plus1.bart")
        .run();
    } catch (Plus1ConversionTracker.TrackIdNotDefinedException e) {
      Log.e("BartActivity", "You must define conversion track id");
    } catch (Plus1ConversionTracker.CallbackUrlNotDefinedException e) {
      Log.e("BartActivity", "You must define callback url");
    }
    */

    mAsker.onResume();
  }

  @Override
  protected void onPause() {
    Log.d("BartActivity", "onPause fired");

    super.onPause();

    if (mp != null) {
      mp.release();
      mp = null;
    }

    mAsker.onPause();
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.d("BartActivity", "onKeyDown fired");

    if ((keyCode == KeyEvent.KEYCODE_BACK) && mBannerView.canGoBack()) {
      mBannerView.goBack();
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }
}




Java Source Code List

ru.wapstart.plus1.bart.BartActivity.java
ru.wapstart.plus1.sdk.AdView.java
ru.wapstart.plus1.sdk.ApplicationBrowser.java
ru.wapstart.plus1.sdk.Base64.java
ru.wapstart.plus1.sdk.BaseAdView.java
ru.wapstart.plus1.sdk.BaseRequestLoader.java
ru.wapstart.plus1.sdk.Constants.java
ru.wapstart.plus1.sdk.HtmlBannerDownloader.java
ru.wapstart.plus1.sdk.InitRequestLoader.java
ru.wapstart.plus1.sdk.JsonHelper.java
ru.wapstart.plus1.sdk.MraidAbstractController.java
ru.wapstart.plus1.sdk.MraidBrowserController.java
ru.wapstart.plus1.sdk.MraidCommandRegistry.java
ru.wapstart.plus1.sdk.MraidCommand.java
ru.wapstart.plus1.sdk.MraidDisplayController.java
ru.wapstart.plus1.sdk.MraidProperty.java
ru.wapstart.plus1.sdk.MraidView.java
ru.wapstart.plus1.sdk.Plus1AdAnimator.java
ru.wapstart.plus1.sdk.Plus1BannerAsker.java
ru.wapstart.plus1.sdk.Plus1BannerDownloadListener.java
ru.wapstart.plus1.sdk.Plus1BannerView.java
ru.wapstart.plus1.sdk.Plus1Helper.java
ru.wapstart.plus1.sdk.Plus1Request.java