Sfoglia il codice sorgente

[메인][New] 이미지 스크롤 작용
- 이미지가 스크린 보다 큰 경우/작은 경우 별도 처리

hyodong.min 7 anni fa
parent
commit
1cc55eb88f

+ 76 - 36
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryImageView.java

@@ -6,12 +6,19 @@ package kr.co.zumo.app.lifeplus.view.screen.main;
 import android.content.Context;
 import android.graphics.Matrix;
 import android.graphics.drawable.Drawable;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.target.Target;
+
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.api.MainContentsBean;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
@@ -107,7 +114,7 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
       // values[0] and values[4] are the zoom factors for the image's width and height respectively. If you zoom at the same factor, these should both be the same value.
 
       /**
-       *
+       * * 이미지가 스크린보다 작을 때
        *           │                       │
        *           ├────────┐     ┌────────┤
        *           │image   │     │  img   │
@@ -119,6 +126,25 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
        *           │                       │
        *           │0                      │ screen width
        *
+       *
+       *  * 이미지가 스크린보다 클 때
+       *           │                       │
+       *  ┌────────┼───────────────────────┤
+       *  │  img   │                       │
+       *  │        │                       ├──────┐
+       *  │        │                       │      │
+       *  │        │                       │ mask │
+       *  │        │                       ├──────┘
+       *  └────────┼───────────────────────┤
+       *           │                       │
+       *           │0                      │ screen width
+       *           ├───────────────────────┼────────┐
+       *           │image                  │        │
+       *    ┌──────┤                       │        │
+       *    │      │                       │        │
+       *    │ mask │                       │        │
+       *    └──────┤                       │        │
+       *           ├───────────────────────┼────────┘
        *              mask == itemView
        */
 
@@ -138,22 +164,22 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
 
       if (x > -maskWidth && x < screenWidth) {  // holder 가 표시되는 부분에서만 계산
 
-        // x = 0 ~ image.w - screen.w
-        ratio = (float) (maskWidth + x) / (maskWidth + screenWidth);
-
         if (imageWidth < screenWidth) {
 
           /**
            * 이미지가 스크린보다 작을 때
-           * - 마스크가 보여지는 면적보다 많이 offset 돼지 않도록 계산한다.
            */
-          tx = -((int) ((imageWidth - maskWidth) * ratio));  // image 이동 구간 -image.w + mask.w ~ 0
+          // x = 0 ~ screen.w - mask.w
+          ratio = (float) x / (screenWidth - maskWidth);
+          tx = -((int) ((imageWidth - maskWidth) * ratio));  // image 이동 구간 0 ~ -image.w-mask.w
 
         }
         else {
           /**
            * 이미지가 스크린보다 클 때
            */
+          // x = 0 ~ image.w - screen.w
+          ratio = (float) (maskWidth + x) / (maskWidth + screenWidth);
           tx = -((int) ((imageWidth + maskWidth) * ratio)) + maskWidth;  // image 이동 구간 -image.w ~ mask.w
         }
 
@@ -176,10 +202,23 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
       y = getScreenY(itemView);
 
       if (y > -maskHeight && y < screenHeight) {  // holder 가 표시되는 부분에서만 계산
-        ratio = (float) y / (screenHeight - maskHeight);
 
-        ty = -((int) ((imageHeight - maskHeight) * ratio));
+        if (imageHeight < screenHeight) {
+          /**
+           * 이미지가 스크린보다 작을 때
+           */
+          ratio = (float) y / (screenHeight - maskHeight);
+          ty = -((int) ((imageHeight - maskHeight) * ratio));
+
+        }
+        else {
+          /**
+           * 이미지가 스크린보다 클 때
+           */
+          ratio = (float) (maskHeight + x) / (maskHeight + screenHeight);
+          ty = -((int) ((imageHeight + maskHeight) * ratio)) + maskHeight;
 
+        }
         cy = (int) values[5];
         dy = ty - cy;
       }
@@ -210,37 +249,38 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
 
     String url = bean.getImageUrl();
 
-    Drawable drawable = imageView.getDrawable();
-//    you should call after the bitmap drawn
-    imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
-    imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
+//    Drawable drawable = imageView.getDrawable();
+////    you should call after the bitmap drawn
+//    imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
+//    imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
 
     onScrolledInternal();
 
-//    Glide.with(imageView)
-//      .load(url)
-//      .listener(new RequestListener<Drawable>() {
-//        @Override
-//        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
-//          return false;
-//        }
-//
-//        @Override
-//        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
-//          Drawable drawable = resource;
-//          //you should call after the bitmap drawn
-//          imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
-//          imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
-//
-////    Log.i("APP# MainContentsCategoryImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
-////    Log.i("APP# MainContentsCategoryImageView | init", "| imageWidth: " + imageWidth + ", imageHeight: " + imageHeight);
-//
-//          onScrolledInternal();
-//
-//          return false;
-//        }
-//      })
-//      .into(imageView);
+    Glide.with(imageView)
+      .load(url)
+      .listener(new RequestListener<Drawable>() {
+        @Override
+        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+          return false;
+        }
+
+        @Override
+        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+          Drawable drawable = resource;
+          //you should call after the bitmap drawn
+          imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
+          imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
+
+//    Log.i("APP# MainContentsCategoryImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
+//    Log.i("APP# MainContentsCategoryImageView | init", "| imageWidth: " + imageWidth + ", imageHeight: " + imageHeight);
+
+          onScrolledInternal();
+
+          return false;
+        }
+
+      })
+      .into(imageView);
 
 
   }