Skip to content

Commit

Permalink
code formatting added
Browse files Browse the repository at this point in the history
  • Loading branch information
alihassan143 committed Sep 12, 2024
1 parent 3e2947d commit ab8aa57
Show file tree
Hide file tree
Showing 26 changed files with 338 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,97 @@
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) {
MobileAds.initialize(context, listener);
}

/** 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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
</application>
</manifest>
1 change: 1 addition & 0 deletions samples/admob/app_open_example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions samples/admob/app_open_example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
</application>
</manifest>
1 change: 1 addition & 0 deletions samples/admob/banner_example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions samples/admob/banner_example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions samples/admob/banner_example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions samples/admob/interstitial_example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
<meta-data
android:name="applovin.sdk.key"
android:value="TODO - add your applovin key"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true"/>
</application>
</manifest>
1 change: 1 addition & 0 deletions samples/admob/rewarded_example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
Loading

0 comments on commit ab8aa57

Please sign in to comment.