Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,22 @@ public void initActionBar(Activity activity) {
if (mActionBarBackgroundDrawable == null) {
mActionBarBackgroundDrawable = activity.getResources().getDrawable(mActionBarBackgroundResId);
}
setActionBarBackgroundDrawable(mActionBarBackgroundDrawable);
applyBackgroundDrawable();
mActionBarBackgroundDrawable.setAlpha(0);
}

public void setActionBarBackground(Drawable background) {
mActionBarBackgroundDrawable = background;
applyBackgroundDrawable();
setAlpha(mLastScrollPosition);
}

private void applyBackgroundDrawable() {
setActionBarBackgroundDrawable(mActionBarBackgroundDrawable);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
mActionBarBackgroundDrawable.setCallback(mDrawableCallback);
}
mActionBarBackgroundDrawable.setAlpha(0);
}
}

protected abstract int getActionBarHeight();
protected abstract boolean isActionBarNull();
Expand Down Expand Up @@ -305,8 +315,13 @@ private void onNewScroll(int scrollPosition) {
if (isActionBarNull()) {
return;
}

setAlpha(scrollPosition);
addParallaxEffect(scrollPosition);
}

int currentHeaderHeight = mHeaderContainer.getHeight();
private void setAlpha(int scrollPosition) {
int currentHeaderHeight = mHeaderContainer.getHeight();
if (currentHeaderHeight != mLastHeaderHeight) {
updateHeaderHeight(currentHeaderHeight);
}
Expand All @@ -315,9 +330,7 @@ private void onNewScroll(int scrollPosition) {
float ratio = (float) Math.min(Math.max(scrollPosition, 0), headerHeight) / headerHeight;
int newAlpha = (int) (ratio * 255);
mActionBarBackgroundDrawable.setAlpha(newAlpha);

addParallaxEffect(scrollPosition);
}
}

private void addParallaxEffect(int scrollPosition) {
float damping = mUseParallax ? 0.5f : 1.0f;
Expand Down