From 22f904c6953ac667153357a8aa2232c24525ba06 Mon Sep 17 00:00:00 2001 From: Kojo Fosu Bempa Edue Date: Thu, 9 Sep 2021 13:24:19 +0000 Subject: [PATCH 1/5] Add animations --- .../quantitizerlibrary/AnimationStyle.kt | 9 ++ .../mcdev/quantitizerlibrary/Extensions.kt | 69 ++++++++++++- .../HorizontalQuantitizer.kt | 96 +++++++++++++++++-- .../quantitizerlibrary/NoValueQuantitizer.kt | 8 +- .../quantitizerlibrary/VerticalQuantitizer.kt | 12 +-- .../mcdev/quantitizer/ButtonsOnlyActivity.kt | 2 + 6 files changed, 172 insertions(+), 24 deletions(-) create mode 100644 QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt new file mode 100644 index 0000000..805c7af --- /dev/null +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt @@ -0,0 +1,9 @@ +package com.mcdev.quantitizerlibrary + + +enum class AnimationStyle { + SWING, + SLIDE_IN_LTR, + SLIDE_IN_RTL, + FALL_IN +} \ No newline at end of file diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt index 9775a7f..908c4ad 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt @@ -28,13 +28,29 @@ fun View.hideKeyboard(): Boolean { } -fun View.enterAnimation(translation: String, startPosition: Float, endPosition: Float) { +fun View.enterAnimationSwing(translation: String, startPosition: Float, endPosition: Float) { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_IN) animator2.start() } -fun View.exitAnimation( translation: String, startPosition: Float, endPosition: Float) { +fun View.exitAnimationSwing(translation: String, startPosition: Float, endPosition: Float) { + Handler(Looper.getMainLooper()).postDelayed( + { + val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) + animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) + animator2.start() + }, DURATION + ) +} + +fun View.enterAnimationSlide(translation: String, startPosition: Float, endPosition: Float) { + val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) + animator2.interpolator = EasingInterpolator(Ease.BACK_IN) + animator2.start() +} + +fun View.exitAnimationSlide(translation: String, startPosition: Float, endPosition: Float) { Handler(Looper.getMainLooper()).postDelayed( { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) @@ -60,9 +76,9 @@ fun QuantitizerListener.activateOnDecrease(){ ) } -fun EditText.updateText(translation: String, startPosition: Float, endPosition: Float, text: String ){ +fun EditText.textAnimSwing(translation: String, startPosition: Float, endPosition: Float, text: String ){ //enter - enterAnimation(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation //exit Handler(Looper.getMainLooper()).postDelayed( { @@ -73,4 +89,49 @@ fun EditText.updateText(translation: String, startPosition: Float, endPosition: animator2.start() }, DURATION ) +} + +fun EditText.textAnimSlideInLTR(translation: String, startPosition: Float, endPosition: Float, text: String ){ + //enter + enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + //exit + Handler(Looper.getMainLooper()).postDelayed( + { + this.setText(text) // update current text + + val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) + animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) + animator2.start() + }, DURATION + ) +} + +fun EditText.textAnimSlideInRTL(translation: String, startPosition: Float, endPosition: Float, text: String ){ + //enter + enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + //exit + Handler(Looper.getMainLooper()).postDelayed( + { + this.setText(text) // update current text + + val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) + animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) + animator2.start() + }, DURATION + ) +} + +fun EditText.textAnimFallIn(translation: String, startPosition: Float, endPosition: Float, text: String ){ + //enter + enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + //exit + Handler(Looper.getMainLooper()).postDelayed( + { + this.setText(text) // update current text + + val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) + animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) + animator2.start() + }, DURATION + ) } \ No newline at end of file diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt index 5d55e39..403547b 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt @@ -33,6 +33,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private var _minValue:Int = 0 private var _maxValue:Int? = null private var _animateButtons: Boolean = true + private var _animationStyle: AnimationStyle = AnimationStyle.SWING var minValue: Int get() = _minValue @@ -59,6 +60,12 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, _animateButtons = value } + var textAnimation: AnimationStyle + get() = _animationStyle + set(value) { + _animationStyle = value + } + init { val a = context.obtainStyledAttributes( attributeSet, R.styleable.Quantitizer, defStyle, 0 @@ -134,7 +141,8 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private fun doInc() { if (currentValue >= maxValue!!) { - wobble(binding.quantityTv) + //Do nothing +// wobble(binding.quantityTv) } else { binding.quantityTv.isCursorVisible = false // hide cursor if it's visible val increasedValue: Int = currentValue.inc() @@ -145,7 +153,8 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private fun doDec() { if (currentValue <= minValue) { - wobble(binding.quantityTv) + //Do nothing +// wobble(binding.quantityTv) } else { binding.quantityTv.isCursorVisible = false // hide cursor if it's visible val decreasedValue: Int = currentValue.dec() @@ -159,8 +168,42 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, animatePlusButton() } - //set current value to edit text - binding.quantityTv.updateText( translation_X, 200f, 0f, currentValue.toString()) // text + //animate and set current value for edit text + when (_animationStyle) { + AnimationStyle.SLIDE_IN_RTL -> { + binding.quantityTv.textAnimSlideInRTL( + translation_X, + -200f, + 0f, + currentValue.toString() + ) // text + } + AnimationStyle.SLIDE_IN_LTR -> { + binding.quantityTv.textAnimSlideInLTR( + translation_X, + 200f, + 0f, + currentValue.toString() + ) + } + AnimationStyle.FALL_IN -> { + binding.quantityTv.textAnimFallIn( + translation_Y, + 60f, + 0f, + currentValue.toString() + ) + } + else -> { + binding.quantityTv.textAnimSwing( + translation_X, + 200f, + 0f, + currentValue.toString() + ) + } + } + } private fun animateDec() { @@ -168,24 +211,57 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, animateMinusButton() } - //set current value to edit text - binding.quantityTv.updateText( translation_X, -200f, 0f, currentValue.toString() ) // text + //animate and set current value for edit text + when (_animationStyle) { + AnimationStyle.SLIDE_IN_RTL -> { + binding.quantityTv.textAnimSlideInRTL( + translation_X, + 200f, + 0f, + currentValue.toString() + ) // text + } + AnimationStyle.SLIDE_IN_LTR -> { + binding.quantityTv.textAnimSlideInLTR( + translation_X, + -200f, + 0f, + currentValue.toString() + ) + } + AnimationStyle.FALL_IN -> { + binding.quantityTv.textAnimFallIn( + translation_Y, + -60f, + 0f, + currentValue.toString() + ) + } + else -> { + binding.quantityTv.textAnimSwing( + translation_X, + -200f, + 0f, + currentValue.toString() + ) + } + } } private fun animatePlusButton() { //enter animation - binding.increaseIb.enterAnimation( translation_X, 0f, 20f ) // view + binding.increaseIb.enterAnimationSwing( translation_X, 0f, 20f ) // view //exit animation - binding.increaseIb.exitAnimation( translation_X, 20f, 0f ) // view + binding.increaseIb.exitAnimationSwing( translation_X, 20f, 0f ) // view } private fun animateMinusButton() { //enter animation - binding.decreaseIb.enterAnimation( translation_X, 0f, -20f ) // view + binding.decreaseIb.enterAnimationSwing( translation_X, 0f, -20f ) // view //exit animation - binding.decreaseIb.exitAnimation( translation_X, -20f, 0f ) // view + binding.decreaseIb.exitAnimationSwing( translation_X, -20f, 0f ) // view } fun setIconWidthAndHeight(width: Int, height: Int) { diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt index 6e0c10b..b3c8f8a 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt @@ -72,13 +72,13 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, } private fun animatePlusButton() { - binding.increaseIb.enterAnimation( translation, 0f, 20f) - binding.increaseIb.exitAnimation( translation, 20f, 0f) + binding.increaseIb.enterAnimationSwing( translation, 0f, 20f) + binding.increaseIb.exitAnimationSwing( translation, 20f, 0f) } private fun animateMinusButton() { - binding.decreaseIb.enterAnimation( translation, 0f, -20f) - binding.decreaseIb.exitAnimation( translation, -20f, 0f) + binding.decreaseIb.enterAnimationSwing( translation, 0f, -20f) + binding.decreaseIb.exitAnimationSwing( translation, -20f, 0f) } fun setIconWidthAndHeight(width: Int, height: Int) { diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt index f1cf931..6fd83d0 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt @@ -163,7 +163,7 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, } //set current value to edit text - binding.quantityTv.updateText( translation_Y, -150f, 0f, currentValue.toString()) // text + binding.quantityTv.textAnimSwing( translation_Y, -150f, 0f, currentValue.toString()) // text } @@ -173,23 +173,23 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, } //set current value to edit text - binding.quantityTv.updateText( translation_Y, 150f, 0f, currentValue.toString() ) // text + binding.quantityTv.textAnimSwing( translation_Y, 150f, 0f, currentValue.toString() ) // text } private fun animatePlusButton() { //enter animation - binding.increaseIb.enterAnimation( translation_Y, 0f, -20f ) // view + binding.increaseIb.enterAnimationSwing( translation_Y, 0f, -20f ) // view //exit animation - binding.increaseIb.exitAnimation( translation_Y, -20f, 0f ) // view + binding.increaseIb.exitAnimationSwing( translation_Y, -20f, 0f ) // view } private fun animateMinusButton() { //enter animation - binding.decreaseIb.enterAnimation( translation_Y, 0f, 20f ) // view + binding.decreaseIb.enterAnimationSwing( translation_Y, 0f, 20f ) // view //exit animation - binding.decreaseIb.exitAnimation( translation_Y, 20f, 0f ) // view + binding.decreaseIb.exitAnimationSwing( translation_Y, 20f, 0f ) // view } fun setIconWidthAndHeight(width: Int, height: Int) { diff --git a/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt b/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt index f8f9d83..5bb1954 100644 --- a/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt +++ b/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt @@ -2,6 +2,7 @@ package com.mcdev.quantitizer import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import com.mcdev.quantitizerlibrary.AnimationStyle import com.mcdev.quantitizerlibrary.HorizontalQuantitizer import com.mcdev.quantitizerlibrary.NoValueQuantitizer import com.mcdev.quantitizerlibrary.VerticalQuantitizer @@ -18,6 +19,7 @@ class ButtonsOnlyActivity : AppCompatActivity() { hq.apply { value = 1 buttonAnimationEnabled = false + textAnimation = AnimationStyle.FALL_IN // setPlusIconBackgroundColor("#C19A6B") // setMinusIconBackgroundColor("#C19A6B") // setMinusIconColor("#ffffff") From e8957c7740fcb050df98feaae1d8e958d4c474d3 Mon Sep 17 00:00:00 2001 From: Kojo Fosu Bempa Edue Date: Thu, 9 Sep 2021 20:50:18 +0000 Subject: [PATCH 2/5] Adds new animations, refactors old code, adds new duration method --- .../quantitizerlibrary/AnimationStyle.kt | 4 +- .../mcdev/quantitizerlibrary/Extensions.kt | 48 ++++++------ .../HorizontalQuantitizer.kt | 57 +++++++++----- .../quantitizerlibrary/NoValueQuantitizer.kt | 19 +++-- .../quantitizerlibrary/VerticalQuantitizer.kt | 77 ++++++++++++++----- .../main/res/layout/vertical_quantitizer.xml | 2 +- .../mcdev/quantitizer/ButtonsOnlyActivity.kt | 4 +- 7 files changed, 139 insertions(+), 72 deletions(-) diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt index 805c7af..2fdec5d 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/AnimationStyle.kt @@ -3,7 +3,7 @@ package com.mcdev.quantitizerlibrary enum class AnimationStyle { SWING, - SLIDE_IN_LTR, - SLIDE_IN_RTL, + SLIDE_IN, + SLIDE_IN_REVERSE, FALL_IN } \ No newline at end of file diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt index 908c4ad..636ec5a 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/Extensions.kt @@ -10,7 +10,7 @@ import android.widget.EditText import com.daasuu.ei.Ease import com.daasuu.ei.EasingInterpolator -const val DURATION = 300L +//var DURATION = 300L const val translation_X = "translationX" const val translation_Y = "translationY" @@ -28,57 +28,59 @@ fun View.hideKeyboard(): Boolean { } -fun View.enterAnimationSwing(translation: String, startPosition: Float, endPosition: Float) { +fun View.enterAnimationSwing(translation: String, startPosition: Float, endPosition: Float, duration: Long) { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_IN) + animator2.duration = duration animator2.start() } -fun View.exitAnimationSwing(translation: String, startPosition: Float, endPosition: Float) { +fun View.exitAnimationSwing(translation: String, startPosition: Float, endPosition: Float, duration: Long) { Handler(Looper.getMainLooper()).postDelayed( { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } -fun View.enterAnimationSlide(translation: String, startPosition: Float, endPosition: Float) { +fun View.enterAnimationSlide(translation: String, startPosition: Float, endPosition: Float, duration: Long) { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_IN) + animator2.duration = duration animator2.start() } -fun View.exitAnimationSlide(translation: String, startPosition: Float, endPosition: Float) { +fun View.exitAnimationSlide(translation: String, startPosition: Float, endPosition: Float, duration: Long) { Handler(Looper.getMainLooper()).postDelayed( { val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } -fun QuantitizerListener.activateOnIncrease(){ +fun QuantitizerListener.activateOnIncrease(duration: Long){ Handler(Looper.getMainLooper()).postDelayed( { this.onIncrease() - }, DURATION + }, duration ) } -fun QuantitizerListener.activateOnDecrease(){ +fun QuantitizerListener.activateOnDecrease(duration: Long){ Handler(Looper.getMainLooper()).postDelayed( { this.onDecrease() - }, DURATION + }, duration ) } -fun EditText.textAnimSwing(translation: String, startPosition: Float, endPosition: Float, text: String ){ +fun EditText.textAnimSwing(translation: String, startPosition: Float, endPosition: Float, text: String , duration: Long){ //enter - enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + enterAnimationSwing(translation, endPosition, startPosition, duration) // first play enter animation. End and Start positions are inverted for proper animation //exit Handler(Looper.getMainLooper()).postDelayed( { @@ -87,13 +89,13 @@ fun EditText.textAnimSwing(translation: String, startPosition: Float, endPositio val animator2 = ObjectAnimator.ofFloat(this, translation, startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } -fun EditText.textAnimSlideInLTR(translation: String, startPosition: Float, endPosition: Float, text: String ){ +fun EditText.textAnimSlideInLTR(translation: String, startPosition: Float, endPosition: Float, text: String, duration: Long){ //enter - enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + enterAnimationSwing(translation, endPosition, startPosition, duration) // first play enter animation. End and Start positions are inverted for proper animation //exit Handler(Looper.getMainLooper()).postDelayed( { @@ -102,13 +104,13 @@ fun EditText.textAnimSlideInLTR(translation: String, startPosition: Float, endPo val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } -fun EditText.textAnimSlideInRTL(translation: String, startPosition: Float, endPosition: Float, text: String ){ +fun EditText.textAnimSlideInRTL(translation: String, startPosition: Float, endPosition: Float, text: String , duration: Long){ //enter - enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + enterAnimationSwing(translation, endPosition, startPosition, duration) // first play enter animation. End and Start positions are inverted for proper animation //exit Handler(Looper.getMainLooper()).postDelayed( { @@ -117,13 +119,13 @@ fun EditText.textAnimSlideInRTL(translation: String, startPosition: Float, endPo val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } -fun EditText.textAnimFallIn(translation: String, startPosition: Float, endPosition: Float, text: String ){ +fun EditText.textAnimFallIn(translation: String, startPosition: Float, endPosition: Float, text: String , duration: Long){ //enter - enterAnimationSwing(translation, endPosition, startPosition) // first play enter animation. End and Start positions are inverted for proper animation + enterAnimationSwing(translation, endPosition, startPosition, duration) // first play enter animation. End and Start positions are inverted for proper animation //exit Handler(Looper.getMainLooper()).postDelayed( { @@ -132,6 +134,6 @@ fun EditText.textAnimFallIn(translation: String, startPosition: Float, endPositi val animator2 = ObjectAnimator.ofFloat(this, translation, -startPosition, endPosition) animator2.interpolator = EasingInterpolator(Ease.BACK_OUT) animator2.start() - }, DURATION + }, duration ) } \ No newline at end of file diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt index 403547b..9979162 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt @@ -30,6 +30,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private val binding = HorizontalQuantitizerBinding.inflate(LayoutInflater.from(context), this, true) private var currentValue: Int = 0 + private var _animationDuration = 300L private var _minValue:Int = 0 private var _maxValue:Int? = null private var _animateButtons: Boolean = true @@ -60,12 +61,18 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, _animateButtons = value } - var textAnimation: AnimationStyle + var textAnimationStyle: AnimationStyle get() = _animationStyle set(value) { _animationStyle = value } + var animationDuration: Long + get() = _animationDuration + set(value) { + _animationDuration = value + } + init { val a = context.obtainStyledAttributes( attributeSet, R.styleable.Quantitizer, defStyle, 0 @@ -89,7 +96,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, doDec() //listener - listener?.activateOnDecrease() + listener?.activateOnDecrease(_animationDuration) } /*increase*/ @@ -98,7 +105,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, doInc() //listener - listener?.activateOnIncrease() + listener?.activateOnIncrease(_animationDuration) } /*make edit text cursor visible when clicked*/ @@ -170,20 +177,22 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, //animate and set current value for edit text when (_animationStyle) { - AnimationStyle.SLIDE_IN_RTL -> { + AnimationStyle.SLIDE_IN_REVERSE -> { binding.quantityTv.textAnimSlideInRTL( translation_X, -200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) // text } - AnimationStyle.SLIDE_IN_LTR -> { + AnimationStyle.SLIDE_IN -> { binding.quantityTv.textAnimSlideInLTR( translation_X, 200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } AnimationStyle.FALL_IN -> { @@ -191,15 +200,17 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, translation_Y, 60f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } else -> { binding.quantityTv.textAnimSwing( - translation_X, + translation_Y, 200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } } @@ -213,20 +224,22 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, //animate and set current value for edit text when (_animationStyle) { - AnimationStyle.SLIDE_IN_RTL -> { + AnimationStyle.SLIDE_IN_REVERSE -> { binding.quantityTv.textAnimSlideInRTL( translation_X, 200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) // text } - AnimationStyle.SLIDE_IN_LTR -> { + AnimationStyle.SLIDE_IN -> { binding.quantityTv.textAnimSlideInLTR( translation_X, -200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } AnimationStyle.FALL_IN -> { @@ -234,15 +247,17 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, translation_Y, -60f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } else -> { binding.quantityTv.textAnimSwing( - translation_X, + translation_Y, -200f, 0f, - currentValue.toString() + currentValue.toString(), + _animationDuration ) } } @@ -250,18 +265,18 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private fun animatePlusButton() { //enter animation - binding.increaseIb.enterAnimationSwing( translation_X, 0f, 20f ) // view + binding.increaseIb.enterAnimationSwing( translation_X, 0f, 20f , _animationDuration) // view //exit animation - binding.increaseIb.exitAnimationSwing( translation_X, 20f, 0f ) // view + binding.increaseIb.exitAnimationSwing( translation_X, 20f, 0f , _animationDuration) // view } private fun animateMinusButton() { //enter animation - binding.decreaseIb.enterAnimationSwing( translation_X, 0f, -20f ) // view + binding.decreaseIb.enterAnimationSwing( translation_X, 0f, -20f , _animationDuration) // view //exit animation - binding.decreaseIb.exitAnimationSwing( translation_X, -20f, 0f ) // view + binding.decreaseIb.exitAnimationSwing( translation_X, -20f, 0f , _animationDuration) // view } fun setIconWidthAndHeight(width: Int, height: Int) { diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt index b3c8f8a..62ae7c3 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/NoValueQuantitizer.kt @@ -23,6 +23,7 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, private val translation = "translationX" private val binding = NoValueQuantitizerBinding.inflate(LayoutInflater.from(context), this, true) + private var _animationDuration = 300L private var _animateButtons = true var buttonAnimationEnabled: Boolean @@ -31,6 +32,12 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, _animateButtons = value } + var animationDuration: Long + get() = _animationDuration + set(value) { + _animationDuration = value + } + init { val a = context.obtainStyledAttributes( attributeSet, R.styleable.Quantitizer, defStyle, 0 @@ -42,7 +49,7 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, animateDec() //listener - listener?.activateOnDecrease() + listener?.activateOnDecrease(_animationDuration) } /*increase*/ @@ -51,7 +58,7 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, animateInc() //listener - listener?.activateOnIncrease() + listener?.activateOnIncrease(_animationDuration) } /*TypedArrays are heavyweight objects that should be recycled immediately @@ -72,13 +79,13 @@ class NoValueQuantitizer @JvmOverloads constructor(context: Context, } private fun animatePlusButton() { - binding.increaseIb.enterAnimationSwing( translation, 0f, 20f) - binding.increaseIb.exitAnimationSwing( translation, 20f, 0f) + binding.increaseIb.enterAnimationSwing( translation, 0f, 20f, _animationDuration) + binding.increaseIb.exitAnimationSwing( translation, 20f, 0f, _animationDuration) } private fun animateMinusButton() { - binding.decreaseIb.enterAnimationSwing( translation, 0f, -20f) - binding.decreaseIb.exitAnimationSwing( translation, -20f, 0f) + binding.decreaseIb.enterAnimationSwing( translation, 0f, -20f, _animationDuration) + binding.decreaseIb.exitAnimationSwing( translation, -20f, 0f, _animationDuration) } fun setIconWidthAndHeight(width: Int, height: Int) { diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt index 6fd83d0..6e5b1fe 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt @@ -30,13 +30,15 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, private var currentValue: Int = 0 + private var _animationDuration = 300L private var _minValue:Int = 0 private var _maxValue:Int? = null private var _animateButtons = true + private var _animationStyle = AnimationStyle.SWING var minValue: Int get() = _minValue - set(value) { + set(value,) { _minValue = value } @@ -59,6 +61,18 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, _animateButtons = value } + var textAnimationStyle: AnimationStyle + get() = _animationStyle + set(value) { + _animationStyle = value + } + + var animationDuration: Long + get() = _animationDuration + set(value) { + _animationDuration = value + } + init { // Load attributes val a = context.obtainStyledAttributes( @@ -88,7 +102,7 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, doDec() //listener - listener?.activateOnDecrease() + listener?.activateOnDecrease(_animationDuration) } /*increase*/ @@ -97,7 +111,7 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, doInc() //listener - listener?.activateOnIncrease() + listener?.activateOnIncrease(_animationDuration) } /*make edit text cursor visible when clicked*/ @@ -137,7 +151,8 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, private fun doInc() { if (currentValue >= maxValue!!) { - wobble(binding.quantityTv) + //do nothing +// wobble(binding.quantityTv) } else { binding.quantityTv.isCursorVisible = false val increasedValue: Int = currentValue.inc() @@ -148,7 +163,8 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, private fun doDec() { if (currentValue <= minValue) { - wobble(binding.quantityTv) + //do nothing +// wobble(binding.quantityTv) } else { binding.quantityTv.isCursorVisible = false val decreasedValue: Int = currentValue.dec() @@ -162,9 +178,23 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, animatePlusButton() } - //set current value to edit text - binding.quantityTv.textAnimSwing( translation_Y, -150f, 0f, currentValue.toString()) // text + //animate and set current value for edit text + when (_animationStyle) { + AnimationStyle.SLIDE_IN_REVERSE -> { + binding.quantityTv.textAnimSlideInRTL( translation_Y, -150f, 0f, currentValue.toString(), _animationDuration) // text + } + AnimationStyle.SLIDE_IN -> { + binding.quantityTv.textAnimSlideInLTR( translation_Y, 150f, 0f, currentValue.toString(), _animationDuration) // text + + } + AnimationStyle.FALL_IN -> { + binding.quantityTv.textAnimFallIn( translation_X, -60f, 0f, currentValue.toString(), _animationDuration) // text + } + else -> { + binding.quantityTv.textAnimSwing( translation_Y, -150f, 0f, currentValue.toString(), _animationDuration) // text + } + } } private fun animateDec() { @@ -172,24 +202,40 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, animateMinusButton() } - //set current value to edit text - binding.quantityTv.textAnimSwing( translation_Y, 150f, 0f, currentValue.toString() ) // text + //animate and set current value for edit text + when (_animationStyle) { + AnimationStyle.SLIDE_IN_REVERSE -> { + binding.quantityTv.textAnimSlideInRTL( translation_Y, 150f, 0f, currentValue.toString(), _animationDuration ) // text + + } + AnimationStyle.SLIDE_IN -> { + binding.quantityTv.textAnimSlideInLTR( translation_Y, -150f, 0f, currentValue.toString() , _animationDuration) // text + + } + AnimationStyle.FALL_IN -> { + binding.quantityTv.textAnimFallIn( translation_X, 60f, 0f, currentValue.toString() , _animationDuration) // text + + } + else -> { + binding.quantityTv.textAnimSwing( translation_Y, 150f, 0f, currentValue.toString() , _animationDuration) // text + } + } } private fun animatePlusButton() { //enter animation - binding.increaseIb.enterAnimationSwing( translation_Y, 0f, -20f ) // view + binding.increaseIb.enterAnimationSwing( translation_Y, 0f, -20f , _animationDuration) // view //exit animation - binding.increaseIb.exitAnimationSwing( translation_Y, -20f, 0f ) // view + binding.increaseIb.exitAnimationSwing( translation_Y, -20f, 0f , _animationDuration) // view } private fun animateMinusButton() { //enter animation - binding.decreaseIb.enterAnimationSwing( translation_Y, 0f, 20f ) // view + binding.decreaseIb.enterAnimationSwing( translation_Y, 0f, 20f , _animationDuration) // view //exit animation - binding.decreaseIb.exitAnimationSwing( translation_Y, 20f, 0f ) // view + binding.decreaseIb.exitAnimationSwing( translation_Y, 20f, 0f , _animationDuration) // view } fun setIconWidthAndHeight(width: Int, height: Int) { @@ -311,9 +357,4 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, fun setQuantitizerListener(listener : QuantitizerListener) { this.listener = listener } - -// companion object { -// private const val DURATION = 300L -// } - } \ No newline at end of file diff --git a/QuantitizerLibrary/src/main/res/layout/vertical_quantitizer.xml b/QuantitizerLibrary/src/main/res/layout/vertical_quantitizer.xml index b06f966..24dd2e6 100644 --- a/QuantitizerLibrary/src/main/res/layout/vertical_quantitizer.xml +++ b/QuantitizerLibrary/src/main/res/layout/vertical_quantitizer.xml @@ -22,7 +22,7 @@ Date: Fri, 10 Sep 2021 11:02:49 +0000 Subject: [PATCH 3/5] Fixes horizontal quant unseen mistake. Update README.md --- .../HorizontalQuantitizer.kt | 21 ++++++------ README.md | 32 ++++++++++++++++++- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt index 9979162..46fef95 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt @@ -147,6 +147,11 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } private fun doInc() { + if (_animateButtons) { + animatePlusButton() + } + + if (currentValue >= maxValue!!) { //Do nothing // wobble(binding.quantityTv) @@ -159,6 +164,10 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } private fun doDec() { + if (_animateButtons) { + animateMinusButton() + } + if (currentValue <= minValue) { //Do nothing // wobble(binding.quantityTv) @@ -171,10 +180,6 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } private fun animateInc() { - if (_animateButtons) { - animatePlusButton() - } - //animate and set current value for edit text when (_animationStyle) { AnimationStyle.SLIDE_IN_REVERSE -> { @@ -206,7 +211,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } else -> { binding.quantityTv.textAnimSwing( - translation_Y, + translation_X, 200f, 0f, currentValue.toString(), @@ -218,10 +223,6 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } private fun animateDec() { - if (_animateButtons) { - animateMinusButton() - } - //animate and set current value for edit text when (_animationStyle) { AnimationStyle.SLIDE_IN_REVERSE -> { @@ -253,7 +254,7 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } else -> { binding.quantityTv.textAnimSwing( - translation_Y, + translation_X, -200f, 0f, currentValue.toString(), diff --git a/README.md b/README.md index 7f2cdc0..83bcc5b 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Sample implementation [here](app/) var hQ: HorizontalQuantitizer = findViewById(R.id.h_q) var selectedValue = hQ.value //get current value ``` + #### Listener ```kotlin hQ.setQuantitizerListener(object: QuantitizerListener{ @@ -104,9 +105,38 @@ Sample implementation [here](app/) ``` ### Customize Quantitizer +#### Change text/value animation style +```kotlin + hQ.textAnimationStyle = AnimationStyle.SLIDE_IN +``` + + +#### List of current animations + +| ANIMATION | DEMO | +| ------------------ | ------------------------------------------------------------ | +| `FALL_IN` | demo | +| `SLIDE_IN` | demo | +| `SLIDE_IN_REVERSE` | demo | +| `SWING` | demo | + + + #### Disable button animations + +demo + +demo + + + +```kotlin + hQ.buttonAnimationEnabled = false //Default true +``` + +#### Change animation duration ```kotlin - hQ.buttonAnimationEnabled = false + hQ.animationDuration = 400L //Default 300L ``` #### Change icons From 433da9f97f4451ae137d499c642c32d49ea51f96 Mon Sep 17 00:00:00 2001 From: Kojo Fosu Bempa Edue Date: Fri, 10 Sep 2021 11:05:48 +0000 Subject: [PATCH 4/5] Update README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83bcc5b..3179508 100644 --- a/README.md +++ b/README.md @@ -124,15 +124,12 @@ Sample implementation [here](app/) #### Disable button animations -demo - -demo - - ```kotlin hQ.buttonAnimationEnabled = false //Default true ``` +demo demo + #### Change animation duration ```kotlin From a978a6cb547fdae7945e400fbc982264775dc961 Mon Sep 17 00:00:00 2001 From: Kojo Fosu Bempa Edue Date: Sun, 24 Oct 2021 15:50:04 +0000 Subject: [PATCH 5/5] Fixes #6 --- .../HorizontalQuantitizer.kt | 76 +++++++++++------- .../quantitizerlibrary/VerticalQuantitizer.kt | 79 ++++++++++++------- .../mcdev/quantitizer/ButtonsOnlyActivity.kt | 6 +- 3 files changed, 104 insertions(+), 57 deletions(-) diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt index 46fef95..1ff2cc5 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/HorizontalQuantitizer.kt @@ -12,6 +12,7 @@ import android.view.LayoutInflater import android.view.View import android.view.animation.Animation import android.view.animation.TranslateAnimation +import android.widget.Toast import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.DrawableRes @@ -32,17 +33,25 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, private var _animationDuration = 300L private var _minValue:Int = 0 - private var _maxValue:Int? = null + private var _maxValue:Int = Int.MAX_VALUE private var _animateButtons: Boolean = true private var _animationStyle: AnimationStyle = AnimationStyle.SWING var minValue: Int get() = _minValue set(value) { - _minValue = value + if (value >= currentValue) { + binding.quantityTv.text = + Editable.Factory.getInstance().newEditable(value.toString()) + currentValue = value + _minValue = value + } else { + _minValue = value + currentValue = value + } } - var maxValue: Int? + var maxValue: Int get() = _maxValue set(value) { _maxValue = value @@ -93,19 +102,28 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, /*decrease*/ binding.decreaseIb.setOnClickListener { hideKeyboard() - doDec() + if (minValue >= currentValue) { + //do nothing + } else { + doDec() - //listener - listener?.activateOnDecrease(_animationDuration) + //listener + listener?.activateOnDecrease(_animationDuration) + } } /*increase*/ binding.increaseIb.setOnClickListener { hideKeyboard() - doInc() + if (maxValue <= currentValue) { + //do nothing + } else { + doInc() + + //listener + listener?.activateOnIncrease(_animationDuration) + } - //listener - listener?.activateOnIncrease(_animationDuration) } /*make edit text cursor visible when clicked*/ @@ -127,7 +145,18 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, } override fun afterTextChanged(s: Editable?) { - //TODO("Not yet implemented") + if (s.toString().isEmpty()) { + //do nothing + }else if (Integer.parseInt(s.toString()) < minValue) { + binding.quantityTv.text = Editable.Factory.getInstance().newEditable(minValue.toString()) + currentValue = minValue + Toast.makeText(context, "Min value is $minValue", Toast.LENGTH_SHORT).show() + }else if (Integer.parseInt(s.toString()) > maxValue) { + binding.quantityTv.text = Editable.Factory.getInstance().newEditable(minValue.toString()) + currentValue = minValue + Toast.makeText(context, "Max value is $maxValue", Toast.LENGTH_SHORT).show() + + } } }) @@ -151,16 +180,11 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, animatePlusButton() } + binding.quantityTv.isCursorVisible = false // hide cursor if it's visible + val increasedValue: Int = currentValue.inc() + currentValue = increasedValue + animateInc() - if (currentValue >= maxValue!!) { - //Do nothing -// wobble(binding.quantityTv) - } else { - binding.quantityTv.isCursorVisible = false // hide cursor if it's visible - val increasedValue: Int = currentValue.inc() - currentValue = increasedValue - animateInc() - } } private fun doDec() { @@ -168,15 +192,11 @@ class HorizontalQuantitizer @JvmOverloads constructor(context: Context, animateMinusButton() } - if (currentValue <= minValue) { - //Do nothing -// wobble(binding.quantityTv) - } else { - binding.quantityTv.isCursorVisible = false // hide cursor if it's visible - val decreasedValue: Int = currentValue.dec() - currentValue = decreasedValue - animateDec() - } + binding.quantityTv.isCursorVisible = false // hide cursor if it's visible + val decreasedValue: Int = currentValue.dec() + currentValue = decreasedValue + animateDec() + } private fun animateInc() { diff --git a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt index 6e5b1fe..0ab89e1 100644 --- a/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt +++ b/QuantitizerLibrary/src/main/java/com/mcdev/quantitizerlibrary/VerticalQuantitizer.kt @@ -12,6 +12,7 @@ import android.view.LayoutInflater import android.view.View import android.view.animation.Animation import android.view.animation.TranslateAnimation +import android.widget.Toast import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.DrawableRes @@ -32,17 +33,25 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, private var _animationDuration = 300L private var _minValue:Int = 0 - private var _maxValue:Int? = null + private var _maxValue:Int = Int.MAX_VALUE private var _animateButtons = true private var _animationStyle = AnimationStyle.SWING var minValue: Int get() = _minValue set(value,) { - _minValue = value + if (value >= currentValue) { + binding.quantityTv.text = + Editable.Factory.getInstance().newEditable(value.toString()) + currentValue = value + _minValue = value + } else { + _minValue = value + currentValue = value + } } - var maxValue: Int? + var maxValue: Int get() = _maxValue set(value) { _maxValue = value @@ -99,19 +108,28 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, /*decrease*/ binding.decreaseIb.setOnClickListener { hideKeyboard() - doDec() - //listener - listener?.activateOnDecrease(_animationDuration) + if (minValue >= currentValue) { + //do nothing + } else { + doDec() + + //listener + listener?.activateOnDecrease(_animationDuration) + } } /*increase*/ binding.increaseIb.setOnClickListener { hideKeyboard() - doInc() + if (maxValue <= currentValue) { + //do nothing + } else { + doInc() - //listener - listener?.activateOnIncrease(_animationDuration) + //listener + listener?.activateOnIncrease(_animationDuration) + } } /*make edit text cursor visible when clicked*/ @@ -133,7 +151,18 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, } override fun afterTextChanged(s: Editable?) { - //TODO("Not yet implemented") + if (s.toString().isEmpty()) { + //do nothing + }else if (Integer.parseInt(s.toString()) < minValue) { + binding.quantityTv.text = Editable.Factory.getInstance().newEditable(minValue.toString()) + currentValue = minValue + Toast.makeText(context, "Min value is $minValue", Toast.LENGTH_SHORT).show() + }else if (Integer.parseInt(s.toString()) > maxValue) { + binding.quantityTv.text = Editable.Factory.getInstance().newEditable(minValue.toString()) + currentValue = minValue + Toast.makeText(context, "Max value is $maxValue", Toast.LENGTH_SHORT).show() + + } } }) @@ -150,27 +179,21 @@ class VerticalQuantitizer @JvmOverloads constructor(context: Context, } private fun doInc() { - if (currentValue >= maxValue!!) { - //do nothing -// wobble(binding.quantityTv) - } else { - binding.quantityTv.isCursorVisible = false - val increasedValue: Int = currentValue.inc() - currentValue = increasedValue - animateInc() - } + + binding.quantityTv.isCursorVisible = false + val increasedValue: Int = currentValue.inc() + currentValue = increasedValue + animateInc() + } private fun doDec() { - if (currentValue <= minValue) { - //do nothing -// wobble(binding.quantityTv) - } else { - binding.quantityTv.isCursorVisible = false - val decreasedValue: Int = currentValue.dec() - currentValue = decreasedValue - animateDec() - } + + binding.quantityTv.isCursorVisible = false + val decreasedValue: Int = currentValue.dec() + currentValue = decreasedValue + animateDec() + } private fun animateInc() { diff --git a/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt b/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt index 839efe8..dd0ebf6 100644 --- a/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt +++ b/app/src/main/java/com/mcdev/quantitizer/ButtonsOnlyActivity.kt @@ -17,10 +17,12 @@ class ButtonsOnlyActivity : AppCompatActivity() { val nvq = findViewById(R.id.nv_quant) hq.apply { - value = 1 +// value = 1 buttonAnimationEnabled = false textAnimationStyle = AnimationStyle.SLIDE_IN animationDuration = 400L + minValue = 3 + maxValue = 7 // setPlusIconBackgroundColor("#C19A6B") // setMinusIconBackgroundColor("#C19A6B") // setMinusIconColor("#ffffff") @@ -33,6 +35,8 @@ class ButtonsOnlyActivity : AppCompatActivity() { value = 1 buttonAnimationEnabled = false textAnimationStyle = AnimationStyle.FALL_IN + minValue = 5 + maxValue = 8 // setPlusIconBackgroundColor("#C19A6B") // setMinusIconBackgroundColor("#C19A6B") // setMinusIconColor("#ffffff")