From 557fc85026ddd1d57e748bac424cc3c886eb399c Mon Sep 17 00:00:00 2001 From: Saul M Date: Tue, 6 Oct 2015 18:58:17 +0200 Subject: [PATCH] Extracted the initialization of some properties into a method --- .../myapplication/AvatarImageBehavior.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java b/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java index 685b478..f8e4361 100644 --- a/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java +++ b/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java @@ -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; @@ -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");