diff --git a/library/build.gradle b/library/build.gradle index 59ee737..c177dbf 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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:git@github.com:sephiroth74/Android-SlideExpandableListView.git" + developerConnection "scm:git:git@github.com: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 'alessandro.crugnola@gmail.com' + 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' } \ No newline at end of file diff --git a/library/src/main/java/com/tjerkw/slideexpandable/library/AbstractSlideExpandableListAdapter.java b/library/src/main/java/com/tjerkw/slideexpandable/library/AbstractSlideExpandableListAdapter.java index f03c03a..14588c4 100644 --- a/library/src/main/java/com/tjerkw/slideexpandable/library/AbstractSlideExpandableListAdapter.java +++ b/library/src/main/java/com/tjerkw/slideexpandable/library/AbstractSlideExpandableListAdapter.java @@ -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. @@ -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 @@ -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); + } } @@ -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); @@ -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 @@ -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); } } }); @@ -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 @@ -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); @@ -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; diff --git a/library/src/main/java/com/tjerkw/slideexpandable/library/ExpandCollapseAnimation.java b/library/src/main/java/com/tjerkw/slideexpandable/library/ExpandCollapseAnimation.java index 7ebc8fb..1fb7b55 100644 --- a/library/src/main/java/com/tjerkw/slideexpandable/library/ExpandCollapseAnimation.java +++ b/library/src/main/java/com/tjerkw/slideexpandable/library/ExpandCollapseAnimation.java @@ -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) { diff --git a/settings.gradle b/settings.gradle index 3732968..27f198d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,5 @@ -include ':library' \ No newline at end of file +include ':library' + +// changing the name because Android Studio doesn't like libraries with +// the same name - version +project(":library").name = "slideexpandable" \ No newline at end of file