Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hasToolbar attribute #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.4.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Sep 30 14:01:47 EEST 2017
#Mon May 06 18:54:08 WAT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ private void notifyListener() {
}
}

public boolean hasToolbar() {
return settings.hasToolbar();
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public ViewOutlineProvider getOutlineProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

public class ScalingLayoutBehavior extends CoordinatorLayout.Behavior<ScalingLayout> {

private final float toolbarHeightInPixel;

public ScalingLayoutBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
toolbarHeightInPixel = context.getResources().getDimensionPixelSize(R.dimen.sl_toolbar_size);
}

@Override
Expand All @@ -27,6 +25,10 @@ public boolean layoutDependsOn(CoordinatorLayout parent, ScalingLayout child, Vi
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, ScalingLayout child, View dependency) {
int totalScrollRange = ((AppBarLayout) dependency).getTotalScrollRange();
int toolbarHeightInPixel ;
if(child.hasToolbar()) toolbarHeightInPixel = parent.getContext().getResources().getDimensionPixelSize(R.dimen.sl_toolbar_size);
else toolbarHeightInPixel = 0 ;

child.setProgress((-dependency.getY()) / totalScrollRange);
if (totalScrollRange + dependency.getY() > (float) child.getMeasuredHeight() / 2) {
child.setTranslationY(totalScrollRange + dependency.getY() + toolbarHeightInPixel - (float) child.getMeasuredHeight() / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public class ScalingLayoutSettings {
private float maxRadius;
private float elevation;
private boolean isInitialized = false;
private boolean hasToolbar ;

public ScalingLayoutSettings(Context context, AttributeSet attributeSet) {
TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ScalingLayout);
radiusFactor = typedArray.getFloat(R.styleable.ScalingLayout_radiusFactor, DEFAULT_RADIUS_FACTOR);
hasToolbar = typedArray.getBoolean(R.styleable.ScalingLayout_hasToolbar,false);
maxWidth = context.getResources().getDisplayMetrics().widthPixels;
typedArray.recycle();

Expand Down Expand Up @@ -62,4 +64,8 @@ public void setElevation(float elevation) {
public float getElevation() {
return elevation;
}

public boolean hasToolbar() {
return hasToolbar;
}
}
1 change: 1 addition & 0 deletions scalinglib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<declare-styleable name="ScalingLayout">
<attr name="radiusFactor" format="float"/>
<attr name="hasToolbar" format="boolean"/>
</declare-styleable>

</resources>