diff --git a/README.md b/README.md index d3c7c6a..07eae60 100644 --- a/README.md +++ b/README.md @@ -103,4 +103,3 @@ You can also use the attribute **discreteSeekBarStyle** on your themes with a cu [Animatable Drawable]:https://developer.android.com/reference/android/graphics/drawable/Animatable.html [PopupWindow]:https://developer.android.com/reference/android/widget/PopupWindow.html [Format]:https://developer.android.com/reference/java/util/Formatter.html - diff --git a/library/src/main/java/com/mardous/discreteseekbar/DiscreteSeekBar.java b/library/src/main/java/com/mardous/discreteseekbar/DiscreteSeekBar.java index 1e1b7da..3321832 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/DiscreteSeekBar.java +++ b/library/src/main/java/com/mardous/discreteseekbar/DiscreteSeekBar.java @@ -335,7 +335,7 @@ public NumericTransformer getNumericTransformer() { * Also if the current progress is out of the new range, it will be set to MIN *
* - * @param max + * @param max the value. * @see #setMin(int) * @see #setProgress(int) */ diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/Marker.java b/library/src/main/java/com/mardous/discreteseekbar/internal/Marker.java index 0ce85a9..42575e4 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/Marker.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/Marker.java @@ -16,6 +16,7 @@ package com.mardous.discreteseekbar.internal; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; @@ -31,7 +32,6 @@ import android.widget.TextView; import androidx.core.view.ViewCompat; import com.mardous.discreteseekbar.R; -import com.mardous.discreteseekbar.internal.compat.SeekBarCompat; import com.mardous.discreteseekbar.internal.drawable.MarkerDrawable; /** @@ -41,9 +41,8 @@ * and the {@link com.mardous.discreteseekbar.internal.drawable.MarkerDrawable} * with the required positions and offsets * - * - * @hide */ +@SuppressLint("ViewConstructor") public class Marker extends ViewGroup implements MarkerDrawable.MarkerAnimationListener { private static final int PADDING_DP = 4; private static final int ELEVATION_DP = 8; @@ -54,14 +53,16 @@ public class Marker extends ViewGroup implements MarkerDrawable.MarkerAnimationL //some distance between the thumb and our bubble marker. //This will be added to our measured height private int mSeparation; - MarkerDrawable mMarkerDrawable; + private MarkerDrawable mMarkerDrawable; public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) { super(context, attrs, defStyleAttr); //as we're reading the parent DiscreteSeekBar attributes, it may wrongly set this view's visibility. setVisibility(View.VISIBLE); - + DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); + + @SuppressLint("CustomViewStyleable") TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar); @@ -71,12 +72,23 @@ public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxV mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); - mNumber.setTextAppearance(context, textAppearanceId); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + mNumber.setTextAppearance(textAppearanceId); + } else { + //noinspection deprecation + mNumber.setTextAppearance(context, textAppearanceId); + } + mNumber.setGravity(Gravity.CENTER); mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setSingleLine(true); - SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + mNumber.setTextDirection(TEXT_DIRECTION_LOCALE); + } + mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped @@ -92,12 +104,25 @@ public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxV mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); - //Elevation for anroid 5+ + //Elevation for Android 5+ float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); + + /* + + This code causes an Exception in Android 10+ + See: https://github.com/AnderWeb/discreteSeekBar/issues/127 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); + setOutlineProvider(new ViewOutlineProvider() { + @Override + public void getOutline(View view, Outline outline) { + outline.setConvexPath(mMarkerDrawable.getPath()); + } + }); } + */ + a.recycle(); } @@ -163,20 +188,20 @@ protected void onAttachedToWindow() { animateOpen(); } - public void setValue(CharSequence value) { - mNumber.setText(value); - } - public CharSequence getValue() { return mNumber.getText(); } - public void animateOpen() { + void setValue(CharSequence value) { + mNumber.setText(value); + } + + void animateOpen() { mMarkerDrawable.stop(); mMarkerDrawable.animateToPressed(); } - public void animateClose() { + void animateClose() { mMarkerDrawable.stop(); mNumber.setVisibility(View.INVISIBLE); mMarkerDrawable.animateToNormal(); diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/PopupIndicator.java b/library/src/main/java/com/mardous/discreteseekbar/internal/PopupIndicator.java index 1719ae1..cce3b92 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/PopupIndicator.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/PopupIndicator.java @@ -38,7 +38,6 @@ * This will attach a View to the Window (full-width, measured-height, positioned just under the thumb) * * - * @hide * @see #showIndicator(android.view.View, android.graphics.Rect) * @see #dismiss() * @see #dismissComplete() @@ -55,7 +54,7 @@ public class PopupIndicator { //... phew! private MarkerDrawable.MarkerAnimationListener mListener; private int[] mDrawingLocation = new int[2]; - Point screenSize = new Point(); + private Point screenSize = new Point(); public PopupIndicator(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) { mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompat.java b/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompat.java index b66009d..a5c1529 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompat.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompat.java @@ -20,44 +20,25 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; import android.os.Build; -import android.view.View; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.core.graphics.drawable.DrawableCompat; import com.mardous.discreteseekbar.internal.drawable.AlmostRippleDrawable; -import com.mardous.discreteseekbar.internal.drawable.MarkerDrawable; /** * Wrapper compatibility class to call some API-Specific methods * And offer alternate procedures when possible - * - * @hide */ public class SeekBarCompat { - - /** - * Sets the custom Outline provider on API>=21. - * Does nothing on API<21 - * - * @param view - * @param markerDrawable - */ - public static void setOutlineProvider(View view, final MarkerDrawable markerDrawable) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - SeekBarCompatDontCrash.setOutlineProvider(view, markerDrawable); - } - } - /** * Our DiscreteSeekBar implementation uses a circular drawable on API < 21 * because we don't set it as Background, but draw it ourselves * - * @param colorStateList - * @return + * @param colorStateList The ripple colors. + * @return The ripple drawable. */ public static Drawable getRipple(ColorStateList colorStateList) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return SeekBarCompatDontCrash.getRipple(colorStateList); + return new RippleDrawable(colorStateList, null, null); } else { return new AlmostRippleDrawable(colorStateList); } @@ -65,8 +46,9 @@ public static Drawable getRipple(ColorStateList colorStateList) { /** * Sets the color of the seekbar ripple - * @param drawable - * @param colorStateList The ColorStateList the track ripple will be changed to + * + * @param drawable The ripple drawable. + * @param colorStateList The ColorStateList the track ripple will be changed to. */ public static void setRippleColor(@NonNull Drawable drawable, ColorStateList colorStateList) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -80,11 +62,7 @@ public static void setRippleColor(@NonNull Drawable drawable, ColorStateList col * As our DiscreteSeekBar implementation uses a circular drawable on API < 21 * we want to use the same method to set its bounds as the Ripple's hotspot bounds. * - * @param drawable - * @param left - * @param top - * @param right - * @param bottom + * @param drawable The drawable to modify. */ public static void setHotspotBounds(Drawable drawable, int left, int top, int right, int bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -95,17 +73,4 @@ public static void setHotspotBounds(Drawable drawable, int left, int top, int ri drawable.setBounds(left, top, right, bottom); } } - - /** - * Sets the TextView text direction attribute when possible - * - * @param textView - * @param textDirection - * @see android.widget.TextView#setTextDirection(int) - */ - public static void setTextDirection(TextView textView, int textDirection) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - SeekBarCompatDontCrash.setTextDirection(textView, textDirection); - } - } } diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompatDontCrash.java b/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompatDontCrash.java deleted file mode 100644 index 6a9aa37..0000000 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/compat/SeekBarCompatDontCrash.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Gustavo Claramunt (AnderWeb) 2014. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mardous.discreteseekbar.internal.compat; - -import android.annotation.TargetApi; -import android.content.res.ColorStateList; -import android.graphics.Outline; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.RippleDrawable; -import android.view.View; -import android.view.ViewOutlineProvider; -import android.widget.TextView; -import com.mardous.discreteseekbar.internal.drawable.MarkerDrawable; - -/** - * Wrapper compatibility class to call some API-Specific methods - * And offer alternate procedures when possible - * - * @hide - */ -@TargetApi(21) -class SeekBarCompatDontCrash { - public static void setOutlineProvider(View marker, final MarkerDrawable markerDrawable) { - marker.setOutlineProvider(new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - outline.setConvexPath(markerDrawable.getPath()); - } - }); - } - - public static Drawable getRipple(ColorStateList colorStateList) { - return new RippleDrawable(colorStateList, null, null); - } - - public static void setTextDirection(TextView number, int textDirection) { - number.setTextDirection(textDirection); - } -} diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/AlmostRippleDrawable.java b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/AlmostRippleDrawable.java index 1e15d65..7739eb2 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/AlmostRippleDrawable.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/AlmostRippleDrawable.java @@ -107,6 +107,7 @@ public boolean setState(int[] stateSet) { for (int i : oldState) { if (i == android.R.attr.state_pressed) { oldPressed = true; + break; } } super.setState(stateSet); diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/MarkerDrawable.java b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/MarkerDrawable.java index d4095ce..030185a 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/MarkerDrawable.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/MarkerDrawable.java @@ -40,8 +40,6 @@ ** Subclasses should implement {@link #doDraw(android.graphics.Canvas, android.graphics.Paint)} *
- * - * @hide */ public abstract class StateDrawable extends Drawable { private ColorStateList mTintStateList; diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/ThumbDrawable.java b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/ThumbDrawable.java index 4d000e5..d245b71 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/ThumbDrawable.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/ThumbDrawable.java @@ -36,8 +36,6 @@ ** This special delay is meant to help avoiding frame glitches while the {@link com.mardous.discreteseekbar.internal.Marker} is added to the Window *
- * - * @hide */ public class ThumbDrawable extends StateDrawable implements Animatable { //The current size for this drawable. Must be converted to real DPs diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackOvalDrawable.java b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackOvalDrawable.java deleted file mode 100644 index 0bde7fc..0000000 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackOvalDrawable.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Gustavo Claramunt (AnderWeb) 2014. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mardous.discreteseekbar.internal.drawable; - -import android.content.res.ColorStateList; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.RectF; -import androidx.annotation.NonNull; - -/** - * Simple {@link com.mardous.discreteseekbar.internal.drawable.StateDrawable} implementation - * to draw circles/ovals - * - * @hide - */ -public class TrackOvalDrawable extends StateDrawable { - private RectF mRectF = new RectF(); - - public TrackOvalDrawable(@NonNull ColorStateList tintStateList) { - super(tintStateList); - } - - @Override - void doDraw(Canvas canvas, Paint paint) { - mRectF.set(getBounds()); - canvas.drawOval(mRectF, paint); - } - -} diff --git a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackRectDrawable.java b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackRectDrawable.java index ba30933..054eb9b 100644 --- a/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackRectDrawable.java +++ b/library/src/main/java/com/mardous/discreteseekbar/internal/drawable/TrackRectDrawable.java @@ -24,8 +24,6 @@ /** * Simple {@link com.mardous.discreteseekbar.internal.drawable.StateDrawable} implementation * to draw rectangles - * - * @hide */ public class TrackRectDrawable extends StateDrawable { public TrackRectDrawable(@NonNull ColorStateList tintStateList) {