Skip to content

Commit

Permalink
Remove most of custom activity transition animations in favor of cons…
Browse files Browse the repository at this point in the history
…istency (ankidroid#14923)

* replace finishWithAnimation usages with finish()
* replace most usages of startActivityWithAnimation with startActivity()
* Replace startActivityWithoutAnimation with startActivity
* replace startActivityForResultWithoutAnimation with startActivityForResult
* replace launchActivityWithAnimation
* refactor: remove unused animation direction
* refactor: remove translucent theme from activities
it made the opening and closing animation not be the default one

* refactor: remove finishActivityWithFade
* refactor: remove manual slide calls
* remove unused resources
* remove launchActivityForResultWithAnimation
  • Loading branch information
BrayanDSO authored Dec 21, 2023
1 parent 524f317 commit 041f9d1
Show file tree
Hide file tree
Showing 35 changed files with 74 additions and 237 deletions.
6 changes: 2 additions & 4 deletions AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,16 @@
the full package path is needed for manageSpaceActivity -->
<activity
android:name="com.ichi2.anki.ui.windows.managespace.ManageSpaceActivity"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
android:exported="true"/>
<activity android:name=".DrawingActivity"
android:label="@string/drawing"
android:exported="false"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity
android:name="com.ichi2.anki.pages.PagesActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
/>
<activity
android:name="com.ichi2.anki.IntentHandler"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object ActivityTransitionAnimation {
Direction.FADE -> activity.overridePendingTransition(R.anim.fade_out, R.anim.fade_in)
Direction.UP -> activity.overridePendingTransition(R.anim.slide_up_in, R.anim.slide_up_out)
Direction.DOWN -> activity.overridePendingTransition(R.anim.slide_down_in, R.anim.slide_down_out)
Direction.DIALOG_EXIT -> activity.overridePendingTransition(R.anim.none, R.anim.dialog_exit)
Direction.NONE -> activity.overridePendingTransition(R.anim.none, R.anim.none)
Direction.DEFAULT -> {
}
Expand All @@ -47,7 +46,6 @@ object ActivityTransitionAnimation {
Direction.FADE -> ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.fade_out, R.anim.fade_in)
Direction.UP -> ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.slide_up_in, R.anim.slide_up_out)
Direction.DOWN -> ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.slide_down_in, R.anim.slide_down_out)
Direction.DIALOG_EXIT -> ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.none, R.anim.dialog_exit)
Direction.NONE -> ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.none, R.anim.none)
Direction.DEFAULT -> // this is the default animation, we shouldn't try to override it
ActivityOptionsCompat.makeBasic()
Expand All @@ -61,7 +59,7 @@ object ActivityTransitionAnimation {

@Parcelize
enum class Direction : Parcelable {
START, END, FADE, UP, DOWN, RIGHT, LEFT, DEFAULT, DIALOG_EXIT, NONE
START, END, FADE, UP, DOWN, RIGHT, LEFT, DEFAULT, NONE
}

/**
Expand All @@ -81,7 +79,6 @@ object ActivityTransitionAnimation {
Direction.FADE -> Direction.FADE
Direction.DEFAULT -> Direction.DEFAULT
Direction.NONE -> Direction.NONE
Direction.DIALOG_EXIT -> Direction.DIALOG_EXIT
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ abstract class AbstractFlashcardViewer :
editCard.putExtra(NoteEditor.EXTRA_CALLER, NoteEditor.CALLER_REVIEWER_EDIT)
editCard.putExtra(FINISH_ANIMATION_EXTRA, getInverseTransition(animation) as Parcelable)
editorCard = currentCard
launchActivityForResultWithAnimation(editCard, editCurrentCardLauncher, animation)
editCurrentCardLauncher.launch(editCard)
}

fun generateQuestionSoundList() {
Expand Down Expand Up @@ -1942,7 +1942,7 @@ abstract class AbstractFlashcardViewer :
mPreviousAnswerIndicator!!.stopAutomaticHide()
mLongClickHandler.removeCallbacks(mStartLongClickAction)
this@AbstractFlashcardViewer.setResult(result)
finishWithAnimation(ActivityTransitionAnimation.Direction.END)
finish()
}

protected fun refreshActionBar() {
Expand Down Expand Up @@ -2575,7 +2575,7 @@ abstract class AbstractFlashcardViewer :
Timber.d("Opening resolved external link \"%s\" with an Intent: %s", url, intent)
}
try {
startActivityWithoutAnimation(intent)
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Timber.w(e) // Don't crash if the intent is not handled
}
Expand Down
20 changes: 2 additions & 18 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.ichi2.anki

import android.app.Activity
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ActivityNotFoundException
Expand Down Expand Up @@ -220,15 +219,6 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener {
}
}

fun launchActivityForResultWithAnimation(
intent: Intent,
launcher: ActivityResultLauncher<Intent?>,
animation: Direction?
) {
enableIntentAnimation(intent)
launchActivityForResult(intent, launcher, animation)
}

override fun finish() {
finishWithAnimation(DEFAULT)
}
Expand Down Expand Up @@ -302,7 +292,7 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener {
val deckPicker = Intent(this, DeckPicker::class.java)
deckPicker.putExtra("collectionLoadError", true) // don't currently do anything with this
deckPicker.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivityWithAnimation(deckPicker, START)
startActivity(deckPicker)
}

fun showProgressBar() {
Expand Down Expand Up @@ -503,7 +493,7 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener {
if (reload) {
val deckPicker = Intent(this, DeckPicker::class.java)
deckPicker.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivityWithoutAnimation(deckPicker)
startActivity(deckPicker)
}
}

Expand Down Expand Up @@ -554,12 +544,6 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener {
/** Extra key to set the finish animation of an activity */
const val FINISH_ANIMATION_EXTRA = "finishAnimation"

/** Finish Activity using FADE animation */
fun finishActivityWithFade(activity: Activity) {
activity.finish()
ActivityTransitionAnimation.slide(activity, FADE)
}

fun showDialogFragment(activity: AnkiActivity, newFragment: DialogFragment) {
showDialogFragment(activity.supportFragmentManager, newFragment)
}
Expand Down
3 changes: 1 addition & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.content.Intent
import android.net.Uri
import com.github.zafarkhaja.semver.Version
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anim.ActivityTransitionAnimation
import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeBuryCard
import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeBuryNote
import com.ichi2.anki.AnkiDroidJsAPIConstants.ankiJsErrorCodeError
Expand Down Expand Up @@ -266,7 +265,7 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) {
putExtra("currentCard", currentCard.id)
putExtra("search_query", apiParams)
}
activity.startActivityWithAnimation(intent, ActivityTransitionAnimation.Direction.START)
activity.startActivity(intent)
convertToByteArray(apiContract, true)
}
"searchCardWithCallback" -> ankiSearchCardWithCallback(apiContract)
Expand Down
13 changes: 6 additions & 7 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import anki.collection.OpChanges
import com.afollestad.materialdialogs.utils.MDUtil.ifNotZero
import com.google.android.material.color.MaterialColors
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anim.ActivityTransitionAnimation
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.Previewer.Companion.toIntent
Expand Down Expand Up @@ -682,7 +681,7 @@ open class CardBrowser :
val editCard = Intent(this, NoteEditor::class.java)
.putExtra(NoteEditor.EXTRA_CALLER, NoteEditor.CALLER_CARDBROWSER_EDIT)
.putExtra(NoteEditor.EXTRA_CARD_ID, cardBrowserCard!!.id)
launchActivityForResultWithAnimation(editCard, onEditCardActivityResult, ActivityTransitionAnimation.Direction.START)
onEditCardActivityResult.launch(editCard)
// #6432 - FIXME - onCreateOptionsMenu crashes if receiving an activity result from edit card when in multiselect
endMultiSelectMode()
}
Expand Down Expand Up @@ -844,8 +843,8 @@ open class CardBrowser :
deckPicker.action = Intent.ACTION_MAIN
deckPicker.addCategory(Intent.CATEGORY_LAUNCHER)
deckPicker.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivityWithAnimation(deckPicker, ActivityTransitionAnimation.Direction.FADE)
finishActivityWithFade(this)
startActivity(deckPicker)
finish()
this.setResult(RESULT_CANCELED)
}

