Skip to content

Commit

Permalink
Add onSettled
Browse files Browse the repository at this point in the history
  • Loading branch information
vo55 committed Mar 18, 2017
1 parent fafe3b3 commit b0a14e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
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() {
@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

0 comments on commit b0a14e9

Please sign in to comment.