Skip to content

Commit

Permalink
update: QMUICollapsingTopBarLayout add method in support of scrim cha…
Browse files Browse the repository at this point in the history
…nge listening #37
  • Loading branch information
cgspine committed Sep 12, 2017
1 parent e947ef7 commit f689275
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class QMUICollapsingTopBarLayout extends FrameLayout {
private int mScrimVisibleHeightTrigger = -1;

private AppBarLayout.OnOffsetChangedListener mOnOffsetChangedListener;
private ValueAnimator.AnimatorUpdateListener mScrimUpdateListener;

int mCurrentOffset;

Expand Down Expand Up @@ -509,6 +510,26 @@ public void setScrimsShown(boolean shown, boolean animate) {
}
}

/**
*
* @param scrimUpdateListener 为 null 则是 removeUpdateListener
*/
public void setScrimUpdateListener(ValueAnimator.AnimatorUpdateListener scrimUpdateListener) {
if (mScrimUpdateListener != scrimUpdateListener) {
if (mScrimAnimator == null) {
mScrimUpdateListener = scrimUpdateListener;
} else {
if (mScrimUpdateListener != null) {
mScrimAnimator.removeUpdateListener(mScrimUpdateListener);
}
mScrimUpdateListener = scrimUpdateListener;
if(mScrimUpdateListener != null){
mScrimAnimator.addUpdateListener(mScrimUpdateListener);
}
}
}
}

private void animateScrim(int targetAlpha) {
ensureToolbar();
if (mScrimAnimator == null) {
Expand All @@ -524,6 +545,9 @@ public void onAnimationUpdate(ValueAnimator animator) {
setScrimAlpha((Integer) animator.getAnimatedValue());
}
});
if (mScrimUpdateListener != null) {
mScrimAnimator.addUpdateListener(mScrimUpdateListener);
}
} else if (mScrimAnimator.isRunning()) {
mScrimAnimator.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.qmuiteam.qmuidemo.fragment.components;

import android.animation.ValueAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

Expand All @@ -23,6 +25,7 @@

@Widget(widgetClass = QMUICollapsingTopBarLayout.class, iconRes = R.mipmap.icon_grid_collapse_top_bar)
public class QDCollapsingTopBarLayoutFragment extends BaseFragment {
private static final String TAG = "CollapsingTopBarLayout";

private View mRootView;
QDRecyclerViewAdapter mRecyclerViewAdapter;
Expand All @@ -44,6 +47,13 @@ protected View onCreateView() {
mRecyclerViewAdapter.setItemCount(10);
mRecyclerView.setAdapter(mRecyclerViewAdapter);

mCollapsingTopBarLayout.setScrimUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Log.i(TAG, "scrim: " + animation.getAnimatedValue());
}
});

return mRootView;
}

Expand Down

0 comments on commit f689275

Please sign in to comment.