Skip to content

Commit

Permalink
Extracted the initialization of some properties into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Oct 6, 2015
1 parent b2b4490 commit 557fc85
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,7 @@ public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child,

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {

// Called once
if (mStartYPosition == 0)
mStartYPosition = (int) (child.getY() + (child.getHeight() / 2));

if (mFinalYPosition == 0)
mFinalYPosition = (dependency.getHeight() /2);

if (mStartHeight == 0)
mStartHeight = child.getHeight();

if (finalHeight == 0)
finalHeight = mContext.getResources().getDimensionPixelOffset(R.dimen.image_final_width);

if (mStartXPosition == 0)
mStartXPosition = (int) (child.getX() + (child.getWidth() / 2));

if (mFinalXPosition == 0)
mFinalXPosition = mContext.getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material) + (finalHeight / 2);

if (mStartToolbarPosition == 0)
mStartToolbarPosition = dependency.getY() + (dependency.getHeight()/2);
shouldInitProperties(child, dependency);

final int maxScrollDistance = (int) (mStartToolbarPosition - getStatusBarHeight());
float expandedPercentageFactor = dependency.getY() / maxScrollDistance;
Expand All @@ -98,6 +77,29 @@ public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView
return true;
}

private void shouldInitProperties(CircleImageView child, View dependency) {
if (mStartYPosition == 0)
mStartYPosition = (int) (child.getY() + (child.getHeight() / 2));

if (mFinalYPosition == 0)
mFinalYPosition = (dependency.getHeight() /2);

if (mStartHeight == 0)
mStartHeight = child.getHeight();

if (finalHeight == 0)
finalHeight = mContext.getResources().getDimensionPixelOffset(R.dimen.image_final_width);

if (mStartXPosition == 0)
mStartXPosition = (int) (child.getX() + (child.getWidth() / 2));

if (mFinalXPosition == 0)
mFinalXPosition = mContext.getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material) + (finalHeight / 2);

if (mStartToolbarPosition == 0)
mStartToolbarPosition = dependency.getY() + (dependency.getHeight()/2);
}

public int getStatusBarHeight() {
int result = 0;
int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
Expand Down

0 comments on commit 557fc85

Please sign in to comment.