diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-03 17:53:47 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-03 17:53:47 +0500 |
| commit | 91e54bfe44b82b80aaef956469d1b505a4d9baae (patch) | |
| tree | 230a12a0f48bc44b0e290d93b7c21838dc35ac16 | |
| parent | cc1c51f9aa30a1a57623b29b8ac709de7bcef2f7 (diff) | |
feat: advertisement (i'm hungry PLEASE I NEED MONEY FOR FOOD)
| -rw-r--r-- | android/AndroidManifest.xml | 5 | ||||
| -rw-r--r-- | android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java | 78 | ||||
| -rw-r--r-- | build.gradle | 1 | ||||
| -rw-r--r-- | gradle.properties | 1 |
4 files changed, 84 insertions, 1 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 00fbed1..a3f0290 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -16,6 +16,11 @@ android:label="@string/app_name" android:theme="@style/AppTheme" tools:ignore="UnusedAttribute"> + <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> + <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> + <meta-data + android:name="com.google.android.gms.ads.APPLICATION_ID" + android:value="ca-app-pub-6822396317563333~6426082247"/> <activity android:name="kz.ilotterytea.maxon.AndroidLauncher" android:label="@string/app_name" diff --git a/android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java b/android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java index 94f678e..2953027 100644 --- a/android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java +++ b/android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java @@ -1,15 +1,91 @@ package kz.ilotterytea.maxon; +import android.annotation.SuppressLint; +import android.graphics.Color; 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.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.AdSize; +import com.google.android.gms.ads.AdView; public class AndroidLauncher extends AndroidApplication { + private static final String AD_UNIT_ID = "ca-app-pub-6822396317563333/7782869287"; + protected AdView adView; + protected View gameView; + @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); - initialize(MaxonGame.getInstance(), config); + + // 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); + + RelativeLayout layout = new RelativeLayout(this); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); + layout.setLayoutParams(params); + + AdView admobView = createAdView(); + layout.addView(admobView); + View gameView = createGameView(config); + layout.addView(gameView); + + setContentView(layout); + startAdvertising(admobView); + } + + @SuppressLint("ResourceType") + private AdView createAdView() { + adView = new AdView(this); + adView.setAdSize(AdSize.SMART_BANNER); + adView.setAdUnitId(AD_UNIT_ID); + adView.setId(12345); // this is an arbitrary id, allows for relative positioning in createGameView() + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); + params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); + adView.setLayoutParams(params); + adView.setBackgroundColor(Color.BLACK); + return adView; + } + + private View createGameView(AndroidApplicationConfiguration cfg) { + gameView = initializeForView(MaxonGame.getInstance(), cfg); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); + params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); + params.addRule(RelativeLayout.BELOW, adView.getId()); + gameView.setLayoutParams(params); + return gameView; + } + + private void startAdvertising(AdView adView) { + AdRequest adRequest = new AdRequest.Builder().build(); + adView.loadAd(adRequest); + } + + @Override + public void onResume() { + super.onResume(); + if (adView != null) adView.resume(); + } + + @Override + public void onPause() { + if (adView != null) adView.pause(); + super.onPause(); + } + + @Override + public void onDestroy() { + if (adView != null) adView.destroy(); + super.onDestroy(); } } diff --git a/build.gradle b/build.gradle index f4e6069..f1338d7 100644 --- a/build.gradle +++ b/build.gradle @@ -63,6 +63,7 @@ project(":android") { natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64" implementation "androidx.core:core:$androidXVersion" + implementation "com.google.android.gms:play-services-ads:$playAdsVersion" } } diff --git a/gradle.properties b/gradle.properties index 5781a3a..8ba24b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,7 @@ gradleVersion=8.6.0-alpha07 androidXVersion=1.13.1 kotlinGradlePluginVersion=1.7.21 kotlinVersion=1.7.21 +playAdsVersion=23.6.0 gdxVersion=1.13.0 gltfVersion=2.2.1 |
