diff --git a/AnkiDroid/src/main/AndroidManifest.xml b/AnkiDroid/src/main/AndroidManifest.xml index 8b83c8b2f76f..c04c52b3d178 100644 --- a/AnkiDroid/src/main/AndroidManifest.xml +++ b/AnkiDroid/src/main/AndroidManifest.xml @@ -587,6 +587,22 @@ --> + + + + + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package com.ichi2.anki.instantnoteeditor + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import com.ichi2.anki.AnkiActivity +import com.ichi2.anki.R +import com.ichi2.themes.setTransparentBackground + +/** + * Single instance Activity for instantly editing and adding cloze card/s without actually opening the app, + * uses a custom dialog layout and a transparent activity theme to achieve the functionality. + **/ +class InstantNoteEditorActivity : AnkiActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + if (showedActivityFailedScreen(savedInstanceState)) { + return + } + super.onCreate(savedInstanceState) + if (!ensureStoragePermissions()) { + return + } + setTransparentBackground() + enableEdgeToEdge() + setContentView(R.layout.activity_instant_note_editor) + onDestroy() + } +} diff --git a/AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt b/AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt index e563b4f28f0b..e019e56b023e 100644 --- a/AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt +++ b/AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt @@ -22,6 +22,7 @@ import android.content.Context import android.content.SharedPreferences import android.content.res.Configuration import android.graphics.Color +import android.graphics.drawable.ColorDrawable import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatDelegate @@ -149,3 +150,7 @@ fun FragmentActivity.setTransparentStatusBar() { !Themes.currentTheme.isNightMode window.statusBarColor = Color.TRANSPARENT } + +fun FragmentActivity.setTransparentBackground() { + window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) +} diff --git a/AnkiDroid/src/main/res/layout/activity_instant_note_editor.xml b/AnkiDroid/src/main/res/layout/activity_instant_note_editor.xml new file mode 100644 index 000000000000..605751b987ea --- /dev/null +++ b/AnkiDroid/src/main/res/layout/activity_instant_note_editor.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/AnkiDroid/src/main/res/values/01-core.xml b/AnkiDroid/src/main/res/values/01-core.xml index 7580091f1c7c..414a22872a0a 100644 --- a/AnkiDroid/src/main/res/values/01-core.xml +++ b/AnkiDroid/src/main/res/values/01-core.xml @@ -285,4 +285,7 @@ Image Occlusion Remove account + + + Instant card diff --git a/AnkiDroid/src/main/res/values/styles.xml b/AnkiDroid/src/main/res/values/styles.xml index d2da90259c0b..d7125d67482e 100644 --- a/AnkiDroid/src/main/res/values/styles.xml +++ b/AnkiDroid/src/main/res/values/styles.xml @@ -230,4 +230,12 @@ 0.8dp + + diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ActivityStartupUnderBackupTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ActivityStartupUnderBackupTest.kt index 4207a0d9ab81..e6949e7a453e 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ActivityStartupUnderBackupTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ActivityStartupUnderBackupTest.kt @@ -18,6 +18,7 @@ package com.ichi2.anki import android.app.Activity import android.os.Looper.getMainLooper import com.canhub.cropper.CropImageActivity +import com.ichi2.anki.instantnoteeditor.InstantNoteEditorActivity import com.ichi2.anki.preferences.Preferences import com.ichi2.testutils.ActivityList import com.ichi2.testutils.ActivityList.ActivityLaunchParam @@ -54,6 +55,7 @@ class ActivityStartupUnderBackupTest : RobolectricTest() { notYetHandled(Preferences::class.java.simpleName, "Not working (or implemented) - inherits from AppCompatPreferenceActivity") notYetHandled(FilteredDeckOptions::class.java.simpleName, "Not working (or implemented) - inherits from AppCompatPreferenceActivity") notYetHandled(SingleFragmentActivity::class.java.simpleName, "Implemented, but the test fails because the activity throws if a specific intent extra isn't set") + notYetHandled(InstantNoteEditorActivity::class.java.simpleName, "Single instance activity so should be used") } /** diff --git a/AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt b/AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt index c27a795efb34..437e5d1227f8 100644 --- a/AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt +++ b/AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt @@ -23,6 +23,7 @@ import com.canhub.cropper.CropImageActivity import com.ichi2.anki.* import com.ichi2.anki.CardTemplateBrowserAppearanceEditor.Companion.INTENT_ANSWER_FORMAT import com.ichi2.anki.CardTemplateBrowserAppearanceEditor.Companion.INTENT_QUESTION_FORMAT +import com.ichi2.anki.instantnoteeditor.InstantNoteEditorActivity import com.ichi2.anki.multimediacard.activity.MultimediaEditFieldActivity import com.ichi2.anki.notetype.ManageNotetypes import com.ichi2.anki.preferences.Preferences @@ -73,7 +74,8 @@ object ActivityList { get(ManageSpaceActivity::class.java), get(PermissionsActivity::class.java), get(SingleFragmentActivity::class.java), - get(CardViewerActivity::class.java) + get(CardViewerActivity::class.java), + get(InstantNoteEditorActivity::class.java) ) }