|
|
@@ -6,6 +6,7 @@ package kr.co.zumo.app.lifeplus.view.screen.main;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.Matrix;
|
|
|
+import android.os.Handler;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.util.Log;
|
|
|
@@ -58,16 +59,73 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
|
|
|
private int screenHeight;
|
|
|
private int spaceWidth;
|
|
|
|
|
|
- public MainCategoryContentsImageView(Context context, View view) {
|
|
|
+ private int categoryIndex;
|
|
|
+
|
|
|
+ public MainCategoryContentsImageView(Context context, View view, int index) {
|
|
|
super(context, view);
|
|
|
+
|
|
|
+ this.categoryIndex = index;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onScrolledVertical(RecyclerView recyclerView, int dx, int dy) {
|
|
|
+ if (categoryIndex == 1) {
|
|
|
+ onScrolledForText();
|
|
|
+ }
|
|
|
+ onScrolledForImage();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
- onScrolledInternal();
|
|
|
+ public void onScrolledHorizontal(RecyclerView recyclerView, int dx, int dy) {
|
|
|
+ if (categoryIndex == 1) {
|
|
|
+ onScrolledForText();
|
|
|
+ }
|
|
|
+ onScrolledForImage();
|
|
|
}
|
|
|
|
|
|
- private void onScrolledInternal() {
|
|
|
+ private void onScrolledForText() {
|
|
|
+ /**
|
|
|
+ * 화면 높이 - 71 보다 아래에 있으면 해당 위치까지 위치시키고,
|
|
|
+ * 내부의 위치가 152보다 높으면 제한
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ // text
|
|
|
+ int cy = getScreenY(textBig);
|
|
|
+
|
|
|
+ // 적당한 위치에 있을 때만 처리한다.
|
|
|
+ // 화면 밖일 경우도 있으므로 스크린 높이의 2배를 허용.
|
|
|
+ if (cy >= 0 && cy < (screenHeight << 2)) {
|
|
|
+ moveText(cy);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void moveText(int cy) {
|
|
|
+ int ty;
|
|
|
+ int gap;
|
|
|
+ int y;
|
|
|
+ int max;
|
|
|
+ int min;
|
|
|
+ ty = textPositionTargetYOnScreen;
|
|
|
+ gap = ty - cy;
|
|
|
+ Log.i("APP# MainCategoryContentsImageView | moveText", "|" + " cy: " + cy + ", ty: " + ty + ", gap: " + gap + ", this:" + this.hashCode());
|
|
|
+
|
|
|
+ y = (int) (textBig.getY() + gap);
|
|
|
+ // 뷰 영역 안에서만 이동 가능
|
|
|
+ max = textPositionMaxYOnMask;
|
|
|
+ min = -400; // 위쪽으로 사라지도록 0 보다 작은 값
|
|
|
+ if (y > max) {
|
|
|
+ y = max;
|
|
|
+ }
|
|
|
+ else if (y < min) {
|
|
|
+ y = min;
|
|
|
+ }
|
|
|
+ textBig.setY(y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void onScrolledForImage() {
|
|
|
/**
|
|
|
* 화면 높이 - 71 보다 아래에 있으면 해당 위치까지 위치시키고,
|
|
|
* 내부의 위치가 152보다 높으면 제한
|
|
|
@@ -76,187 +134,162 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
|
|
|
int cx;
|
|
|
int cy;
|
|
|
int ty;
|
|
|
- int tx;
|
|
|
- int gap;
|
|
|
+ int tx = 0;
|
|
|
int x;
|
|
|
int y;
|
|
|
float dx = 0f;
|
|
|
float dy = 0f;
|
|
|
- int max;
|
|
|
- int min;
|
|
|
float ratio;
|
|
|
|
|
|
- // text
|
|
|
- /*if (null != textBig) {
|
|
|
- cy = getScreenY(textBig);
|
|
|
-
|
|
|
- // 적당한 위치에 있을 때만 처리한다.
|
|
|
- if (cy > 0 && cy < (screenHeight << 1)) {
|
|
|
- ty = textPositionTargetYOnScreen;
|
|
|
- gap = ty - cy;
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolled", "|" + " cy: " + cy + ", ty: " + ty + ", gap: " + gap + ", this:" + this.hashCode());
|
|
|
-
|
|
|
- y = (int) (textBig.getY() + gap);
|
|
|
- // 뷰 영역 안에서만 이동 가능
|
|
|
- max = textPositionMaxYOnMask;
|
|
|
- min = -400; // 위쪽으로 사라지도록 0 보다 작은 값
|
|
|
- if (y > max) {
|
|
|
- y = max;
|
|
|
- }
|
|
|
- else if (y < min) {
|
|
|
- y = min;
|
|
|
- }
|
|
|
- textBig.setY(y);
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
// image
|
|
|
- if (null != imageView) {
|
|
|
- Matrix matrix = new Matrix();
|
|
|
- matrix.set(imageView.getImageMatrix());
|
|
|
- // Get the values of the matrix
|
|
|
- float[] values = new float[9];
|
|
|
- matrix.getValues(values);
|
|
|
-
|
|
|
- // values[2] and values[5] are the x,y coordinates of the top left corner of the drawable image, regardless of the zoom factor.
|
|
|
- // 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 │
|
|
|
- * ├──────┐ │ │ ┌──────┤
|
|
|
- * │ │ │ │ │ │
|
|
|
- * │ mask │ │ │ │ mask │
|
|
|
- * ├──────┘ │ │ └──────┤
|
|
|
- * ├────────┘ └────────┤
|
|
|
- * │ │
|
|
|
- * │0 │ screen width
|
|
|
- *
|
|
|
- *
|
|
|
- * * 이미지가 스크린보다 클 때
|
|
|
- * │ │
|
|
|
- * ┌────────┼───────────────────────┤
|
|
|
- * │ img │ │
|
|
|
- * │ │ ├──────┐
|
|
|
- * │ │ │ │
|
|
|
- * │ │ │ mask │
|
|
|
- * │ │ ├──────┘
|
|
|
- * └────────┼───────────────────────┤
|
|
|
- * │ │
|
|
|
- * │0 │ screen width
|
|
|
- * ├───────────────────────┼────────┐
|
|
|
- * │image │ │
|
|
|
- * ┌──────┤ │ │
|
|
|
- * │ │ │ │
|
|
|
- * │ mask │ │ │
|
|
|
- * └──────┤ │ │
|
|
|
- * ├───────────────────────┼────────┘
|
|
|
- * mask == itemView
|
|
|
- */
|
|
|
-
|
|
|
- /**
|
|
|
- mask.x : 0 ~ screen.w-mask.w
|
|
|
-
|
|
|
- if mask.x == 0 => image.x = 0;
|
|
|
- if mask.x == screen.w-mask.w => image.x = image.w-mask.w
|
|
|
-
|
|
|
- image.x : 0 ~ -(image.w-mask.w)
|
|
|
-
|
|
|
- - 화면에 표시되는 영역만 계산하고 나머지는 비율에 맞게 움직이도록 처리
|
|
|
-
|
|
|
- */
|
|
|
-
|
|
|
- x = (int) itemView.getX();
|
|
|
-
|
|
|
- if (x > -maskWidth && x < screenWidth) { // holder 가 표시되는 부분에서만 계산
|
|
|
-
|
|
|
- // modify itemView x -------------------------------------------------
|
|
|
- tx = 0;
|
|
|
-// cx = x + (maskWidth >> 1);
|
|
|
-// ratio = (float) -cx / (maskWidth >> 1);
|
|
|
-//
|
|
|
-// if (ratio > 1) {
|
|
|
-// ratio = 1;
|
|
|
-// }
|
|
|
-// else if (ratio < 0) {
|
|
|
-// ratio = 0;
|
|
|
-// }
|
|
|
-// tx = (int) -(spaceWidth * ratio);
|
|
|
-//
|
|
|
-// // 이미지와 dim 마스크 함께 이동.
|
|
|
-// imageView.setX(tx);
|
|
|
-// mask0.setX(tx);
|
|
|
-// mask1.setX(tx);
|
|
|
-// mask2.setX(tx);
|
|
|
- // modify itemView x -------------------------------------------------
|
|
|
-
|
|
|
- // bitmap x -------------------------------------------------------
|
|
|
- if (imageWidth > screenWidth) {
|
|
|
- /**
|
|
|
- * 이미지가 스크린보다 클 때
|
|
|
- */
|
|
|
- // x = 0 ~ image.w - screen.w
|
|
|
- ratio = (float) (maskWidth + x) / (maskWidth + screenWidth);
|
|
|
- tx = -((int) ((imageWidth + maskWidth) * ratio)) + maskWidth - tx; // image 이동 구간 -image.w ~ mask.w, 이미지 view 이동 구간 반영
|
|
|
- }
|
|
|
- else {
|
|
|
- /**
|
|
|
- * 이미지가 스크린보다 작을 때
|
|
|
- */
|
|
|
- // x = 0 ~ screen.w - mask.w
|
|
|
- ratio = (float) x / (screenWidth - maskWidth);
|
|
|
- tx = -((int) ((imageWidth - maskWidth) * ratio)) - tx; // image 이동 구간 0 ~ -image.w-mask.w, 이미지 view 이동 구간 반영
|
|
|
- }
|
|
|
+ Matrix matrix = new Matrix();
|
|
|
+ matrix.set(imageView.getImageMatrix());
|
|
|
+ // Get the values of the matrix
|
|
|
+ float[] values = new float[9];
|
|
|
+ matrix.getValues(values);
|
|
|
|
|
|
- cx = (int) values[2];
|
|
|
- dx = tx - cx;
|
|
|
- // bitmap x -------------------------------------------------------
|
|
|
+ // values[2] and values[5] are the x,y coordinates of the top left corner of the drawable image, regardless of the zoom factor.
|
|
|
+ // 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.
|
|
|
|
|
|
-// if (index == 2) {
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " x: " + x);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " ratio: " + ratio);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " imageWidth: " + imageWidth);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " maskWidth: " + maskWidth);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " tx: " + tx);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " dx: " + dx);
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "| item x: " + itemView.getX());
|
|
|
-// Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "| item y: " + itemView.getY());
|
|
|
-// }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * * 이미지가 스크린보다 작을 때
|
|
|
+ * │ │
|
|
|
+ * ├────────┐ ┌────────┤
|
|
|
+ * │image │ │ img │
|
|
|
+ * ├──────┐ │ │ ┌──────┤
|
|
|
+ * │ │ │ │ │ │
|
|
|
+ * │ mask │ │ │ │ mask │
|
|
|
+ * ├──────┘ │ │ └──────┤
|
|
|
+ * ├────────┘ └────────┤
|
|
|
+ * │ │
|
|
|
+ * │0 │ screen width
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * * 이미지가 스크린보다 클 때
|
|
|
+ * │ │
|
|
|
+ * ┌────────┼───────────────────────┤
|
|
|
+ * │ img │ │
|
|
|
+ * │ │ ├──────┐
|
|
|
+ * │ │ │ │
|
|
|
+ * │ │ │ mask │
|
|
|
+ * │ │ ├──────┘
|
|
|
+ * └────────┼───────────────────────┤
|
|
|
+ * │ │
|
|
|
+ * │0 │ screen width
|
|
|
+ * ├───────────────────────┼────────┐
|
|
|
+ * │image │ │
|
|
|
+ * ┌──────┤ │ │
|
|
|
+ * │ │ │ │
|
|
|
+ * │ mask │ │ │
|
|
|
+ * └──────┤ │ │
|
|
|
+ * ├───────────────────────┼────────┘
|
|
|
+ * mask == itemView
|
|
|
+ */
|
|
|
|
|
|
+ /**
|
|
|
+ mask.x : 0 ~ screen.w-mask.w
|
|
|
|
|
|
- y = getScreenY(itemView);
|
|
|
+ if mask.x == 0 => image.x = 0;
|
|
|
+ if mask.x == screen.w-mask.w => image.x = image.w-mask.w
|
|
|
|
|
|
- if (y > -maskHeight && y < screenHeight) { // holder 가 표시되는 부분에서만 계산
|
|
|
+ image.x : 0 ~ -(image.w-mask.w)
|
|
|
|
|
|
- // bitmap y -------------------------------------------------------
|
|
|
- if (imageHeight > screenHeight) {
|
|
|
- /**
|
|
|
- * 이미지가 스크린보다 클 때
|
|
|
- */
|
|
|
- ratio = (float) (maskHeight + y) / (maskHeight + screenHeight);
|
|
|
- ty = -((int) ((imageHeight + maskHeight) * ratio)) + maskHeight;
|
|
|
- }
|
|
|
- else {
|
|
|
- /**
|
|
|
- * 이미지가 스크린보다 작을 때
|
|
|
- */
|
|
|
- ratio = (float) y / (screenHeight - maskHeight);
|
|
|
- ty = -((int) ((imageHeight - maskHeight) * ratio));
|
|
|
- }
|
|
|
- cy = (int) values[5];
|
|
|
- dy = ty - cy;
|
|
|
- // bitmap y -------------------------------------------------------
|
|
|
+ - 화면에 표시되는 영역만 계산하고 나머지는 비율에 맞게 움직이도록 처리
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+ x = (int) itemView.getX();
|
|
|
+
|
|
|
+ if (x > -maskWidth && x < screenWidth) { // holder 가 표시되는 부분에서만 계산
|
|
|
+
|
|
|
+ // modify itemView x -------------------------------------------------
|
|
|
+ int widthHalf = maskWidth >> 1;
|
|
|
+ cx = x + widthHalf;
|
|
|
+ ratio = (float) cx / (widthHalf - spaceWidth);
|
|
|
|
|
|
+// if (index == 0) {
|
|
|
+// Log.w("APP# MainCategoryContentsImageView | onScrolledForImage", "| x: " + x + ", cx: " + cx + ", ratio: " + ratio);
|
|
|
+// }
|
|
|
+
|
|
|
+ if (ratio < -1) {
|
|
|
+ ratio = -1;
|
|
|
+ }
|
|
|
+ else if (ratio > 0) {
|
|
|
+ ratio = 0;
|
|
|
+ }
|
|
|
+ tx = (int) (spaceWidth * ratio);
|
|
|
+
|
|
|
+ // 이미지와 dim 마스크 함께 이동.
|
|
|
+ imageView.setX(tx);
|
|
|
+ mask0.setX(tx);
|
|
|
+ mask1.setX(tx);
|
|
|
+ mask2.setX(tx);
|
|
|
+ // modify itemView x -------------------------------------------------
|
|
|
+
|
|
|
+ // bitmap x -------------------------------------------------------
|
|
|
+ if (imageWidth > screenWidth) {
|
|
|
+ /**
|
|
|
+ * 이미지가 스크린보다 클 때
|
|
|
+ */
|
|
|
+ // x = 0 ~ image.w - screen.w
|
|
|
+ ratio = (float) (maskWidth + x) / (maskWidth + screenWidth);
|
|
|
+ tx = -((int) ((imageWidth + maskWidth) * ratio)) + maskWidth - tx; // image 이동 구간 -image.w ~ mask.w, 이미지 view 이동 구간 반영
|
|
|
}
|
|
|
+ else {
|
|
|
+ /**
|
|
|
+ * 이미지가 스크린보다 작을 때
|
|
|
+ */
|
|
|
+ // x = 0 ~ screen.w - mask.w
|
|
|
+ ratio = (float) x / (screenWidth - maskWidth);
|
|
|
+ tx = -((int) ((imageWidth - maskWidth) * ratio)) - tx; // image 이동 구간 0 ~ -image.w-mask.w, 이미지 view 이동 구간 반영
|
|
|
+ }
|
|
|
+
|
|
|
+ cx = (int) values[2];
|
|
|
+ dx = tx - cx;
|
|
|
+ // bitmap x -------------------------------------------------------
|
|
|
+
|
|
|
+// if (index == 2) {
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " x: " + x);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " ratio: " + ratio);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " imageWidth: " + imageWidth);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " maskWidth: " + maskWidth);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " tx: " + tx);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "|" + " dx: " + dx);
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "| item x: " + itemView.getX());
|
|
|
+// Log.i("APP# MainCategoryContentsImageView | onScrolledForText", "| item y: " + itemView.getY());
|
|
|
+// }
|
|
|
+ }
|
|
|
|
|
|
- matrix.postTranslate(dx, dy);
|
|
|
|
|
|
- imageView.setImageMatrix(matrix);
|
|
|
+ y = getScreenY(itemView);
|
|
|
+
|
|
|
+ if (y > -maskHeight && y < screenHeight) { // holder 가 표시되는 부분에서만 계산
|
|
|
+
|
|
|
+ // bitmap y -------------------------------------------------------
|
|
|
+ if (imageHeight > screenHeight) {
|
|
|
+ /**
|
|
|
+ * 이미지가 스크린보다 클 때
|
|
|
+ */
|
|
|
+ ratio = (float) (maskHeight + y) / (maskHeight + screenHeight);
|
|
|
+ ty = -((int) ((imageHeight + maskHeight) * ratio)) + maskHeight;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ /**
|
|
|
+ * 이미지가 스크린보다 작을 때
|
|
|
+ */
|
|
|
+ ratio = (float) y / (screenHeight - maskHeight);
|
|
|
+ ty = -((int) ((imageHeight - maskHeight) * ratio));
|
|
|
+ }
|
|
|
+ cy = (int) values[5];
|
|
|
+ dy = ty - cy;
|
|
|
+ // bitmap y -------------------------------------------------------
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ matrix.postTranslate(dx, dy);
|
|
|
+
|
|
|
+ imageView.setImageMatrix(matrix);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -285,11 +318,12 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
|
|
|
maskWidth = ResourceUtil.getDimension(R.dimen.main_contents_image_width);
|
|
|
maskHeight = ResourceUtil.getDimension(R.dimen.main_contents_image_height);
|
|
|
|
|
|
- spaceWidth = ResourceUtil.getDimension(R.dimen.main_contents_start_gap);
|
|
|
+ spaceWidth = ResourceUtil.getDimension(R.dimen.main_contents_start_gap) - ResourceUtil.getDimension(R.dimen.main_contents_image_padding_end);
|
|
|
|
|
|
String url = bean.getImageUrl();
|
|
|
|
|
|
- onScrolledInternal();
|
|
|
+ // 텍스트 위치 조절
|
|
|
+ new Handler().post(() -> moveText(getScreenY(textBig)));
|
|
|
|
|
|
imageWidth = Math.max(maskWidth + ResourceUtil.dpToPx(50), screenWidth - ResourceUtil.dpToPx(50));
|
|
|
imageHeight = maskHeight + ResourceUtil.dpToPx(50);
|
|
|
@@ -317,15 +351,13 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
|
|
|
Log.i("APP# MainCategoryContentsImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
|
|
|
Log.i("APP# MainCategoryContentsImageView | init", "| imageWidth: " + imageLoadedWidth + ", imageHeight: " + imageLoadedHeight);
|
|
|
|
|
|
- onScrolledInternal();
|
|
|
+ onScrolledForImage();
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
})
|
|
|
.into(imageView);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|