Skip to content
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 @@ -24,6 +24,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -104,6 +105,8 @@ public class WheelView extends View {
private float mLastWheelTouchX;
private float mLastWheelTouchY;

private long lastSelectionUpdate;

private CacheItem[] mItemCacheArray;
private Drawable mWheelDrawable;
private Drawable mEmptyItemDrawable;
Expand Down Expand Up @@ -348,6 +351,7 @@ public interface OnWheelItemSelectListener {
* @param position of the adapter that is closest to the selection angle
*/
void onWheelItemSelected(WheelView parent, Drawable itemDrawable, int position);
void onWheelItemSettled(WheelView parent, Drawable itemDrawable, int position);

//TODO onWheelItemSettled?
}
Expand Down Expand Up @@ -942,6 +946,7 @@ public boolean isEmptyItemPosition(int position) {
}

private void setSelectedPosition(int position) {
lastSelectionUpdate = SystemClock.uptimeMillis();
if (mRawSelectedPosition == position) return;

mRawSelectedPosition = position;
Expand All @@ -950,6 +955,23 @@ private void setSelectedPosition(int position) {
int adapterPos = getSelectedPosition();
mOnItemSelectListener.onWheelItemSelected(this, getWheelItemDrawable(adapterPos), adapterPos);
}

informIfSettled(getSelectedPosition());

}

private void informIfSettled(final int position){
final WheelView wheelView = this;
new Handler().postDelayed(new Runnable() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - Although I'd like to avoid using a delayed runnable if possible. 🤔

@Override
public void run() {
if (SystemClock.uptimeMillis() - 100 > lastSelectionUpdate &&
mOnItemSelectListener != null && !isEmptyItemPosition(position)){
int adapterPos = getSelectedPosition();
mOnItemSelectListener.onWheelItemSettled(wheelView, getWheelItemDrawable(adapterPos), adapterPos);
}
}
}, 600);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public void onWheelItemSelected(WheelView parent, Drawable itemDrawable, int pos
Map.Entry<String, Integer> selectedEntry = ((MaterialColorAdapter) parent.getAdapter()).getItem(position);
parent.setSelectionColor(getContrastColor(selectedEntry));
}

@Override
public void onWheelItemSettled(WheelView parent, Drawable itemDrawable, int position) {
int testPos = position;
}
});

wheelView.setOnWheelItemClickListener(new WheelView.OnWheelItemClickListener() {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Dec 30 12:47:40 GMT 2016
#Sat Mar 18 15:06:37 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip