From 4b31bad381ceff28af82291a9e8381942e9e6d25 Mon Sep 17 00:00:00 2001 From: Ahmad Abu Hasan Date: Sun, 12 Mar 2023 04:01:40 +0700 Subject: [PATCH] setup Ads --- .../ahmadabuhasan/qrbarcode/MainActivity.java | 25 ------------------- .../com/ahmadabuhasan/qrbarcode/Utils.java | 16 +++--------- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/ahmadabuhasan/qrbarcode/MainActivity.java b/app/src/main/java/com/ahmadabuhasan/qrbarcode/MainActivity.java index acf7330..8b359e9 100644 --- a/app/src/main/java/com/ahmadabuhasan/qrbarcode/MainActivity.java +++ b/app/src/main/java/com/ahmadabuhasan/qrbarcode/MainActivity.java @@ -30,7 +30,6 @@ public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler { private static final int PERMISSION_CODE = 100; - //private static final String TAG = "ConfigCat"; private static final String FLASH_STATE = "FLASH_STATE"; private static long pressedTime; private boolean flashlight; @@ -50,7 +49,6 @@ protected void onCreate(Bundle savedInstanceState) { MobileAds.initialize(this, initializationStatus -> { }); - new Utils().interstitialAdsShow(this); AdRequest adRequest = new AdRequest.Builder().build(); binding.adView.loadAd(adRequest); @@ -59,8 +57,6 @@ protected void onCreate(Bundle savedInstanceState) { flashOn(); flashOff(); - - //ConfigCat(); } private void flashOn() { @@ -151,30 +147,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { public void onBackPressed() { if (pressedTime + 2000 > System.currentTimeMillis()) { finishAndRemoveTask(); - if (Utils.interstitialAd.isLoaded()) { - Utils.interstitialAd.show(); - } else { - super.onBackPressed(); - finish(); - } - finishAndRemoveTask(); } else { Toast.makeText(this, "Press once again to exit", Toast.LENGTH_SHORT).show(); } pressedTime = System.currentTimeMillis(); } - - /*private void ConfigCat() { - String SDK = BuildConfig.SDK; - ConfigCatClient client = ConfigCatClient.newBuilder() - .logLevel(LogLevel.INFO) - .logLevel(LogLevel.DEBUG) - .build(SDK); - - User user = User.newBuilder() - .email("example@email.com") - .build(SDK); - - Log.d(TAG, "ConfigCat: " + client + user); - }*/ } \ No newline at end of file diff --git a/app/src/main/java/com/ahmadabuhasan/qrbarcode/Utils.java b/app/src/main/java/com/ahmadabuhasan/qrbarcode/Utils.java index b879291..0670fe5 100644 --- a/app/src/main/java/com/ahmadabuhasan/qrbarcode/Utils.java +++ b/app/src/main/java/com/ahmadabuhasan/qrbarcode/Utils.java @@ -2,7 +2,6 @@ import android.content.Context; import android.os.Handler; -import android.util.Log; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; @@ -19,19 +18,10 @@ public void interstitialAdsShow(Context context) { interstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { - AdsDelay(); - Log.d("interstitialAd", "Show"); + if (interstitialAd.isLoaded()) { + interstitialAd.show(); + } } }); } - - public void AdsDelay() { - Handler handler = new Handler(); - handler.postDelayed(() -> { - if (interstitialAd == null || !interstitialAd.isLoaded()) { - return; - } - interstitialAd.show(); - }, 30000); - } } \ No newline at end of file