Skip to content

Commit 30359c7

Browse files
Merge pull request #34 from collinjackson/flutter/plugins#1942
* [firebase_admob] update AGP, gradle and admob * Update CHANGELOG entry with description of #2
2 parents 0e1d2fa + 367257d commit 30359c7

File tree

10 files changed

+62
-51
lines changed

10 files changed

+62
-51
lines changed

packages/firebase_admob/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.9.0+7
2+
3+
* Update Android gradle plugin, gradle, and Admob versions.
4+
* Improvements to the Android implementation, fixing warnings about a possible null pointer exception.
5+
* Fixed an issue where an advertisement could incorrectly remain displayed when transitioning to another screen.
6+
17
## 0.9.0+6
28

39
* Remove duplicate example from documentation.

packages/firebase_admob/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ buildscript {
2121
}
2222

2323
dependencies {
24-
classpath 'com.android.tools.build:gradle:3.3.0'
24+
classpath 'com.android.tools.build:gradle:3.4.2'
2525
}
2626
}
2727

@@ -45,6 +45,6 @@ android {
4545
disable 'InvalidPackage'
4646
}
4747
dependencies {
48-
api 'com.google.firebase:firebase-ads:17.2.0'
48+
api 'com.google.firebase:firebase-ads:18.1.1'
4949
}
5050
}

packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.google.android.gms.ads.AdRequest;
1111
import java.util.ArrayList;
1212
import java.util.Date;
13+
import java.util.List;
1314
import java.util.Map;
1415

