Explorar o código

[메인][New] 등장 에니메이션 적용 2

hyodong.min %!s(int64=7) %!d(string=hai) anos
pai
achega
afdc0e76e5

+ 22 - 15
app/src/main/java/kr/co/zumo/app/lifeplus/model/SuperModelInit.java

@@ -32,31 +32,38 @@ public class SuperModelInit {
    */
   public static void init(Context context) {
     WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
-    Display display = wm.getDefaultDisplay();
-    Point size = new Point();
-    display.getSize(size);
-    int width = size.x;
-    int height = size.y;
-
-    height += getSoftButtonsBarHeight(context);
+    int width = 0;
+    int height = 0;
+    if (wm != null) {
+      Display display = wm.getDefaultDisplay();
+      Point size = new Point();
+      display.getSize(size);
+      width = size.x;
+      height = size.y + getSoftButtonsBarHeight(context);
+    }
 
     Log.w("APP# SuperModelInit | init", "|" + " SCREEN W: " + width + ", H: " + height);
 
     SuperModel.getInstance().init(new LifeplusPreferences(new BaseSharedPreferences(PreferenceManager.getDefaultSharedPreferences(context))), width, height);
-
     SuperModel.getInstance().setDeviceId(AppUtil.getDeviceId(context));
   }
 
   private static int getSoftButtonsBarHeight(Context context) {
     // getRealMetrics is only available with API 17 and +
     WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
-    DisplayMetrics metrics = new DisplayMetrics();
-    wm.getDefaultDisplay().getMetrics(metrics);
-    int usableHeight = metrics.heightPixels;
-    wm.getDefaultDisplay().getRealMetrics(metrics);
-    int realHeight = metrics.heightPixels;
-    if (realHeight > usableHeight) {
-      return realHeight - usableHeight;
+    if (wm != null) {
+      Display display = wm.getDefaultDisplay();
+      DisplayMetrics metrics = new DisplayMetrics();
+      display.getMetrics(metrics);
+      int usableHeight = metrics.heightPixels;
+      display.getRealMetrics(metrics);
+      int realHeight = metrics.heightPixels;
+      if (realHeight > usableHeight) {
+        return realHeight - usableHeight;
+      }
+      else {
+        return 0;
+      }
     }
     else {
       return 0;

+ 15 - 9
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsImageView.java

@@ -52,6 +52,7 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
   private int maskWidth;
   private int maskHeight;
   private int textPositionMaxYOnMask;       // mask(itemView) 에서 텍스트가 위치할 수 있는 최대값
+  private int textPositionMinYOnMask;       // mask(itemView) 에서 텍스트가 위치할 수 있는 최소값
   private int textPositionTargetYOnScreen;  // screen 에서 텍스트가 위치할 Y 값
   private int imageWidth;
   private int imageHeight;
@@ -114,7 +115,7 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
     y = (int) (textBig.getY() + gap);
     // 뷰 영역 안에서만 이동 가능
     max = textPositionMaxYOnMask;
-    min = -400;    // 위쪽으로 사라지도록 0 보다 작은 값
+    min = textPositionMinYOnMask;    // 위쪽으로 사라지도록 0 보다 작은 값
     if (y > max) {
       y = max;
     }
@@ -228,14 +229,15 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
 
       // 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*/ {
+      else*/
+      {
         /**
          * 이미지가 스크린보다 작을 때
          */
@@ -307,10 +309,14 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
     mask2 = itemView.findViewById(R.id.mask_2);
     imageView.setOnClickListener(v -> listener.onEvent(new Event.Builder(Event.CONTENTS).integer(index).build()));
 
+    int textYFromBottom = ResourceUtil.dpToPx(71);
     this.screenWidth = SuperModel.getInstance().getScreenWidth();
     this.screenHeight = SuperModel.getInstance().getScreenHeight();
-    this.textPositionMaxYOnMask = (((ViewGroup.MarginLayoutParams) textBig.getLayoutParams()).topMargin); //ResourceUtil.dpToPx(218); <- 레이아웃의 위치를 최대값으로 지정.
-    this.textPositionTargetYOnScreen = screenHeight - ResourceUtil.dpToPx(71);
+    this.textPositionMaxYOnMask = (((ViewGroup.MarginLayoutParams) textBig.getLayoutParams()).topMargin); // <- 레이아웃의 위치를 최대값으로 지정.
+    this.textPositionMinYOnMask = (ResourceUtil.getDimension(R.dimen.main_contents_first_image_height)
+      - ResourceUtil.dpToPx(70 + 26 + 12) // 70: holder top padding + 26: text height + 12: text padding bottom
+      - textYFromBottom);
+    this.textPositionTargetYOnScreen = screenHeight - textYFromBottom;
 
     textBig.setText(bean.getTwoLineTitle());
     textSmall.setText(bean.getSubTitleWithTrim());
@@ -318,12 +324,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) - ResourceUtil.getDimension(R.dimen.main_contents_image_padding_end);
+    spaceWidth = ResourceUtil.getDimension(R.dimen.main_contents_start_gap) - ResourceUtil.getDimension(R.dimen.main_contents_image_horizontal_padding_end);
 
     String url = bean.getImageUrl();
 
     // 텍스트 위치 조절
-    if(categoryIndex == 1) {
+    if (categoryIndex == 1) {
       new Handler().post(() -> moveText(getScreenY(textBig)));
     }
 

+ 4 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryHolder.java

@@ -82,7 +82,7 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
 
       AnimatorManager.getInstance().add(textViewAnimator);
 
-      recyclerView.setTranslationY(ResourceUtil.dpToPx(330));
+      recyclerView.setTranslationY(ResourceUtil.getDimension(R.dimen.main_contents_first_image_height));
 
       ObjectAnimator viewAnimator = ObjectAnimator.ofFloat(recyclerView, "translationY", 0f);
       viewAnimator.setDuration(600);
@@ -92,6 +92,9 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
           recyclerView.setTranslationY(0f);
         }
       });
+      viewAnimator.addUpdateListener(animation -> {
+        onScrolledVertical(recyclerView, 0, 0);
+      });
 
       AnimatorManager.getInstance().add(viewAnimator);
     }

+ 11 - 11
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsWeatherHolder.java

@@ -76,7 +76,7 @@ public class MainContentsWeatherHolder extends MainContentsHolder /*implements V
 
   private TextView textTopView;
   private TextView textBottomView;
-  private ImageView weahterView;
+  private ImageView weatherIcon;
   private ViewGroup layoutWeatherBottom;
 
   @Override
@@ -84,14 +84,14 @@ public class MainContentsWeatherHolder extends MainContentsHolder /*implements V
     weather = itemView.findViewById(R.id.layout_container_weather);
     textTopView = itemView.findViewById(R.id.text_weather_top);
     textBottomView = itemView.findViewById(R.id.text_weather_bottom);
-    weahterView = itemView.findViewById(R.id.icon_weather);
+    weatherIcon = itemView.findViewById(R.id.icon_weather);
     layoutWeatherBottom = itemView.findViewById(R.id.layout_weather_bottom);
 
     int statusBarHeight = ResourceUtil.getStatusBarHeightManual();
 
     // 첫 번째 카테고리 내용이 약간 가려지도록 일정 높이를 조절한다.
     ViewGroup.LayoutParams params = itemView.getLayoutParams();
-    params.height = SuperModel.getInstance().getScreenHeight() - ResourceUtil.dpToPx(330);
+    params.height = SuperModel.getInstance().getScreenHeight() - ResourceUtil.getDimension(R.dimen.main_contents_first_image_height);
 //    itemView.getViewTreeObserver().addOnGlobalLayoutListener(this);
 
     initWeatherY = ResourceUtil.getDimension(R.dimen.main_contents_weather_margin_top) + statusBarHeight;
@@ -108,8 +108,8 @@ public class MainContentsWeatherHolder extends MainContentsHolder /*implements V
 //    Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
 //    Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
 //    PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
-//    ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(weahterView, pvhRotation);
-    ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(weahterView, "rotation", 0f, 360f);
+//    ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(weatherIcon, pvhRotation);
+    ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(weatherIcon, "rotation", 0f, 360f);
     rotationAnim.setDuration(17000);
     rotationAnim.setInterpolator(new LinearInterpolator());
     rotationAnim.setRepeatCount(Animation.INFINITE);
@@ -117,23 +117,23 @@ public class MainContentsWeatherHolder extends MainContentsHolder /*implements V
     rotationAnim.start();
 
     if (AnimatorManager.getInstance().isCompleted() == false) {
-      weahterView.setTranslationY(100f);
-      ObjectAnimator weatherAnimator = ObjectAnimator.ofFloat(weahterView, "translationY", 0f);
+      weatherIcon.setTranslationY(100f);
+      ObjectAnimator weatherAnimator = ObjectAnimator.ofFloat(weatherIcon, "translationY", 0f);
       weatherAnimator.setDuration(500);
       weatherAnimator.addListener(new AnimatorManager.SimpleListener() {
         @Override
         public void onAnimationCancel(Animator animation) {
-          weahterView.setTranslationY(0f);
+          weatherIcon.setTranslationY(0f);
         }
       });
 
-      weahterView.setAlpha(0f);
-      ObjectAnimator weatherAlphaAnimator = ObjectAnimator.ofFloat(weahterView, "alpha", 1f);
+      weatherIcon.setAlpha(0f);
+      ObjectAnimator weatherAlphaAnimator = ObjectAnimator.ofFloat(weatherIcon, "alpha", 1f);
       weatherAlphaAnimator.setDuration(800);
       weatherAlphaAnimator.addListener(new AnimatorManager.SimpleListener() {
         @Override
         public void onAnimationCancel(Animator animation) {
-          weahterView.setAlpha(1f);
+          weatherIcon.setAlpha(1f);
         }
       });
 

+ 8 - 8
app/src/main/res/layout/main_contents_category_image.xml

@@ -5,7 +5,7 @@
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
-  android:paddingEnd="@dimen/main_contents_image_padding_end">
+  android:paddingEnd="@dimen/main_contents_image_horizontal_padding_end">
 
   <ImageView
     android:id="@+id/image_contents"
@@ -42,16 +42,16 @@
     app:layout_constraintGuide_begin="32dp"/>
 
   <!--<android.support.constraint.Guideline-->
-    <!--android:id="@+id/guide_horizontal"-->
-    <!--android:layout_width="match_parent"-->
-    <!--android:layout_height="match_parent"-->
-    <!--android:orientation="horizontal"-->
-    <!--app:layout_constraintGuide_begin="218dp"/>-->
+  <!--android:id="@+id/guide_horizontal"-->
+  <!--android:layout_width="match_parent"-->
+  <!--android:layout_height="match_parent"-->
+  <!--android:orientation="horizontal"-->
+  <!--app:layout_constraintGuide_begin="218dp"/>-->
   <TextView
-    android:layout_marginTop="218dp"
     android:id="@+id/text_big"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
+    android:layout_marginTop="218dp"
     android:lineSpacingExtra="4dp"
     android:textColor="#ffffff"
     android:textSize="19sp"
@@ -64,8 +64,8 @@
     android:id="@+id/text_small"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
-    android:layout_marginBottom="28.5dp"
     android:layout_marginEnd="20dp"
+    android:layout_marginBottom="28.5dp"
     android:lineSpacingExtra="9.5sp"
     android:maxLines="1"
     android:textColor="#ffffff"

+ 2 - 1
app/src/main/res/values/dimens.xml

@@ -9,6 +9,7 @@
   <dimen name="main_contents_start_gap">57dp</dimen>
   <dimen name="main_contents_image_width">285dp</dimen>
   <dimen name="main_contents_image_height">328dp</dimen>
-  <dimen name="main_contents_image_padding_end">12dp</dimen>
+  <dimen name="main_contents_image_horizontal_padding_end">12dp</dimen>
+  <dimen name="main_contents_first_image_height">330dp</dimen> <!-- 70dp + 26dp + 12dp + 222dp -->
 
 </resources>