Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Create an ad.
- adView = new AdView(this);
- adView.setAdSize(AdSize.BANNER);
- adView.setAdUnitId(AD_UNIT_ID);
- // Add the AdView to the view hierarchy. The view will have no size
- // until the ad is loaded.
- RelativeLayout layout = new RelativeLayout(this);
- layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- // Create an ad request. Check logcat output for the hashed device ID to
- // get test ads on a physical device.
- AdRequest adRequest = new AdRequest.Builder()
- .addTestDevice(TestDeviceID)
- .build();
- // Start loading the ad in the background.
- adView.loadAd(adRequest);
- //Request full screen
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- //Create a displayMetrics object to get pixel width and height
- metrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(metrics);
- width = metrics.widthPixels;
- height = metrics.heightPixels;
- //Work out values for resizing screen while keeping aspect ratio
- width = (int) Math.min(width, height * 1.702127659574468);
- height = (int) Math.min(height, width / 1.702127659574468);
- //Create and set GL view (OpenGL View)
- myView = new MyGLSurfaceView(MainActivity.this);
- RelativeLayout.LayoutParams adParams =
- new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
- RelativeLayout.LayoutParams.WRAP_CONTENT);
- adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
- //Set the colour if we don't, the ad won't show (bug?)
- adView.setBackgroundColor(Color.BLACK);
- layout.addView(myView);
- layout.addView(adView, adParams);
- //Create a copy of the Bundle
- if (savedInstanceState != null){
- newBundle = new Bundle(savedInstanceState);
- }
- setContentView(layout);
- }
- AdSize adSize = AdSize.SMART_BANNER;
- DisplayMetrics dm = getResources().getDisplayMetrics();
- double density = dm.density * 160;
- double x = Math.pow(dm.widthPixels / density, 2);
- double y = Math.pow(dm.heightPixels / density, 2);
- double screenInches = Math.sqrt(x + y);
- if (screenInches > 8) { // > 728 X 90
- adSize = AdSize.LEADERBOARD;
- } else if (screenInches > 6) { // > 468 X 60
- adSize = AdSize.MEDIUM_RECTANGLE;
- } else { // > 320 X 50
- adSize = AdSize.BANNER;
- }
- // Create an ad.
- adView = new AdView(this);
- adView.setAdSize(adSize);
- adView.setAdUnitId(AD_UNIT_ID);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement