Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling wheel rotation by "rotatable" boolean attribute. #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class WheelView extends View {
private Drawable mEmptyItemDrawable;
private Drawable mSelectionDrawable;

private boolean mIsWheelRotatable = true;
private boolean mIsRepeatable;
private boolean mIsWheelDrawableRotatable = true;

Expand Down Expand Up @@ -216,6 +217,7 @@ public WheelView(Context context, AttributeSet attrs, int defStyle) {
setSelectionColor(color);
}

mIsWheelRotatable = a.getBoolean(R.styleable.WheelView_rotatable, true);
mSelectionPadding = a.getDimensionPixelSize(R.styleable.WheelView_selectionPadding, 0);
mIsRepeatable = a.getBoolean(R.styleable.WheelView_repeatItems, false);
mIsWheelDrawableRotatable = a.getBoolean(R.styleable.WheelView_rotatableWheelDrawable, true);
Expand Down Expand Up @@ -402,6 +404,21 @@ public WheelAdapter getAdapter() {
return mAdapter;
}

/**
* @return {@code true} if the wheel rotates.
*/
public boolean isWheelRotatable() {
return mIsWheelRotatable;
}

/**
* <p> When true the wheel is rotated.
* <p> The default value is true
*/
public void setWheelRotatable(boolean isWheelRotatable) {
mIsWheelRotatable = isWheelRotatable;
}

public void setWheelItemTransformer(WheelItemTransformer itemTransformer) {
if (itemTransformer == null) throw new IllegalArgumentException("WheelItemTransformer cannot be null");
mItemTransformer = itemTransformer;
Expand Down Expand Up @@ -1022,6 +1039,9 @@ private void addAngle(float degrees) {

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

if (!mIsWheelRotatable) return true;

final float x = event.getX();
final float y = event.getY();

Expand Down
1 change: 1 addition & 0 deletions WheelViewLib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="WheelView">
<attr name="rotatable" format="boolean" />
<attr name="wheelDrawable" format="reference"/>
<attr name="wheelColor" format="color"/>
<attr name="wheelItemTransformer" format="string"/>
Expand Down