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

Fixed position after expand start, added grid support #78

Open
wants to merge 6 commits 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
93 changes: 91 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,102 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'com.android.tools.build:gradle:0.10.2'
}
}

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'android-library'
apply plugin: 'signing'

group 'it.sephiroth.android.library.fork.slideexpandable'
version '1.0.3.1'

android {
compileSdkVersion 19
buildToolsVersion = '19.0.1'
buildToolsVersion = '19.0.3'

defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName version
}
}

signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

def generatePom() {
def pom = pom{
project {
name 'slideexpandable'
packaging 'aar'
groupId project.group
artifactId project.name
version project.version
description 'Fork of the original Android-SlideExpandableListView at https://github.com/tjerkw/Android-SlideExpandableListView'
url 'https://github.com/sephiroth74/Android-SlideExpandableListView'

licenses {
license {
name 'Apache License 2.0'
url 'https://github.com/tjerkw/Android-SlideExpandableListView/blob/master/LICENSE.txt'
distribution 'repo'
}
}

scm {
url "https://github.com/sephiroth74/Android-SlideExpandableListView"
connection "scm:git:[email protected]:sephiroth74/Android-SlideExpandableListView.git"
developerConnection "scm:git:[email protected]:sephiroth74/Android-SlideExpandableListView.git"
}

developers {
developer {
id 'tjerkw'
name 'Tjerk Wolterink'
url 'http://tjerkw.com/'
roles {
role 'author'
}
}
developer {
id 'sephiroth74'
name 'Alessandro Crugnola'
email '[email protected]'
url 'http://blog.sephiroth.it'
roles {
role 'contributor'
}
}
}
}
}
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
pom = generatePom()

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: sonatypeUsername, password: sonatypePassword )
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
authentication(userName: sonatypeUsername, password: sonatypePassword )
}
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AbsListView;

