Supporting ExpandableListView
mevcloud opened this issue · 1 comments
Hi,
I was trying to include the Jazzy effect in a ExpandableListView. I just took the code from the JazzyListView but I extended from ExpandableListView instead of ListView
package com.twotoasters.jazzylistview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ExpandableListView;
public class JazzyExpandableListView extends ExpandableListView {
private final JazzyHelper mHelper;
public JazzyExpandableListView(Context context) {
super(context);
mHelper = init(context, null);
}
public JazzyExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
mHelper = init(context, attrs);
}
public JazzyExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mHelper = init(context, attrs);
}
private JazzyHelper init(Context context, AttributeSet attrs) {
JazzyHelper helper = new JazzyHelper(context, attrs);
super.setOnScrollListener(helper);
return helper;
}
@Override
public final void setOnScrollListener(OnScrollListener l) {
mHelper.setOnScrollListener(l);
}
/**
* Sets the desired transition effect.
*
* @param transitionEffect Numeric constant representing a bundled transition effect.
*/
public void setTransitionEffect(int transitionEffect) {
mHelper.setTransitionEffect(transitionEffect);
}
/**
* Sets the desired transition effect.
*
* @param transitionEffect The non-bundled transition provided by the client.
*/
public void setTransitionEffect(JazzyEffect transitionEffect) {
mHelper.setTransitionEffect(transitionEffect);
}
/**
* Sets whether new items or all items should be animated when they become visible.
*
* @param onlyAnimateNew True if only new items should be animated; false otherwise.
*/
public void setShouldOnlyAnimateNewItems(boolean onlyAnimateNew) {
mHelper.setShouldOnlyAnimateNewItems(onlyAnimateNew);
}
/**
* If true animation will only occur when scrolling without the users finger on the screen.
*
* @param onlyFlingEvents
*/
public void setShouldOnlyAnimateFling(boolean onlyFling) {
mHelper.setShouldOnlyAnimateFling(onlyFling);
}
/**
* Stop animations after the list has reached a certain velocity. When the list slows down
* it will start animating again. This gives a performance boost as well as preventing
* the list from animating under the users finger if they suddenly stop it.
*
* @param itemsPerSecond, set to JazzyHelper.MAX_VELOCITY_OFF to turn off max velocity.
* While 13 is a good default, it is dependent on the size of your items.
*/
public void setMaxAnimationVelocity(int itemsPerSecond) {
mHelper.setMaxAnimationVelocity(itemsPerSecond);
}
/**
* Enable this if you are using a list with items that should act like grid items.
*
* @param simulateGridWithList
*/
public void setSimulateGridWithList(boolean simulateGridWithList) {
mHelper.setSimulateGridWithList(simulateGridWithList);
setClipChildren(!simulateGridWithList);
}
}
My problem is that when I enable fast scrolling I get aq NullPointerException
java.lang.NullPointerException
E/AndroidRuntime(20260): at com.nineoldandroids.view.ViewPropertyAnimatorICS.(ViewPropertyAnimatorICS.java:22)
E/AndroidRuntime(20260): at com.nineoldandroids.view.ViewPropertyAnimator.animate(ViewPropertyAnimator.java:62)
E/AndroidRuntime(20260): at com.twotoasters.jazzylistview.JazzyHelper.doJazzinessImpl(JazzyHelper.java:196)
i tried putting an additional check in the JazzyHelper to check if the element is null, but when I do that, it does not look quite right because the first and last visible elements sometimes disappear.
Is there anything I could do to make this work?
I did not realize before there was a setting to allow the animation only when flinging. So i just set that to true whenever i have fast scrolling enabled and it works great.
Sorry for not seeing that before.
By the way could the setShouldOnlyAnimateFling be added to the JazzyGridView too? it is missing there.