Parcourir la source

[온보딩][New] webView 의 드래그/스와이프 이벤트가 부드럽게 작동하지 않아서 native 의 스와이프 이벤트로 좌우 스크롤 시킴
- 드래그는 안됨

hyodong.min il y a 6 ans
Parent
commit
c6d2c7c64a

+ 22 - 0
app/src/main/assets/on_boarding/new/app.js

@@ -27,6 +27,7 @@ all = new FlexibleScreen({
 Main_Page = new PageComponent({
   parent: all,
   size: all.size,
+  scrollHorizontal: false,
   scrollVertical: false
 });
 
@@ -34,9 +35,30 @@ Main_Page.content.draggable.overdrag = false;
 
 Tuto_Page = new PageComponent({
   size: all.size,
+  scrollHorizontal: false,
   scrollVertical: false
 });
 
+//scrollNext = function() {
+//  if(Main_Page.currentPage === Tuto_Page) {
+//    Tuto_Page.snapToNextPage();
+//  }
+//  else {
+//    Main_Page.snapToPage(Tuto_Page);
+//  }
+//  return null;
+//};
+//
+//scrollPrev = function() {
+//  if(Main_Page.currentPage === Tuto_Page) {
+//    Tuto_Page.snapToPreviousPage();
+//  }
+//  else {
+//    //
+//  }
+//  return null;
+//};
+
 Tuto_Page.content.draggable.overdrag = false;
 
 Main_Page.addPage(Title);

+ 22 - 0
app/src/main/assets/on_boarding/zumo/app.js

@@ -27,6 +27,7 @@ all = new FlexibleScreen({
 Main_Page = new PageComponent({
   parent: all,
   size: all.size,
+  scrollHorizontal: false,
   scrollVertical: false
 });
 
@@ -34,9 +35,30 @@ Main_Page.content.draggable.overdrag = false;
 
 Tuto_Page = new PageComponent({
   size: all.size,
+  scrollHorizontal: false,
   scrollVertical: false
 });
 
+//scrollNext = function() {
+//  if(Main_Page.currentPage === Tuto_Page) {
+//    Tuto_Page.snapToNextPage();
+//  }
+//  else {
+//    Main_Page.snapToPage(Tuto_Page);
+//  }
+//  return null;
+//};
+//
+//scrollPrev = function() {
+//  if(Main_Page.currentPage === Tuto_Page) {
+//    Tuto_Page.snapToPreviousPage();
+//  }
+//  else {
+//    //
+//  }
+//  return null;
+//};
+
 Tuto_Page.content.draggable.overdrag = false;
 
 Main_Page.addPage(Title);

+ 117 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/onboarding/OnBoardingFragment.java

@@ -3,12 +3,17 @@
  */
 package kr.co.zumo.app.lifeplus.view.screen.onboarding;
 
+import android.annotation.SuppressLint;
+import android.content.Context;
 import android.net.http.SslError;
+import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.util.Log;
+import android.view.GestureDetector;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.webkit.ConsoleMessage;
@@ -22,6 +27,7 @@ import android.webkit.WebViewClient;
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.helper.ActionBarHelper;
 import kr.co.zumo.app.lifeplus.model.BlankModel;
+import kr.co.zumo.app.lifeplus.util.AppUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.WebConstant;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
@@ -81,8 +87,39 @@ public class OnBoardingFragment extends FragmentBase<OnBoardingPresenter> implem
     return true;
   }
 
+
+  @SuppressLint("ClickableViewAccessibility")
   @Override
   public void draw(boolean isZumoUser) {
+    /**
+     * webView 의 드래그/스와이프 이벤트가 부드럽게 작동하지 않아서
+     * native 의 스와이프 이벤트로 좌우 스크롤 시킴
+     * 드래그는 안됨.
+     */
+
+    webView.setOnTouchListener(new OnSwipeTouchListener(getActivity()) {
+      @Override
+      public void onSwipeRight() {
+        webView.evaluateJavascript("(function() { if(Main_Page.currentPage === Tuto_Page) {\n" +
+          "    Tuto_Page.snapToPreviousPage();\n" +
+          "  }\n" +
+          "  else {\n" +
+          "  }\n" +
+          "  return null;})();", s -> {});
+      }
+
+      @Override
+      public void onSwipeLeft() {
+        webView.evaluateJavascript("(function() {  if(Main_Page.currentPage === Tuto_Page) {\n" +
+          "    Tuto_Page.snapToNextPage();\n" +
+          "  }\n" +
+          "  else {\n" +
+          "    Main_Page.snapToPage(Tuto_Page);\n" +
+          "  }\n" +
+          "  return null;})();", s -> {});
+      }
+    });
+
     webView.addJavascriptInterface(this, WebConstant.OBJECT_ID);
 
     webView.setWebViewClient(new WebViewClient() {
@@ -165,8 +202,88 @@ public class OnBoardingFragment extends FragmentBase<OnBoardingPresenter> implem
     settings.setDatabaseEnabled(true);
     settings.setDomStorageEnabled(true);
 
+
     // 캐쉬 사용 방법을 정의
     settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
 
+    // debug
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+      if (AppUtil.isDebug()) {
+        WebView.setWebContentsDebuggingEnabled(true);
+      }
+    }
+  }
+
+
+  /***********************************
+   * Swipe event
+   ***********************************/
+  public class OnSwipeTouchListener implements View.OnTouchListener {
+
+    private final GestureDetector gestureDetector;
+
+    public OnSwipeTouchListener(Context ctx) {
+      gestureDetector = new GestureDetector(ctx, new GestureListener());
+    }
+
+    @Override
+    public boolean onTouch(View v, MotionEvent event) {
+      return gestureDetector.onTouchEvent(event);
+    }
+
+    private final class GestureListener extends GestureDetector.SimpleOnGestureListener {
+
+      private static final int SWIPE_THRESHOLD = 10;
+      private static final int SWIPE_VELOCITY_THRESHOLD = 10;
+
+      @Override
+      public boolean onDown(MotionEvent e) {
+        return false;
+      }
+
+      @Override
+      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
+        boolean result = false;
+        try {
+          float diffY = e2.getY() - e1.getY();
+          float diffX = e2.getX() - e1.getX();
+          if (Math.abs(diffX) > Math.abs(diffY)) {
+            if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
+              if (diffX > 0) {
+                onSwipeRight();
+              }
+              else {
+                onSwipeLeft();
+              }
+              result = true;
+            }
+          }
+          else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
+            if (diffY > 0) {
+              onSwipeBottom();
+            }
+            else {
+              onSwipeTop();
+            }
+            result = true;
+          }
+        } catch (Exception exception) {
+          exception.printStackTrace();
+        }
+        return result;
+      }
+    }
+
+    public void onSwipeRight() {
+    }
+
+    public void onSwipeLeft() {
+    }
+
+    public void onSwipeTop() {
+    }
+
+    public void onSwipeBottom() {
+    }
   }
 }