Browse Source

增加机构首页小工具

Pq 1 năm trước cách đây
mục cha
commit
d9e11b1356

+ 79 - 14
BaseLibrary/src/main/java/com/cooleshow/base/widgets/CustomDragView.java

@@ -3,15 +3,14 @@ package com.cooleshow.base.widgets;
 import android.animation.ValueAnimator;
 import android.content.Context;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
+import android.view.ViewGroup;
 
+import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.ScreenUtils;
 import com.cooleshow.base.utils.SizeUtils;
 
-import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.appcompat.widget.AppCompatImageView;
 
@@ -21,7 +20,8 @@ import androidx.appcompat.widget.AppCompatImageView;
 public class CustomDragView extends AppCompatImageView {
 
 
-    private int hideSize = 0;
+    private int hideSize = -SizeUtils.dp2px(6);
+    private int paddingBottom = SizeUtils.dp2px(10);
     private int lastX, lastY;
     private int mStartX, mStartY = 0;
     private boolean isMove = false;
@@ -40,7 +40,7 @@ public class CustomDragView extends AppCompatImageView {
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        Log.i("pq", "event action:" + event.getAction());
+//        Log.i("pq", "event action:" + event.getAction());
         int x = (int) event.getRawX();
         int y = (int) event.getRawY();
         switch (event.getAction()) {
@@ -58,18 +58,29 @@ public class CustomDragView extends AppCompatImageView {
                 int top = getTop();
                 int left = getLeft();
                 int right = getRight();
+
                 int bottom = getBottom();
+                LOG.i("getBottom:" + bottom);
                 //高度范围
                 if (top < 0) {
                     top = 0;
                     bottom = getHeight();
                 }
-
+                LOG.i("screenHeight:" + screenHeight());
                 if (bottom >= screenHeight()) {
                     top = screenHeight() - getHeight();
                     bottom = screenHeight();
                 }
 
+                ViewGroup parent = (ViewGroup) getParent();
+                LOG.i(" parent.getBottom():" + parent.getBottom());
+                LOG.i("bottom1:" + bottom);
+                if (bottom > parent.getBottom()) {
+                    top = parent.getBottom() - getHeight() - paddingBottom;
+                    bottom = parent.getBottom() - paddingBottom;
+                }
+                LOG.i("bottom2:" + bottom);
+
                 //宽度范围
                 if (left < -hideSize) {
                     left = -hideSize;
@@ -86,8 +97,8 @@ public class CustomDragView extends AppCompatImageView {
 
                 float deltaX1 = x - mStartX;
                 float deltaY1 = y - mStartY;
-                Log.i("pq", "deltaX:" + deltaX1 + "--x:" + x + "--mStartX:" + mStartX);
-                Log.i("pq", "deltaY:" + deltaY1 + "--y:" + y + "--mStartY:" + mStartY);
+//                Log.i("pq", "deltaX:" + deltaX1 + "--x:" + x + "--mStartX:" + mStartX);
+//                Log.i("pq", "deltaY:" + deltaY1 + "--y:" + y + "--mStartY:" + mStartY);
                 if (Math.abs(deltaX1) <= 5 && Math.abs(deltaY1) <= 5) {
                     isMove = false;
                 } else {
@@ -95,18 +106,28 @@ public class CustomDragView extends AppCompatImageView {
                 }
                 break;
             case MotionEvent.ACTION_UP:
-                if(isMove){
+                if (isMove) {
                     int maxDuration = 500;
                     int duration = 0;
                     int leftLimit = (screenWidth() - getWidth()) / 2;
                     if (getLeft() < leftLimit) {
-    //                    layout(0,getTop(),getWidth(),getBottom());
+                        //                    layout(0,getTop(),getWidth(),getBottom());
                         duration = maxDuration * (getLeft() + hideSize) / (leftLimit + hideSize);
                         animSlide(this, getLeft(), -hideSize, duration);
                     } else {
                         duration = maxDuration * (screenWidth() - getRight() + hideSize) / (leftLimit + hideSize);
                         animSlide(this, getLeft(), screenWidth() - getWidth() + hideSize, 500);
-    //                    layout(screenWidth()-getWidth(),getTop(),screenWidth(),getBottom());
+                        //                    layout(screenWidth()-getWidth(),getTop(),screenWidth(),getBottom());
+                    }
+                    ViewGroup  parent1 = (ViewGroup) getParent();
+                    int limitBottom = parent1.getBottom()-paddingBottom;
+                    int limitTop = parent1.getTop()+paddingBottom;
+                    if(getBottom()>limitBottom){
+                        LOG.i("超出了容器bottom--"+getBottom()+"---limitBottom:"+limitBottom);
+                        animSlideVertical(this, getBottom(),limitBottom, 500);
+                    }else if(getTop()<limitTop){
+                        LOG.i("超出了容器bottom--"+getTop()+"---limitTop:"+limitTop);
+                        animSlideVertical(this, getTop()+getHeight(),limitTop+getHeight(), 500);
                     }
                 }
                 break;
@@ -129,11 +150,55 @@ public class CustomDragView extends AppCompatImageView {
         valueAnimator.start();
     }
 
+    /**
+     * 垂直方向动画
+     * @param view
+     * @param from
+     * @param to
+     * @param duration
+     */
+    public void animSlideVertical(View view, int from, int to, int duration) {
+        ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to);
+        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+            @Override
+            public void onAnimationUpdate(ValueAnimator animation) {
+                int animValue = (int) animation.getAnimatedValue();
+                LOG.i("animValue:"+animValue);
+                layout(getLeft(),animValue-view.getHeight(), getRight(), animValue);
+            }
+        });
+        //为防止溢出边界时,duration时间为负值,做下0判断
+        valueAnimator.setDuration(duration < 0 ? 0 : duration);
+        valueAnimator.start();
+    }
+
+//    /**
+//     * 垂直方向动画
+//     * @param view
+//     * @param from
+//     * @param to
+//     * @param duration
+//     */
+//    public void animSlideVerticalForTop(View view, int from, int to, int duration) {
+//        ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to);
+//        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+//            @Override
+//            public void onAnimationUpdate(ValueAnimator animation) {
+//                int animValue = (int) animation.getAnimatedValue();
+//                LOG.i("animValue:"+animValue);
+//                layout(getLeft(),animValue, getRight(), animValue+getHeight());
+//            }
+//        });
+//        //为防止溢出边界时,duration时间为负值,做下0判断
+//        valueAnimator.setDuration(duration < 0 ? 0 : duration);
+//        valueAnimator.start();
+//    }
+
     public int screenWidth() {
-        return getContext().getResources().getDisplayMetrics().widthPixels;
+        return ScreenUtils.getScreenWidth();
     }
 
     public int screenHeight() {
-        return getContext().getResources().getDisplayMetrics().heightPixels - SizeUtils.dp2px(50);
+        return ScreenUtils.getScreenHeight() - SizeUtils.dp2px(50);
     }
 }

+ 13 - 0
institution/src/main/java/com/cooleshow/institution/stu/ui/main/HomeFragment.java

@@ -2,6 +2,8 @@ package com.cooleshow.institution.stu.ui.main;
 
 import android.view.View;
 
+import com.alibaba.android.arouter.launcher.ARouter;
+import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.fragment.BaseFragment;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.LOG;
@@ -47,6 +49,17 @@ public class HomeFragment extends BaseFragment<FgHomeLayoutBinding> {
         mViewBinding.viewPager.setOffscreenPageLimit(fragments.size());
         mViewBinding.viewPager.setUserInputEnabled(false);
         mViewBinding.viewPager.setSaveEnabled(false);
+
+        initListener();
+    }
+
+    private void initListener() {
+        mViewBinding.viewSuspension.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ARouter.getInstance().build(RouterPath.BaseCenter.SMALL_TOOLS).navigation();
+            }
+        });
     }
 
     private void initViewModel() {

BIN
institution/src/main/res/drawable-xhdpi/jg_icon_small_tools.png


BIN
institution/src/main/res/drawable-xxhdpi/jg_icon_small_tools.png


+ 21 - 1
institution/src/main/res/layout/fg_home_layout.xml

@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
     <com.cooleshow.institution.stu.widget.NestedScrollableHost
         android:layout_width="match_parent"
         android:layout_height="match_parent">
@@ -10,4 +11,23 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent" />
     </com.cooleshow.institution.stu.widget.NestedScrollableHost>
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="bottom|right"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <com.cooleshow.base.widgets.CustomDragView
+            android:id="@+id/view_suspension"
+            android:layout_width="62dp"
+            android:layout_height="62dp"
+            android:layout_gravity="bottom|right"
+            android:layout_marginEnd="6dp"
+            android:layout_marginBottom="10dp"
+            android:src="@drawable/jg_icon_small_tools"
+            android:visibility="visible"
+            app:layout_constraintRight_toRightOf="parent" />
+    </FrameLayout>
 </FrameLayout>