Skip to content

Commit

Permalink
braille-systems#278 make gradient flash
Browse files Browse the repository at this point in the history
  • Loading branch information
zuevval committed Oct 17, 2020
1 parent 86fab49 commit 114e439
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.braillesystems.learnbraille.ui.screens.practice

import android.graphics.drawable.TransitionDrawable
import android.os.Bundle
import android.os.Vibrator
import android.view.*
Expand All @@ -17,8 +18,6 @@ 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.utils.announceCorrect
import com.github.braillesystems.learnbraille.utils.announceIncorrect
import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainer
import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainerSignalHandler
import com.github.braillesystems.learnbraille.ui.inputPrint
Expand Down Expand Up @@ -120,9 +119,10 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) {
block = { title = title(viewModel) },
softBlock = {
announceCorrect()
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)
binding.constraintLayout.background = context?.let { ContextCompat.getDrawable(it, R.drawable.background_animation_green) }
val transition = binding.constraintLayout.background as TransitionDrawable
transition.startTransition(500)
transition.reverseTransition(500)
}
)

Expand All @@ -134,9 +134,10 @@ 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.colorBackground) }
val colorTo = context?.let { ContextCompat.getColor(it, R.color.lightRed) }
animateView(binding.constraintLayout, colorFrom, colorTo)
binding.constraintLayout.background = context?.let { ContextCompat.getDrawable(it, R.drawable.background_animation_red) }
val transition = binding.constraintLayout.background as TransitionDrawable
transition.startTransition(500)
transition.reverseTransition(500)
}

viewModel.observeEventHint(
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/background_animation_green.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_blank" />
<item android:drawable="@drawable/background_gradient_green" />
</transition>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/background_animation_red.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_blank" />
<item android:drawable="@drawable/background_gradient_red" />
</transition>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/background_blank.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorBackground" />
</shape>
</item>
</selector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/background_gradient_green.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="@color/colorBackground"
android:endColor="@color/lightGreen"
android:angle="90"/>
</shape>
</item>
</selector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/background_gradient_red.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="@color/colorBackground"
android:centerColor="@color/colorBackground"
android:endColor="@color/lightRed"
android:angle="90"/>
</shape>
</item>
</selector>
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_animation_red"
tools:context=".ui.screens.practice.CardFragment">

<TextView
Expand Down

0 comments on commit 114e439

Please sign in to comment.