diff --git a/app/build.gradle b/app/build.gradle index 192a82b..3954047 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { applicationId "com.warkiz.indicatorseekbar" minSdkVersion 24 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 3 versionName "2.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -21,6 +20,6 @@ android { dependencies { implementation project(':indicatorseekbar') - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support:design:28.0.0' } diff --git a/app/src/main/res/layout/discrete.xml b/app/src/main/res/layout/discrete.xml index cad420f..3b03c67 100644 --- a/app/src/main/res/layout/discrete.xml +++ b/app/src/main/res/layout/discrete.xml @@ -222,6 +222,23 @@ app:isb_tick_texts_array="@array/last_next_length_6" app:isb_ticks_count="6" /> + + + + diff --git a/build.gradle b/build.gradle index 614f3db..4a7a96a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,9 +6,9 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' + classpath 'com.android.tools.build:gradle:3.5.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b9614d3..d2ae0b4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/indicatorseekbar/build.gradle b/indicatorseekbar/build.gradle index 0ad9288..1b78e5c 100644 --- a/indicatorseekbar/build.gradle +++ b/indicatorseekbar/build.gradle @@ -27,12 +27,11 @@ ext { } android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 3 versionName VERSION_NAME } @@ -45,7 +44,7 @@ android { } dependencies { - compileOnly 'com.android.support:appcompat-v7:27.1.1' + compileOnly 'com.android.support:appcompat-v7:28.0.0' } diff --git a/indicatorseekbar/src/main/java/com/warkiz/widget/Builder.java b/indicatorseekbar/src/main/java/com/warkiz/widget/Builder.java index a95cb4b..6662182 100644 --- a/indicatorseekbar/src/main/java/com/warkiz/widget/Builder.java +++ b/indicatorseekbar/src/main/java/com/warkiz/widget/Builder.java @@ -39,6 +39,8 @@ public class Builder { boolean userSeekable = true; boolean onlyThumbDraggable = false; boolean clearPadding = false; + boolean longClick = false; + int longClickTime = 0; //indicator int showIndicatorType = IndicatorType.ROUNDED_RECTANGLE; int indicatorColor = Color.parseColor("#FF4081"); @@ -173,6 +175,28 @@ public Builder clearPadding(boolean clearPadding) { return this; } + /** + * seek bar will respond only on longClick + * + * @param longClick true to set longClick behaviour + * @return Builder + */ + public Builder longClick(boolean longClick){ + this.longClick = longClick; + return this; + } + + /** + * seek bar will respond on longClick after a time expressed in ms + * + * @param longClickTime time (in ms) before to respond + * @return Builder + */ + public Builder longClickTime(int longClickTime){ + this.longClickTime = longClickTime; + return this; + } + /** * prevent user from touching to seek or not * diff --git a/indicatorseekbar/src/main/java/com/warkiz/widget/IndicatorSeekBar.java b/indicatorseekbar/src/main/java/com/warkiz/widget/IndicatorSeekBar.java index 092bfea..d667b59 100644 --- a/indicatorseekbar/src/main/java/com/warkiz/widget/IndicatorSeekBar.java +++ b/indicatorseekbar/src/main/java/com/warkiz/widget/IndicatorSeekBar.java @@ -31,6 +31,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.util.Date; /** * created by zhuangguangquan on 2017/9/1 @@ -51,7 +52,6 @@ */ public class IndicatorSeekBar extends View { - private static final int THUMB_MAX_WIDTH = 30; private static final String FORMAT_PROGRESS = "${PROGRESS}"; private static final String FORMAT_TICK_TEXT = "${TICK_TEXT}"; private Context mContext; @@ -83,6 +83,10 @@ public class IndicatorSeekBar extends View { private boolean mSeekSmoothly;//seek continuously private float[] mProgressArr;//save the progress which at tickMark position. private boolean mR2L;//right to left,compat local problem. + private boolean mLongClick;//true if seekbar responds on longClick + private int mLongClickTime;//time (in ms) passed before responds onlongClick + private long startTime; + private long endTime; //tick texts private boolean mShowTickText;//the palace where the tick text show . private boolean mShowBothTickTextsOnly;//show the tick texts on the both ends of seek bar before. @@ -201,6 +205,8 @@ private void initAttrs(Context context, AttributeSet attrs) { mOnlyThumbDraggable = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_only_thumb_draggable, builder.onlyThumbDraggable); mSeekSmoothly = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_seek_smoothly, builder.seekSmoothly); mR2L = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_r2l, builder.r2l); + mLongClick = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_longclick, builder.longClick); + mLongClickTime = ta.getInteger(R.styleable.IndicatorSeekBar_isb_longclick_time, builder.longClickTime); //track mBackgroundTrackSize = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_track_background_size, builder.trackBackgroundSize); mProgressTrackSize = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_track_progress_size, builder.trackProgressSize); @@ -254,13 +260,13 @@ private void initParams() { mThumbRadius = mThumbSize / 2.0f; mThumbTouchRadius = mThumbRadius * 1.2f; } else { - mThumbRadius = Math.min(SizeUtils.dp2px(mContext, THUMB_MAX_WIDTH), mThumbSize) / 2.0f; + mThumbRadius = mThumbSize / 2.0f; mThumbTouchRadius = mThumbRadius; } if (mTickMarksDrawable == null) { mTickRadius = mTickMarksSize / 2.0f; } else { - mTickRadius = Math.min(SizeUtils.dp2px(mContext, THUMB_MAX_WIDTH), mTickMarksSize) / 2.0f; + mTickRadius = mTickMarksSize / 2.0f; } mCustomDrawableMaxHeight = Math.max(mThumbTouchRadius, mTickRadius) * 2.0f; initStrokePaint(); @@ -725,7 +731,7 @@ private Bitmap getDrawBitmap(Drawable drawable, boolean isThumb) { } int width; int height; - int maxRange = SizeUtils.dp2px(mContext, THUMB_MAX_WIDTH); + int maxRange = mThumbSize; int intrinsicWidth = drawable.getIntrinsicWidth(); if (intrinsicWidth > maxRange) { if (isThumb) { @@ -1214,18 +1220,43 @@ public boolean onTouchEvent(MotionEvent event) { if (mSeekChangeListener != null) { mSeekChangeListener.onStartTrackingTouch(this); } - refreshSeekBar(event); + if(!mLongClick) { + refreshSeekBar(event); + } + else{ + startTime = event.getEventTime(); + } return true; } break; case MotionEvent.ACTION_MOVE: - refreshSeekBar(event); + if(mLongClick) { + endTime = event.getEventTime(); + if (endTime - startTime > mLongClickTime) { + refreshSeekBar(event); + } + } + else{ + refreshSeekBar(event); + } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsTouching = false; - if (mSeekChangeListener != null) { - mSeekChangeListener.onStopTrackingTouch(this); + + if(mLongClick) { + endTime = event.getEventTime(); + if (endTime - startTime > mLongClickTime) { + refreshSeekBar(event); + if (mSeekChangeListener != null) { + mSeekChangeListener.onStopTrackingTouch(this); + } + } + } + else{ + if (mSeekChangeListener != null) { + mSeekChangeListener.onStopTrackingTouch(this); + } } if (!autoAdjustThumb()) { invalidate(); @@ -1703,7 +1734,7 @@ public void setThumbDrawable(Drawable drawable) { this.mPressedThumbBitmap = null; } else { this.mThumbDrawable = drawable; - this.mThumbRadius = Math.min(SizeUtils.dp2px(mContext, THUMB_MAX_WIDTH), mThumbSize) / 2.0f; + this.mThumbRadius = mThumbSize / 2.0f; this.mThumbTouchRadius = mThumbRadius; this.mCustomDrawableMaxHeight = Math.max(mThumbTouchRadius, mTickRadius) * 2.0f; initThumbBitmap(); @@ -1773,7 +1804,7 @@ public void setTickMarksDrawable(Drawable drawable) { this.mSelectTickMarksBitmap = null; } else { this.mTickMarksDrawable = drawable; - this.mTickRadius = Math.min(SizeUtils.dp2px(mContext, THUMB_MAX_WIDTH), mTickMarksSize) / 2.0f; + this.mTickRadius = mTickMarksSize / 2.0f; this.mCustomDrawableMaxHeight = Math.max(mThumbTouchRadius, mTickRadius) * 2.0f; initTickMarksBitmap(); } diff --git a/indicatorseekbar/src/main/res/values/attr.xml b/indicatorseekbar/src/main/res/values/attr.xml index a15081a..26d13e7 100644 --- a/indicatorseekbar/src/main/res/values/attr.xml +++ b/indicatorseekbar/src/main/res/values/attr.xml @@ -12,6 +12,8 @@ + + //indicator