Skip to content

Commit

Permalink
Adopt Ferris Wheel animation colors to different themes
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Sep 26, 2024
1 parent 9c3ae47 commit 4b1a8b4
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.piepmeyer.gauguin.ui.main

import android.content.res.Configuration
import android.graphics.Color
import com.google.android.material.color.MaterialColors
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.piepmeyer.gauguin.R
import org.piepmeyer.gauguin.Theme
import org.piepmeyer.gauguin.preferences.ApplicationPreferences
import ru.github.igla.ferriswheel.CabinStyle
import ru.github.igla.ferriswheel.CoreStyle
import ru.github.igla.ferriswheel.FerrisWheelView
import ru.github.igla.ferriswheel.StarIcon

class FerrisWheelConfigurer(
private val ferrisWheel: FerrisWheelView,
) : KoinComponent {
private val applicationPreferences: ApplicationPreferences by inject()

fun configure() {
ferrisWheel.baseColor =
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorOnSurfaceVariant)
ferrisWheel.wheelColor =
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorOnSurfaceVariant)
ferrisWheel.outlineAmbientShadowColor = Color.WHITE
ferrisWheel.coreStyle =
CoreStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorSecondary),
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorOnSecondary),
StarIcon(MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorSurfaceVariant)),
)
ferrisWheel.cabinColors =
when (applicationPreferences.theme) {
Theme.DARK -> cabinColorsDark()
Theme.LIGHT -> cabinColorsLight()
Theme.DYNAMIC_COLORS -> cabinColorsDynamic()
Theme.SYSTEM_DEFAULT -> {
when (isNightMode()) {
true -> cabinColorsDark()
false -> cabinColorsLight()
}
}
}

ferrisWheel.numberOfCabins = 9
}

private fun isNightMode(): Boolean {
val mode =
ferrisWheel.context
?.resources
?.configuration
?.uiMode ?: return false

return (mode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
}

private fun cabinColorsDark(): List<CabinStyle> =
listOf(
CabinStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorPrimaryVariant),
Color.TRANSPARENT,
),
CabinStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorSecondaryVariant),
Color.TRANSPARENT,
),
CabinStyle(
ferrisWheel.resources.getColor(R.color.gridSelected, null),
Color.TRANSPARENT,
),
)

private fun cabinColorsLight(): List<CabinStyle> =
listOf(
CabinStyle(
ferrisWheel.resources.getColor(R.color.md_theme_light_inversePrimary, null),
Color.TRANSPARENT,
),
CabinStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorSecondaryVariant),
Color.TRANSPARENT,
),
CabinStyle(
MaterialColors.getColor(ferrisWheel, R.attr.colorMainTopPanelBackground),
Color.TRANSPARENT,
),
)

