From b0a14e92de6b329d362449c453a58bb93628aa1b Mon Sep 17 00:00:00 2001 From: Philip Barwikowski Date: Sat, 18 Mar 2017 16:02:32 +0100 Subject: [PATCH] Add onSettled --- .../com/lukedeighton/wheelview/WheelView.java | 22 +++++++++++++++++++ .../wheelsample/MainActivity.java | 5 +++++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/WheelViewLib/src/main/java/com/lukedeighton/wheelview/WheelView.java b/WheelViewLib/src/main/java/com/lukedeighton/wheelview/WheelView.java index eee021b..8875489 100644 --- a/WheelViewLib/src/main/java/com/lukedeighton/wheelview/WheelView.java +++ b/WheelViewLib/src/main/java/com/lukedeighton/wheelview/WheelView.java @@ -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; @@ -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; @@ -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? } @@ -942,6 +946,7 @@ public boolean isEmptyItemPosition(int position) { } private void setSelectedPosition(int position) { + lastSelectionUpdate = SystemClock.uptimeMillis(); if (mRawSelectedPosition == position) return; mRawSelectedPosition = position; @@ -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); } /** diff --git a/WheelViewSample/src/main/java/com/lukedeighton/wheelsample/MainActivity.java b/WheelViewSample/src/main/java/com/lukedeighton/wheelsample/MainActivity.java index 69cea9d..d4e65a4 100644 --- a/WheelViewSample/src/main/java/com/lukedeighton/wheelsample/MainActivity.java +++ b/WheelViewSample/src/main/java/com/lukedeighton/wheelsample/MainActivity.java @@ -46,6 +46,11 @@ public void onWheelItemSelected(WheelView parent, Drawable itemDrawable, int pos Map.Entry 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() { diff --git a/build.gradle b/build.gradle index 6949ce9..5321a18 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 23c54e2..86170ba 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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