0
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AdRequest adRequest = new AdRequest.Builder().build();
// adView.loadAd(adRequest);
interstitial = new InterstitialAd(MainActivity.this);
interstitial.setAdUnitId("a1536a2f71c5059");
interstitial.loadAd(adRequest);
mGLView = new MyGLES10SurfaceView(MainActivity.this);
setContentView(mGLView);
final AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("How to use");
builder.setMessage("1.Crack Screen: touch screen.\n\n2.Exit: Press Back Button 5 times");
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog alert = builder.create();
alert.cancel();
displayInterstitial();
}
});
AlertDialog alert = builder.create();
alert.show();
}
class MyGLES10SurfaceView extends GLSurfaceView {
public MyGLES10SurfaceView(Context context) {
super(context);
this.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
this.setRenderer(new MyRenderer(context));
this.getHolder().setFormat(PixelFormat.TRANSPARENT);
}
public boolean onTouchEvent(final MotionEvent event) {
objPlayer = MediaPlayer.create(MainActivity.this, R.raw.breaks);
objPlayer.start();
setContentView(R.layout.main);
adView = (com.google.android.gms.ads.AdView)
findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
return true;
}
}
public class MyRenderer implements GLSurfaceView.Renderer {
public MyRenderer(Context contextin) {
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
public void onDrawFrame(GL10 gl) {
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
}
}
@Override
public void onBackPressed() {
if (i == 5) {
MainActivity.this.finish();
displayInterstitial();
}
i++;
// do nothing.
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
Я попытался отобразить объявления google в макете main.xml после использования события touch. Я помещал java-код объявления в метод события onTouch. Сначала я установлюContentView, как main.xml, и покажу рекламу после касания.Как отображать объявления Google после события onTouch?