Skip to content

Commit

Permalink
Add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
TangKe committed Aug 17, 2012
1 parent 89a795d commit ed00189
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 177 deletions.
19 changes: 16 additions & 3 deletions Aretha/src/com/aretha/widget/WaveLayout.java
Expand Up @@ -92,7 +92,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int paddingTop = getPaddingTop();
int paddingLeft = getPaddingBottom();
int paddingLeft = getPaddingLeft();
int offset = 0;
for (int index = 0; index < childCount; index++) {
View child = getChildAt(index);
Expand All @@ -104,11 +104,13 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {

if (isHorizontal) {
switch (gravity) {
case Gravity.LEFT:
case Gravity.TOP:
child.layout(offset + paddingLeft, position + paddingTop,
offset + childWidth + paddingLeft, childHeight
+ position + paddingTop);
break;
case Gravity.RIGHT:
case Gravity.BOTTOM:
child.layout(offset + paddingLeft, height - childHeight
- position - paddingBottom, offset + childWidth
Expand All @@ -118,11 +120,13 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {

} else {
switch (gravity) {
case Gravity.TOP:
case Gravity.LEFT:
child.layout(position + paddingLeft, offset + paddingTop,
position + childWidth + paddingLeft, offset
+ childHeight + paddingTop);
break;
case Gravity.BOTTOM:
case Gravity.RIGHT:
child.layout(width - position - childWidth - paddingRight,
offset + paddingTop, width - position
Expand Down Expand Up @@ -237,9 +241,13 @@ public boolean onTouchEvent(MotionEvent event) {
for (int index = 0; index < count; index++) {
View child = getChildAt(index);
child.getHitRect(pointCheckRect);
if (pointCheckRect.contains(pointCheckRect.centerX(),
(int) y)) {
if ((mOrientation == VERTICAL && pointCheckRect.contains(
pointCheckRect.centerX(), (int) y))
|| (mOrientation == HORIZONTAL && pointCheckRect
.contains((int) x, pointCheckRect.centerY()))) {
if (mLastPointIndex != index) {
child.setPressed(true);
getChildAt(mLastPointIndex).setPressed(false);
mOnWaveLayoutChangeListener.onIndexChange(child,
index);
}
Expand All @@ -256,6 +264,7 @@ public boolean onTouchEvent(MotionEvent event) {
if (null != mOnWaveLayoutChangeListener) {
mOnWaveLayoutChangeListener.onWaveEnd();
}
getChildAt(mLastPointIndex).setPressed(false);
requestDisallowInterceptTouchEvent(false);
mScroller.startScroll(mCurrentWaveAmplitude, 0,
0 - mCurrentWaveAmplitude, 0);
Expand All @@ -272,6 +281,8 @@ public int getGravity() {

public void setGravity(int gravity) {
this.mGravity = gravity;
invalidate();
requestLayout();
}

public int getOrientation() {
Expand All @@ -280,6 +291,8 @@ public int getOrientation() {

public void setOrientation(int orientation) {
this.mOrientation = orientation;
invalidate();
requestLayout();
}

public int getMaxWaveAmplitude() {
Expand Down

0 comments on commit ed00189

Please sign in to comment.