Skip to content

Commit

Permalink
init instant note editor activity
Browse files Browse the repository at this point in the history
* setup the style and manifest file to make activity transparent and single instance
  • Loading branch information
criticalAY authored and lukstbit committed Jun 1, 2024
1 parent 6b6ec74 commit cc6c8af
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 1 deletion.
16 changes: 16 additions & 0 deletions AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,22 @@
-->
<meta-data android:name="android.webkit.WebView.MetricsOptOut" android:value="true" />

<!--
Transparent Single instance activity, and is cleared from recent tasks as we want to mimic
the behaviour of not opening the application and still be able to access the dialog.
Task affinity allows us to separate the activity allowing us to define that an activity belongs to a
different task, it ensures that the activity does not interfere with other tasks in our application.
-->
<activity
android:name="com.ichi2.anki.instantnoteeditor.InstantNoteEditorActivity"
android:exported="false"
android:label="@string/instant_card"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@style/Theme.AppCompat.Transparent.NoActionBar" >
</activity>



<provider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Ashish Yadav <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

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()
}
}
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/themes/Themes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -149,3 +150,7 @@ fun FragmentActivity.setTransparentStatusBar() {
!Themes.currentTheme.isNightMode
window.statusBarColor = Color.TRANSPARENT
}

fun FragmentActivity.setTransparentBackground() {
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
23 changes: 23 additions & 0 deletions AnkiDroid/src/main/res/layout/activity_instant_note_editor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2024 Ashish Yadav <[email protected]>
~
~ 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 <http://www.gnu.org/licenses/>.
-->

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/root_layout"
android:layout_height="match_parent" >

</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 3 additions & 0 deletions AnkiDroid/src/main/res/values/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,7 @@
<string name="image_occlusion">Image Occlusion</string>

<string name="remove_account" comment="open a website to start the deletion of an AnkiWeb account">Remove account</string>

<!-- Instant Note Editor -->
<string name="instant_card" comment="This does not need to be translated literally, translate the concept of quickly adding a Cloze note with a popup. Used in the Android system context menu/share dialog.">Instant card</string>
</resources>
8 changes: 8 additions & 0 deletions AnkiDroid/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,12 @@
<item name="android:elevation">0.8dp</item>
</style>

<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

/**
Expand Down
4 changes: 3 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
}

Expand Down

0 comments on commit cc6c8af

Please sign in to comment.