Rev 1838 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1004 | chris | 1 | package com.gebauz.burutaru; |
| 2 | |||
| 1203 | chris | 3 | import android.annotation.TargetApi; |
| 1109 | chris | 4 | import android.app.Dialog; |
| 1203 | chris | 5 | import android.os.Build; |
| 1004 | chris | 6 | import android.os.Bundle; |
| 1108 | chris | 7 | import android.view.View; |
| 8 | import android.view.Window; |
||
| 1004 | chris | 9 | import android.view.WindowManager; |
| 1108 | chris | 10 | import android.widget.RelativeLayout; |
| 1004 | chris | 11 | |
| 12 | import com.badlogic.gdx.backends.android.AndroidApplication; |
||
| 13 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; |
||
| 14 | |||
| 1108 | chris | 15 | import com.gebauz.bauzoid.app.AdHandler; |
| 16 | import com.google.android.gms.ads.AdRequest; |
||
| 17 | import com.google.android.gms.ads.AdSize; |
||
| 18 | import com.google.android.gms.ads.AdView; |
||
| 1109 | chris | 19 | import com.google.android.gms.common.ConnectionResult; |
| 20 | import com.google.android.gms.common.GooglePlayServicesUtil; |
||
| 1108 | chris | 21 | |
| 1203 | chris | 22 | public class MainActivity extends AndroidApplication |
| 23 | { |
||
| 1838 | chris | 24 | public static final boolean useGooglePlaySdk = false; |
| 1203 | chris | 25 | |
| 26 | @Override |
||
| 27 | public void onCreate(Bundle savedInstanceState) |
||
| 28 | { |
||
| 1004 | chris | 29 | super.onCreate(savedInstanceState); |
| 30 | |||
| 31 | AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); |
||
| 1841 | chris | 32 | //cfg.useGLSurfaceView20API18 = true; |
| 1004 | chris | 33 | |
| 1838 | chris | 34 | if (useGooglePlaySdk) |
| 1109 | chris | 35 | { |
| 1838 | chris | 36 | // check for google play services sdk |
| 37 | int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); |
||
| 38 | if (result != ConnectionResult.SUCCESS) |
||
| 39 | { |
||
| 40 | Dialog dlg = GooglePlayServicesUtil.getErrorDialog(result, this, 0); |
||
| 41 | if (dlg != null) |
||
| 42 | dlg.show(); |
||
| 43 | } |
||
| 44 | |||
| 45 | // Create Ad View |
||
| 46 | RelativeLayout layout = new RelativeLayout(this); |
||
| 47 | |||
| 48 | // Do the stuff that initialize() would do for you |
||
| 49 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
||
| 50 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
||
| 51 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
||
| 52 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); |
||
| 53 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
||
| 54 | |||
| 55 | BurutaruApp app = new BurutaruApp(true); |
||
| 56 | |||
| 57 | // Create the libgdx View |
||
| 58 | View gameView = initializeForView(app, cfg); |
||
| 59 | |||
| 60 | // Create and setup the AdMob view |
||
| 61 | AdView adView = new AdView(this); |
||
| 62 | adView.setAdSize(AdSize.BANNER); |
||
| 63 | adView.setAdUnitId("a151922aa6be37c"); |
||
| 64 | adView.loadAd(new AdRequest.Builder().build()); |
||
| 65 | |||
| 66 | app.setAdHandler(new AdHandler(this, adView)); |
||
| 67 | |||
| 68 | // Add the libgdx view |
||
| 69 | layout.addView(gameView); |
||
| 70 | |||
| 71 | // Add the AdMob view |
||
| 72 | RelativeLayout.LayoutParams adParams = |
||
| 73 | new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, |
||
| 74 | RelativeLayout.LayoutParams.WRAP_CONTENT); |
||
| 75 | adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
||
| 76 | adParams.addRule(RelativeLayout.CENTER_IN_PARENT); |
||
| 77 | |||
| 78 | layout.addView(adView, adParams); |
||
| 79 | |||
| 80 | // Hook it all up |
||
| 81 | setContentView(layout); |
||
| 1109 | chris | 82 | } |
| 1838 | chris | 83 | else |
| 1203 | chris | 84 | { |
| 1838 | chris | 85 | initialize(new BurutaruApp(false), cfg); |
| 86 | } |
||
| 1004 | chris | 87 | } |
| 1203 | chris | 88 | |
| 89 | @Override |
||
| 90 | public void onWindowFocusChanged(boolean hasFocus) |
||
| 91 | { |
||
| 92 | super.onWindowFocusChanged(hasFocus); |
||
| 93 | applyViewParameters(getWindow().getDecorView()); |
||
| 94 | } |
||
| 95 | |||
| 1204 | chris | 96 | @TargetApi(Build.VERSION_CODES.KITKAT) |
| 1203 | chris | 97 | public static void applyViewParameters(View view) |
| 98 | { |
||
| 99 | if (getAndroidAPILevel() >= 11) |
||
| 100 | { |
||
| 101 | view.setSystemUiVisibility( |
||
| 102 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
||
| 103 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
||
| 104 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
||
| 105 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
||
| 106 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
||
| 107 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | public static int getAndroidAPILevel() |
||
| 112 | { |
||
| 113 | |||
| 114 | String androidOS = android.os.Build.VERSION.RELEASE; |
||
| 115 | int api = 0; |
||
| 116 | |||
| 117 | // SDK_INT is introduced in 1.6 (API Level 4) so code referencing that would fail |
||
| 118 | // Also we can't use SDK_INT since some modified ROMs play around with this value, RELEASE is most versatile variable |
||
| 119 | if (androidOS.startsWith("1.6")) api = 4; |
||
| 120 | if (androidOS.startsWith("2.0")) api = 5; |
||
| 121 | if (androidOS.startsWith("2.1")) api = 7; |
||
| 122 | if (androidOS.startsWith("2.2")) api = 8; |
||
| 123 | if (androidOS.startsWith("2.3")) api = 9; |
||
| 124 | if (androidOS.startsWith("3.0")) api = 11; |
||
| 125 | if (androidOS.startsWith("3.1")) api = 12; |
||
| 126 | if (androidOS.startsWith("3.2")) api = 13; |
||
| 127 | if (androidOS.startsWith("4.0")) api = 14; |
||
| 128 | if (androidOS.startsWith("4.1")) api = 16; |
||
| 129 | if (androidOS.startsWith("4.2")) api = 17; |
||
| 130 | if (androidOS.startsWith("4.3")) api = 18; |
||
| 131 | if (androidOS.startsWith("4.4")) api = 19; |
||
| 132 | |||
| 133 | return api; |
||
| 134 | } |
||
| 1004 | chris | 135 | } |