Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4.  
  5. // Create an ad.
  6. adView = new AdView(this);
  7. adView.setAdSize(AdSize.BANNER);
  8. adView.setAdUnitId(AD_UNIT_ID);
  9.  
  10. // Add the AdView to the view hierarchy. The view will have no size
  11. // until the ad is loaded.
  12. RelativeLayout layout = new RelativeLayout(this);
  13. layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  14.  
  15. // Create an ad request. Check logcat output for the hashed device ID to
  16. // get test ads on a physical device.
  17. AdRequest adRequest = new AdRequest.Builder()
  18. .addTestDevice(TestDeviceID)
  19. .build();
  20.  
  21. // Start loading the ad in the background.
  22. adView.loadAd(adRequest);
  23.  
  24. //Request full screen
  25. requestWindowFeature(Window.FEATURE_NO_TITLE);
  26. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  27. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  28.  
  29. //Create a displayMetrics object to get pixel width and height
  30. metrics = new DisplayMetrics();
  31. getWindowManager().getDefaultDisplay().getMetrics(metrics);
  32. width = metrics.widthPixels;
  33. height = metrics.heightPixels;
  34.  
  35. //Work out values for resizing screen while keeping aspect ratio
  36.  
  37. width = (int) Math.min(width, height * 1.702127659574468);
  38. height = (int) Math.min(height, width / 1.702127659574468);
  39.  
  40. //Create and set GL view (OpenGL View)
  41. myView = new MyGLSurfaceView(MainActivity.this);
  42.  
  43. RelativeLayout.LayoutParams adParams =
  44. new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
  45. RelativeLayout.LayoutParams.WRAP_CONTENT);
  46. adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  47. adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
  48.  
  49. //Set the colour if we don't, the ad won't show (bug?)
  50. adView.setBackgroundColor(Color.BLACK);
  51. layout.addView(myView);
  52. layout.addView(adView, adParams);
  53.  
  54. //Create a copy of the Bundle
  55. if (savedInstanceState != null){
  56. newBundle = new Bundle(savedInstanceState);
  57. }
  58.  
  59.  
  60. setContentView(layout);
  61.  
  62. }
  63.  
  64. AdSize adSize = AdSize.SMART_BANNER;
  65.  
  66. DisplayMetrics dm = getResources().getDisplayMetrics();
  67.  
  68. double density = dm.density * 160;
  69. double x = Math.pow(dm.widthPixels / density, 2);
  70. double y = Math.pow(dm.heightPixels / density, 2);
  71. double screenInches = Math.sqrt(x + y);
  72.  
  73. if (screenInches > 8) { // > 728 X 90
  74. adSize = AdSize.LEADERBOARD;
  75. } else if (screenInches > 6) { // > 468 X 60
  76. adSize = AdSize.MEDIUM_RECTANGLE;
  77. } else { // > 320 X 50
  78. adSize = AdSize.BANNER;
  79. }
  80.  
  81.  
  82.  
  83. // Create an ad.
  84. adView = new AdView(this);
  85. adView.setAdSize(adSize);
  86. adView.setAdUnitId(AD_UNIT_ID);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement