Skip to content

Commit

Permalink
Merge pull request #27 from AAkira/v1.4.0
Browse files Browse the repository at this point in the history
V1.4.0
  • Loading branch information
AAkira committed Nov 3, 2015
2 parents b4491de + 32690f5 commit 2430eee
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 57 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ expandableLayout.setListener(new ExpandableLayoutListener() {
public void onClosed() {
}
});
```
* `ExpandableLayoutListenerAdapter`
- You can set listeners only you need.

```java

expandableLayout.setListener(new ExpandableLayoutListenerAdapter() {
@Override
public void onPreOpen() {
}

@Override
public void onPreClose() {
}
});

```

### Attributes
Expand All @@ -166,6 +182,8 @@ expandableLayout.setListener(new ExpandableLayoutListener() {
|:-:|:-:|
|ael_duration|The length of the expand or collapse animation|
|ael_expanded|The layout is expanded if you set true|
|ael_defaultChildIndex|The layout is expanded at index of child view. (Only `ExpandableRelativeLayout`)|
|ael_defaultPosition|The layout is expanded at the position. (Only `ExpandableRelativeLayout`)|
|ael_orientation|The orientation of animation(horizontal \| vertical)|
|ael_interpolator|Sets [interpolator](#interpolator)|

Expand Down Expand Up @@ -211,7 +229,7 @@ buildscript {
}
dependencies {
compile 'com.github.aakira:expandable-layout:1.3.0@aar'
compile 'com.github.aakira:expandable-layout:1.4.0@aar'
}
```

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=22.0.1
MIN_SDK_VERSION=11
TARGET_SDK_VERSION=23
VERSION_CODE=4
VERSION_NAME=1.3.0
VERSION_CODE=5
VERSION_NAME=1.4.0

SUPPORT_APP_COMPAT_VERSION=23.0.1

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public interface ExpandableLayout {

/**
* Initializes this layout.
*
* @param isMaintain The state of expanse is maintained if you set true.
*/
void initLayout();
void initLayout(final boolean isMaintain);

/**
* Sets the expandable layout listener.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.aakira.expandablelayout;

public abstract class ExpandableLayoutListenerAdapter implements ExpandableLayoutListener {
/**
* {@inheritDoc}
*/
@Override
public void onAnimationStart() {
}

/**
* {@inheritDoc}
*/
public void onAnimationEnd() {
}

/**
* {@inheritDoc}
*/
public void onPreOpen() {
}

/**
* {@inheritDoc}
*/
public void onPreClose() {
}

/**
* {@inheritDoc}
*/
public void onOpened() {
}

/**
* {@inheritDoc}
*/
public void onClosed() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class ExpandableRelativeLayout extends RelativeLayout implements Expandab
private boolean isExpanded;
private TimeInterpolator interpolator = new LinearInterpolator();
private int orientation;
/**
* You cannot define {@link #isExpanded}, {@link #defaultChildIndex}
* and {@link #defaultChildPosition} at the same time.
* {@link #defaultChildPosition} has priority over {@link #isExpanded}
* and {@link #defaultChildIndex} if you set them at the same time.
*/
private int defaultChildIndex;
private int defaultChildPosition;
/**
* The close position is width from left of layout if orientation is horizontal.
* The close position is height from top of layout if orientation is vertical.
Expand Down Expand Up @@ -65,6 +73,10 @@ private void init(final Context context, final AttributeSet attrs, final int def
duration = a.getInteger(R.styleable.expandableLayout_ael_duration, DEFAULT_DURATION);
isExpanded = a.getBoolean(R.styleable.expandableLayout_ael_expanded, DEFAULT_EXPANDED);
orientation = a.getInteger(R.styleable.expandableLayout_ael_orientation, VERTICAL);
defaultChildIndex = a.getInteger(R.styleable.expandableLayout_ael_defaultChildIndex,
Integer.MAX_VALUE);
defaultChildPosition = a.getInteger(R.styleable.expandableLayout_ael_defaultPosition,
Integer.MIN_VALUE);
final int interpolatorType = a.getInteger(R.styleable.expandableLayout_ael_interpolator,
Utils.LINEAR_INTERPOLATOR);
interpolator = Utils.createInterpolator(interpolatorType);
Expand Down Expand Up @@ -107,11 +119,19 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isArranged) {
return;
}

if (isExpanded) {
setLayoutSize(layoutSize);
} else {
setLayoutSize(closePosition);
}
final int childNumbers = childPositionList.size();
if (childNumbers > defaultChildIndex && childNumbers > 0) {
moveChild(defaultChildIndex, 0, null);
}
if (defaultChildPosition > 0 && layoutSize >= defaultChildPosition && layoutSize > 0) {
move(defaultChildPosition, 0, null);
}
isArranged = true;

if (savedState == null) {
Expand Down Expand Up @@ -168,7 +188,8 @@ public void expand() {
if (isAnimating) {
return;
}
createExpandAnimator(getCurrentPosition(), layoutSize).start();
createExpandAnimator(getCurrentPosition(), layoutSize,
duration, interpolator).start();
}

/**
Expand All @@ -179,17 +200,18 @@ public void collapse() {
if (isAnimating) {
return;
}
createExpandAnimator(getCurrentPosition(), closePosition).start();
createExpandAnimator(getCurrentPosition(), closePosition,
duration, interpolator).start();
}

/**
* {@inheritDoc}
*/
@Override
public void initLayout() {
public void initLayout(final boolean isMaintain) {
closePosition = 0;
layoutSize = 0;
isArranged = false;
isArranged = isMaintain;
isCalculatedSize = false;
savedState = null;

Expand All @@ -214,6 +236,7 @@ public void setDuration(final int duration) {
@Override
public void setExpanded(boolean expanded) {
isExpanded = expanded;
isArranged = false;
requestLayout();
}

Expand All @@ -233,31 +256,53 @@ public void setInterpolator(@NonNull final TimeInterpolator interpolator) {
this.interpolator = interpolator;
}

/**
* @param position
* @see #move(int, long, TimeInterpolator)
*/
public void move(int position) {
move(position, duration, interpolator);
}

/**
* Moves to position
*
* @param position
* @param duration
* @param interpolator
*/
public void move(int position) {
public void move(int position, long duration, TimeInterpolator interpolator) {
if (isAnimating) {
return;
}
if (0 > position || layoutSize < position) {
return;
}
createExpandAnimator(getCurrentPosition(), position).start();
createExpandAnimator(getCurrentPosition(), position,
duration, interpolator).start();
}

/**
* Moves to bottom(VERTICAL) or right(HORIZONTAL) of child view
*
* @param index child view index
* @see #moveChild(int, long, TimeInterpolator)
*/
public void moveChild(int index) {
moveChild(index, duration, interpolator);
}

/**
* Moves to bottom(VERTICAL) or right(HORIZONTAL) of child view
*
* @param index index child view index
* @param duration
* @param interpolator
*/
public void moveChild(int index, long duration, TimeInterpolator interpolator) {
if (isAnimating) {
return;
}
createExpandAnimator(getCurrentPosition(), childPositionList.get(index)).start();
createExpandAnimator(getCurrentPosition(), childPositionList.get(index),
duration, interpolator).start();
}

/**
Expand Down Expand Up @@ -325,10 +370,6 @@ public void setClosePositionIndex(final int childIndex) {
this.closePosition = getChildPosition(childIndex);
}

private void updateLayout() {
super.requestLayout();
}

private boolean isVertical() {
return orientation == VERTICAL;
}
Expand All @@ -348,9 +389,12 @@ private void setLayoutSize(int size) {
*
* @param from
* @param to
* @param duration
* @param interpolator
* @return
*/
private ValueAnimator createExpandAnimator(final int from, final int to) {
private ValueAnimator createExpandAnimator(
final int from, final int to, final long duration, final TimeInterpolator interpolator) {
final ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to);
valueAnimator.setDuration(duration);
valueAnimator.setInterpolator(interpolator);
Expand All @@ -362,7 +406,7 @@ public void onAnimationUpdate(final ValueAnimator animator) {
} else {
getLayoutParams().width = (int) animator.getAnimatedValue();
}
updateLayout();
requestLayout();
}
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public void collapse() {
* {@inheritDoc}
*/
@Override
public void initLayout() {
public void initLayout(final boolean isMaintain) {
layoutWeight = 0;
isArranged = false;
isArranged = isMaintain;
isCalculatedSize = false;
savedState = null;

Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<declare-styleable name="expandableLayout">
<attr name="ael_duration" format="integer" />
<attr name="ael_expanded" format="boolean" />
<attr name="ael_defaultChildIndex" format="integer" />
<attr name="ael_defaultPosition" format="integer" />
<attr name="ael_orientation" format="enum">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import android.widget.TextView;

import com.github.aakira.expandablelayout.ExpandableLayout;
import com.github.aakira.expandablelayout.ExpandableLayoutListener;
import com.github.aakira.expandablelayout.ExpandableLayoutListenerAdapter;
import com.github.aakira.expandablelayout.ExpandableRelativeLayout;
import com.github.aakira.expandablelayout.Utils;

Expand Down Expand Up @@ -49,37 +49,21 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.expandableLayout.setBackgroundColor(resource.getColor(item.colorId2));
holder.expandableLayout.setInterpolator(item.interpolator);
holder.expandableLayout.setExpanded(expandState.get(position));
holder.expandableLayout.setListener(new ExpandableLayoutListener() {
@Override
public void onAnimationStart() {
}

@Override
public void onAnimationEnd() {

}

holder.expandableLayout.setListener(new ExpandableLayoutListenerAdapter() {
@Override
public void onPreOpen() {
createRotateAnimator(holder.buttonLayout, 0f, 180f).start();
expandState.put(position, true);
}

@Override
public void onPreClose() {
createRotateAnimator(holder.buttonLayout, 180f, 0f).start();
}

@Override
public void onOpened() {
expandState.put(position, true);
}

@Override
public void onClosed() {
expandState.put(position, false);
}
});

holder.buttonLayout.setRotation(expandState.get(position) ? 180f : 0f);
holder.buttonLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Expand Down Expand Up @@ -116,4 +100,4 @@ public ObjectAnimator createRotateAnimator(final View target, final float from,
animator.setInterpolator(Utils.createInterpolator(Utils.LINEAR_INTERPOLATOR));
return animator;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.widget.Button;

import com.github.aakira.expandablelayout.ExpandableRelativeLayout;

import jp.android.aakira.sample.expandablelayout.R;

public class ExpandableLayoutActivity extends AppCompatActivity implements View.OnClickListener {
Expand All @@ -33,8 +34,8 @@ protected void onCreate(Bundle savedInstanceState) {
mExpandButton = (Button) findViewById(R.id.expandButton);
mMoveChildButton = (Button) findViewById(R.id.moveChildButton);
mMoveChildButton2 = (Button) findViewById(R.id.moveChildButton2);
mMoveTopButton = (Button)findViewById(R.id.moveTopButton);
mSetCloseHeihgtButton = (Button) findViewById(R.id.setCloseHeightButton);
mMoveTopButton = (Button) findViewById(R.id.moveTopButton);
mSetCloseHeihgtButton = (Button) findViewById(R.id.setCloseHeightButton);
mExpandLayout = (ExpandableRelativeLayout) findViewById(R.id.expandableLayout);
mExpandButton.setOnClickListener(this);
mMoveChildButton.setOnClickListener(this);
Expand Down

0 comments on commit 2430eee

Please sign in to comment.