Rev 1838 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.burutaru;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.gebauz.bauzoid.app.AdHandler;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity
extends AndroidApplication
{
public static final boolean useGooglePlaySdk =
false;
@
Override
public void onCreate
(Bundle savedInstanceState
)
{
super.
onCreate(savedInstanceState
);
AndroidApplicationConfiguration cfg =
new AndroidApplicationConfiguration
();
//cfg.useGLSurfaceView20API18 = true;
if (useGooglePlaySdk
)
{
// check for google play services sdk
int result = GooglePlayServicesUtil.
isGooglePlayServicesAvailable(this);
if (result
!= ConnectionResult.
SUCCESS)
{
Dialog dlg = GooglePlayServicesUtil.
getErrorDialog(result,
this,
0);
if (dlg
!=
null)
dlg.
show();
}
// Create Ad View
RelativeLayout layout =
new RelativeLayout
(this);
// Do the stuff that initialize() would do for you
requestWindowFeature
(Window.
FEATURE_NO_TITLE);
getWindow
().
setFlags(WindowManager.
LayoutParams.
FLAG_FULLSCREEN,
WindowManager.
LayoutParams.
FLAG_FULLSCREEN);
getWindow
().
clearFlags(WindowManager.
LayoutParams.
FLAG_FORCE_NOT_FULLSCREEN);
getWindow
().
addFlags(WindowManager.
LayoutParams.
FLAG_KEEP_SCREEN_ON);
BurutaruApp app =
new BurutaruApp
(true);
// Create the libgdx View
View gameView = initializeForView
(app, cfg
);
// Create and setup the AdMob view
AdView adView =
new AdView
(this);
adView.
setAdSize(AdSize.
BANNER);
adView.
setAdUnitId("a151922aa6be37c");
adView.
loadAd(new AdRequest.
Builder().
build());
app.
setAdHandler(new AdHandler
(this, adView
));
// Add the libgdx view
layout.
addView(gameView
);
// Add the AdMob view
RelativeLayout.
LayoutParams adParams =
new RelativeLayout.
LayoutParams(RelativeLayout.
LayoutParams.
WRAP_CONTENT,
RelativeLayout.
LayoutParams.
WRAP_CONTENT);
adParams.
addRule(RelativeLayout.
ALIGN_PARENT_TOP);
adParams.
addRule(RelativeLayout.
CENTER_IN_PARENT);
layout.
addView(adView, adParams
);
// Hook it all up
setContentView
(layout
);
}
else
{
initialize
(new BurutaruApp
(false), cfg
);
}
}
@
Override
public void onWindowFocusChanged
(boolean hasFocus
)
{
super.
onWindowFocusChanged(hasFocus
);
applyViewParameters
(getWindow
().
getDecorView());
}
@TargetApi
(Build.
VERSION_CODES.
KITKAT)
public static void applyViewParameters
(View view
)
{
if (getAndroidAPILevel
() >=
11)
{
view.
setSystemUiVisibility(
View.
SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
View.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
View.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
View.
SYSTEM_UI_FLAG_FULLSCREEN
|
View.
SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
public static int getAndroidAPILevel
()
{
String androidOS = android.
os.
Build.
VERSION.
RELEASE;
int api =
0;
// SDK_INT is introduced in 1.6 (API Level 4) so code referencing that would fail
// Also we can't use SDK_INT since some modified ROMs play around with this value, RELEASE is most versatile variable
if (androidOS.
startsWith("1.6")) api =
4;
if (androidOS.
startsWith("2.0")) api =
5;
if (androidOS.
startsWith("2.1")) api =
7;
if (androidOS.
startsWith("2.2")) api =
8;
if (androidOS.
startsWith("2.3")) api =
9;
if (androidOS.
startsWith("3.0")) api =
11;
if (androidOS.
startsWith("3.1")) api =
12;
if (androidOS.
startsWith("3.2")) api =
13;
if (androidOS.
startsWith("4.0")) api =
14;
if (androidOS.
startsWith("4.1")) api =
16;
if (androidOS.
startsWith("4.2")) api =
17;
if (androidOS.
startsWith("4.3")) api =
18;
if (androidOS.
startsWith("4.4")) api =
19;
return api
;
}
}