Expand Down Expand Up @@ -1159,7 +1158,7 @@ open class CardBrowser :
R.id.action_view_card_info -> {
viewModel.cardInfoDestination?.let { destination ->
val intent: Intent = destination.toIntent(this)
startActivityWithAnimation(intent, ActivityTransitionAnimation.Direction.FADE)
startActivity(intent)
}
return true
}
Expand Down Expand Up @@ -1313,7 +1312,7 @@ open class CardBrowser :
}

private fun addNoteFromCardBrowser() {
launchActivityForResultWithAnimation(addNoteIntent, onAddNoteActivityResult, ActivityTransitionAnimation.Direction.START)
onAddNoteActivityResult.launch(addNoteIntent)
}

private val reviewerCardId: CardId
Expand Down Expand Up @@ -1700,7 +1699,7 @@ open class CardBrowser :
private fun closeCardBrowser(result: Int, data: Intent? = null) {
// Set result and finish
setResult(result, data)
finishWithAnimation(ActivityTransitionAnimation.Direction.END)
finish()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CardTemplateBrowserAppearanceEditor : AnkiActivity() {
val bundle = savedInstanceState ?: intent.extras
if (bundle == null) {
UIUtils.showThemedToast(this, getString(R.string.card_template_editor_card_browser_appearance_failed), true)
finishActivityWithFade(this)
finish()
return
}
initializeUiFromBundle(bundle)
Expand Down Expand Up @@ -157,7 +157,7 @@ class CardTemplateBrowserAppearanceEditor : AnkiActivity() {
private fun discardChangesAndClose() {
Timber.i("Closing and discarding changes")
setResult(RESULT_CANCELED)
finishActivityWithFade(this)
finish()
}

private fun saveAndExit() {
Expand All @@ -167,7 +167,7 @@ class CardTemplateBrowserAppearanceEditor : AnkiActivity() {
putExtra(INTENT_ANSWER_FORMAT, answerFormat)
}
setResult(RESULT_OK, data)
finishActivityWithFade(this)
finish()
}

private fun hasChanges(): Boolean {
Expand Down
7 changes: 3 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.ichi2.anim.ActivityTransitionAnimation.Direction.END
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.dialogs.ConfirmationDialog
import com.ichi2.anki.dialogs.DeckSelectionDialog
Expand Down Expand Up @@ -202,7 +201,7 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener {
// Clear the edited model from any cache files, and clear it from this objects memory to discard changes
CardTemplateNotetype.clearTempModelFiles()
tempModel = null
finishWithAnimation(END)
finish()
}

/** When a deck is selected via Deck Override */
Expand Down Expand Up @@ -556,7 +555,7 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener {
}
} else {
Timber.d("CardTemplateEditor:: model has not changed, exiting")
mTemplateEditor.finishWithAnimation(END)
mTemplateEditor.finish()
}

return true
Expand All @@ -583,7 +582,7 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener {
button.isEnabled = true
}
mTemplateEditor.tempModel = null
mTemplateEditor.finishWithAnimation(END)
mTemplateEditor.finish()
}

fun performPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.ichi2.anki

import android.os.Bundle
import android.view.View
import com.ichi2.anim.ActivityTransitionAnimation
import com.ichi2.anki.UIUtils.showThemedToast
import com.ichi2.anki.cardviewer.PreviewLayout
import com.ichi2.anki.cardviewer.PreviewLayout.Companion.createAndDisplay
Expand Down Expand Up @@ -117,7 +116,7 @@ open class CardTemplatePreviewer : AbstractFlashcardViewer() {
Timber.d("CardTemplatePreviewer:: closeCardTemplatePreviewer()")
setResult(RESULT_OK)
CardTemplateNotetype.clearTempModelFiles()
finishWithAnimation(ActivityTransitionAnimation.Direction.END)
finish()
}

@Deprecated("Deprecated in Java")
Expand All @@ -130,7 +129,7 @@ open class CardTemplatePreviewer : AbstractFlashcardViewer() {

override fun performReload() {
// This should not happen.
finishWithAnimation(ActivityTransitionAnimation.Direction.END)
finish()
}

override fun onNavigationPressed() {
Expand Down
Loading

0 comments on commit 041f9d1

Please sign in to comment.