Skip to content

add end animation listener #19

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

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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ buttonToggle.setOnClickListener(new View.OnClickListener()
expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
{
@Override
public void onExpand(final ExpandableTextView view)
public void onStartExpand(final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView expanded");
}

@Override
public void onCollapse(final ExpandableTextView view)
public void onStartCollapse(final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView collapsed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public void onClick(final View v)
expandableTextView.addOnExpandListener(new ExpandableTextView.OnExpandListener()
{
@Override
public void onExpand(@NonNull final ExpandableTextView view)
public void onStartExpand(@NonNull final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView expanded");
}

@Override
public void onCollapse(@NonNull final ExpandableTextView view)
public void onStartCollapse(@NonNull final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView collapsed");
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean expand()
if (!this.expanded && !this.animating && this.maxLines >= 0)
{
// notify listener
this.notifyOnExpand();
this.notifyOnStartExpand();

// measure collapsed height
this.measure
Expand Down Expand Up @@ -169,6 +169,7 @@ public void onAnimationEnd(final Animator animation)
// keep track of current status
ExpandableTextView.this.expanded = true;
ExpandableTextView.this.animating = false;
notifyOnEndExpand();
}
});

Expand All @@ -195,7 +196,7 @@ public boolean collapse()
if (this.expanded && !this.animating && this.maxLines >= 0)
{
// notify listener
this.notifyOnCollapse();
this.notifyOnStartCollapse();

// measure expanded height
final int expandedHeight = this.getMeasuredHeight();
Expand Down Expand Up @@ -232,6 +233,7 @@ public void onAnimationEnd(final Animator animation)
final ViewGroup.LayoutParams layoutParams = ExpandableTextView.this.getLayoutParams();
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
ExpandableTextView.this.setLayoutParams(layoutParams);
notifyOnEndCollapse();
}
});

Expand Down Expand Up @@ -338,24 +340,45 @@ public boolean isExpanded()
//endregion

/**
* This method will notify the listener about this view being expanded.
* This method will notify the listener about this view starts to collapse.
*/
private void notifyOnCollapse()
private void notifyOnStartCollapse()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onCollapse(this);
onExpandListener.onStartCollapse(this);
}
}

/**
* This method will notify the listener about this view being collapsed.
* This method will notify the listener about this view starts to expand.
*/
private void notifyOnExpand()
private void notifyOnStartExpand()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onExpand(this);
onExpandListener.onStartExpand(this);
}
}
/**
* This method will notify the listener about this view finishes to collapse.
*/
private void notifyOnEndCollapse()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onEndCollapse(this);
}
}

/**
* This method will notify the listener about this view finishes to expand.
*/
private void notifyOnEndExpand()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onEndExpand(this);
}
}

Expand All @@ -368,16 +391,28 @@ private void notifyOnExpand()
public interface OnExpandListener
{
/**
* The {@link ExpandableTextView} is being expanded.
* The {@link ExpandableTextView} starts to expand.
* @param view the textview
*/
void onExpand(@NonNull ExpandableTextView view);
void onStartExpand(@NonNull ExpandableTextView view);

/**
* The {@link ExpandableTextView} is being collapsed.
* The {@link ExpandableTextView} starts to collapse.
* @param view the textview
*/
void onCollapse(@NonNull ExpandableTextView view);
void onStartCollapse(@NonNull ExpandableTextView view);

/**
* The {@link ExpandableTextView} finishes to expand.
* @param view the textview
*/
void onEndExpand(@NonNull ExpandableTextView view);

/**
* The {@link ExpandableTextView} finishes to collapse.
* @param view the textview
*/
void onEndCollapse(@NonNull ExpandableTextView view);
}

/**
Expand All @@ -388,16 +423,26 @@ public interface OnExpandListener
public static class SimpleOnExpandListener implements OnExpandListener
{
@Override
public void onExpand(@NonNull final ExpandableTextView view)
public void onStartExpand(@NonNull final ExpandableTextView view)
{
// empty implementation
}

@Override
public void onCollapse(@NonNull final ExpandableTextView view)
public void onStartCollapse(@NonNull final ExpandableTextView view)
{
// empty implementation
}

@Override
public void onEndExpand(@NonNull ExpandableTextView view) {
// empty implementation
}

@Override
public void onEndCollapse(@NonNull ExpandableTextView view) {
// empty implementation
}
}

//endregion
Expand Down