Bug 1390454 - Apply Banner fix for Leanplum SDK. r?maliu
Since we want to update our fork of Leanplum SDK as minimum as possible, this patch only pick the patch from Leanplum repo:
https://github.com/Leanplum/Leanplum-Android-SDK/pull/41
MozReview-Commit-ID: 5qFgH9xhHfy
--- a/mobile/android/thirdparty/com/leanplum/messagetemplates/HTMLTemplate.java
+++ b/mobile/android/thirdparty/com/leanplum/messagetemplates/HTMLTemplate.java
@@ -27,16 +27,17 @@ import android.util.Log;
import android.view.MotionEvent;
import com.leanplum.ActionContext;
import com.leanplum.Leanplum;
import com.leanplum.LeanplumActivityHelper;
import com.leanplum.callbacks.ActionCallback;
import com.leanplum.callbacks.PostponableAction;
import com.leanplum.callbacks.VariablesChangedCallback;
+import com.leanplum.utils.SizeUtil;
/**
* Registers a Leanplum action that displays a HTML message.
*
* @author Anna Orlova
*/
@SuppressWarnings("WeakerAccess")
public class HTMLTemplate extends BaseMessageDialog {
@@ -45,20 +46,22 @@ public class HTMLTemplate extends BaseMe
public HTMLTemplate(Activity activity, HTMLOptions htmlOptions) {
super(activity, htmlOptions.isFullScreen(), null, null, htmlOptions);
this.htmlOptions = htmlOptions;
}
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
if (!htmlOptions.isFullScreen()) {
+ int height = SizeUtil.dpToPx(Leanplum.getContext(), htmlOptions.getHtmlHeight());
+ int statusBarHeight = SizeUtil.getStatusBarHeight(Leanplum.getContext());
if (htmlOptions.getHtmlAlign().equals(MessageTemplates.Args.HTML_ALIGN_TOP) && ev.getY()
- > htmlOptions.getHtmlHeight() ||
+ > height + statusBarHeight ||
htmlOptions.getHtmlAlign().equals(MessageTemplates.Args.HTML_ALIGN_BOTTOM) && ev.getY()
- < dialogView.getHeight() - htmlOptions.getHtmlHeight()) {
+ < dialogView.getHeight() + statusBarHeight - height) {
activity.dispatchTouchEvent(ev);
}
}
return super.dispatchTouchEvent(ev);
}
public static void register() {
Leanplum.defineAction(NAME, Leanplum.ACTION_KIND_MESSAGE | Leanplum.ACTION_KIND_ACTION,
--- a/mobile/android/thirdparty/com/leanplum/utils/SizeUtil.java
+++ b/mobile/android/thirdparty/com/leanplum/utils/SizeUtil.java
@@ -109,9 +109,22 @@ public class SizeUtil {
int result = 0;
int resourceId = activity.getResources().getIdentifier("status_bar_height",
"dimen", "android");
if (resourceId > 0) {
result = activity.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
+
+ public static int getStatusBarHeight(Context context) {
+ init(context);
+ int result = 0;
+ try {
+ int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ if (resourceId > 0) {
+ result = context.getResources().getDimensionPixelSize(resourceId);
+ }
+ } catch (Throwable ignored) {
+ }
+ return result;
+ }
}