-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
463 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/ch/beerpro/ToolbarScrollingBehaviour.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ch.beerpro; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.graphics.Color; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout; | ||
import androidx.core.graphics.ColorUtils; | ||
import androidx.core.view.ViewCompat; | ||
|
||
public class ToolbarScrollingBehaviour<V extends View> extends CoordinatorLayout.Behavior<V> { | ||
|
||
private static final String TAG = "ToolbarScrollingBehavio"; | ||
|
||
public ToolbarScrollingBehaviour(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull V child, | ||
@NonNull View directTargetChild, @NonNull View target, int axes, int type) { | ||
return axes == ViewCompat.SCROLL_AXIS_VERTICAL; | ||
} | ||
|
||
@Override | ||
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull V child, @NonNull View target, | ||
int dx, int dy, @NonNull int[] consumed, int type) { | ||
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); | ||
LinearLayout toolbarLayout = (LinearLayout) child; | ||
View statusBar = toolbarLayout.getChildAt(0); | ||
Toolbar toolbar = (Toolbar) toolbarLayout.getChildAt(1); | ||
|
||
int toolbarHeight = toolbarLayout.getHeight(); | ||
|
||
int scrollY = target.getScrollY() + dy; | ||
float alpha = (scrollY - (toolbarHeight / 2f)) / (1.0f * toolbarHeight); | ||
|
||
Resources resources = child.getResources(); | ||
|
||
int newToolbarColor = ColorUtils.setAlphaComponent(resources.getColor(R.color.colorPrimary), | ||
Math.max(Math.min((int) (255 * alpha), 255), 0)); | ||
toolbarLayout.setBackgroundColor(newToolbarColor); | ||
|
||
int newToolbarTextColor = ColorUtils.setAlphaComponent(resources.getColor(R.color.colorAccent), | ||
Math.max(Math.min((int) (255 * alpha), 255), 0)); | ||
toolbar.setTitleTextColor(newToolbarTextColor); | ||
|
||
int newStatusbarColor = ColorUtils.setAlphaComponent(resources.getColor(R.color.colorPrimaryDark), | ||
Math.max(Math.min((int) (255 * alpha), 255), 0)); | ||
statusBar.setBackgroundColor(newStatusbarColor); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.