From 757eda43155fd13f6b8c02a6eaf189029273973b Mon Sep 17 00:00:00 2001 From: zuevval Date: Sat, 3 Oct 2020 17:39:53 +0300 Subject: [PATCH] #278 change button animation to background animation --- .../learnbraille/ui/Messages.kt | 5 +++ .../ui/screens/browser/SymbolViewFragment.kt | 8 +++- .../ui/screens/practice/CardFragment.kt | 24 +++++------- .../theory/steps/AbstractStepFragment.kt | 1 - .../steps/input/AbstractInputStepFragment.kt | 39 +++---------------- .../theory/steps/input/InputSymbolFragment.kt | 6 +-- .../learnbraille/ui/views/BrailleDotsView.kt | 14 ------- .../learnbraille/utils/Utils.kt | 12 ++++++ app/src/main/res/drawable/left_border.xml | 18 --------- app/src/main/res/drawable/right_border.xml | 18 --------- app/src/main/res/layout/braille_dots_view.xml | 3 +- app/src/main/res/values/colors.xml | 4 +- 12 files changed, 44 insertions(+), 108 deletions(-) delete mode 100644 app/src/main/res/drawable/left_border.xml delete mode 100644 app/src/main/res/drawable/right_border.xml diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt index 16d27b34..c1da70e0 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt @@ -11,6 +11,11 @@ import com.github.braillesystems.learnbraille.res.showSymbolPrintRules import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode import com.github.braillesystems.learnbraille.utils.* +fun Fragment.showCorrectToast() = toast(getString(R.string.input_correct)) + +fun Fragment.showIncorrectToast(hint: String = "") = + toast("${getString(R.string.input_incorrect)} $hint") + fun Fragment.announceCorrect() = announce(getString(R.string.input_correct)) fun Fragment.announceIncorrect(hint: String = "") = diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt index dd29e978..3ddec4c4 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt @@ -1,5 +1,7 @@ package com.github.braillesystems.learnbraille.ui.screens.browser +import android.animation.ObjectAnimator +import android.animation.TypeEvaluator import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup @@ -10,7 +12,6 @@ import com.github.braillesystems.learnbraille.data.entities.Material import com.github.braillesystems.learnbraille.data.entities.Symbol import com.github.braillesystems.learnbraille.databinding.FragmentSymbolViewBinding import com.github.braillesystems.learnbraille.res.captionRules -import com.github.braillesystems.learnbraille.ui.dotsMode import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo import com.github.braillesystems.learnbraille.ui.screens.FragmentBinding @@ -18,7 +19,10 @@ import com.github.braillesystems.learnbraille.ui.showPrint import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode import com.github.braillesystems.learnbraille.ui.views.display import com.github.braillesystems.learnbraille.ui.views.dotsState -import com.github.braillesystems.learnbraille.utils.* +import com.github.braillesystems.learnbraille.utils.checkedAnnounce +import com.github.braillesystems.learnbraille.utils.getFragmentStringArg +import com.github.braillesystems.learnbraille.utils.getValue +import com.github.braillesystems.learnbraille.utils.parse class SymbolViewFragment : AbstractFragmentWithHelp(R.string.browser_symbol_view_help) { diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt index e5945f0a..632fb72f 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt @@ -7,6 +7,7 @@ import android.os.Vibrator import android.view.* import android.widget.Button import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import androidx.databinding.DataBindingUtil @@ -19,13 +20,13 @@ import com.github.braillesystems.learnbraille.databinding.FragmentCardBinding import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.res.deckTagToName import com.github.braillesystems.learnbraille.res.inputMarkerPrintRules +import com.github.braillesystems.learnbraille.ui.announceCorrect +import com.github.braillesystems.learnbraille.ui.announceIncorrect import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainer import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainerSignalHandler import com.github.braillesystems.learnbraille.ui.inputPrint import com.github.braillesystems.learnbraille.ui.screens.* import com.github.braillesystems.learnbraille.ui.showHintToast -import com.github.braillesystems.learnbraille.ui.announceIncorrect -import com.github.braillesystems.learnbraille.ui.announceCorrect import com.github.braillesystems.learnbraille.ui.views.* import com.github.braillesystems.learnbraille.utils.* import com.google.android.material.button.MaterialButton @@ -123,9 +124,9 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) { block = { title = title(viewModel) }, softBlock = { announceCorrect() - val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorPrimary) } - val colorTo = context?.let { ContextCompat.getColor(it, R.color.colorGreen) } - animateButton(binding.nextButton, colorFrom, colorTo) + val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorBackground) } + val colorTo = context?.let { ContextCompat.getColor(it, R.color.lightGreen) } + animateView(binding.constraintLayout, colorFrom, colorTo) } ) @@ -137,9 +138,9 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) { ?: checkedToast(getString(R.string.input_loading)) title = title(viewModel) - val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorPrimary) } - val colorTo = context?.let { ContextCompat.getColor(it, R.color.colorRed) } - animateButton(binding.nextButton, colorFrom, colorTo) + val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorBackground) } + val colorTo = context?.let { ContextCompat.getColor(it, R.color.lightRed) } + animateView(binding.constraintLayout, colorFrom, colorTo) } viewModel.observeEventHint( @@ -185,13 +186,6 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) { }.root - private fun animateButton(button: MaterialButton, colorFrom: Int?, colorTo: Int?){ - val duration = 1000 - ObjectAnimator.ofObject(button, "backgroundColor", ArgbEvaluator(), colorFrom, colorTo, colorFrom) - .setDuration(duration.toLong()) - .start() - } - private fun title(viewModel: CardViewModel? = null): String = getString(R.string.practice_actionbar_title_template).run { if (viewModel == null) format(0, 0) diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/AbstractStepFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/AbstractStepFragment.kt index 1d9bc363..20e85375 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/AbstractStepFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/AbstractStepFragment.kt @@ -17,7 +17,6 @@ import com.github.braillesystems.learnbraille.ui.screens.theory.getStepArg import com.github.braillesystems.learnbraille.ui.screens.theory.toCurrentStep import com.github.braillesystems.learnbraille.ui.screens.theory.toNextStep import com.github.braillesystems.learnbraille.ui.screens.theory.toPrevStep -import com.github.braillesystems.learnbraille.utils.checkedAnnounce import com.github.braillesystems.learnbraille.utils.navigate import com.github.braillesystems.learnbraille.utils.title diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt index 6f98cdc3..26049080 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt @@ -1,22 +1,17 @@ package com.github.braillesystems.learnbraille.ui.screens.theory.steps.input -import android.animation.ArgbEvaluator -import android.animation.ObjectAnimator import android.os.Vibrator import android.view.View -import android.widget.Button -import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import androidx.lifecycle.ViewModelProvider -import com.github.braillesystems.learnbraille.R import com.github.braillesystems.learnbraille.data.entities.BaseInput import com.github.braillesystems.learnbraille.data.entities.StepData import com.github.braillesystems.learnbraille.ui.screens.* import com.github.braillesystems.learnbraille.ui.screens.theory.steps.AbstractStepFragment import com.github.braillesystems.learnbraille.ui.screens.theory.toNextStep -import com.github.braillesystems.learnbraille.ui.announceCorrect +import com.github.braillesystems.learnbraille.ui.showCorrectToast import com.github.braillesystems.learnbraille.ui.showHintToast -import com.github.braillesystems.learnbraille.ui.announceIncorrect +import com.github.braillesystems.learnbraille.ui.showIncorrectToast import com.github.braillesystems.learnbraille.ui.views.* import com.github.braillesystems.learnbraille.utils.application import com.github.braillesystems.learnbraille.utils.checkedBuzz @@ -71,12 +66,7 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra viewModel.observeCheckedOnFly( viewLifecycleOwner, { dotsState }, buzzer, block = { toNextStep(step, markThisAsPassed = true) }, - softBlock = { - announceCorrect() - val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorPrimary) } - val colorTo = context?.let { ContextCompat.getColor(it, R.color.colorGreen) } - animateButton(binding.rightButton, colorFrom, colorTo) - } + softBlock = { showCorrectToast() } ) viewModel.observeEventHint( @@ -90,14 +80,11 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra viewLifecycleOwner, { dotsState } ) { fun notify() { - announceIncorrect(data) + toastIncorrect(data) buzzer.checkedBuzz( preferenceRepository.incorrectBuzzPattern, preferenceRepository ) - val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorPrimary) } - val colorTo = context?.let { ContextCompat.getColor(it, R.color.colorRed) } - animateButton(binding.rightButton, colorFrom, colorTo) } if (userTouchedDots) notify() else toNextStep(step, markThisAsPassed = false) { notify() } @@ -114,23 +101,9 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra } } - protected open fun announceIncorrect(data: StepData) { - announceIncorrect() + protected open fun toastIncorrect(data: StepData) { + showIncorrectToast() } protected open fun onPassHint(data: StepData) = Unit - - private fun animateButton(button: Button?, colorFrom: Int?, colorTo: Int?) { - val duration = 1000 - ObjectAnimator.ofObject( - button, - "backgroundColor", - ArgbEvaluator(), - colorFrom, - colorTo, - colorFrom - ) - .setDuration(duration.toLong()) - .start() - } } diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputSymbolFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputSymbolFragment.kt index 34af2d4f..93a5e9ca 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputSymbolFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputSymbolFragment.kt @@ -14,7 +14,7 @@ import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.res.inputSymbolPrintRules import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo import com.github.braillesystems.learnbraille.ui.screens.theory.steps.StepBinding -import com.github.braillesystems.learnbraille.ui.announceIncorrect +import com.github.braillesystems.learnbraille.ui.showIncorrectToast import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode import com.github.braillesystems.learnbraille.utils.checkedAnnounce import com.github.braillesystems.learnbraille.utils.getValue @@ -68,8 +68,8 @@ class InputSymbolFragment : AbstractInputStepFragment(R.string.lessons_help_inpu return material.data.char } - override fun announceIncorrect(data: StepData) { - announceIncorrect(inputSymbolPrintRules.getValue(data.char())) + override fun toastIncorrect(data: StepData) { + showIncorrectToast(inputSymbolPrintRules.getValue(data.char())) } override fun onPassHint(data: StepData) { diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt index d4551ec8..6a8a6a09 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt @@ -94,12 +94,6 @@ class BrailleDotsView : ConstraintLayout, KoinComponent { reflectChecks() } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { - setBackgroundMode(mode) - } else { - Timber.w("Unable to set braille dots background due to low API level") - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { setTraversalMode(mode) } else { @@ -184,14 +178,6 @@ class BrailleDotsView : ConstraintLayout, KoinComponent { next.accessibilityTraversalAfter = prev.id } } - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - private fun setBackgroundMode(mode: BrailleDotsViewMode) { - background = when (mode) { - Writing -> context.getDrawable(R.drawable.right_border) - Reading -> context.getDrawable(R.drawable.left_border) - } - } } val BrailleDotsView.dotsState: BrailleDotsState diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/utils/Utils.kt b/app/src/main/java/com/github/braillesystems/learnbraille/utils/Utils.kt index 2bd2ae90..e401b0ca 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/utils/Utils.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/utils/Utils.kt @@ -1,11 +1,15 @@ package com.github.braillesystems.learnbraille.utils +import android.animation.ArgbEvaluator +import android.animation.ObjectAnimator import android.content.Context import android.os.Vibrator +import android.view.View import android.view.accessibility.AccessibilityEvent import android.widget.Toast import androidx.appcompat.app.ActionBar import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout import androidx.fragment.app.Fragment import com.github.braillesystems.learnbraille.LearnBrailleApplication import com.github.braillesystems.learnbraille.R @@ -88,6 +92,14 @@ fun Fragment.updateTitle(title: String) { this.title = title } +fun animateView(obj: View?, colorFrom: Int?, colorTo: Int?){ + val duration = 1000 + ObjectAnimator + .ofObject(obj, "backgroundColor", ArgbEvaluator(), colorFrom, colorTo, colorFrom) + .setDuration(duration.toLong()) + .start() +} + fun stringify(s: SerializationStrategy, obj: T) = Json.stringify(s, obj) fun parse(d: DeserializationStrategy, s: String) = Json.parse(d, s) diff --git a/app/src/main/res/drawable/left_border.xml b/app/src/main/res/drawable/left_border.xml deleted file mode 100644 index 58fc9043..00000000 --- a/app/src/main/res/drawable/left_border.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/right_border.xml b/app/src/main/res/drawable/right_border.xml deleted file mode 100644 index 80e932f5..00000000 --- a/app/src/main/res/drawable/right_border.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/braille_dots_view.xml b/app/src/main/res/layout/braille_dots_view.xml index b17e598b..599e082f 100644 --- a/app/src/main/res/layout/braille_dots_view.xml +++ b/app/src/main/res/layout/braille_dots_view.xml @@ -4,8 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/constraintLayoutButtons" android:layout_width="wrap_content" - android:layout_height="wrap_content" - tools:background="@drawable/left_border"> + android:layout_height="wrap_content"> - #00de7a - #f70000 + #9ff57a + #ff8282 #263238 #9e3d9a #ffffff