private fun cabinColorsDynamic(): List<CabinStyle> =
listOf(
CabinStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorPrimaryVariant),
Color.TRANSPARENT,
),
CabinStyle(
MaterialColors.getColor(ferrisWheel, com.google.android.material.R.attr.colorSecondaryVariant),
Color.TRANSPARENT,
),
CabinStyle(
MaterialColors.getColor(ferrisWheel, R.attr.colorMainTopPanelBackground),
Color.TRANSPARENT,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class MainActivity :
calculationService.addListener(createGridCalculationListener())
configureActivity()

FerrisWheelConfigurer(binding.ferrisWheelView).configure()

val specialListener =
OnSharedPreferenceChangeListener { _: SharedPreferences, key: String? ->
if (key == "theme" || key == "maximumCellSize") {
Expand Down
18 changes: 11 additions & 7 deletions gauguin-app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
android:layout_height="match_parent"
android:elevation="20dp" />

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:visibility="invisible" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -46,6 +39,17 @@
app:layout_constraintTop_toTopOf="parent"
/>

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@id/gridview"
app:layout_constraintEnd_toEndOf="@id/gridview"
app:layout_constraintTop_toTopOf="@id/gridview"
app:layout_constraintBottom_toBottomOf="@id/gridview"
android:layout_margin="16dp"
android:visibility="invisible" />

<FrameLayout
android:id="@+id/gameTopFrame"
android:layout_width="0dp"
Expand Down
17 changes: 10 additions & 7 deletions gauguin-app/src/main/res/layout-sw600dp-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
android:layout_height="match_parent"
android:elevation="20dp" />

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:visibility="invisible" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -58,6 +51,16 @@
app:layout_constraintEnd_toStartOf="@id/keypadFrame"
app:layout_constraintTop_toBottomOf="@id/gameTopFrame" />

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="500dp"
android:layout_height="500dp"
app:layout_constraintTop_toTopOf="@id/gridview"
app:layout_constraintBottom_toBottomOf="@id/gridview"
app:layout_constraintStart_toStartOf="@id/gridview"
app:layout_constraintEnd_toEndOf="@id/gridview"
android:visibility="invisible"/>

<ImageView
android:id="@+id/pendingNextGridCalculation"
android:layout_width="wrap_content"
Expand Down
21 changes: 10 additions & 11 deletions gauguin-app/src/main/res/layout-sw600dp/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
app:layout_constraintEnd_toEndOf="parent"
/>

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="500dp"
android:layout_height="500dp"
app:layout_constraintTop_toTopOf="@id/gridview"
app:layout_constraintBottom_toBottomOf="@id/gridview"
app:layout_constraintStart_toStartOf="@id/gridview"
app:layout_constraintEnd_toEndOf="@id/gridview"
android:visibility="invisible"/>

<ImageView
android:id="@+id/pendingNextGridCalculation"
android:layout_width="20dp"
Expand Down Expand Up @@ -103,17 +113,6 @@
app:layout_constraintEnd_toEndOf="@id/keypadFrame"
/>

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintTop_toBottomOf="@+id/gameTopFrame"
app:layout_constraintBottom_toTopOf="@id/keypadFrame"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:visibility="invisible"/>

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.bottomappbar.BottomAppBar
Expand Down
20 changes: 10 additions & 10 deletions gauguin-app/src/main/res/layout-sw840dp-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
app:layout_constraintEnd_toStartOf="@id/keypadFrame"
app:layout_constraintTop_toBottomOf="@id/gameTopFrame" />

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="500dp"
android:layout_height="500dp"
app:layout_constraintTop_toTopOf="@id/gridview"
app:layout_constraintBottom_toBottomOf="@id/gridview"
app:layout_constraintStart_toStartOf="@id/gridview"
app:layout_constraintEnd_toEndOf="@id/gridview"
android:visibility="invisible"/>

<ImageView
android:id="@+id/pendingNextGridCalculation"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -102,16 +112,6 @@
app:layout_constraintTop_toBottomOf="@id/gameTopFrame"
app:layout_constraintBottom_toBottomOf="parent"/>

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/gameTopFrame"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:visibility="invisible"/>

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.bottomappbar.BottomAppBar
Expand Down
21 changes: 10 additions & 11 deletions gauguin-app/src/main/res/layout-sw840dp/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
app:layout_constraintEnd_toStartOf="@id/keypadFrame"
app:layout_constraintTop_toBottomOf="@id/gameTopFrame" />

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="500dp"
android:layout_height="500dp"
app:layout_constraintTop_toTopOf="@id/gridview"
app:layout_constraintBottom_toBottomOf="@id/gridview"
app:layout_constraintStart_toStartOf="@id/gridview"
app:layout_constraintEnd_toEndOf="@id/gridview"
android:visibility="invisible"/>

<FrameLayout
android:id="@+id/keypadFrame"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -85,17 +95,6 @@
app:layout_constraintBottom_toBottomOf="parent"
/>

<ru.github.igla.ferriswheel.FerrisWheelView
android:id="@+id/ferrisWheelView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintTop_toBottomOf="@+id/gameTopFrame"
app:layout_constraintBottom_toTopOf="@id/keypadFrame"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:visibility="invisible"/>

<ImageView
android:id="@+id/pendingNextGridCalculation"
android:layout_width="wrap_content"
Expand Down

0 comments on commit 4b1a8b4

Please sign in to comment.