-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: make interstitial ad fullscreen and fix cutouts #462 Fix close, counter, and learn more button positions when there are cutouts or bottom navigation. Create custom theme for all interstitial ads. * fix: read timeout for file download tasks #462 * fix: increase creative factory timeout for interstitial cases #462 * fix: buttons visibility in interstitial ads #462 Fix Learn more button position. Show Learn more button in every video interstitial ad. Show count down button only for rewarded. * fix: insets fixes #462 Fix insets for other orientations. * fix: displaying Learn more #462 * fix: button positions after rotation #462 * fix: scaling end cards for any resolution #462
- Loading branch information
1 parent
b9b3ca6
commit 55dc976
Showing
17 changed files
with
377 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ebidMobile-core/src/main/java/org/prebid/mobile/rendering/utils/helpers/CustomInsets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.prebid.mobile.rendering.utils.helpers; | ||
|
||
public class CustomInsets { | ||
|
||
private int top; | ||
private int right; | ||
private int bottom; | ||
private int left; | ||
|
||
public CustomInsets( | ||
int top, | ||
int right, | ||
int bottom, | ||
int left | ||
) { | ||
this.top = top; | ||
this.right = right; | ||
this.bottom = bottom; | ||
this.left = left; | ||
} | ||
|
||
public int getTop() { | ||
return top; | ||
} | ||
|
||
public void setTop(int top) { | ||
this.top = top; | ||
} | ||
|
||
public int getRight() { | ||
return right; | ||
} | ||
|
||
public void setRight(int right) { | ||
this.right = right; | ||
} | ||
|
||
public int getBottom() { | ||
return bottom; | ||
} | ||
|
||
public void setBottom(int bottom) { | ||
this.bottom = bottom; | ||
} | ||
|
||
public int getLeft() { | ||
return left; | ||
} | ||
|
||
public void setLeft(int left) { | ||
this.left = left; | ||
} | ||
|
||
} |
158 changes: 158 additions & 0 deletions
158
...rebidMobile-core/src/main/java/org/prebid/mobile/rendering/utils/helpers/InsetsUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package org.prebid.mobile.rendering.utils.helpers; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.graphics.Insets; | ||
import android.os.Build; | ||
import android.view.*; | ||
import android.widget.FrameLayout; | ||
import android.widget.RelativeLayout; | ||
import androidx.annotation.Nullable; | ||
import org.prebid.mobile.LogUtil; | ||
|
||
public class InsetsUtils { | ||
|
||
private static final String TAG = InsetsUtils.class.getSimpleName(); | ||
|
||
/** | ||
* Adds to the view insets from navigation bar and cutout. | ||
* Insets must be calculated as we use translucent status and navigation bar in | ||
* interstitial ad. Must be applied to every view in interstitial ad. | ||
* <p> | ||
* It supports view where parents are RelativeLayout or FrameLayout. | ||
*/ | ||
public static void addCutoutAndNavigationInsets(@Nullable View view) { | ||
if (view == null) return; | ||
ViewGroup.LayoutParams params = view.getLayoutParams(); | ||
CustomInsets navigationInsets = getNavigationInsets(view.getContext()); | ||
CustomInsets cutoutInsets = getCutoutInsets(view.getContext()); | ||
CustomInsets insets = new CustomInsets( | ||
navigationInsets.getTop() + cutoutInsets.getTop(), | ||
navigationInsets.getRight() + cutoutInsets.getRight(), | ||
navigationInsets.getBottom() + cutoutInsets.getBottom(), | ||
navigationInsets.getLeft() + cutoutInsets.getLeft() | ||
); | ||
|
||
if (params instanceof FrameLayout.LayoutParams) { | ||
FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params; | ||
int gravity = frameParams.gravity; | ||
if ((gravity & Gravity.TOP) == Gravity.TOP) { | ||
frameParams.topMargin += insets.getTop(); | ||
} | ||
if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { | ||
frameParams.bottomMargin += insets.getBottom(); | ||
} | ||
if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { | ||
frameParams.rightMargin += insets.getRight(); | ||
} | ||
if ((gravity & Gravity.LEFT) == Gravity.LEFT) { | ||
frameParams.leftMargin += insets.getLeft(); | ||
} | ||
view.setLayoutParams(frameParams); | ||
} else if (params instanceof RelativeLayout.LayoutParams) { | ||
RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) params; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (relativeParams.getRule(RelativeLayout.ALIGN_PARENT_TOP) == RelativeLayout.TRUE) { | ||
relativeParams.topMargin += insets.getTop(); | ||
} | ||
if (relativeParams.getRule(RelativeLayout.ALIGN_PARENT_BOTTOM) == RelativeLayout.TRUE) { | ||
relativeParams.bottomMargin += insets.getBottom(); | ||
} | ||
if (relativeParams.getRule(RelativeLayout.ALIGN_PARENT_RIGHT) == RelativeLayout.TRUE | ||
|| relativeParams.getRule(RelativeLayout.ALIGN_PARENT_END) == RelativeLayout.TRUE | ||
) { | ||
relativeParams.rightMargin += insets.getRight(); | ||
} | ||
if (relativeParams.getRule(RelativeLayout.ALIGN_PARENT_LEFT) == RelativeLayout.TRUE | ||
|| relativeParams.getRule(RelativeLayout.ALIGN_PARENT_START) == RelativeLayout.TRUE | ||
) { | ||
relativeParams.leftMargin += insets.getLeft(); | ||
} | ||
} | ||
view.setLayoutParams(relativeParams); | ||
} else { | ||
LogUtil.error(TAG, "Can't set insets, unsupported LayoutParams type."); | ||
} | ||
} | ||
|
||
public static CustomInsets getCutoutInsets(Context context) { | ||
if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
DisplayCutout cutout = null; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
cutout = context.getDisplay().getCutout(); | ||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
if (context instanceof Activity) { | ||
Activity activity = (Activity) context; | ||
cutout = activity.getWindowManager().getDefaultDisplay().getCutout(); | ||
} | ||
} else { | ||
WindowInsets windowInsets = getWindowInsets(context); | ||
if (windowInsets != null) { | ||
cutout = windowInsets.getDisplayCutout(); | ||
} | ||
} | ||
if (cutout != null) { | ||
return new CustomInsets( | ||
cutout.getSafeInsetTop(), | ||
cutout.getSafeInsetRight(), | ||
cutout.getSafeInsetBottom(), | ||
cutout.getSafeInsetLeft() | ||
); | ||
} | ||
} | ||
return new CustomInsets(0, 0, 0, 0); | ||
} | ||
|
||
public static CustomInsets getNavigationInsets(Context context) { | ||
WindowInsets windowInsets = getWindowInsets(context); | ||
if (windowInsets != null) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
Insets insets = windowInsets.getInsets(WindowInsets.Type.navigationBars()); | ||
return new CustomInsets(insets.top, insets.right, insets.bottom, insets.left); | ||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
// noinspection deprecation | ||
return new CustomInsets( | ||
windowInsets.getStableInsetTop(), | ||
windowInsets.getStableInsetRight(), | ||
windowInsets.getStableInsetBottom(), | ||
windowInsets.getStableInsetLeft() | ||
); | ||
} | ||
} | ||
return new CustomInsets(0, 0, 0, 0); | ||
} | ||
|
||
public static void resetMargins(@Nullable View view) { | ||
int defaultMargin = 16; | ||
if (view != null) { | ||
ViewGroup.LayoutParams params = view.getLayoutParams(); | ||
if (params instanceof FrameLayout.LayoutParams) { | ||
FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params; | ||
frameParams.setMargins(defaultMargin, defaultMargin, defaultMargin, defaultMargin); | ||
view.setLayoutParams(frameParams); | ||
} else if (params instanceof RelativeLayout.LayoutParams) { | ||
RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) params; | ||
relativeParams.setMargins(defaultMargin, defaultMargin, defaultMargin, defaultMargin); | ||
view.setLayoutParams(relativeParams); | ||
} else { | ||
LogUtil.debug(TAG, "Can't reset margins."); | ||
} | ||
} | ||
} | ||
|
||
@Nullable | ||
private static WindowInsets getWindowInsets(@Nullable Context context) { | ||
if (context != null) { | ||
if (context instanceof Activity) { | ||
Activity activity = (Activity) context; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
return activity.getWindow().getDecorView().getRootWindowInsets(); | ||
} | ||
} else { | ||
LogUtil.debug(TAG, "Can't get window insets, Context is not Activity type."); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.