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

[Feature] Add Splash screen #14837

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<activity
android:name="com.ichi2.anki.IntentHandler"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:theme="@style/Theme_Dark.Launcher"
android:exported="true"
>
<intent-filter>
Expand Down
83 changes: 59 additions & 24 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package com.ichi2.anki
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import androidx.annotation.CheckResult
import androidx.annotation.VisibleForTesting
Expand All @@ -31,6 +34,7 @@ import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.servicelayer.ScopedStorageService
import com.ichi2.anki.services.ReminderService
import com.ichi2.annotations.NeedsTest
import com.ichi2.libanki.utils.TimeManager
import com.ichi2.themes.Themes
import com.ichi2.themes.Themes.disableXiaomiForceDarkMode
import com.ichi2.utils.FileUtil
Expand All @@ -44,6 +48,8 @@ import com.ichi2.utils.copyToClipboard
import com.ichi2.utils.trimToLength
import timber.log.Timber
import java.io.File
import java.time.Duration
import java.time.Instant
import java.util.function.Consumer
import kotlin.math.max
import kotlin.math.min
Expand All @@ -56,32 +62,61 @@ import kotlin.math.min
*/
class IntentHandler : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Note: This is our entry point from the launcher with intent: android.intent.action.MAIN
super.onCreate(savedInstanceState)
Themes.setTheme(this)
disableXiaomiForceDarkMode(this)
setContentView(R.layout.progress_bar)
val intent = intent
Timber.v(intent.toString())
val reloadIntent = Intent(this, DeckPicker::class.java)
reloadIntent.setDataAndType(getIntent().data, getIntent().type)
val action = intent.action
// #6157 - We want to block actions that need permissions we don't have, but not the default case
// as this requires nothing
val runIfStoragePermissions = Consumer { runnable: Runnable -> performActionIfStorageAccessible(runnable, reloadIntent, action) }
when (getLaunchType(intent)) {
LaunchType.FILE_IMPORT -> runIfStoragePermissions.accept(Runnable { handleFileImport(intent, reloadIntent, action) })
LaunchType.SYNC -> runIfStoragePermissions.accept(Runnable { handleSyncIntent(reloadIntent, action) })
LaunchType.REVIEW -> runIfStoragePermissions.accept(Runnable { handleReviewIntent(intent) })
LaunchType.DEFAULT_START_APP_IF_NEW -> {
Timber.d("onCreate() performing default action")
launchDeckPickerIfNoOtherTasks(reloadIntent)
}
LaunchType.COPY_DEBUG_INFO -> {
copyDebugInfoToClipboard(intent)
finish()
val init = {
// setContentView(R.layout.progress_bar)
}
val handleScreen = { delay: Long ->
Handler(Looper.getMainLooper()).postDelayed({
Themes.setTheme(this)
disableXiaomiForceDarkMode(this)
val intent = intent
Timber.v(intent.toString())
val reloadIntent = Intent(this, DeckPicker::class.java)
reloadIntent.setDataAndType(getIntent().data, getIntent().type)
val action = intent.action
// #6157 - We want to block actions that need permissions we don't have, but not the default case
// as this requires nothing
val runIfStoragePermissions = Consumer { runnable: Runnable ->
performActionIfStorageAccessible(runnable, reloadIntent, action)
}
when (getLaunchType(intent)) {
LaunchType.FILE_IMPORT -> runIfStoragePermissions.accept(Runnable { handleFileImport(intent, reloadIntent, action) })
LaunchType.SYNC -> runIfStoragePermissions.accept(Runnable { handleSyncIntent(reloadIntent, action) })
LaunchType.REVIEW -> runIfStoragePermissions.accept(Runnable { handleReviewIntent(intent) })
LaunchType.DEFAULT_START_APP_IF_NEW -> {
Timber.d("onCreate() performing default action")
launchDeckPickerIfNoOtherTasks(reloadIntent)
}
LaunchType.COPY_DEBUG_INFO -> {
copyDebugInfoToClipboard(intent)
finish()
}
}
}, delay)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
splashScreen.setOnExitAnimationListener { splashScreenView ->
val animationDuration = splashScreenView.iconAnimationDuration
val animationStart = splashScreenView.iconAnimationStart

Timber.v("duration :${animationDuration?.toMillis()} start $animationStart")
val remainingDuration = if (animationDuration != null && animationStart != null) {
(animationDuration - Duration.between(animationStart, Instant.ofEpochMilli(TimeManager.time.intTimeMS())))
.toMillis()
.coerceAtLeast(0L)
} else {
0L
}
Timber.v("remainDuration :$remainingDuration")
handleScreen(remainingDuration)
}
init()
super.onCreate(savedInstanceState)
} else {
handleScreen(1000L)
super.onCreate(savedInstanceState)
}
// Note: This is our entry point from the launcher with intent: android.intent.action.MAIN
}

private fun copyDebugInfoToClipboard(intent: Intent) {
Expand Down
21 changes: 11 additions & 10 deletions AnkiDroid/src/main/res/drawable/launch_screen.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@color/material_theme_grey"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/logo_star_144dp"
<!-- Your product logo - 192dp color version of your app icon -->
<item
android:width="288dp"
android:height="288dp"
android:drawable="@drawable/splash_icon"
android:gravity="center"/>
</item>
<item android:top="200dp">
<bitmap
android:src="@drawable/ankidroid_txt"
android:gravity="center"/>
</item>
<item
android:width="200dp"
android:height="80dp"
android:drawable="@drawable/splash_branding"
android:gravity="center|bottom"
android:bottom="48dp"/>
</layer-list>
13 changes: 13 additions & 0 deletions AnkiDroid/src/main/res/drawable/splash_branding.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="200dp"
android:height="80dp"
android:drawable="@android:color/transparent"
android:gravity="center" />
<item
android:drawable="@drawable/ankidroid_txt"
android:height="31.9dp"
android:width="200dp"
android:gravity="center" />
</layer-list>
Loading
Loading