Skip to content
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 @@ -119,7 +119,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
120 changes: 76 additions & 44 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.content.Context
import android.content.Intent
import android.net.Uri
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 Down Expand Up @@ -54,6 +57,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
import java.time.Duration
import java.time.Instant
import kotlin.math.max
import kotlin.math.min

Expand All @@ -67,54 +72,81 @@ import kotlin.math.min
class IntentHandler : AbstractIntentHandler() {
override fun onCreate(savedInstanceState: Bundle?) {
// Note: This is our entry point from the launcher with intent: android.intent.action.MAIN
super.onCreate(savedInstanceState)
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 = { runnable: () -> Unit -> performActionIfStorageAccessible(reloadIntent, action) { runnable() } }
val launchType = getLaunchType(intent)
// TODO block the UI with some kind of ProgressDialog instead of cancelling the sync work
if (requiresCollectionAccess(launchType)) {
// # 18899
if (WorkManager.isInitialized()) {
SyncWorker.cancel(this)
}
}
when (launchType) {
LaunchType.FILE_IMPORT ->
runIfStoragePermissions {
handleFileImport(fileIntent, reloadIntent, action)
finish()
}
LaunchType.TEXT_IMPORT ->
runIfStoragePermissions {
onSelectedCsvForImport(fileIntent)
finish()

val handleScreen = { delay: Long ->
Handler(Looper.getMainLooper()).postDelayed({
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 = { runnable: () -> Unit ->
performActionIfStorageAccessible(reloadIntent, action) { runnable() }
}
LaunchType.IMAGE_IMPORT ->
runIfStoragePermissions {
handleImageImport(intent)
finish()
val launchType = getLaunchType(intent)
// TODO block the UI with some kind of ProgressDialog instead of cancelling the sync work
if (requiresCollectionAccess(launchType)) {
// # 18899
if (WorkManager.isInitialized()) {
SyncWorker.cancel(this)
}
}
LaunchType.SHARED_TEXT ->
runIfStoragePermissions {
handleSharedText(intent)
finish()
when (launchType) {
LaunchType.FILE_IMPORT ->
runIfStoragePermissions {
handleFileImport(fileIntent, reloadIntent, action)
finish()
}
LaunchType.TEXT_IMPORT ->
runIfStoragePermissions {
onSelectedCsvForImport(fileIntent)
finish()
}
LaunchType.IMAGE_IMPORT ->
runIfStoragePermissions {
handleImageImport(intent)
finish()
}
LaunchType.SHARED_TEXT ->
runIfStoragePermissions {
handleSharedText(intent)
finish()
}
LaunchType.SYNC -> runIfStoragePermissions { handleSyncIntent(reloadIntent, action) }
LaunchType.REVIEW -> runIfStoragePermissions { handleReviewIntent(reloadIntent, intent) }
LaunchType.DEFAULT_START_APP_IF_NEW -> {
Timber.d("onCreate() performing default action")
launchDeckPickerIfNoOtherTasks(reloadIntent)
}
LaunchType.COPY_DEBUG_INFO -> {
copyDebugInfoToClipboard(intent)
finish()
}
}
LaunchType.SYNC -> runIfStoragePermissions { handleSyncIntent(reloadIntent, action) }
LaunchType.REVIEW -> runIfStoragePermissions { handleReviewIntent(reloadIntent, 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.now())).toMillis().coerceAtLeast(0L)
} else {
0L
}
Timber.v("remainDuration: $remainingDuration")
handleScreen(remainingDuration)
}
super.onCreate(savedInstanceState)
} else {
super.onCreate(savedInstanceState)
handleScreen(0L) // No delay for older Android versions
}
}

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
Expand Up @@ -2,14 +2,15 @@
<!-- 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"
android:gravity="center"/>
</item>
<item android:top="200dp">
<bitmap
android:src="@drawable/ankidroid_txt"
android:gravity="center"/>
</item>
<item
android:width="288dp"
android:height="288dp"
android:drawable="@drawable/splash_icon"
android:gravity="center"/>
<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