diff --git a/README.md b/README.md index 40cb673..56a8fb2 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ buildscript { } dependencies { - compile 'com.github.aakira:expandable-layout:1.2.0@aar' + compile 'com.github.aakira:expandable-layout:1.3.0@aar' } ``` diff --git a/gradle.properties b/gradle.properties index a30faa4..55d8708 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ COMPILE_SDK_VERSION=23 BUILD_TOOLS_VERSION=22.0.1 MIN_SDK_VERSION=11 TARGET_SDK_VERSION=23 -VERSION_CODE=3 -VERSION_NAME=1.2.0 +VERSION_CODE=4 +VERSION_NAME=1.3.0 SUPPORT_APP_COMPAT_VERSION=23.0.1 diff --git a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableLayout.java b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableLayout.java index 1cc2f06..306491c 100644 --- a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableLayout.java +++ b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableLayout.java @@ -35,22 +35,27 @@ public interface ExpandableLayout { } /** - * Starts animation the state of the view to the inverse of its current state + * Starts animation the state of the view to the inverse of its current state. */ void toggle(); /** - * Starts expand animation + * Starts expand animation. */ void expand(); /** - * Starts collapse animation + * Starts collapse animation. */ void collapse(); /** - * Sets the expandable layout listener + * Initializes this layout. + */ + void initLayout(); + + /** + * Sets the expandable layout listener. * * @param listener ExpandableLayoutListener */ @@ -65,12 +70,19 @@ public interface ExpandableLayout { void setDuration(final int duration); /** - * Sets state of expanse + * Sets state of expanse. * * @param expanded The layout is visible if expanded is true */ void setExpanded(final boolean expanded); + /** + * Gets state of expanse. + * + * @return true if the layout is visible + */ + boolean isExpanded(); + /** * The time interpolator used in calculating the elapsed fraction of this animation. The * interpolator determines whether the animation runs with linear or non-linear motion, diff --git a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableRelativeLayout.java b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableRelativeLayout.java index bea5888..35a373b 100644 --- a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableRelativeLayout.java +++ b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableRelativeLayout.java @@ -140,12 +140,6 @@ protected void onRestoreInstanceState(final Parcelable state) { savedState = ss; } - @Override - public void requestLayout() { - isArranged = false; - super.requestLayout(); - } - /** * {@inheritDoc} */ @@ -188,6 +182,20 @@ public void collapse() { createExpandAnimator(getCurrentPosition(), closePosition).start(); } + /** + * {@inheritDoc} + */ + @Override + public void initLayout() { + closePosition = 0; + layoutSize = 0; + isArranged = false; + isCalculatedSize = false; + savedState = null; + + super.requestLayout(); + } + /** * {@inheritDoc} */ @@ -209,6 +217,14 @@ public void setExpanded(boolean expanded) { requestLayout(); } + /** + * {@inheritDoc} + */ + @Override + public boolean isExpanded() { + return isExpanded; + } + /** * {@inheritDoc} */ @@ -353,7 +369,6 @@ public void onAnimationUpdate(final ValueAnimator animator) { @Override public void onAnimationStart(Animator animator) { isAnimating = true; - if (listener == null) { return; } @@ -371,13 +386,15 @@ public void onAnimationStart(Animator animator) { @Override public void onAnimationEnd(Animator animator) { isAnimating = false; + final int currentSize = isVertical() + ? getLayoutParams().height : getLayoutParams().width; + isExpanded = currentSize > closePosition; + if (listener == null) { return; } listener.onAnimationEnd(); - final int currentSize = isVertical() - ? getLayoutParams().height : getLayoutParams().width; if (currentSize == layoutSize) { listener.onOpened(); return; diff --git a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableWeightLayout.java b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableWeightLayout.java index ddbc3b0..885eca1 100644 --- a/library/src/main/java/com/github/aakira/expandablelayout/ExpandableWeightLayout.java +++ b/library/src/main/java/com/github/aakira/expandablelayout/ExpandableWeightLayout.java @@ -126,12 +126,6 @@ protected void onRestoreInstanceState(final Parcelable state) { savedState = ss; } - @Override - public void requestLayout() { - isArranged = false; - super.requestLayout(); - } - /** * {@inheritDoc} */ @@ -177,6 +171,19 @@ public void collapse() { createExpandAnimator(layoutWeight, 0).start(); } + /** + * {@inheritDoc} + */ + @Override + public void initLayout() { + layoutWeight = 0; + isArranged = false; + isCalculatedSize = false; + savedState = null; + + super.requestLayout(); + } + /** * {@inheritDoc} */ @@ -198,6 +205,14 @@ public void setExpanded(boolean expanded) { requestLayout(); } + /** + * {@inheritDoc} + */ + @Override + public boolean isExpanded() { + return isExpanded; + } + /** * {@inheritDoc} */ @@ -256,6 +271,8 @@ public void onAnimationStart(Animator animation) { @Override public void onAnimationEnd(Animator animation) { isAnimating = false; + final float currentWeight = ((LinearLayout.LayoutParams) getLayoutParams()).weight; + isExpanded = currentWeight > 0; if (listener == null) { return; @@ -266,7 +283,6 @@ public void onAnimationEnd(Animator animation) { return; } - final float currentWeight = ((LinearLayout.LayoutParams) getLayoutParams()).weight; if (currentWeight == layoutWeight) { listener.onOpened(); return;