Skip to content

Commit

Permalink
code formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
alihassan143 committed Sep 18, 2024
1 parent ab8aa57 commit 5aea9b2
Showing 1 changed file with 61 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,97 +18,76 @@
import android.os.Build;
import android.util.Log;
import android.webkit.WebView;

import androidx.annotation.NonNull;

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.OnAdInspectorClosedListener;
import com.google.android.gms.ads.RequestConfiguration;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.webviewflutter.WebViewFlutterAndroidExternalApi;

/**
* A wrapper around static methods in {@link com.google.android.gms.ads.MobileAds}.
*/
/** A wrapper around static methods in {@link com.google.android.gms.ads.MobileAds}. */
public class FlutterMobileAdsWrapper {

private static final String TAG = "FlutterMobileAdsWrapper";

public FlutterMobileAdsWrapper() {
}

/**
* Initializes the sdk.
*/
public void initialize(@NonNull Context context, @NonNull OnInitializationCompleteListener listener) {
new Thread(() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(context, listener);
}).start();
}

/**
* Wrapper for setAppMuted.
*/
public void setAppMuted(boolean muted) {
MobileAds.setAppMuted(muted);
}

/**
* Wrapper for setAppVolume.
*/
public void setAppVolume(double volume) {
MobileAds.setAppVolume((float) volume);
}

/**
* Wrapper for disableMediationInitialization.
*/
public void disableMediationInitialization(@NonNull Context context) {
MobileAds.disableMediationAdapterInitialization(context);
}

/**
* Wrapper for getVersionString.
*/
public String getVersionString() {
return MobileAds.getVersion().toString();
}

/**
* Wrapper for getRequestConfiguration.
*/
public RequestConfiguration getRequestConfiguration() {
return MobileAds.getRequestConfiguration();
}

/**
* Wrapper for openDebugMenu.
*/
public void openDebugMenu(Context context, String adUnitId) {
MobileAds.openDebugMenu(context, adUnitId);
}

/**
* Open the ad inspector.
*/
public void openAdInspector(Context context, OnAdInspectorClosedListener listener) {
MobileAds.openAdInspector(context, listener);
}

/**
* Register the webView for monetization.
*/
public void registerWebView(int webViewId, FlutterEngine flutterEngine) {
WebView webView = WebViewFlutterAndroidExternalApi.getWebView(flutterEngine, webViewId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Log.w(TAG, "MobileAds.registerWebView does not support API levels less than 21");
} else if (webView == null) {
Log.w(TAG, "MobileAds.registerWebView unable to find webView with id: " + webViewId);
} else {
MobileAds.registerWebView(webView);
}
private static final String TAG = "FlutterMobileAdsWrapper";

public FlutterMobileAdsWrapper() {}

/** Initializes the sdk. */
public void initialize(
@NonNull Context context, @NonNull OnInitializationCompleteListener listener) {
new Thread(
() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(context, listener);
})
.start();
}

/** Wrapper for setAppMuted. */
public void setAppMuted(boolean muted) {
MobileAds.setAppMuted(muted);
}

/** Wrapper for setAppVolume. */
public void setAppVolume(double volume) {
MobileAds.setAppVolume((float) volume);
}

/** Wrapper for disableMediationInitialization. */
public void disableMediationInitialization(@NonNull Context context) {
MobileAds.disableMediationAdapterInitialization(context);
}

/** Wrapper for getVersionString. */
public String getVersionString() {
return MobileAds.getVersion().toString();
}

/** Wrapper for getRequestConfiguration. */
public RequestConfiguration getRequestConfiguration() {
return MobileAds.getRequestConfiguration();
}

/** Wrapper for openDebugMenu. */
public void openDebugMenu(Context context, String adUnitId) {
MobileAds.openDebugMenu(context, adUnitId);
}

/** Open the ad inspector. */
public void openAdInspector(Context context, OnAdInspectorClosedListener listener) {
MobileAds.openAdInspector(context, listener);
}

/** Register the webView for monetization. */
public void registerWebView(int webViewId, FlutterEngine flutterEngine) {
WebView webView = WebViewFlutterAndroidExternalApi.getWebView(flutterEngine, webViewId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Log.w(TAG, "MobileAds.registerWebView does not support API levels less than 21");
} else if (webView == null) {
Log.w(TAG, "MobileAds.registerWebView unable to find webView with id: " + webViewId);
} else {
MobileAds.registerWebView(webView);
}
}
}

0 comments on commit 5aea9b2

Please sign in to comment.