office: receive shared documents (#483) and add document dark mode (#479)
- Commit
02f61413096190aa7c4ab5375e8a3849f61cc401- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-10 17:09 UTC (3 months ago)
- Parents
02dc0ef
Diff
office/src/main/AndroidManifest.xml
diff --git a/office/src/main/AndroidManifest.xml b/office/src/main/AndroidManifest.xmlindex 58a7eecb3a..8af05a02b2 100644--- a/office/src/main/AndroidManifest.xml+++ b/office/src/main/AndroidManifest.xml@@ -97,6 +97,68 @@ <data android:scheme="content" /> <data android:scheme="file" /> </intent-filter>++ <!-- Receive documents shared from other apps (e.g. an encrypted file from+ Image-Toolbox). SEND carries the payload in EXTRA_STREAM and matches on+ type only, so no scheme/data entries here. -->+ <intent-filter>+ <action android:name="android.intent.action.SEND" />+ <category android:name="android.intent.category.DEFAULT" />++ <!-- OpenDocument Format (odt/ods/odp/odg + templates). -->+ <data android:mimeType="application/vnd.oasis.opendocument.text" />+ <data android:mimeType="application/vnd.oasis.opendocument.spreadsheet" />+ <data android:mimeType="application/vnd.oasis.opendocument.presentation" />+ <data android:mimeType="application/vnd.oasis.opendocument.graphics" />+ <data android:mimeType="application/vnd.oasis.opendocument.text-template" />+ <data android:mimeType="application/vnd.oasis.opendocument.spreadsheet-template" />+ <data android:mimeType="application/vnd.oasis.opendocument.presentation-template" />+ <data android:mimeType="application/vnd.oasis.opendocument.graphics-template" />++ <!-- Word (docx/docm/dotx/dotm) -->+ <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />+ <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.template" />+ <data android:mimeType="application/vnd.ms-word.document.macroenabled.12" />+ <data android:mimeType="application/vnd.ms-word.template.macroenabled.12" />++ <!-- Excel (xlsx/xlsm/xltx/xltm) -->+ <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />+ <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.template" />+ <data android:mimeType="application/vnd.ms-excel.sheet.macroenabled.12" />+ <data android:mimeType="application/vnd.ms-excel.template.macroenabled.12" />++ <!-- PowerPoint (pptx/pptm/potx/potm/ppsx/ppsm) -->+ <data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" />+ <data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.template" />+ <data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.slideshow" />+ <data android:mimeType="application/vnd.ms-powerpoint.presentation.macroenabled.12" />+ <data android:mimeType="application/vnd.ms-powerpoint.template.macroenabled.12" />+ <data android:mimeType="application/vnd.ms-powerpoint.slideshow.macroenabled.12" />++ <!-- CSV / TSV -->+ <data android:mimeType="text/csv" />+ <data android:mimeType="text/comma-separated-values" />+ <data android:mimeType="text/tab-separated-values" />++ <!-- Markdown -->+ <data android:mimeType="text/markdown" />+ <data android:mimeType="text/x-markdown" />++ <!-- HTML -->+ <data android:mimeType="text/html" />+ <data android:mimeType="application/xhtml+xml" />++ <!-- Rich Text -->+ <data android:mimeType="application/rtf" />+ <data android:mimeType="text/rtf" />++ <!-- Flat-ODF (fodt/fods/fodp/fodg) and .xml -->+ <data android:mimeType="application/xml" />+ <data android:mimeType="text/xml" />++ <!-- Plain text (txt/text/log) -->+ <data android:mimeType="text/plain" />+ </intent-filter> </activity> </application>
office/src/main/java/com/vayunmathur/office/MainActivity.kt
diff --git a/office/src/main/java/com/vayunmathur/office/MainActivity.kt b/office/src/main/java/com/vayunmathur/office/MainActivity.ktindex bc0d52e741..aed158ffa9 100644--- a/office/src/main/java/com/vayunmathur/office/MainActivity.kt+++ b/office/src/main/java/com/vayunmathur/office/MainActivity.kt@@ -10,6 +10,7 @@ import android.webkit.WebViewClient import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.BackHandler+import androidx.core.content.IntentCompat import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle@@ -110,8 +111,14 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.drawWithContent+import androidx.compose.ui.geometry.Rect import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.ColorFilter+import androidx.compose.ui.graphics.ColorMatrix+import androidx.compose.ui.graphics.Paint+import androidx.compose.ui.graphics.drawscope.drawIntoCanvas import androidx.compose.ui.res.stringResource import com.vayunmathur.office.R import androidx.compose.ui.text.font.FontWeight@@ -136,6 +143,33 @@ fun OfficeLightTheme(content: @Composable () -> Unit) { MaterialTheme(colorScheme = colorScheme, typography = Typography(), content = content) } +// Inverts luminance (white paper <-> black) while preserving hue, matching the+// "invert(1) hue-rotate(180deg)" trick used for document dark modes like Google Docs.+private val DocumentDarkModeColorMatrix = ColorMatrix(+ floatArrayOf(+ 0.574f, -1.430f, -0.144f, 0f, 255f,+ -0.426f, -0.430f, -0.144f, 0f, 255f,+ -0.426f, -1.430f, 0.856f, 0f, 255f,+ 0f, 0f, 0f, 1f, 0f,+ ),+)++/**+ * Renders the content into an offscreen layer and paints it back through a+ * luminance-inverting color filter, so the displayed document appears dark+ * without altering the underlying document colors. View-only (#479).+ */+fun Modifier.documentDarkModeInvert(): Modifier = this.drawWithContent {+ val paint = Paint().apply {+ colorFilter = ColorFilter.colorMatrix(DocumentDarkModeColorMatrix)+ }+ drawIntoCanvas { canvas ->+ canvas.saveLayer(Rect(0f, 0f, size.width, size.height), paint)+ drawContent()+ canvas.restore()+ }+}+ @Composable private fun OfficeAppTheme(content: @Composable () -> Unit) { // The app chrome (menus, toolbars, home) is dark; the document content re-wraps in the light theme.@@ -168,7 +202,7 @@ class MainActivity : ComponentActivity() { // them out of the document-loading path (their scheme isn't content/file). val joinLink = parseJoinLink(intent) if (joinLink != null) handleJoinLink(joinLink)- val intentUri: Uri? = intent.data?.takeIf { joinLink == null }+ val intentUri: Uri? = if (joinLink == null) extractDocumentUri(intent) else null setContent { val startedWithIntent = intentUri != null@@ -309,6 +343,16 @@ class MainActivity : ComponentActivity() { val ownerId = data.getQueryParameter("owner")?.takeIf { it.isNotBlank() } ?: return null return docId to ownerId }++ /**+ * Resolves the document uri to open from an intent. VIEW/edit intents carry it+ * in [Intent.getData]; SEND intents (files shared from other apps) carry it in+ * [Intent.EXTRA_STREAM].+ */+ private fun extractDocumentUri(intent: Intent): Uri? = when (intent.action) {+ Intent.ACTION_SEND -> IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)+ else -> intent.data+ } } /**@@ -727,6 +771,7 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity: val canRedo by viewModel.canRedo.collectAsState() val autoSaveEnabled by viewModel.autoSaveEnabled.collectAsState() val nightMode by viewModel.nightMode.collectAsState()+ val documentDarkMode by viewModel.documentDarkMode.collectAsState() var showWordBar by remember { mutableStateOf(false) } var showComments by remember { mutableStateOf(false) } var showChanges by remember { mutableStateOf(false) }@@ -980,6 +1025,7 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity: if (isTextDoc && (headings.isNotEmpty() || bookmarks.isNotEmpty())) DropdownMenuItem(text = { Text(stringResource(R.string.outline)) }, onClick = { viewMenu = false; scope.launch { drawerState.open() } }) DropdownMenuItem(text = { Text(stringResource(R.string.zoom_text)) }, onClick = { viewMenu = false; showFontControl = !showFontControl }) DropdownMenuItem(text = { Text(if (nightMode) stringResource(R.string.night_reading_mode) else stringResource(R.string.night_reading_mode_1)) }, onClick = { viewMenu = false; viewModel.toggleNightMode() })+ DropdownMenuItem(text = { Text(if (documentDarkMode) stringResource(R.string.document_dark_mode) else stringResource(R.string.document_dark_mode_1)) }, onClick = { viewMenu = false; viewModel.toggleDocumentDarkMode() }) if (isTextDoc) DropdownMenuItem(text = { Text(if (showWordBar) stringResource(R.string.word_count_bar) else stringResource(R.string.word_count_bar_1)) }, onClick = { viewMenu = false; showWordBar = !showWordBar }) if (isTextDoc) DropdownMenuItem(text = { Text(stringResource(R.string.comments)) }, onClick = { viewMenu = false; showComments = true }) if (isTextDoc) DropdownMenuItem(text = { Text(stringResource(R.string.track_changes)) }, onClick = { viewMenu = false; showChanges = true })@@ -1124,7 +1170,12 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity: } } OfficeLightTheme {- Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {+ Surface(+ Modifier+ .fillMaxSize()+ .then(if (documentDarkMode) Modifier.documentDarkModeInvert() else Modifier),+ color = MaterialTheme.colorScheme.background,+ ) { when (document) { is OdfDocument.TextDocument -> TextDocumentView(doc = document, searchQuery = searchQuery, fontSizeMultiplier = fontSizeMultiplier, listState = listState, remoteCarets = remoteCarets,
office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt
diff --git a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.ktindex 9b2b8c03fe..63c7b2f315 100644--- a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt+++ b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt@@ -138,6 +138,11 @@ class OfficeViewModel(application: Application) : AndroidViewModel(application) private val _nightMode = MutableStateFlow(false) val nightMode: StateFlow<Boolean> = _nightMode + // Google-Docs-style dark mode: inverts the displayed colors of the document so the+ // paper appears dark, without modifying the document itself. View-only, not persisted.+ private val _documentDarkMode = MutableStateFlow(false)+ val documentDarkMode: StateFlow<Boolean> = _documentDarkMode+ // Incremented whenever the document changes shape via undo/redo so the UI can // reset/clamp hoisted selection state (active cell/slide/element). (A4) private val _selectionInvalidation = MutableStateFlow(0)@@ -302,6 +307,7 @@ class OfficeViewModel(application: Application) : AndroidViewModel(application) // --- Night mode --- fun toggleNightMode() { _nightMode.value = !_nightMode.value }+ fun toggleDocumentDarkMode() { _documentDarkMode.value = !_documentDarkMode.value } // --- Load / Clear ---
office/src/main/res/values/strings.xml
diff --git a/office/src/main/res/values/strings.xml b/office/src/main/res/values/strings.xmlindex 9a2b010198..beaaa80816 100644--- a/office/src/main/res/values/strings.xml+++ b/office/src/main/res/values/strings.xml@@ -533,6 +533,10 @@ <string name="night_reading_mode">โ Night reading mode</string> <!-- MainActivity: Unchecked menu night reading mode --> <string name="night_reading_mode_1">Night reading mode</string>+ <!-- MainActivity: Checked menu document dark mode with checkmark -->+ <string name="document_dark_mode">โ Document dark mode</string>+ <!-- MainActivity: Unchecked menu document dark mode -->+ <string name="document_dark_mode_1">Document dark mode</string> <!-- MainActivity: Checked menu word count bar with checkmark --> <string name="word_count_bar">โ Word count bar</string> <!-- MainActivity: Unchecked menu word count bar -->