|
|
@@ -1,6 +1,9 @@
|
|
|
package com.itant.shibei.widget;
|
|
|
|
|
|
+import android.animation.ObjectAnimator;
|
|
|
+import android.app.Activity;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
|
import com.google.android.material.appbar.AppBarLayout;
|
|
|
|
|
|
@@ -15,29 +18,32 @@ public class AppbarTranslateListener implements AppBarLayout.OnOffsetChangedList
|
|
|
private static final int STATUS_CLOSE = 1;
|
|
|
private static final int STATUS_OPEN = 2;
|
|
|
private static final int STATUS_MOVE = 3;
|
|
|
-
|
|
|
- private double mDefaultImageSize;
|
|
|
- private double mDefaultWidth;
|
|
|
/**
|
|
|
* 1. 完全关闭 2. 完全打开 3.运动中
|
|
|
*/
|
|
|
private int mLastStatus = STATUS_CLOSE;
|
|
|
|
|
|
+ private double mDefaultHeight;
|
|
|
+ private double mDefaultWidth;
|
|
|
+
|
|
|
+ private ViewGroup mViewGroup;
|
|
|
private View rl_search_top;
|
|
|
+ private View rl_search_top_shadow;
|
|
|
private View rl_search;
|
|
|
- private View iv_search_top;
|
|
|
- private View iv_search;
|
|
|
|
|
|
private long mLastAnimateMillis;
|
|
|
|
|
|
- public AppbarTranslateListener(double defaultWidth, double defaultImageSize, View rl_search_top,
|
|
|
- View iv_search_top, View rl_search, View iv_search) {
|
|
|
+ public AppbarTranslateListener(Activity activity,
|
|
|
+ double defaultWidth, double defaultHeight,
|
|
|
+ View rl_search_top, View rl_search_top_shadow,
|
|
|
+ View rl_search) {
|
|
|
+ mViewGroup = (ViewGroup) activity.getWindow().getDecorView();
|
|
|
+
|
|
|
mDefaultWidth = defaultWidth;
|
|
|
- mDefaultImageSize = defaultImageSize;
|
|
|
+ mDefaultHeight = defaultHeight;
|
|
|
this.rl_search = rl_search;
|
|
|
this.rl_search_top = rl_search_top;
|
|
|
- this.iv_search = iv_search;
|
|
|
- this.iv_search_top = iv_search_top;
|
|
|
+ this.rl_search_top_shadow = rl_search_top_shadow;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -55,31 +61,36 @@ public class AppbarTranslateListener implements AppBarLayout.OnOffsetChangedList
|
|
|
if (reFraction < 0.007) {
|
|
|
// 完全折叠
|
|
|
if (mLastStatus != STATUS_CLOSE) {
|
|
|
- rl_search_top.setVisibility(View.GONE);
|
|
|
+ mViewGroup.getOverlay().remove(rl_search_top);
|
|
|
rl_search.setVisibility(View.VISIBLE);
|
|
|
mLastStatus = STATUS_CLOSE;
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- } else if (reFraction > 0.988) {
|
|
|
- // 完全展开
|
|
|
- if (mLastStatus != STATUS_OPEN) {
|
|
|
- rl_search.setVisibility(View.GONE);
|
|
|
- rl_search_top.setVisibility(View.VISIBLE);
|
|
|
- mLastStatus = STATUS_OPEN;
|
|
|
+ } else {
|
|
|
+ rl_search.setVisibility(View.GONE);
|
|
|
+ if (reFraction > 0.988) {
|
|
|
+ // 完全展开
|
|
|
+ if (mLastStatus != STATUS_OPEN) {
|
|
|
+ mLastStatus = STATUS_OPEN;
|
|
|
+ rl_search.setVisibility(View.GONE);
|
|
|
+ rl_search_top_shadow.setVisibility(View.VISIBLE);
|
|
|
+ mViewGroup.getOverlay().add(rl_search_top);
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
} else {
|
|
|
- return;
|
|
|
- }
|
|
|
- } /*else {
|
|
|
- if (mLastStatus != STATUS_MOVE) {
|
|
|
- rl_search.setVisibility(View.VISIBLE);
|
|
|
- rl_search_top.setVisibility(View.VISIBLE);
|
|
|
- mLastStatus = STATUS_MOVE;
|
|
|
+ // 移动中
|
|
|
+ if (mLastStatus != STATUS_MOVE) {
|
|
|
+ mLastStatus = STATUS_MOVE;
|
|
|
+ rl_search_top_shadow.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- double searchSize = mDefaultImageSize * fraction;
|
|
|
+ followFinger(fraction);
|
|
|
+
|
|
|
+ /*double searchSize = mDefaultImageSize * fraction;
|
|
|
ViewGroup.LayoutParams searchParams = iv_search.getLayoutParams();
|
|
|
searchParams.width = (int) searchSize;
|
|
|
searchParams.height = (int) searchSize;
|
|
|
@@ -91,4 +102,28 @@ public class AppbarTranslateListener implements AppBarLayout.OnOffsetChangedList
|
|
|
topSearchParams.height = (int) topSearchSize;
|
|
|
iv_search_top.requestLayout();*/
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void followFinger(float fraction) {
|
|
|
+ // 完全展开时fraction为0,所以实时translationX为mDefaultWidth*fraction,
|
|
|
+ // translationY为mDefaultHeight*fraction
|
|
|
+
|
|
|
+ // add之后,要紧接动画
|
|
|
+ mViewGroup.getOverlay().add(rl_search_top);
|
|
|
+ // 横向移动
|
|
|
+ ObjectAnimator tranXAnim = ObjectAnimator.ofFloat(rl_search_top, "translationX", (float) (mDefaultWidth*fraction));
|
|
|
+ tranXAnim.setDuration(0);
|
|
|
+ // 纵向移动
|
|
|
+ //ObjectAnimator tranYAnim = ObjectAnimator.ofFloat(rl_search_top, "translationY", (float) (mDefaultHeight*fraction));
|
|
|
+ //tranYAnim.setDuration(0);
|
|
|
+
|
|
|
+ tranXAnim.start();
|
|
|
+
|
|
|
+ // 一起做运动
|
|
|
+ //AnimatorSet set = new AnimatorSet();
|
|
|
+ //set.playTogether(tranXAnim, tranYAnim);
|
|
|
+ //set.start();
|
|
|
+ }
|
|
|
}
|