Bug 1390454 - Apply Banner fix for Leanplum SDK. r?maliu draft
authorNevin Chen <cnevinchen@gmail.com>
Wed, 15 Nov 2017 14:53:55 +0800
changeset 698060 f4f9efef5a66125509e383295487460f3819d3a2
parent 698059 6182dca6b8ef5dbe7cd67ce4ba11a61be0cc022e
child 740284 d1e99aae7e136e86e15cf29471f76b93c7ccd565
push id89188
push userbmo:cnevinchen@gmail.com
push dateWed, 15 Nov 2017 07:01:45 +0000
reviewersmaliu
bugs1390454
milestone58.0a1
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
mobile/android/thirdparty/com/leanplum/messagetemplates/HTMLTemplate.java
mobile/android/thirdparty/com/leanplum/utils/SizeUtil.java
--- 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;
+  }
 }