1516
class AdRequestBuilderFactory {
@@ -53,29 +54,28 @@ private Integer getTargetingInfoInteger(String key, Object value) {
5354
return (Integer) value;
5455
}
5556

56-
private ArrayList getTargetingInfoArrayList(String key, Object value) {
57+
private List getTargetingInfoArrayList(String key, Object value) {
5758
if (value == null) return null;
5859
if (!(value instanceof ArrayList)) {
5960
Log.w(TAG, "targeting info " + key + ": expected an ArrayList");
6061
return null;
6162
}
62-
return (ArrayList) value;
63+
return (List) value;
6364
}
6465

6566
AdRequest.Builder createAdRequestBuilder() {
6667
AdRequest.Builder builder = new AdRequest.Builder();
6768
if (targetingInfo == null) return builder;
6869

69-
ArrayList testDevices =
70-
getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices"));
70+
List testDevices = getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices"));
7171
if (testDevices != null) {
7272
for (Object deviceValue : testDevices) {
7373
String device = getTargetingInfoString("testDevices element", deviceValue);
7474
if (device != null) builder.addTestDevice(device);
7575
}
7676
}
7777

78-
ArrayList keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords"));
78+
List keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords"));
7979
if (keywords != null) {
8080
for (Object keywordValue : keywords) {
8181
String keyword = getTargetingInfoString("keywords element", keywordValue);

packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
1515
import io.flutter.plugin.common.MethodChannel.Result;
1616
import io.flutter.plugin.common.PluginRegistry.Registrar;
17+
import java.util.Locale;
1718
import java.util.Map;
1819

1920
public class FirebaseAdMobPlugin implements MethodCallHandler {
@@ -51,34 +52,41 @@ private void callInitialize(MethodCall call, Result result) {
5152
result.success(Boolean.TRUE);
5253
}
5354

54-
private void callLoadBannerAd(
55-
int id, Activity activity, MethodChannel channel, MethodCall call, Result result) {
55+
private void callLoadBannerAd(Integer id, Activity activity, MethodCall call, Result result) {
5656
String adUnitId = call.argument("adUnitId");
5757
if (adUnitId == null || adUnitId.isEmpty()) {
5858
result.error("no_unit_id", "a null or empty adUnitId was provided for ad id=" + id, null);
5959
return;
6060
}
6161

62-
int width = call.argument("width");
63-
int height = call.argument("height");
64-
String adSizeType = call.argument("adSizeType");
62+
final Integer width = call.argument("width");
63+
final Integer height = call.argument("height");
64+
final String adSizeType = call.argument("adSizeType");
6565

66-
if (!adSizeType.equals("AdSizeType.WidthAndHeight")
67-
&& !adSizeType.equals("AdSizeType.SmartBanner")) {
66+
if (!"AdSizeType.WidthAndHeight".equals(adSizeType)
67+
&& !"AdSizeType.SmartBanner".equals(adSizeType)) {
6868
String errMsg =
69-
String.format("an invalid adSizeType (%s) was provided for banner id=%d", adSizeType, id);
69+
String.format(
70+
Locale.ENGLISH,
71+
"an invalid adSizeType (%s) was provided for banner id=%d",
72+
adSizeType,
73+
id);
7074
result.error("invalid_adsizetype", errMsg, null);
7175
}
7276

73-
if (adSizeType.equals("AdSizeType.WidthAndHeight") && (width <= 0 || height <= 0)) {
77+
if ("AdSizeType.WidthAndHeight".equals(adSizeType) && (width <= 0 || height <= 0)) {
7478
String errMsg =
7579
String.format(
76-
"an invalid AdSize (%d, %d) was provided for banner id=%d", width, height, id);
80+
Locale.ENGLISH,
81+
"an invalid AdSize (%d, %d) was provided for banner id=%d",
82+
width,
83+
height,
84+
id);
7785
result.error("invalid_adsize", errMsg, null);
7886
}
7987

8088
AdSize adSize;
81-
if (adSizeType.equals("AdSizeType.SmartBanner")) {
89+
if ("AdSizeType.SmartBanner".equals(adSizeType)) {
8290
adSize = AdSize.SMART_BANNER;
8391
} else {
8492
adSize = new AdSize(width, height);
@@ -142,28 +150,30 @@ private void callLoadRewardedVideoAd(MethodCall call, Result result) {
142150
result.success(Boolean.TRUE);
143151
}
144152

145-
private void callShowAd(int id, MethodCall call, Result result) {
153+
private void callShowAd(Integer id, MethodCall call, Result result) {
146154
MobileAd ad = MobileAd.getAdForId(id);
147155
if (ad == null) {
148156
result.error("ad_not_loaded", "show failed, the specified ad was not loaded id=" + id, null);
149157
return;
150158
}
151-
if (call.argument("anchorOffset") != null) {
152-
ad.anchorOffset = Double.parseDouble((String) call.argument("anchorOffset"));
159+
final String anchorOffset = call.argument("anchorOffset");
160+
final String horizontalCenterOffset = call.argument("horizontalCenterOffset");
161+
final String anchorType = call.argument("anchorType");
162+
if (anchorOffset != null) {
163+
ad.anchorOffset = Double.parseDouble(anchorOffset);
153164
}
154-
if (call.argument("horizontalCenterOffset") != null) {
155-
ad.horizontalCenterOffset =
156-
Double.parseDouble((String) call.argument("horizontalCenterOffset"));
165+
if (anchorType != null) {
166+
ad.horizontalCenterOffset = Double.parseDouble(horizontalCenterOffset);
157167
}
158-
if (call.argument("anchorType") != null) {
159-
ad.anchorType = call.argument("anchorType").equals("bottom") ? Gravity.BOTTOM : Gravity.TOP;
168+
if (anchorType != null) {
169+
ad.anchorType = "bottom".equals(anchorType) ? Gravity.BOTTOM : Gravity.TOP;
160170
}
161171

162172
ad.show();
163173
result.success(Boolean.TRUE);
164174
}
165175

166-
private void callIsAdLoaded(int id, MethodCall call, Result result) {
176+
private void callIsAdLoaded(Integer id, Result result) {
167177
MobileAd ad = MobileAd.getAdForId(id);
168178
if (ad == null) {
169179
result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null);
@@ -172,7 +182,7 @@ private void callIsAdLoaded(int id, MethodCall call, Result result) {
172182
result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE);
173183
}
174184

175-
private void callShowRewardedVideoAd(MethodCall call, Result result) {
185+
private void callShowRewardedVideoAd(Result result) {
176186
if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) {
177187
rewardedWrapper.show();
178188
result.success(Boolean.TRUE);
@@ -181,7 +191,7 @@ private void callShowRewardedVideoAd(MethodCall call, Result result) {
181191
}
182192
}
183193

184-
private void callDisposeAd(int id, MethodCall call, Result result) {
194+
private void callDisposeAd(Integer id, Result result) {
185195
MobileAd ad = MobileAd.getAdForId(id);
186196
if (ad == null) {
187197
result.error("no_ad_for_id", "dispose failed, no add exists for id=" + id, null);
@@ -194,10 +204,6 @@ private void callDisposeAd(int id, MethodCall call, Result result) {
194204

195205
@Override
196206
public void onMethodCall(MethodCall call, Result result) {
197-
if (call.method.equals("initialize")) {
198-
callInitialize(call, result);
199-
return;
200-
}
201207

202208
Activity activity = registrar.activity();
203209
if (activity == null) {
@@ -208,8 +214,11 @@ public void onMethodCall(MethodCall call, Result result) {
208214
Integer id = call.argument("id");
209215

210216
switch (call.method) {
217+
case "initialize":
218+
callInitialize(call, result);
219+
break;
211220
case "loadBannerAd":
212-
callLoadBannerAd(id, activity, channel, call, result);
221+
callLoadBannerAd(id, activity, call, result);
213222
break;
214223
case "loadInterstitialAd":
215224
callLoadInterstitialAd(MobileAd.createInterstitial(id, activity, channel), call, result);
@@ -221,13 +230,13 @@ public void onMethodCall(MethodCall call, Result result) {
221230
callShowAd(id, call, result);
222231
break;
223232
case "showRewardedVideoAd":
224-
callShowRewardedVideoAd(call, result);
233+
callShowRewardedVideoAd(result);
225234
break;
226235
case "disposeAd":
227-
callDisposeAd(id, call, result);
236+
callDisposeAd(id, result);
228237
break;
229238
case "isAdLoaded":
230-
callIsAdLoaded(id, call, result);
239+
callIsAdLoaded(id, result);
231240
break;
232241
default:
233242
result.notImplemented();

packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/MobileAd.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import android.view.View;
1212
import android.view.ViewGroup;
1313
import android.widget.LinearLayout;
14-
import com.google.android.gms.ads.AdListener;
15-
import com.google.android.gms.ads.AdSize;
16-
import com.google.android.gms.ads.AdView;
17-
import com.google.android.gms.ads.InterstitialAd;
14+
import com.google.android.gms.ads.*;
1815
import io.flutter.plugin.common.MethodChannel;
1916
import java.util.HashMap;
2017
import java.util.Map;

packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/RewardedVideoAdWrapper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
public class RewardedVideoAdWrapper implements RewardedVideoAdListener {
1818
private static final String TAG = "flutter";
1919

20-
final RewardedVideoAd rewardedInstance;
21-
final Activity activity;
22-
final MethodChannel channel;
23-
Status status;
20+
private final RewardedVideoAd rewardedInstance;
21+
private final MethodChannel channel;
22+
private Status status;
2423

2524
@Override
2625
public void onRewardedVideoAdLoaded() {
@@ -76,7 +75,6 @@ enum Status {
7675
}
7776

7877
public RewardedVideoAdWrapper(Activity activity, MethodChannel channel) {
79-
this.activity = activity;
8078
this.channel = channel;
8179
this.status = Status.CREATED;
8280
this.rewardedInstance = MobileAds.getRewardedVideoAdInstance(activity);

packages/firebase_admob/example/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ flutter {
5555

5656
dependencies {
5757
testImplementation 'junit:junit:4.12'
58-
androidTestImplementation 'androidx.test:runner:1.1.1'
59-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
58+
androidTestImplementation 'androidx.test:runner:1.2.0'
59+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
6060
}
6161

6262
apply plugin: 'com.google.gms.google-services'

packages/firebase_admob/example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.3.0'
9+
classpath 'com.android.tools.build:gradle:3.4.2'
1010
classpath 'com.google.gms:google-services:4.3.0'
1111
}
1212
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Thu Aug 01 22:44:13 BRT 2019
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

packages/firebase_admob/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Firebase AdMob, supporting
33
banner, interstitial (full-screen), and rewarded video ads
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_admob
6-
version: 0.9.0+6
6+
version: 0.9.0+7
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)