Skip to content

Commit 2bea826

Browse files
malandr2copybara-github
authored andcommitted
Fix API >= 35 layout for Interstitial examples
PiperOrigin-RevId: 852397433
1 parent 2e78ece commit 2bea826

File tree

19 files changed

+250
-102
lines changed

19 files changed

+250
-102
lines changed

java/admanager/InterstitialExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ android {
2222
dependencies {
2323
implementation 'androidx.appcompat:appcompat:1.2.0'
2424
implementation 'com.google.android.gms:play-services-ads:24.9.0'
25+
implementation 'com.google.android.material:material:1.13.0'
2526
implementation 'com.google.android.ump:user-messaging-platform:4.0.0'
2627
}

java/admanager/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import android.widget.Toast;
2929
import androidx.annotation.NonNull;
3030
import androidx.appcompat.app.AppCompatActivity;
31+
import androidx.core.graphics.Insets;
32+
import androidx.core.view.ViewCompat;
33+
import androidx.core.view.WindowInsetsCompat;
3134
import com.google.android.gms.ads.AdError;
3235
import com.google.android.gms.ads.FullScreenContentCallback;
3336
import com.google.android.gms.ads.LoadAdError;
@@ -68,6 +71,16 @@ public class MyActivity extends AppCompatActivity {
6871
protected void onCreate(Bundle savedInstanceState) {
6972
super.onCreate(savedInstanceState);
7073
setContentView(R.layout.activity_my);
74+
setSupportActionBar(findViewById(R.id.toolBar));
75+
76+
ViewCompat.setOnApplyWindowInsetsListener(
77+
findViewById(R.id.container),
78+
(view, insets) -> {
79+
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
80+
view.setPadding(
81+
systemBarsInsets.left, 0, systemBarsInsets.right, systemBarsInsets.bottom);
82+
return insets;
83+
});
7184

7285
// Log the Mobile Ads SDK version.
7386
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
22
xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:id="@+id/container"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
tools:context=".MyActivity"
78
tools:ignore="MergeRootFrame">
89

9-
<TextView
10-
android:id="@+id/game_title"
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:layout_centerHorizontal="true"
14-
android:layout_marginTop="50dp"
15-
android:text="@string/impossible_game"
16-
android:textAppearance="?android:attr/textAppearanceLarge" />
10+
<com.google.android.material.appbar.AppBarLayout
11+
android:id="@+id/app_bar_layout"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:fitsSystemWindows="true"
15+
android:background="?attr/colorPrimary">
1716

18-
<TextView
19-
android:id="@+id/timer"
20-
android:layout_width="wrap_content"
21-
android:layout_height="wrap_content"
22-
android:layout_below="@+id/game_title"
23-
android:layout_centerHorizontal="true"
24-
android:textAppearance="?android:attr/textAppearanceLarge" />
17+
<com.google.android.material.appbar.MaterialToolbar
18+
android:id="@+id/toolBar"
19+
android:layout_width="match_parent"
20+
android:layout_height="?attr/actionBarSize"
21+
app:titleTextColor="@android:color/white"
22+
app:title="@string/app_name" />
2523

26-
<Button
27-
android:id="@+id/retry_button"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:layout_centerHorizontal="true"
31-
android:layout_centerVertical="true"
32-
android:text="Retry" />
24+
</com.google.android.material.appbar.AppBarLayout>
25+
26+
<TextView
27+
android:id="@+id/game_title"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_below="@id/app_bar_layout"
31+
android:layout_centerHorizontal="true"
32+
android:layout_marginTop="50dp"
33+
android:text="@string/impossible_game"
34+
android:textAppearance="?android:attr/textAppearanceLarge" />
35+
36+
<TextView
37+
android:id="@+id/timer"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_below="@+id/game_title"
41+
android:layout_centerHorizontal="true"
42+
android:textAppearance="?android:attr/textAppearanceLarge" />
43+
44+
<Button
45+
android:id="@+id/retry_button"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_centerHorizontal="true"
49+
android:layout_centerVertical="true"
50+
android:text="Retry" />
3351

3452
</RelativeLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5-
<!-- Customize your theme here. -->
6-
</style>
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
710

811
</resources>

java/admob/InterstitialExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ android {
2222
dependencies {
2323
implementation 'androidx.appcompat:appcompat:1.2.0'
2424
implementation 'com.google.android.gms:play-services-ads:24.9.0'
25+
implementation 'com.google.android.material:material:1.13.0'
2526
implementation 'com.google.android.ump:user-messaging-platform:4.0.0'
2627
}

java/admob/InterstitialExample/app/src/main/java/com/google/android/gms/example/interstitialexample/MyActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import android.widget.Toast;
2929
import androidx.annotation.NonNull;
3030
import androidx.appcompat.app.AppCompatActivity;
31+
import androidx.core.graphics.Insets;
32+
import androidx.core.view.ViewCompat;
33+
import androidx.core.view.WindowInsetsCompat;
3134
import com.google.android.gms.ads.AdError;
3235
import com.google.android.gms.ads.AdRequest;
3336
import com.google.android.gms.ads.FullScreenContentCallback;
@@ -68,6 +71,16 @@ public class MyActivity extends AppCompatActivity {
6871
protected void onCreate(Bundle savedInstanceState) {
6972
super.onCreate(savedInstanceState);
7073
setContentView(R.layout.activity_my);
74+
setSupportActionBar(findViewById(R.id.toolBar));
75+
76+
ViewCompat.setOnApplyWindowInsetsListener(
77+
findViewById(R.id.container),
78+
(view, insets) -> {
79+
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
80+
view.setPadding(
81+
systemBarsInsets.left, 0, systemBarsInsets.right, systemBarsInsets.bottom);
82+
return insets;
83+
});
7184

7285
// Log the Mobile Ads SDK version.
7386
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
22
xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:id="@+id/container"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
tools:context=".MyActivity"
78
tools:ignore="MergeRootFrame">
89

9-
<TextView
10-
android:id="@+id/game_title"
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:layout_centerHorizontal="true"
14-
android:layout_marginTop="50dp"
15-
android:text="@string/impossible_game"
16-
android:textAppearance="?android:attr/textAppearanceLarge" />
10+
<com.google.android.material.appbar.AppBarLayout
11+
android:id="@+id/app_bar_layout"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:fitsSystemWindows="true"
15+
android:background="?attr/colorPrimary">
1716

18-
<TextView
19-
android:id="@+id/timer"
20-
android:layout_width="wrap_content"
21-
android:layout_height="wrap_content"
22-
android:layout_below="@+id/game_title"
23-
android:layout_centerHorizontal="true"
24-
android:textAppearance="?android:attr/textAppearanceLarge" />
17+
<com.google.android.material.appbar.MaterialToolbar
18+
android:id="@+id/toolBar"
19+
android:layout_width="match_parent"
20+
android:layout_height="?attr/actionBarSize"
21+
app:titleTextColor="@android:color/white"
22+
app:title="@string/app_name" />
2523

26-
<Button
27-
android:id="@+id/retry_button"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:layout_centerHorizontal="true"
31-
android:layout_centerVertical="true"
32-
android:text="Retry" />
24+
</com.google.android.material.appbar.AppBarLayout>
25+
26+
<TextView
27+
android:id="@+id/game_title"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_below="@id/app_bar_layout"
31+
android:layout_centerHorizontal="true"
32+
android:layout_marginTop="50dp"
33+
android:text="@string/impossible_game"
34+
android:textAppearance="?android:attr/textAppearanceLarge" />
35+
36+
<TextView
37+
android:id="@+id/timer"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_below="@+id/game_title"
41+
android:layout_centerHorizontal="true"
42+
android:textAppearance="?android:attr/textAppearanceLarge" />
43+
44+
<Button
45+
android:id="@+id/retry_button"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_centerHorizontal="true"
49+
android:layout_centerVertical="true"
50+
android:text="Retry" />
3351

3452
</RelativeLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5-
<!-- Customize your theme here. -->
6-
</style>
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
710

811
</resources>
12+

0 commit comments

Comments
 (0)