好库网
package com.vanco.abplayer;

import java.util.Timer;
import java.util.TimerTask;

import cn.waps.AppConnect;
import cn.waps.AppListener;

import com.vanco.abplayer.adapter.MainTabAdapter;
import com.vanco.abplayer.util.AdPublic;
import com.viewpagerindicator.PageIndicator;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.Window;

public class MainActivity extends ActionBarActivity {
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if (msg.what == 1) {
				// todo something....
				AdPublic.addAd(MainActivity.this);
			}
		}
	};
	private Timer timer = new Timer(true);
	private TimerTask task = new TimerTask() {
		public void run() {
			Message msg = new Message();
			msg.what = 1;
			handler.sendMessage(msg);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE); // 鏃犳爣棰?		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		AppConnect.getInstance("f8755a8e1f84ce7d34a2efad7962adb0", this);
		FragmentPagerAdapter adapter = new MainTabAdapter(
				getSupportFragmentManager());
		// 瑙嗗浘鍒囨崲鍣?		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		pager.setOffscreenPageLimit(1);
		pager.setAdapter(adapter);

		// 椤甸潰鎸囩ず鍣?		PageIndicator indicator = (PageIndicator) findViewById(R.id.indicator);
		indicator.setViewPager(pager);
//		ad();
		AdPublic.addAd(MainActivity.this);
		// 鍚姩瀹氭椂鍣? 	timer.schedule(task, 0, AdPublic.time);
	}

	private void ad() {
		
		AppConnect.getInstance(MainActivity.this).initPopAd(this);
		// 璁剧疆鎻掑睆骞垮憡鏃犳暟鎹椂鐨勫洖璋冪洃鍚紙璇ユ柟娉曞繀椤诲湪showPopAd涔嬪墠璋冪敤锛?		AppConnect.getInstance(this).setPopAdNoDataListener(new AppListener() {

			@Override
			public void onPopNoData() {
				Log.i("debug", "鎻掑睆骞垮憡鏆傛棤鍙敤鏁版嵁");
			}

		});
		// 鏄剧ず鎻掑睆骞垮憡
		AppConnect.getInstance(this).showPopAd(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	/**
	 * On key up.
	 * 
	 * @param keyCode
	 *            the key code
	 * @param event
	 *            the event
	 * @return true, if successful
	 */
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			show_existDialog();
			return false;
		} else {
			return true;
		}
	}

	private void show_existDialog() {
		// 寮瑰嚭閫€鍑哄璇濇
		Builder dialog = new AlertDialog.Builder(MainActivity.this)
				.setMessage("鎮ㄧ‘瀹氳閫€鍑哄悧锛?)
				.setPositiveButton("纭畾", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// 閫€鍑虹▼搴?						finish();
						AppConnect.getInstance(MainActivity.this).close();
					}
				})
				.setNegativeButton("鏀寔鎴?,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface arg0, int arg1) {/*
																				 * SpotManager
																				 * .
																				 * getInstance
																				 * (
																				 * MainActivity
																				 * .
																				 * this
																				 * )
																				 * .
																				 * showSpotAds
																				 * (
																				 * MainActivity
																				 * .
																				 * this
																				 * ,
																				 * new
																				 * SpotDialogListener
																				 * (
																				 * )
																				 * {
																				 * 
																				 * @
																				 * Override
																				 * public
																				 * void
																				 * onShowSuccess
																				 * (
																				 * )
																				 * {
																				 * Log
																				 * .
																				 * i
																				 * (
																				 * "YoumiAdDemo"
																				 * ,
																				 * "灞曠ず鎴愬姛"
																				 * )
																				 * ;
																				 * }
																				 * 
																				 * @
																				 * Override
																				 * public
																				 * void
																				 * onShowFailed
																				 * (
																				 * )
																				 * {
																				 * Log
																				 * .
																				 * i
																				 * (
																				 * "YoumiAdDemo"
																				 * ,
																				 * "灞曠ず澶辫触"
																				 * )
																				 * ;
																				 * }
																				 * 
																				 * @
																				 * Override
																				 * public
																				 * void
																				 * onSpotClosed
																				 * (
																				 * )
																				 * {
																				 * Log
																				 * .
																				 * i
																				 * (
																				 * "YoumiAdDemo"
																				 * ,
																				 * "灞曠ず鍏抽棴"
																				 * )
																				 * ;
																				 * }
																				 * 
																				 * }
																				 * )
																				 * ;
																				 */
							}
						});
		dialog.show();
	}

	public void onBackPressed() {
		// 濡傛灉鏈夐渶瑕侊紝鍙互鐐瑰嚮鍚庨€€鍏抽棴鎻掓挱骞垮憡銆?		// if (!SpotManager.getInstance(this).disMiss()) {
		// // 寮瑰嚭閫€鍑虹獥鍙o紝鍙互浣跨敤鑷畾涔夐€€灞忓脊鍑哄拰鍥為€€鍔ㄧ敾,鍙傜収demo,鑻ヤ笉浣跨敤鍔ㄧ敾锛屼紶鍏?1
		// super.onBackPressed();
		// }
	}

	@Override
	protected void onStop() {
		// 濡傛灉涓嶈皟鐢ㄦ鏂规硶锛屽垯鎸塰ome閿殑鏃跺€欎細鍑虹幇鍥炬爣鏃犳硶鏄剧ず鐨勬儏鍐点€?		// SpotManager.getInstance(this).onStop();
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		// SpotManager.getInstance(this).onDestroy();
		super.onDestroy();
	}

}