summaryrefslogtreecommitdiff
path: root/android/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-01-03 17:53:47 +0500
committerilotterytea <iltsu@alright.party>2025-01-03 17:53:47 +0500
commit91e54bfe44b82b80aaef956469d1b505a4d9baae (patch)
tree230a12a0f48bc44b0e290d93b7c21838dc35ac16 /android/src
parentcc1c51f9aa30a1a57623b29b8ac709de7bcef2f7 (diff)
feat: advertisement (i'm hungry PLEASE I NEED MONEY FOR FOOD)
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/java/kz/ilotterytea/maxon/AndroidLauncher.java78
1 files changed, 77 insertions, 1 deletions
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();
}
}