/**
* Wraps a ListAdapter to give it expandable list view functionality.
Expand All @@ -22,6 +23,7 @@
* @date 6/9/12 4:41 PM
*/
public abstract class AbstractSlideExpandableListAdapter extends WrapperListAdapterImpl {
private static final String TAG = "AbstractSlideExpandableListAdapter";
/**
* Reference to the last expanded list item.
* Since lists are recycled this might be null if
Expand Down Expand Up @@ -89,36 +91,35 @@ public void removeItemExpandCollapseListener() {
*/
public interface OnItemExpandCollapseListener {
/**
* Called when an item is expanded.
*
* @param itemView
* the view of the list item
* @param position
* the position in the list view
* Called when an item is expanding/collapsing.
*
* @param itemView the view of the list item
* @param position the position in the list view
* @param expanding true if expanding, false otherwise
*/
public void onExpand(View itemView, int position);
public void onExpandStart(View itemView, int position, boolean expanding);

/**
* Called when an item is collapsed.
*
* @param itemView
* the view of the list item
* @param position
* the position in the list view
* Called when an item is finished animating.
*
* @param itemView the view of the list item
* @param position the position in the list view
* @param expanded true if expanded, false otherwise
*/
public void onCollapse(View itemView, int position);
public void onExpandEnd(View itemView, int position, boolean expanded);

}

private void notifiyExpandCollapseListener(int type, View view, int position) {
private void notifiyBeginExpandCollapseListener(int type, View view, int position) {
if (expandCollapseListener != null) {
if (type == ExpandCollapseAnimation.EXPAND) {
expandCollapseListener.onExpand(view, position);
} else if (type == ExpandCollapseAnimation.COLLAPSE) {
expandCollapseListener.onCollapse(view, position);
}
expandCollapseListener.onExpandStart(view, position, type == ExpandCollapseAnimation.EXPAND);
}
}

private void notifiyEndExpandCollapseListener(int type, View view, int position) {
if (expandCollapseListener != null) {
expandCollapseListener.onExpandEnd(view, position, type == ExpandCollapseAnimation.EXPAND);
}
}


Expand Down Expand Up @@ -202,6 +203,10 @@ public boolean isAnyItemExpanded() {
public void enableFor(View parent, int position) {
View more = getExpandToggleButton(parent);
View itemToolbar = getExpandableView(parent);

// if toggle or expandable view are null just stop it
if(null == more || null == itemToolbar) return;

itemToolbar.measure(parent.getWidth(), parent.getHeight());

enableFor(more, itemToolbar, position);
Expand Down Expand Up @@ -233,7 +238,7 @@ public void onClick(final View view) {

Animation a = target.getAnimation();

if (a != null && a.hasStarted() && !a.hasEnded()) {
if (a != null && a.hasStarted() && ! a.hasEnded()) {

a.setAnimationListener(new Animation.AnimationListener() {
@Override
Expand All @@ -250,38 +255,38 @@ public void onAnimationRepeat(Animation animation) {
}
});

} else {
}
else {

target.setAnimation(null);

int type = target.getVisibility() == View.VISIBLE
? ExpandCollapseAnimation.COLLAPSE
: ExpandCollapseAnimation.EXPAND;
int type =
target.getVisibility() == View.VISIBLE ? ExpandCollapseAnimation.COLLAPSE : ExpandCollapseAnimation.EXPAND;

// remember the state
if (type == ExpandCollapseAnimation.EXPAND) {
openItems.set(position, true);
} else {
}
else {
openItems.set(position, false);
}
// check if we need to collapse a different view
if (type == ExpandCollapseAnimation.EXPAND) {
if (lastOpenPosition != -1 && lastOpenPosition != position) {
if (lastOpenPosition != - 1 && lastOpenPosition != position) {
if (lastOpen != null) {
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE);
notifiyExpandCollapseListener(
ExpandCollapseAnimation.COLLAPSE,
lastOpen, lastOpenPosition);
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE, lastOpenPosition);
notifiyBeginExpandCollapseListener(ExpandCollapseAnimation.COLLAPSE, lastOpen, lastOpenPosition);
}
openItems.set(lastOpenPosition, false);
}
lastOpen = target;
lastOpenPosition = position;
} else if (lastOpenPosition == position) {
lastOpenPosition = -1;
}
animateView(target, type);
notifiyExpandCollapseListener(type, target, position);
else if (lastOpenPosition == position) {
lastOpenPosition = - 1;
}
animateView(target, type, position);
notifiyBeginExpandCollapseListener(type, target, position);
}
}
});
Expand All @@ -299,13 +304,17 @@ private void updateExpandable(View target, int position) {
}
}

public boolean isExpanded(int position) {
return openItems.get(position);
}

/**
* Performs either COLLAPSE or EXPAND animation on the target view
* @param target the view to animate
* @param type the animation type, either ExpandCollapseAnimation.COLLAPSE
* or ExpandCollapseAnimation.EXPAND
*/
private void animateView(final View target, final int type) {
private void animateView(final View target, final int type, final int position) {
Animation anim = new ExpandCollapseAnimation(
target,
type
Expand All @@ -322,25 +331,32 @@ public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
if (type == ExpandCollapseAnimation.EXPAND) {
if (parent instanceof ListView) {
ListView listView = (ListView) parent;
int movement = target.getBottom();
if (parent instanceof AbsListView) {
AbsListView listView = (AbsListView) parent;

Rect r = new Rect();
boolean visible = target.getGlobalVisibleRect(r);

Rect r2 = new Rect();
listView.getGlobalVisibleRect(r2);


Rect r3 = new Rect();
target.getDrawingRect(r3);

final int[] location = new int[2];
target.getLocationInWindow(location);
int bottom = location[1] + r3.height();

if (!visible) {
listView.smoothScrollBy(movement, getAnimationDuration());
listView.smoothScrollBy(bottom - r2.bottom, getAnimationDuration());
} else {
if (r2.bottom == r.bottom) {
listView.smoothScrollBy(movement, getAnimationDuration());
if (bottom > r2.bottom) {
listView.smoothScrollBy(bottom - r2.bottom, getAnimationDuration());
}
}
}
}

notifiyEndExpandCollapseListener(type, target, position);
}
});
target.startAnimation(anim);
Expand All @@ -357,7 +373,7 @@ public boolean collapseLastOpen() {
if(isAnyItemExpanded()) {
// if visible animate it out
if(lastOpen != null) {
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE);
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE, lastOpenPosition);
}
openItems.set(lastOpenPosition, false);
lastOpenPosition = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void applyTransformation(float interpolatedTime, Transformation t) {
} else {
mLayoutParams.bottomMargin = - (int) (mEndHeight * interpolatedTime);
}
Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin);
// Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin);
mAnimatedView.requestLayout();
} else {
if(mType == EXPAND) {
Expand Down
6 changes: 5 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include ':library'
include ':library'

// changing the name because Android Studio doesn't like libraries with
// the same name - version
project(":library").name = "slideexpandable"