Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize image resources #18

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
Expand Down Expand Up @@ -48,10 +50,12 @@ fun BrandHeader(
val backgroundLayers = backgroundLayers.map {
val backgroundLayer = it.toCanvasLayer(resources)
val transition = if (animated) {
rememberInfiniteTransition().animateFloat(
initialValue = 0F, targetValue = 360F, animationSpec = infiniteRepeatable(
rememberInfiniteTransition(label = "background").animateFloat(
initialValue = 0F, targetValue = 360F,
animationSpec = infiniteRepeatable(
animation = tween(it.duration, easing = LinearEasing)
)
),
label = ""
)
} else null

Expand All @@ -62,19 +66,23 @@ fun BrandHeader(

val truckLayer = truckFrames.map { it.toCanvasLayer(resources) }
val truckTransition = if (animated) {
rememberInfiniteTransition().animateFloat(
initialValue = 1F, targetValue = 12F, animationSpec = infiniteRepeatable(
rememberInfiniteTransition(label = "truck").animateFloat(
initialValue = 1F, targetValue = 12F,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing)
)
),
label = ""
)
} else null

val foregroundLayer = foreground.toCanvasLayer(resources)
val foregroundTransition = if (animated) {
rememberInfiniteTransition().animateFloat(
initialValue = 0F, targetValue = 360F, animationSpec = infiniteRepeatable(
rememberInfiniteTransition(label = "foreground").animateFloat(
initialValue = 0F,
targetValue = 360F,
animationSpec = infiniteRepeatable(
animation = tween(foreground.duration, easing = LinearEasing)
)
), label = ""
)
} else null

Expand All @@ -84,17 +92,21 @@ fun BrandHeader(
.clipToBounds()
.height(160.dp * headerSize.value)
) {
Canvas(
modifier = Modifier.fillMaxSize()
) {
drawRect(
brush = Brush.radialGradient(
colors = skyGradient, center = Offset(
x = size.center.x * 0.5F, y = 400F * scale
), radius = 600F
)
)
}
Spacer(
Modifier
.fillMaxSize()
.drawWithCache {
onDrawBehind {
drawRect(
brush = Brush.radialGradient(
colors = skyGradient, center = Offset(
x = size.center.x * 0.5F, y = 400F * scale
), radius = 600F
)
)
}
}
)

val canvasSize = (-160).dp * headerSize.value
Canvas(
Expand All @@ -107,10 +119,10 @@ fun BrandHeader(
}
) {
val centerX = size.width * 0.5F
val yOffsetBackground = if (density < 3.0F) 420.dp.toPx() else 460.dp.toPx()
val yOffsetBackground = if (density < 3.0F) 365.dp.toPx() else 360.dp.toPx()
val yOffsetRoad = if (density < 3.0F) 280.dp.toPx() else 295.dp.toPx()
val yOffsetTruck = if (density < 3.0F) 265.dp.toPx() else 275.dp.toPx()
val yOffsetForeground = if (density < 3.0F) 440.dp.toPx() else 480.dp.toPx()
val yOffsetForeground = if (density < 3.0F) 385.dp.toPx() else 375.dp.toPx()

// draw background
backgroundLayers.map { (layer, rotation) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun TruckView(
.verticalScroll(rememberScrollState())
) {
Box {
BrandHeader(animated = false)
BrandHeader(animated = true)
NavigationHeader(
previousViewTitle = previousViewTitle,
currentViewTitle = currentViewTitle,
Expand Down
Binary file modified app/src/main/res/drawable-hdpi/balloons_and_ships.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/big_clouds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/box_bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/box_inside.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/box_lid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/box_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/food_truck_frame_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/food_truck_frame_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/food_truck_frame_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/food_truck_frame_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/medium_clouds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/mountains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/ocean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/road.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/small_clouds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_sprinkles_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_straight_green_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_blue_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_green_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_orange_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_pink_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_white_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/topping_zigzag_yellow_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/tree_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.