Add splash screen animation

This commit is contained in:
William Brawner 2022-06-25 13:42:38 -05:00
parent a44e48d1e1
commit deff195d1f
7 changed files with 35 additions and 3 deletions

View file

@ -15,7 +15,6 @@
<option value="$PROJECT_DIR$/shared" /> <option value="$PROJECT_DIR$/shared" />
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View file

@ -36,6 +36,7 @@
<entry key="app/src/main/res/drawable-v26/ic_shortcut_pause.xml" value="0.27447916666666666" /> <entry key="app/src/main/res/drawable-v26/ic_shortcut_pause.xml" value="0.27447916666666666" />
<entry key="app/src/main/res/drawable/background_splash.xml" value="0.409375" /> <entry key="app/src/main/res/drawable/background_splash.xml" value="0.409375" />
<entry key="app/src/main/res/drawable/horizontal_rule.xml" value="0.1" /> <entry key="app/src/main/res/drawable/horizontal_rule.xml" value="0.1" />
<entry key="app/src/main/res/drawable/ic_app_logo.xml" value="0.1065" />
<entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.27447916666666666" /> <entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.27447916666666666" />
<entry key="app/src/main/res/drawable/ic_pause.xml" value="0.409375" /> <entry key="app/src/main/res/drawable/ic_pause.xml" value="0.409375" />
<entry key="app/src/main/res/drawable/ic_play.xml" value="0.27447916666666666" /> <entry key="app/src/main/res/drawable/ic_play.xml" value="0.27447916666666666" />

View file

@ -1,6 +1,6 @@
import java.util.Properties
import java.io.FileInputStream import java.io.FileInputStream
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.util.*
plugins { plugins {
id("com.android.application") id("com.android.application")
@ -75,6 +75,7 @@ dependencies {
kapt(libs.hilt.android.kapt) kapt(libs.hilt.android.kapt)
implementation(libs.androidx.core) implementation(libs.androidx.core)
implementation(libs.androidx.appcompat) implementation(libs.androidx.appcompat)
implementation(libs.androidx.splash)
implementation(libs.material) implementation(libs.material)
implementation("androidx.constraintlayout:constraintlayout:2.0.4") implementation("androidx.constraintlayout:constraintlayout:2.0.4")
implementation("androidx.legacy:legacy-support-v4:1.0.0") implementation("androidx.legacy:legacy-support-v4:1.0.0")

View file

@ -13,7 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/Theme.App.Starting">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize"

View file

@ -1,9 +1,11 @@
package com.wbrawner.pihelper package com.wbrawner.pihelper
import android.animation.ObjectAnimator
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.WindowInsetsController import android.view.WindowInsetsController
import android.view.animation.AnticipateInterpolator
import android.widget.Toast import android.widget.Toast
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -22,7 +24,9 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.core.animation.doOnEnd
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
@ -41,6 +45,7 @@ class MainActivity : AppCompatActivity() {
lateinit var store: Store lateinit var store: Store
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
val isDarkTheme = isSystemInDarkTheme() val isDarkTheme = isSystemInDarkTheme()
@ -117,6 +122,23 @@ class MainActivity : AppCompatActivity() {
} }
} }
} }
splashScreen.setOnExitAnimationListener { splashScreenView ->
listOf(View.SCALE_X, View.SCALE_Y).forEach { axis ->
ObjectAnimator.ofFloat(
splashScreenView,
axis,
1f,
0.45f
).apply {
interpolator = AnticipateInterpolator()
duration = 200L
doOnEnd {
splashScreenView.remove()
}
start()
}
}
}
} }
override fun onBackPressed() { override fun onBackPressed() {

View file

@ -10,4 +10,11 @@
<style name="AppTheme" parent="BaseTheme"> <style name="AppTheme" parent="BaseTheme">
<item name="android:windowLightStatusBar">true</item> <item name="android:windowLightStatusBar">true</item>
</style> </style>
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/colorSurface</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
</resources> </resources>

View file

@ -1,6 +1,7 @@
[versions] [versions]
androidx-core = "1.3.2" androidx-core = "1.3.2"
androidx-appcompat = "1.2.0" androidx-appcompat = "1.2.0"
androidx-splash = "1.0.0-beta02"
compose = "1.1.1" compose = "1.1.1"
coroutines = "1.4.3" coroutines = "1.4.3"
espresso = "3.3.0" espresso = "3.3.0"
@ -24,6 +25,7 @@ versionName = "1.0"
android-gradle = { module = "com.android.tools.build:gradle", version = "7.1.2"} android-gradle = { module = "com.android.tools.build:gradle", version = "7.1.2"}
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" } androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-splash = { module = "androidx.core:core-splashscreen", version.ref = "androidx-splash" }
compose-activity = { module = "androidx.activity:activity-compose", version = "1.4.0" } compose-activity = { module = "androidx.activity:activity-compose", version = "1.4.0" }
compose-material = { module = "androidx.compose.material:material", version.ref = "compose" } compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }
compose-test = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" } compose-test = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }