Skip to content

Commit 415b946

Browse files
committed
Add PhasedInteractionListener
1 parent d82b419 commit 415b946

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ademar.phasedseekbar;
2+
3+
import android.view.MotionEvent;
4+
5+
public interface PhasedInteractionListener {
6+
7+
void onInteracted(int x, int y, int position, MotionEvent motionEvent);
8+
9+
}

phased-seekbar/src/main/java/ademar/phasedseekbar/PhasedSeekBar.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,26 @@ public class PhasedSeekBar extends View {
1919
protected static final int[] STATE_PRESSED = new int[] { android.R.attr.state_pressed };
2020

2121
protected int[] mState = STATE_SELECTED;
22+
2223
protected boolean mModeIsHorizontal = true;
2324
protected boolean mFirstDraw = true;
2425
protected boolean mUpdateFromPosition = false;
2526
protected boolean mDrawOnOff = true;
2627
protected boolean mFixPoint = true;
28+
2729
protected Drawable mBackgroundDrawable;
2830
protected RectF mBackgroundPaddingRect;
31+
2932
protected int mCurrentX, mCurrentY;
3033
protected int mPivotX, mPivotY;
3134
protected int mItemHalfWidth, mItemHalfHeight;
3235
protected int mItemAnchorHalfWidth, mItemAnchorHalfHeight;
3336
protected int[][] mAnchors;
3437
protected int mCurrentItem;
38+
3539
protected PhasedAdapter mAdapter;
3640
protected PhasedListener mListener;
41+
protected PhasedInteractionListener mInteractionListener;
3742

3843
public PhasedSeekBar(Context context) {
3944
super(context);
@@ -169,9 +174,13 @@ public boolean onTouchEvent(MotionEvent event) {
169174
mCurrentY = !mModeIsHorizontal ? getNormalizedY(event) : mPivotY;
170175
int action = event.getAction();
171176
mUpdateFromPosition = mFixPoint && action == MotionEvent.ACTION_UP;
172-
mState = action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
173-
? STATE_SELECTED : STATE_PRESSED;
177+
mState = action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL ? STATE_SELECTED : STATE_PRESSED;
174178
invalidate();
179+
180+
if (mInteractionListener != null) {
181+
mInteractionListener.onInteracted(mCurrentX, mCurrentY, mCurrentItem, event);
182+
}
183+
175184
switch (action) {
176185
case MotionEvent.ACTION_DOWN:
177186
case MotionEvent.ACTION_UP:
@@ -204,6 +213,10 @@ public void setListener(PhasedListener listener) {
204213
mListener = listener;
205214
}
206215

216+
public void setInteractionListener(PhasedInteractionListener interactionListener) {
217+
mInteractionListener = interactionListener;
218+
}
219+
207220
public void setPosition(int position) {
208221
position = position < 0 ? 0 : position;
209222
position = position >= mAdapter.getCount() ? mAdapter.getCount() - 1 : position;

sample/src/main/java/ademar/phasedseekbar/sample/SampleActivity.java

+10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import android.content.res.Resources;
44
import android.os.Bundle;
55
import android.support.v7.app.ActionBarActivity;
6+
import android.util.Log;
7+
import android.view.MotionEvent;
68
import android.view.View;
79

10+
import ademar.phasedseekbar.PhasedInteractionListener;
811
import ademar.phasedseekbar.PhasedListener;
912
import ademar.phasedseekbar.PhasedSeekBar;
1013
import ademar.phasedseekbar.SimplePhasedAdapter;
@@ -51,6 +54,13 @@ public void onPositionSelected(int position) {
5154
}
5255
});
5356

57+
psbHorizontal.setInteractionListener(new PhasedInteractionListener() {
58+
@Override
59+
public void onInteracted(int x, int y, int position, MotionEvent motionEvent) {
60+
Log.d("PSB", String.format("onInteracted %d %d %d %d", x, y, position, motionEvent.getAction()));
61+
}
62+
});
63+
5464
psbLike.setPosition(0);
5565
}
5666

0 commit comments

Comments
 (0)