Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

Reader: simplify glass controls and dark-mode contrast (#47)

Chethan Krishnab099c5194432
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
index 9e7ed20..b2216a8 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
@@ -3,6 +3,24 @@ package com.chethan616.clearpdf.ui.components
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.spring
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.BasicTextField
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.text.input.VisualTransformation
+import androidx.compose.ui.unit.Dp
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
@@ -101,9 +119,11 @@ fun GlassDialog(
BackHandler(enabled = visible) { onDismiss() }
val isLight = !LocalIsDarkMode.current
- // Lighter wash + scrim than the catalog so the live screen behind stays visible through the
- // glass — a heavy scrim leaves the lens nothing to refract.
- val containerColor = if (isLight) Color(0xFFFAFAFA).copy(0.5f) else Color(0xFF121212).copy(0.34f)
+ // Theme-owned wash, dense enough that the dialog's text holds contrast over ANY page behind it
+ // (a 34-50% wash let a black PDF page turn the light-theme panel charcoal under dark text, and a
+ // white page turn the dark panel pale under white text). The lens rim and blur still refract the
+ // live screen, so it keeps reading as glass rather than a card.
+ val containerColor = glassDialogSurface(!isLight)
val dimColor = if (isLight) Color(0xFF29293A).copy(0.16f) else Color(0xFF000000).copy(0.32f)
val blurDp = if (isLight) 16.dp else 8.dp
val contentColor = LiquidGlassColors.text(!isLight)
@@ -227,7 +247,10 @@ fun RowScope.GlassDialogAction(
.weight(1f)
.graphicsLayer { alpha = if (enabled) 1f else 0.4f },
tint = pillTint,
- surfaceColor = if (pillTint == Color.Unspecified) LocalDialogSurface.current else Color.Unspecified,
+ // Neutral pills get a SOLID theme platter, not the panel's wash: they refract the screen
+ // behind the dialog (not the panel), so a translucent fill let a white page show through
+ // under white ink — the blank "Cancel" pills. Primary/destructive pills are vivid tints.
+ surfaceColor = if (pillTint == Color.Unspecified) glassDialogPlatter(isDark) else Color.Unspecified,
blurRadius = LocalDialogBlur.current,
// Three equal actions must still leave room for translated labels such as “Discard”.
horizontalContentPadding = 8.dp
@@ -239,3 +262,142 @@ fun RowScope.GlassDialogAction(
)
}
}
+
+
+// ── Dialog material, shared by every in-window glass dialog ─────────────────────────────────────
+
+/** Panel wash for in-window dialogs: translucent, but dense enough to own its text contrast. */
+fun glassDialogSurface(isDark: Boolean): Color =
+ if (isDark) Color(0xFF1C1D22).copy(0.68f) else Color(0xFFFAFAFC).copy(0.70f)
+
+/** Solid platter for neutral controls inside a dialog (buttons, fields, segment tracks). */
+fun glassDialogPlatter(isDark: Boolean): Color =
+ if (isDark) Color(0xFF2E3038).copy(0.94f) else Color.White.copy(0.94f)
+
+/** Ink for content inside a dialog. Follows the app theme, never the page under the dialog. */
+@Composable
+fun glassDialogInk(): Color = LiquidGlassColors.text(LocalIsDarkMode.current)
+
+@Composable
+fun glassDialogInkSoft(): Color = LiquidGlassColors.secondary(LocalIsDarkMode.current)
+
+/**
+ * Text field for [GlassDialog] content: a solid rounded platter (no glass-on-glass), theme ink,
+ * placeholder, optional focus requester.
+ */
+@Composable
+fun GlassDialogField(
+ value: String,
+ onValueChange: (String) -> Unit,
+ modifier: Modifier = Modifier,
+ placeholder: String = "",
+ singleLine: Boolean = true,
+ keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
+ keyboardActions: androidx.compose.foundation.text.KeyboardActions = androidx.compose.foundation.text.KeyboardActions.Default,
+ visualTransformation: VisualTransformation = VisualTransformation.None,
+ textStyle: TextStyle = TextStyle(fontSize = 16.sp),
+ minHeight: Dp = 48.dp,
+ focusRequester: FocusRequester? = null
+) {
+ val isDark = LocalIsDarkMode.current
+ val ink = LiquidGlassColors.text(isDark)
+ val shape = RoundedCornerShape(16.dp)
+ Box(
+ modifier
+ .heightIn(min = minHeight)
+ .clip(shape)
+ .background(glassDialogPlatter(isDark))
+ .border(1.dp, ink.copy(alpha = if (isDark) 0.10f else 0.08f), shape)
+ .padding(horizontal = 14.dp, vertical = 12.dp),
+ contentAlignment = Alignment.CenterStart
+ ) {
+ if (value.isEmpty() && placeholder.isNotEmpty()) {
+ BasicText(
+ placeholder,
+ style = textStyle.merge(TextStyle(color = LiquidGlassColors.secondary(isDark))),
+ maxLines = if (singleLine) 1 else Int.MAX_VALUE
+ )
+ }
+ BasicTextField(
+ value = value,
+ onValueChange = onValueChange,
+ singleLine = singleLine,
+ textStyle = textStyle.merge(TextStyle(color = ink)),
+ cursorBrush = SolidColor(LiquidGlassColors.Blue),
+ keyboardOptions = keyboardOptions,
+ keyboardActions = keyboardActions,
+ visualTransformation = visualTransformation,
+ modifier = Modifier
+ .fillMaxWidth()
+ .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier)
+ )
+ }
+}
+
+/**
+ * Segmented choice for [GlassDialog] content: a solid capsule track with a vivid sliding thumb
+ * (the "Get it" tint), springing between segments. Solid on purpose — a glass thumb inside a glass
+ * panel would refract the page behind the dialog, not the panel.
+ */
+@Composable
+fun GlassDialogSegmented(
+ options: List<String>,
+ selectedIndex: Int,
+ onSelect: (Int) -> Unit,
+ modifier: Modifier = Modifier,
+ accent: Color = LiquidGlassColors.Blue
+) {
+ if (options.isEmpty()) return
+ val isDark = LocalIsDarkMode.current
+ val ink = LiquidGlassColors.text(isDark)
+ val haptics = LocalHapticFeedback.current
+ val index = selectedIndex.coerceIn(0, options.lastIndex)
+ val thumb by animateFloatAsState(index.toFloat(), GlassMotion.morph(), label = "dialogSegment")
+ BoxWithConstraints(
+ modifier
+ .fillMaxWidth()
+ .height(46.dp)
+ .clip(RoundedCornerShape(50))
+ .background(glassDialogPlatter(isDark))
+ .padding(4.dp)
+ ) {
+ val segment = maxWidth / options.size
+ Box(
+ Modifier
+ .width(segment)
+ .fillMaxHeight()
+ .graphicsLayer { translationX = thumb * segment.toPx() }
+ .clip(RoundedCornerShape(50))
+ .background(accent)
+ .background(Brush.verticalGradient(listOf(Color.White.copy(0.22f), Color.Transparent)))
+ )
+ Row(Modifier.fillMaxSize()) {
+ options.forEachIndexed { i, label ->
+ val sel = i == index
+ val labelColor by animateColorAsState(if (sel) Color.White else ink, label = "segInk$i")
+ Box(
+ Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ .clip(RoundedCornerShape(50))
+ .clickable(
+ interactionSource = remember { MutableInteractionSource() },
+ indication = null
+ ) {
+ if (i != index) {
+ haptics.performHapticFeedback(HapticFeedbackType.SegmentTick)
+ onSelect(i)
+ }
+ },
+ contentAlignment = Alignment.Center
+ ) {
+ BasicText(
+ label,
+ style = TextStyle(labelColor, 15.sp, if (sel) FontWeight.SemiBold else FontWeight.Medium),
+ maxLines = 1
+ )
+ }
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
index f910d56..180cb16 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
@@ -31,6 +31,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceIn
import androidx.compose.ui.util.fastRoundToInt
@@ -64,14 +65,16 @@ fun LiquidBottomTabs(
backdrop: Backdrop,
tabsCount: Int,
modifier: Modifier = Modifier,
+ barHeight: Dp = 64.dp,
+ surfaceColor: Color? = null,
content: @Composable RowScope.() -> Unit
) {
val isDarkMode = LocalIsDarkMode.current
val isLightTheme = !isDarkMode
val accentColor = LiquidGlassColors.Blue
- val containerColor =
- if (isLightTheme) Color(0xFFFAFAFA).copy(0.4f)
- else Color(0xFF121212).copy(0.4f)
+ val containerColor = surfaceColor ?: if (isLightTheme) Color(0xFFFAFAFA).copy(0.4f)
+ else Color(0xFF121212).copy(0.4f)
+ val contentHeight = (barHeight - 8.dp).coerceAtLeast(0.dp)
val tabsBackdrop = rememberLayerBackdrop()
@@ -185,7 +188,7 @@ fun LiquidBottomTabs(
onDrawSurface = { drawRect(containerColor) }
)
.then(interactiveHighlight.modifier)
- .height(64f.dp)
+ .height(barHeight)
.fillMaxWidth()
.padding(4f.dp),
verticalAlignment = Alignment.CenterVertically,
@@ -224,7 +227,7 @@ fun LiquidBottomTabs(
onDrawSurface = { drawRect(containerColor) }
)
.then(interactiveHighlight.modifier)
- .height(56f.dp)
+ .height(contentHeight)
.fillMaxWidth()
.padding(horizontal = 4f.dp)
.graphicsLayer(colorFilter = ColorFilter.tint(accentColor)),
@@ -290,7 +293,7 @@ fun LiquidBottomTabs(
drawRect(Color.White.copy(alpha = 0.04f * progress))
}
)
- .height(56f.dp)
+ .height(contentHeight)
.fillMaxWidth(1f / tabsCount)
)
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt
index 09b0460..986ac26 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt
@@ -1,5 +1,10 @@
package com.chethan616.clearpdf.ui.screen
+import androidx.compose.ui.graphics.graphicsLayer
+import com.kyant.backdrop.Backdrop
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.material.icons.rounded.Edit
import android.graphics.Bitmap
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
@@ -691,56 +696,27 @@ internal fun PdfContinuousPage(
selM.movableBounds()?.let { b ->
val density = LocalDensity.current
val gapPx = with(density) { 12.dp.toPx() }
- val barHpx = with(density) { 44.dp.toPx() }
- val barWpx = with(density) { 216.dp.toPx() }
+ val barHpx = with(density) { MarkupBarHeight.toPx() }
+ val barWpx = with(density) { MarkupBarWidth.toPx() }
val placeBelow = b.top < barHpx + gapPx
val by = (if (placeBelow) b.bottom + gapPx else b.top - barHpx - gapPx)
.coerceIn(0f, (csz.height - barHpx).coerceAtLeast(0f))
val bx = ((b.left + b.right) / 2f - barWpx / 2f)
.coerceIn(0f, (csz.width - barWpx).coerceAtLeast(0f))
- Row(
- Modifier
- .offset { IntOffset(bx.roundToInt(), by.roundToInt()) }
- .viewerGlass(backdrop, Color(0xD91C1F26), shape = { RoundedCornerShape(22.dp) })
- .padding(horizontal = 4.dp, vertical = 3.dp),
- verticalAlignment = Alignment.CenterVertically
- ) {
- BasicText(
- "Edit",
- style = TextStyle(Color.White, 13.sp, FontWeight.SemiBold),
- modifier = Modifier
- .clip(RoundedCornerShape(18.dp))
- .clickable {
- when (selM) {
- is PdfMarkup.TextBoxMarkup -> onEditAnnotation(selM.id)
- is PdfMarkup.NoteMarkup -> onEditAnnotation(selM.id)
- else -> onEditShape(selectedMarkupIndex)
- }
- }
- .padding(horizontal = 16.dp, vertical = 9.dp)
- )
- Box(Modifier.width(1.dp).height(20.dp).background(Color.White.copy(0.14f)))
- BasicText(
- "Delete",
- style = TextStyle(Color(0xFFFF6B6B), 13.sp, FontWeight.SemiBold),
- modifier = Modifier
- .clip(RoundedCornerShape(18.dp))
- .clickable { onDeleteMarkup(selectedMarkupIndex) }
- .padding(horizontal = 16.dp, vertical = 9.dp)
- )
- Box(Modifier.width(1.dp).height(20.dp).background(Color.White.copy(0.16f)))
- Icon(
- Icons.Rounded.Close,
- contentDescription = stringResource(R.string.done),
- tint = Color.White.copy(0.9f),
- modifier = Modifier
- .clip(CircleShape)
- .clickable { onSelectMarkup(-1) }
- .padding(8.dp)
- .size(16.dp)
- )
- }
+ MarkupActionBar(
+ backdrop = backdrop,
+ onEdit = {
+ when (selM) {
+ is PdfMarkup.TextBoxMarkup -> onEditAnnotation(selM.id)
+ is PdfMarkup.NoteMarkup -> onEditAnnotation(selM.id)
+ else -> onEditShape(selectedMarkupIndex)
+ }
+ },
+ onDelete = { onDeleteMarkup(selectedMarkupIndex) },
+ onDismiss = { onSelectMarkup(-1) },
+ modifier = Modifier.offset { IntOffset(bx.roundToInt(), by.roundToInt()) }
+ )
}
}
@@ -758,52 +734,112 @@ internal fun PdfContinuousPage(
} else rangeRect
val density = LocalDensity.current
val gapPx = with(density) { 10.dp.toPx() }
- val barHpx = with(density) { 44.dp.toPx() }
- val barWpx = with(density) { 224.dp.toPx() }
+ val barHpx = with(density) { MarkupBarHeight.toPx() }
+ val barWpx = with(density) { MarkupBarWidth.toPx() }
val placeBelow = anchorRect.top < barHpx + gapPx
val by = (if (placeBelow) anchorRect.bottom + gapPx else anchorRect.top - barHpx - gapPx)
.coerceIn(0f, (csz.height - barHpx).coerceAtLeast(0f))
val bx = ((anchorRect.left + anchorRect.right) / 2f - barWpx / 2f)
.coerceIn(0f, (csz.width - barWpx).coerceAtLeast(0f))
- Row(
- Modifier
- .offset { IntOffset(bx.roundToInt(), by.roundToInt()) }
- .viewerGlass(backdrop, Color(0xE522252A), shape = { RoundedCornerShape(14.dp) })
- .padding(horizontal = 2.dp, vertical = 2.dp),
- verticalAlignment = Alignment.CenterVertically
- ) {
- // Same Edit affordance as shapes/text/notes — opens the shared recolor
- // popover (ShapeEditorPopup handles highlight/underline/strike too).
- BasicText(
- "Edit",
- style = TextStyle(Color(0xFFECECEC), 13.sp, FontWeight.Medium),
- modifier = Modifier
- .clip(RoundedCornerShape(6.dp))
- .clickable { onEditShape(selectedMarkupIndex) }
- .padding(horizontal = 16.dp, vertical = 10.dp)
- )
- BasicText(
- "Delete",
- style = TextStyle(Color(0xFFEF5350), 13.sp, FontWeight.Medium),
- modifier = Modifier
- .clip(RoundedCornerShape(6.dp))
- .clickable { onDeleteMarkup(selectedMarkupIndex) }
- .padding(horizontal = 16.dp, vertical = 10.dp)
- )
- Box(Modifier.width(1.dp).height(20.dp).background(Color.White.copy(0.16f)))
- Icon(
- Icons.Rounded.Close,
- contentDescription = stringResource(R.string.done),
- tint = Color.White.copy(0.9f),
- modifier = Modifier
- .clip(CircleShape)
- .clickable { onSelectMarkup(-1) }
- .padding(8.dp)
- .size(16.dp)
- )
- }
+ MarkupActionBar(
+ backdrop = backdrop,
+ onEdit = { onEditShape(selectedMarkupIndex) },
+ onDelete = { onDeleteMarkup(selectedMarkupIndex) },
+ onDismiss = { onSelectMarkup(-1) },
+ modifier = Modifier.offset { IntOffset(bx.roundToInt(), by.roundToInt()) }
+ )
}
}
}
}
+
+private val MarkupBarWidth = 236.dp
+private val MarkupBarHeight = 48.dp
+
+/**
+ * Contextual Edit / Delete / dismiss capsule for a selected markup (shape, text box, note, text
+ * highlight/underline/strike). Same frosted material and theme ink as the selection toolbar and the
+ * dialogs, instead of the old near-opaque dark slab with hard-coded English labels. Dismissal also
+ * works by tapping anywhere else in the viewer or pressing Back.
+ */
+@Composable
+private fun MarkupActionBar(
+ backdrop: Backdrop,
+ onEdit: () -> Unit,
+ onDelete: () -> Unit,
+ onDismiss: () -> Unit,
+ modifier: Modifier = Modifier
+) {
+ val isDark = com.chethan616.clearpdf.ui.theme.LocalIsDarkMode.current
+ val ink = com.chethan616.clearpdf.ui.theme.LiquidGlassColors.text(isDark)
+ val red = com.chethan616.clearpdf.ui.theme.LiquidGlassColors.Red
+ val haptics = androidx.compose.ui.platform.LocalHapticFeedback.current
+ var shown by remember { mutableStateOf(false) }
+ LaunchedEffect(Unit) { shown = true }
+ val pop by androidx.compose.animation.core.animateFloatAsState(
+ if (shown) 1f else 0f,
+ com.chethan616.clearpdf.ui.components.GlassMotion.pop(),
+ label = "markupBarPop"
+ )
+ Row(
+ modifier
+ .width(MarkupBarWidth)
+ .height(MarkupBarHeight)
+ .graphicsLayer {
+ alpha = pop.coerceIn(0f, 1f)
+ val sc = 0.9f + 0.1f * pop
+ scaleX = sc; scaleY = sc
+ }
+ .viewerGlass(
+ backdrop,
+ com.chethan616.clearpdf.ui.components.glassDialogSurface(isDark),
+ shape = { com.kyant.shapes.Capsule }
+ )
+ .padding(horizontal = 4.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ MarkupBarItem(Icons.Rounded.Edit, stringResource(R.string.edit), ink, Modifier.weight(1f)) {
+ haptics.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.ContextClick)
+ onEdit()
+ }
+ Box(Modifier.width(1.dp).height(22.dp).background(ink.copy(0.12f)))
+ MarkupBarItem(Icons.Rounded.Delete, stringResource(R.string.delete), red, Modifier.weight(1f)) {
+ haptics.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress)
+ onDelete()
+ }
+ Box(Modifier.width(1.dp).height(22.dp).background(ink.copy(0.12f)))
+ Box(
+ Modifier
+ .size(40.dp)
+ .clip(CircleShape)
+ .clickable(onClick = onDismiss),
+ contentAlignment = Alignment.Center
+ ) {
+ Icon(Icons.Rounded.Close, stringResource(R.string.done), Modifier.size(18.dp), ink.copy(0.85f))
+ }
+ }
+}
+
+@Composable
+private fun MarkupBarItem(
+ icon: androidx.compose.ui.graphics.vector.ImageVector,
+ label: String,
+ color: Color,
+ modifier: Modifier = Modifier,
+ onClick: () -> Unit
+) {
+ Row(
+ modifier
+ .fillMaxHeight()
+ .padding(vertical = 4.dp)
+ .clip(com.kyant.shapes.Capsule)
+ .clickable(onClick = onClick)
+ .padding(horizontal = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.CenterHorizontally)
+ ) {
+ Icon(icon, null, Modifier.size(17.dp), color)
+ BasicText(label, style = TextStyle(color, 14.sp, FontWeight.SemiBold), maxLines = 1)
+ }
+}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfPageScrubber.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfPageScrubber.kt
index 5e9eb97..0c43b75 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfPageScrubber.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfPageScrubber.kt
@@ -44,6 +44,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
@@ -88,9 +90,22 @@ internal fun PageScrubber(
*/
onDraggingChange: (Boolean) -> Unit = {},
isScrolling: Boolean = false,
+ darkPageAppearance: Boolean = false,
modifier: Modifier = Modifier
) {
- val isDark = LocalIsDarkMode.current
+ val isDark = LocalIsDarkMode.current || darkPageAppearance
+ val pageColorFilter = remember(darkPageAppearance) {
+ if (!darkPageAppearance) null else ColorFilter.colorMatrix(
+ ColorMatrix(
+ floatArrayOf(
+ -1f, 0f, 0f, 0f, 255f,
+ 0f, -1f, 0f, 0f, 255f,
+ 0f, 0f, -1f, 0f, 255f,
+ 0f, 0f, 0f, 1f, 0f
+ )
+ )
+ )
+ }
val view = LocalView.current
val accent = Color(0xFF0A84FF)
// Idle thumb: soft light blue — visible on both themes, not harsh like pure white.
@@ -242,7 +257,8 @@ internal fun PageScrubber(
bitmap = shown.asImageBitmap(),
contentDescription = stringResource(R.string.preview_page, dragPage + 1),
contentScale = ContentScale.Fit,
- modifier = Modifier.fillMaxSize()
+ modifier = Modifier.fillMaxSize(),
+ colorFilter = pageColorFilter
)
} else {
// Nothing rendered yet at all → a faint spinner (only on the very first preview).
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfSearchBar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfSearchBar.kt
index d421704..b6afde9 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfSearchBar.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfSearchBar.kt
@@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
@@ -98,13 +99,11 @@ internal fun PdfSearchBar(
}
)
- // 40 dp and `surface`, matching the top bar's circles exactly. `field` is only 6-10% alpha,
- // which sets no value of its own and leaves the button refracting whatever is behind it —
- // the same reason single-page chrome went invisible.
+ // 40 dp, no fill: the top bar's circles exactly (pure refraction, adaptive ink). A tinted
+ // fill here made the find controls read as grey slabs under clear glass up top.
LiquidIconButton(
onClick = onPrevMatch,
backdrop = backdrop,
- surfaceColor = surface,
modifier = Modifier.size(FindBarButtonSize)
) {
Icon(Icons.Rounded.KeyboardArrowUp, stringResource(R.string.previous), Modifier.size(20.dp), fg)
@@ -112,18 +111,18 @@ internal fun PdfSearchBar(
LiquidIconButton(
onClick = onNextMatch,
backdrop = backdrop,
- surfaceColor = surface,
modifier = Modifier.size(FindBarButtonSize)
) {
Icon(Icons.Rounded.KeyboardArrowDown, stringResource(R.string.next), Modifier.size(20.dp), fg)
}
+ val closeTint = if (fg.luminance() > 0.5f) Color(0xFFD78A92) else Color(0xFFA84D58)
LiquidIconButton(
onClick = onClose,
backdrop = backdrop,
- surfaceColor = Color(0xFFEF5350).copy(0.22f),
- modifier = Modifier.size(FindBarButtonSize)
+ modifier = Modifier.size(FindBarButtonSize),
+ surfaceColor = closeTint.copy(alpha = 0.12f)
) {
- CloseCrossIcon(Modifier.size(13.dp), fg)
+ CloseCrossIcon(Modifier.size(13.dp), closeTint)
}
}
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
index c56e203..a485435 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
@@ -38,8 +38,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.icons.Icons
@@ -49,7 +51,8 @@ import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.CropSquare
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.Edit
-import androidx.compose.material.icons.rounded.MoreHoriz
+import androidx.compose.material.icons.rounded.Pause
+import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.material.icons.rounded.FormatListNumbered
import androidx.compose.material.icons.rounded.Gesture
import androidx.compose.material.icons.rounded.RadioButtonUnchecked
@@ -61,7 +64,8 @@ import androidx.compose.material.icons.rounded.SwapVert
import androidx.compose.material.icons.rounded.Undo
import androidx.compose.material.icons.rounded.ZoomIn
import androidx.compose.material.icons.rounded.ZoomOut
-import androidx.compose.material.icons.rounded.UploadFile
+import androidx.compose.material.icons.rounded.IosShare
+import androidx.compose.material.icons.rounded.Comment
import androidx.compose.material3.Icon
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
@@ -132,7 +136,7 @@ internal fun PdfViewerBottomToolbar(
drawingToolActive: Boolean,
showFindBar: Boolean,
showSignaturePad: Boolean,
- quickActionsVisible: Boolean,
+ autoScrollActive: Boolean,
activeImageId: Long?,
currentColor: Color,
currentColorLong: Long,
@@ -167,7 +171,7 @@ internal fun PdfViewerBottomToolbar(
onOpenExportedFile: () -> Unit,
onOpenAnotherPdf: () -> Unit,
onShareDocument: () -> Unit,
- onOpenQuickActions: () -> Unit,
+ onToggleAutoScroll: () -> Unit,
onEditorOpenChanged: (Boolean) -> Unit = {},
// Same purpose as [onEditorOpenChanged]: a long-press on the share capsule is a gesture the
// viewer cannot see, so without this the 5s chrome auto-hide fires mid-hold and takes the button
@@ -198,6 +202,7 @@ internal fun PdfViewerBottomToolbar(
// export-feedback strip): those are dense rows of controls that need a plate to sit on, and they
// cover the document rather than floating over it.
val pillGlass = Color.Transparent
+ val usePresentationDock = docKind == DocKind.Ppt
val showDrawTools = drawingToolActive
val showImageTools = activeTool == PdfEditTool.Image && activeImageId != null
@@ -228,13 +233,12 @@ internal fun PdfViewerBottomToolbar(
// Collapsed by default (just the "Editor Tools" pill + "Open PDF" circle). Tapping
// the pill expands the tool set above it. Image selection auto-expands so its tools show.
var editorOpen by remember { mutableStateOf(false) }
- val quickActionsOpen = quickActionsVisible
// Idle: the tool panels cover the FULL width (scale 1). While the share capsule is morphed up,
// the panels above the Editor-Tools pill COMPRESS horizontally toward the left (scaleX), freeing
// room for the cylinder — the whole pill + its buttons shrink together, so nothing is cut.
var shareActive by remember { mutableStateOf(false) }
val toolCompress by animateFloatAsState(
- if (shareActive) 0.84f else 1f,
+ if (shareActive) if (usePresentationDock) 0.68f else 0.84f else 1f,
// Bounce, matching the share capsule's own morph — both now run on GlassMotion.morph(), so the
// pill springs shut (and back open) with the same weight the cylinder has instead of deflating
// limply beside it. Safe to overshoot because this drives `scaleX`, a DRAW-time property: no
@@ -243,8 +247,8 @@ internal fun PdfViewerBottomToolbar(
label = "toolCompress"
)
// Tell the viewer when the Editor Tools panel is open so it won't auto-hide the chrome.
- LaunchedEffect(editorOpen, quickActionsOpen, showSignaturePad) {
- onEditorOpenChanged(editorOpen || quickActionsOpen || showSignaturePad)
+ LaunchedEffect(editorOpen, showSignaturePad) {
+ onEditorOpenChanged(editorOpen || showSignaturePad)
}
// Any active tool implies the editor is open (survives the chrome auto-hiding/returning).
LaunchedEffect(activeTool, activeImageId) {
@@ -343,8 +347,11 @@ internal fun PdfViewerBottomToolbar(
)
drawTools.forEach { (tool, icon, labelRes) ->
val active = activeTool == tool
+ // Inactive tools are clear glass with adaptive ink, like the top
+ // bar's circles; `chip` (a 74% near-black on dark pages) made them
+ // read as heavy black discs. The active tool fills with the ink.
val surf by animateColorAsState(
- if (active) currentColor.copy(0.95f) else chip,
+ if (active) currentColor.copy(0.95f) else Color.Transparent,
tween(150), label = "toolSurface"
)
val ink by animateColorAsState(if (active) Color.White else fg, tween(150), label = "toolInk")
@@ -359,7 +366,6 @@ internal fun PdfViewerBottomToolbar(
LiquidIconButton(
onClick = onUndo,
backdrop = backdrop,
- surfaceColor = chip,
modifier = Modifier.size(40.dp)
) { Icon(Icons.Rounded.Undo, stringResource(R.string.viewer_undo), Modifier.size(19.dp), fg.copy(if (canUndo) 1f else 0.35f)) }
LiquidIconButton(
@@ -434,7 +440,7 @@ internal fun PdfViewerBottomToolbar(
if (showDrawTools) {
listOf("S" to 3f, "M" to 6f, "L" to 11f, "XL" to 18f).forEach { (label, w) ->
val sel = currentStrokeWidth == w
- val surf by animateColorAsState(if (sel) currentColor.copy(0.85f) else chip, tween(150), label = "sizeSurface")
+ val surf by animateColorAsState(if (sel) currentColor.copy(0.85f) else Color.Transparent, tween(150), label = "sizeSurface")
val ink by animateColorAsState(if (sel) Color.White else fg, tween(150), label = "sizeInk")
LiquidButton(onClick = { onSetStrokeWidth(w) }, backdrop = backdrop, surfaceColor = surf) {
BasicText(label, style = TextStyle(ink, 12.sp, FontWeight.Medium))
@@ -729,98 +735,146 @@ internal fun PdfViewerBottomToolbar(
}
}
- // ── Collapsed home bar: one "Editor Tools" pill (expands the tools above it)
- // + a compact circular "Open another PDF" button. Hidden while a sub-tool is
- // active so that focused mode shows ONLY the sub-toolbar (one panel).
+ // ── Compact reader dock: auto-scroll, annotations, and ShareMorph in one glass capsule.
AnimatedVisibility(
- // Same `selectorGate` as the tool chips above, so the blue "Editor Tools" pill fades out
- // in lockstep with them — "both pills at the same time" — before the sub-toolbar arrives.
+ // Same `selectorGate` as the tool chips above, so the controls fade out together
+ // before the focused sub-toolbar arrives.
visible = selectorGate && !showFindBar && !showSignaturePad,
enter = fadeIn(tween(180)),
- exit = fadeOut(tween(FaceHandoffMillis))
+ exit = fadeOut(tween(FaceHandoffMillis)),
+ modifier = Modifier.align(Alignment.CenterHorizontally)
) {
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(10.dp),
- // Bottom-align so the "Editor Tools" pill stays pinned to the toolbar's base while
- // the share capsule (whose real layout height grows) extends UPWARD only — the
- // toolbar column is bottom-anchored on screen, so added height goes up.
- verticalAlignment = Alignment.Bottom
- ) {
- LiquidButton(
- onClick = {
- editorOpen = !editorOpen
- if (!editorOpen) onSetActiveTool(PdfEditTool.None)
- },
- backdrop = backdrop,
- tint = if (editorOpen) accent else Color.Unspecified,
- surfaceColor = if (editorOpen) Color.Unspecified
- else if (readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.22f) else pillGlass,
- modifier = Modifier.weight(1f)
+ if (usePresentationDock) {
+ Box(
+ Modifier.widthIn(max = 320.dp).fillMaxWidth(),
+ contentAlignment = Alignment.BottomCenter
) {
- Row(
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- verticalAlignment = Alignment.CenterVertically,
- modifier = Modifier.padding(vertical = 8.dp)
+ // Keep the background at its resting height. The morph button is a sibling so its
+ // capsule can grow upward without clipping the glass or re-blurring a moving panel.
+ Box(
+ Modifier
+ .fillMaxWidth()
+ .height(64.dp)
+ .align(Alignment.BottomCenter)
+ .viewerGlass(backdrop, pillGlass, shape = { com.kyant.shapes.Capsule })
+ )
+ Row(
+ Modifier.fillMaxWidth().height(64.dp).padding(horizontal = 8.dp),
+ horizontalArrangement = Arrangement.SpaceEvenly,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ LiquidIconButton(
+ onClick = onToggleAutoScroll,
+ backdrop = backdrop,
+ modifier = Modifier.size(52.dp),
+ tint = if (autoScrollActive) LiquidGlassColors.Green else Color.Unspecified
) {
- Icon(Icons.Rounded.Edit, null, Modifier.size(18.dp), if (editorOpen) Color.White else fg)
- BasicText(
- stringResource(R.string.viewer_editor_tools),
- style = TextStyle(if (editorOpen) Color.White else fg, 14.sp, FontWeight.SemiBold),
- maxLines = 1
+ Icon(
+ if (autoScrollActive) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,
+ stringResource(if (autoScrollActive) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),
+ Modifier.size(24.dp),
+ if (autoScrollActive) Color.White else fg
)
}
- }
- // ShareMorph overlays the final 52 dp slot. Keep this separate glass action
- // immediately beside it so neither control obscures the other.
- Box(Modifier.width(52.dp).height(52.dp), contentAlignment = Alignment.Center) {
LiquidIconButton(
- onClick = onOpenQuickActions,
+ onClick = {
+ editorOpen = !editorOpen
+ if (!editorOpen) onSetActiveTool(PdfEditTool.None)
+ },
backdrop = backdrop,
- modifier = Modifier.size(40.dp),
- tint = if (quickActionsOpen) accent else Color.Unspecified,
- surfaceColor = if (quickActionsOpen) accent.copy(alpha = 0.22f) else Color.Unspecified
+ modifier = Modifier.size(52.dp),
+ tint = if (editorOpen) accent else Color.Unspecified,
+ surfaceColor = if (!editorOpen && readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.16f) else Color.Unspecified
) {
- Icon(
- Icons.Rounded.MoreHoriz,
- stringResource(R.string.viewer_quick_actions),
- Modifier.size(22.dp),
- if (quickActionsOpen) Color.White else fg
- )
+ Icon(Icons.Rounded.Comment, stringResource(R.string.viewer_editor_tools), Modifier.size(24.dp), if (editorOpen) Color.White else fg)
}
+ // Reserve the final slot for the morphing share action layered over this row.
+ Spacer(Modifier.size(52.dp))
+ }
+ ShareMorphButton(
+ backdrop = backdrop,
+ glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.16f) else pillGlass,
+ fg = fg,
+ onOpen = onShareDocument,
+ onShare = onShareDocument,
+ onShareModeChanged = { shareActive = it; onShareHoldChanged(it) },
+ idleIcon = Icons.Rounded.IosShare,
+ idleContentDesc = stringResource(R.string.viewer_share_document),
+ modifier = Modifier.align(Alignment.BottomEnd).offset(x = (-33).dp)
+ )
+ }
+ } else {
+ // Restore the reader controls used by PDFs, Word, and other document types.
+ Row(
+ Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(10.dp),
+ verticalAlignment = Alignment.Bottom
+ ) {
+ Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {
+ LiquidIconButton(
+ onClick = {
+ editorOpen = !editorOpen
+ if (!editorOpen) onSetActiveTool(PdfEditTool.None)
+ },
+ backdrop = backdrop,
+ modifier = Modifier.size(52.dp),
+ tint = if (editorOpen) accent else Color.Unspecified,
+ surfaceColor = if (!editorOpen && readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.22f) else Color.Unspecified
+ ) {
+ Icon(Icons.Rounded.Edit, stringResource(R.string.viewer_editor_tools), Modifier.size(21.dp), if (editorOpen) Color.White else fg)
+ }
+ }
+ Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {
+ LiquidIconButton(
+ onClick = onToggleAutoScroll,
+ backdrop = backdrop,
+ modifier = Modifier.size(52.dp),
+ tint = if (autoScrollActive) LiquidGlassColors.Green else Color.Unspecified
+ ) {
+ Icon(
+ if (autoScrollActive) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,
+ stringResource(if (autoScrollActive) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),
+ Modifier.size(21.dp),
+ if (autoScrollActive) Color.White else fg
+ )
+ }
+ }
+ Spacer(Modifier.weight(1f))
+ Spacer(Modifier.size(52.dp))
}
- Spacer(Modifier.width(52.dp).height(52.dp))
}
}
}
- // ── File actions OVERLAY ───────────────────────────────────────────
- // The morph capsule owns both reader actions: tap to open another file, hold and swipe up to share.
- AnimatedVisibility(
- visible = selectorGate && !showFindBar && !showSignaturePad,
- enter = fadeIn(tween(180)),
- exit = fadeOut(tween(FaceHandoffMillis)),
- modifier = Modifier.align(Alignment.BottomEnd).zIndex(3f)
- ) {
- ShareMorphButton(
- backdrop = backdrop,
- glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.2f) else pillGlass,
- fg = fg,
- onOpen = onOpenAnotherPdf,
- onShare = onShareDocument,
- onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }
- )
+ if (!usePresentationDock) {
+ // PDFs and the other readers keep the original ShareMorph placement and open-file tap.
+ AnimatedVisibility(
+ visible = selectorGate && !showFindBar && !showSignaturePad,
+ enter = fadeIn(tween(180)),
+ exit = fadeOut(tween(FaceHandoffMillis)),
+ modifier = Modifier.align(Alignment.BottomEnd).zIndex(3f)
+ ) {
+ ShareMorphButton(
+ backdrop = backdrop,
+ glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.2f) else pillGlass,
+ fg = fg,
+ onOpen = onOpenAnotherPdf,
+ onShare = onShareDocument,
+ onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }
+ )
+ }
}
GlassGuideCallout(
visible = readerTourStep == 0,
title = stringResource(R.string.tour_reader_tools_title),
- message = stringResource(R.string.tour_reader_tools_message),
+ message = stringResource(if (usePresentationDock) R.string.tour_reader_tools_ppt_message else R.string.tour_reader_tools_message),
backdrop = backdrop,
isLastStep = false,
onNext = onReaderTourNext,
onSkip = onReaderTourDismiss,
- modifier = Modifier.align(Alignment.BottomStart).padding(start = 12.dp, bottom = 116.dp).zIndex(5f)
+ modifier = if (usePresentationDock) Modifier.align(Alignment.BottomCenter).padding(start = 12.dp, end = 12.dp, bottom = 116.dp).zIndex(5f)
+ else Modifier.align(Alignment.BottomStart).padding(start = 12.dp, bottom = 116.dp).zIndex(5f)
)
GlassGuideCallout(
visible = readerTourStep == 1,
@@ -831,7 +885,8 @@ internal fun PdfViewerBottomToolbar(
arrowAtEnd = true,
onNext = onReaderTourNext,
onSkip = onReaderTourDismiss,
- modifier = Modifier.align(Alignment.BottomEnd).padding(end = 12.dp, bottom = 116.dp).zIndex(5f)
+ modifier = if (usePresentationDock) Modifier.align(Alignment.BottomCenter).padding(start = 12.dp, end = 12.dp, bottom = 116.dp).zIndex(5f)
+ else Modifier.align(Alignment.BottomEnd).padding(end = 12.dp, bottom = 116.dp).zIndex(5f)
)
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt
index 39cf57e..4821e41 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt
@@ -1,5 +1,22 @@
package com.chethan616.clearpdf.ui.screen
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.height
+import com.chethan616.clearpdf.ui.theme.LocalIsDarkMode
+import com.chethan616.clearpdf.ui.components.glassDialogPlatter
+import com.chethan616.clearpdf.ui.components.glassDialogInkSoft
+import com.chethan616.clearpdf.ui.components.glassDialogInk
+import com.chethan616.clearpdf.ui.components.GlassDialogSegmented
+import com.chethan616.clearpdf.ui.components.GlassDialogField
+import com.chethan616.clearpdf.ui.components.GlassDialogAction
+import com.chethan616.clearpdf.ui.components.GlassDialog
+import androidx.compose.animation.shrinkVertically
+import androidx.compose.animation.expandVertically
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.text.input.PasswordVisualTransformation
+import androidx.compose.ui.text.input.ImeAction
+import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.Spring
@@ -97,163 +114,127 @@ internal fun LiquidPageJumpPopup(
currentPage: Int,
pageCount: Int,
backdrop: LayerBackdrop,
- uiSensor: UISensor,
- // Adaptive chrome palette (dark ink on light pages, white on dark pages).
- fg: Color,
- fgSoft: Color,
- surface: Color,
- field: Color,
bookmarkedPages: List<Int>,
onDismiss: () -> Unit,
onJumpToPage: (Int) -> Unit,
onToggleCurrentBookmark: () -> Unit,
onRemoveBookmark: (Int) -> Unit
) {
+ // The app's one dialog: GlassDialog (the "Save changes?" card), so every reader dialog shares its
+ // entrance, scrim, material and action pills. Its ink follows the app theme, never the page under
+ // it — the old popup took its text colour from the page and its button fill from elsewhere, which
+ // is how "Cancel" ended up white-on-white.
var targetText by remember(visible, currentPage) { mutableStateOf((currentPage + 1).toString()) }
-
- Box(Modifier.fillMaxSize()) {
- // Dimming scrim — tap outside to dismiss.
- AnimatedVisibility(
- visible = visible,
- enter = fadeIn(tween(200)),
- exit = fadeOut(tween(180)),
- modifier = Modifier.fillMaxSize()
+ val focus = remember { FocusRequester() }
+ val ink = glassDialogInk()
+ val soft = glassDialogInkSoft()
+ val marked = currentPage in bookmarkedPages
+ fun go() {
+ targetText.toIntOrNull()?.minus(1)?.coerceIn(0, (pageCount - 1).coerceAtLeast(0))?.let(onJumpToPage)
+ }
+ LaunchedEffect(visible) {
+ if (visible) { delay(260); runCatching { focus.requestFocus() } }
+ }
+ GlassDialog(
+ visible = visible,
+ onDismiss = onDismiss,
+ backdrop = backdrop,
+ title = stringResource(R.string.viewer_jump_to_page),
+ actions = {
+ GlassDialogAction(stringResource(R.string.cancel), onDismiss)
+ GlassDialogAction(stringResource(R.string.viewer_go), { go() }, primary = true)
+ }
+ ) {
+ Row(
+ Modifier.fillMaxWidth(),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
- Box(
- Modifier
- .fillMaxSize()
- .background(Color.Black.copy(0.45f))
- .pointerInput(Unit) { detectTapGestures { onDismiss() } }
+ GlassDialogField(
+ value = targetText,
+ onValueChange = { targetText = it.filter { c -> c.isDigit() }.take(6) },
+ modifier = Modifier.weight(1f),
+ textStyle = TextStyle(fontSize = 22.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center),
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Go),
+ keyboardActions = KeyboardActions(onGo = { go() }),
+ minHeight = 54.dp,
+ focusRequester = focus
)
+ BasicText("/ $pageCount", style = TextStyle(soft, 18.sp, FontWeight.Medium))
}
-
- // Glass popup panel — springy but non-bouncy scale-in.
- AnimatedVisibility(
- visible = visible,
- enter = fadeIn(tween(220)) +
- scaleIn(
- initialScale = 0.85f,
- animationSpec = spring(dampingRatio = 0.72f, stiffness = Spring.StiffnessMediumLow)
- ),
- exit = fadeOut(tween(140)) + scaleOut(targetScale = 0.9f, animationSpec = tween(150)),
- modifier = Modifier.align(Alignment.Center).imePadding()
- ) {
+ Spacer(Modifier.height(12.dp))
+ DialogRow(
+ icon = if (marked) Icons.Rounded.Bookmark else Icons.Rounded.BookmarkBorder,
+ iconTint = if (marked) LiquidGlassColors.Orange else ink,
+ label = stringResource(if (marked) R.string.viewer_bookmark_remove else R.string.viewer_bookmark_add),
+ onClick = onToggleCurrentBookmark
+ )
+ if (bookmarkedPages.isNotEmpty()) {
+ Spacer(Modifier.height(8.dp))
Column(
- Modifier
- .widthIn(max = 300.dp)
- .fillMaxWidth(0.78f)
- .liquidGlassPanel(backdrop, uiSensor, surface)
- .padding(22.dp),
- verticalArrangement = Arrangement.spacedBy(18.dp),
- horizontalAlignment = Alignment.CenterHorizontally
+ Modifier.fillMaxWidth().heightIn(max = 168.dp).verticalScroll(rememberScrollState()),
+ verticalArrangement = Arrangement.spacedBy(6.dp)
) {
- BasicText(
- stringResource(R.string.viewer_jump_to_page),
- style = TextStyle(fg, 16.sp, fontWeight = FontWeight.Bold)
- )
-
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- BasicTextField(
- value = targetText,
- onValueChange = { targetText = it.filter { c -> c.isDigit() } },
- textStyle = TextStyle(fg, 18.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center),
- singleLine = true,
- cursorBrush = SolidColor(fg),
- modifier = Modifier
- .width(96.dp)
- .clip(RoundedCornerShape(14.dp))
- .background(field)
- .border(1.dp, fg.copy(0.22f), RoundedCornerShape(14.dp))
- .padding(horizontal = 12.dp, vertical = 12.dp)
- )
-
- BasicText(
- "/ $pageCount",
- style = TextStyle(fgSoft, 16.sp, fontWeight = FontWeight.Medium)
- )
- }
-
- LiquidButton(
- onClick = onToggleCurrentBookmark,
- backdrop = backdrop,
- surfaceColor = field,
- modifier = Modifier.fillMaxWidth()
- ) {
- Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- Icon(
- if (currentPage in bookmarkedPages) Icons.Rounded.Bookmark else Icons.Rounded.BookmarkBorder,
- null,
- Modifier.size(17.dp),
- if (currentPage in bookmarkedPages) LiquidGlassColors.Blue else fg
- )
- BasicText(
- stringResource(if (currentPage in bookmarkedPages) R.string.viewer_bookmark_remove else R.string.viewer_bookmark_add),
- style = TextStyle(fg, 13.sp, FontWeight.Medium)
- )
- }
- }
-
- if (bookmarkedPages.isNotEmpty()) {
- Column(
- Modifier.fillMaxWidth().heightIn(max = 132.dp).verticalScroll(rememberScrollState()),
- verticalArrangement = Arrangement.spacedBy(6.dp)
- ) {
- bookmarkedPages.forEach { page ->
- Row(
- Modifier.fillMaxWidth(),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(6.dp)
+ bookmarkedPages.forEach { page ->
+ DialogRow(
+ icon = Icons.Rounded.Bookmark,
+ iconTint = LiquidGlassColors.Orange,
+ label = stringResource(R.string.viewer_bookmark_page, page + 1),
+ onClick = { onJumpToPage(page) },
+ trailing = {
+ Box(
+ Modifier
+ .size(32.dp)
+ .clip(CircleShape)
+ .clickable { onRemoveBookmark(page) },
+ contentAlignment = Alignment.Center
) {
- LiquidButton(
- onClick = { onJumpToPage(page) },
- backdrop = backdrop,
- surfaceColor = field,
- modifier = Modifier.weight(1f)
- ) {
- BasicText(
- stringResource(R.string.viewer_bookmark_page, page + 1),
- style = TextStyle(fg, 12.sp, FontWeight.Medium)
- )
- }
- LiquidButton(onClick = { onRemoveBookmark(page) }, backdrop = backdrop, surfaceColor = field) {
- Icon(Icons.Rounded.Close, stringResource(R.string.viewer_bookmark_remove), Modifier.size(15.dp), fgSoft)
- }
+ Icon(Icons.Rounded.Close, stringResource(R.string.viewer_bookmark_remove), Modifier.size(16.dp), soft)
}
}
- }
- }
-
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.End)
- ) {
- LiquidButton(onClick = onDismiss, backdrop = backdrop, surfaceColor = field) {
- BasicText(stringResource(R.string.cancel), style = TextStyle(fg, 13.sp, FontWeight.Medium))
- }
- LiquidButton(
- onClick = {
- val p = targetText.toIntOrNull()?.minus(1)?.coerceIn(0, pageCount - 1)
- if (p != null) onJumpToPage(p)
- },
- backdrop = backdrop,
- tint = LiquidGlassColors.Blue
- ) {
- BasicText(stringResource(R.string.viewer_go), style = TextStyle(Color.White, 13.sp, FontWeight.Bold))
- }
+ )
}
}
}
}
}
+/** A tappable row on a solid dialog platter: icon, label, optional trailing control. */
+@Composable
+private fun DialogRow(
+ icon: ImageVector,
+ iconTint: Color,
+ label: String,
+ onClick: () -> Unit,
+ trailing: (@Composable () -> Unit)? = null
+) {
+ val isDark = LocalIsDarkMode.current
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .heightIn(min = 48.dp)
+ .clip(RoundedCornerShape(16.dp))
+ .background(glassDialogPlatter(isDark))
+ .clickable(onClick = onClick)
+ .padding(start = 14.dp, end = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(12.dp)
+ ) {
+ Icon(icon, null, Modifier.size(20.dp), iconTint)
+ BasicText(
+ label,
+ modifier = Modifier.weight(1f).padding(vertical = 12.dp),
+ style = TextStyle(LiquidGlassColors.text(isDark), 15.sp, FontWeight.Medium),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ trailing?.invoke()
+ }
+}
+
/**
- * Editor for an inserted text box or sticky note. Rendered IN-WINDOW (not a [Dialog])
- * so the glass panel samples the real page content instead of the wallpaper PNG.
- * Adaptive colours keep it readable over any page; fade-only so glass never re-blurs
- * mid-transition. Lifts above the keyboard via [imePadding].
+ * Editor for an inserted text box or sticky note, on the shared [GlassDialog] card (in-window, so the
+ * glass samples the real page). Theme ink, solid field, vivid Save.
*/
@Composable
internal fun AnnotationEditorDialog(
@@ -261,11 +242,6 @@ internal fun AnnotationEditorDialog(
initialText: String,
initialColor: Color,
backdrop: LayerBackdrop,
- uiSensor: UISensor,
- fg: Color,
- fgSoft: Color,
- surface: Color,
- field: Color,
onDismiss: () -> Unit,
onDelete: () -> Unit,
onSave: (String, Color) -> Unit
@@ -274,85 +250,30 @@ internal fun AnnotationEditorDialog(
var color by remember { mutableStateOf(initialColor) }
val focus = remember { FocusRequester() }
var shown by remember { mutableStateOf(false) }
- LaunchedEffect(Unit) { shown = true; delay(160); runCatching { focus.requestFocus() } }
-
- Box(Modifier.fillMaxSize()) {
- AnimatedVisibility(
- visible = shown,
- enter = fadeIn(tween(180)),
- exit = fadeOut(tween(140)),
- modifier = Modifier.fillMaxSize()
- ) {
- Box(
- Modifier
- .fillMaxSize()
- .background(Color.Black.copy(0.45f))
- .pointerInput(Unit) { detectTapGestures { onDismiss() } }
- )
- }
-
- AnimatedVisibility(
- visible = shown,
- enter = fadeIn(tween(200)),
- exit = fadeOut(tween(140)),
- modifier = Modifier.align(Alignment.Center).fillMaxWidth().imePadding()
- ) {
- Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
- Column(
- Modifier
- .fillMaxWidth(0.9f)
- .widthIn(max = 440.dp)
- .liquidGlassPanel(backdrop, uiSensor, surface)
- .padding(18.dp),
- verticalArrangement = Arrangement.spacedBy(14.dp)
- ) {
- BasicText(
- if (isNote) stringResource(R.string.anno_note_title) else stringResource(R.string.anno_text_title),
- style = TextStyle(fg, 16.sp, fontWeight = FontWeight.Bold)
- )
-
- Box(
- Modifier
- .fillMaxWidth()
- .heightIn(min = 54.dp)
- .clip(RoundedCornerShape(12.dp))
- .background(field)
- .padding(horizontal = 12.dp, vertical = 10.dp)
- ) {
- if (text.isEmpty()) {
- BasicText(
- stringResource(R.string.anno_hint),
- style = TextStyle(fgSoft, 14.sp)
- )
- }
- BasicTextField(
- value = text,
- onValueChange = { text = it },
- textStyle = TextStyle(fg, 14.sp),
- cursorBrush = SolidColor(fg),
- modifier = Modifier.fillMaxWidth().focusRequester(focus)
- )
- }
-
- // Colour picker — recolour the text / sticky note.
- AnnotationColorRow(selected = color, backdrop = backdrop, fgSoft = fgSoft, onPick = { color = it })
-
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(10.dp, Alignment.End),
- verticalAlignment = Alignment.CenterVertically
- ) {
- DestructiveGlassButton(stringResource(R.string.delete), onDelete, backdrop)
- LiquidButton(onClick = onDismiss, backdrop = backdrop, surfaceColor = field) {
- BasicText(stringResource(R.string.cancel), style = TextStyle(fg, 13.sp))
- }
- LiquidButton(onClick = { onSave(text, color) }, backdrop = backdrop, tint = LiquidGlassColors.Blue) {
- BasicText(stringResource(R.string.anno_save), style = TextStyle(Color.White, 13.sp, FontWeight.Bold))
- }
- }
- }
- }
+ LaunchedEffect(Unit) { shown = true; delay(260); runCatching { focus.requestFocus() } }
+
+ GlassDialog(
+ visible = shown,
+ onDismiss = onDismiss,
+ backdrop = backdrop,
+ title = if (isNote) stringResource(R.string.anno_note_title) else stringResource(R.string.anno_text_title),
+ actions = {
+ GlassDialogAction(stringResource(R.string.delete), onDelete, destructive = true)
+ GlassDialogAction(stringResource(R.string.cancel), onDismiss)
+ GlassDialogAction(stringResource(R.string.anno_save), { onSave(text, color) }, primary = true)
}
+ ) {
+ GlassDialogField(
+ value = text,
+ onValueChange = { text = it },
+ modifier = Modifier.fillMaxWidth(),
+ placeholder = stringResource(R.string.anno_hint),
+ singleLine = false,
+ minHeight = 96.dp,
+ focusRequester = focus
+ )
+ Spacer(Modifier.height(14.dp))
+ AnnotationColorRow(selected = color, backdrop = backdrop, fgSoft = glassDialogInkSoft(), onPick = { color = it })
}
}
@@ -360,13 +281,13 @@ internal fun AnnotationEditorDialog(
internal enum class ShareFormat { ORIGINAL, PDF }
/**
- * Share/export chooser, rendered in-window in the same glass family as [LiquidPageJumpPopup]. For a
- * converted document (a .docx opened as a PDF) it offers the original file *or* a PDF via a bouncy
- * [LiquidGlassDropdown]; when PDF is the target it can encrypt with a password. A plain PDF skips the
- * format row and just offers the encrypt toggle.
+ * Share/export chooser on the shared [GlassDialog] card. For a converted document (a .docx opened as
+ * a PDF) it offers the original file or a PDF; when PDF is the target it can encrypt with a password.
+ * Both choices are [GlassDialogSegmented] controls — solid tracks with a vivid sliding thumb — so
+ * every option is legible over any page (the old glass pills went blank on light pages).
*
- * The dialog only collects intent — the actual file work (encrypt, wrap, chooser) happens off the UI
- * thread in the caller.
+ * The dialog only collects intent — the file work (encrypt, wrap, chooser) runs off the UI thread in
+ * the caller.
*/
@Composable
internal fun ExportShareDialog(
@@ -374,11 +295,6 @@ internal fun ExportShareDialog(
// Uppercase token for the original file when it isn't a PDF (e.g. "DOCX"); null for a plain PDF.
originalExt: String?,
backdrop: LayerBackdrop,
- uiSensor: UISensor,
- fg: Color,
- fgSoft: Color,
- surface: Color,
- field: Color,
onDismiss: () -> Unit,
onShare: (format: ShareFormat, encrypt: Boolean, password: String) -> Unit
) {
@@ -386,245 +302,79 @@ internal fun ExportShareDialog(
var formatIndex by remember(visible) { mutableStateOf(0) }
var encrypt by remember(visible) { mutableStateOf(false) }
var password by remember(visible) { mutableStateOf("") }
- var dropdownOpen by remember(visible) { mutableStateOf(false) }
val passwordFocus = remember { FocusRequester() }
- val density = LocalDensity.current
+ val soft = glassDialogInkSoft()
val pdfOnly = originalExt == null
val pdfSelected = pdfOnly || formatIndex == 1
val canShare = !(pdfSelected && encrypt && password.isBlank())
- val options = if (pdfOnly) emptyList() else listOf(originalExt, stringResource(R.string.viewer_share_pdf))
-
- // Trigger anchor in the dialog Box's coordinate space, so the dropdown menu is an OVERLAY that
- // never grows the glass panel. Growing that panel re-runs its blur+lens every frame — the exact
- // "expand/minimize lag" being fixed here.
- var boxWin by remember { mutableStateOf(Offset.Zero) }
- var trigWin by remember { mutableStateOf(Offset.Zero) }
- var trigSize by remember { mutableStateOf(IntSize.Zero) }
-
- val chevron by animateFloatAsState(if (dropdownOpen) 180f else 0f, GlassMotion.morph(), label = "shareDropChevron")
LaunchedEffect(encrypt, pdfSelected) {
- if (encrypt && pdfSelected) { delay(120); runCatching { passwordFocus.requestFocus() } }
+ if (encrypt && pdfSelected) { delay(160); runCatching { passwordFocus.requestFocus() } }
}
- Box(Modifier.fillMaxSize()) {
- AnimatedVisibility(
- visible = visible,
- enter = fadeIn(tween(200)),
- exit = fadeOut(tween(180)),
- modifier = Modifier.fillMaxSize()
- ) {
- Box(
- Modifier
- .fillMaxSize()
- .background(Color.Black.copy(0.45f))
- .pointerInput(Unit) { detectTapGestures { onDismiss() } }
+ GlassDialog(
+ visible = visible,
+ onDismiss = onDismiss,
+ backdrop = backdrop,
+ title = stringResource(R.string.viewer_share_title),
+ actions = {
+ GlassDialogAction(stringResource(R.string.cancel), onDismiss)
+ GlassDialogAction(
+ stringResource(R.string.viewer_share_button),
+ {
+ if (canShare) onShare(
+ if (pdfSelected) ShareFormat.PDF else ShareFormat.ORIGINAL,
+ encrypt && pdfSelected,
+ password
+ )
+ },
+ primary = true,
+ enabled = canShare
)
}
-
- AnimatedVisibility(
- visible = visible,
- enter = fadeIn(tween(220)) +
- scaleIn(initialScale = 0.85f, animationSpec = spring(dampingRatio = 0.72f, stiffness = Spring.StiffnessMediumLow)),
- exit = fadeOut(tween(140)) + scaleOut(targetScale = 0.9f, animationSpec = tween(150)),
- modifier = Modifier.align(Alignment.Center).imePadding()
- ) {
- Box(
- Modifier
- .widthIn(max = 340.dp)
- .fillMaxWidth(0.86f)
- .onGloballyPositioned { boxWin = it.positionInWindow() }
+ ) {
+ Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
+ if (!pdfOnly) {
+ BasicText(
+ stringResource(R.string.viewer_share_format),
+ style = TextStyle(soft, 13.sp, FontWeight.Medium)
+ )
+ GlassDialogSegmented(
+ options = listOf(originalExt.orEmpty(), stringResource(R.string.viewer_share_pdf)),
+ selectedIndex = formatIndex,
+ onSelect = { formatIndex = it }
+ )
+ }
+ AnimatedVisibility(
+ visible = pdfSelected,
+ enter = fadeIn(tween(160)) + expandVertically(GlassMotion.settle()),
+ exit = fadeOut(tween(120)) + shrinkVertically(GlassMotion.settle())
) {
- Column(
- Modifier
- .fillMaxWidth()
- .liquidGlassPanel(backdrop, uiSensor, surface)
- .padding(22.dp),
- verticalArrangement = Arrangement.spacedBy(16.dp)
- ) {
- BasicText(
- stringResource(R.string.viewer_share_title),
- style = TextStyle(fg, 17.sp, fontWeight = FontWeight.Bold)
+ Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
+ GlassDialogSegmented(
+ options = listOf(
+ stringResource(R.string.viewer_share_normal),
+ stringResource(R.string.viewer_share_encrypted)
+ ),
+ selectedIndex = if (encrypt) 1 else 0,
+ onSelect = { encrypt = it == 1 },
+ accent = if (encrypt) LiquidGlassColors.Indigo else LiquidGlassColors.Blue
)
-
- if (!pdfOnly) {
- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- BasicText(
- stringResource(R.string.viewer_share_format),
- style = TextStyle(fgSoft, 12.sp, fontWeight = FontWeight.Medium)
- )
- // Trigger only — the menu is drawn as a dialog overlay below (so the panel
- // never resizes). Reports its window position + size to anchor that menu.
- LiquidButton(
- onClick = { dropdownOpen = !dropdownOpen },
- backdrop = backdrop,
- surfaceColor = field,
- modifier = Modifier
- .fillMaxWidth()
- .onGloballyPositioned { trigWin = it.positionInWindow(); trigSize = it.size }
- ) {
- Row(
- Modifier.fillMaxWidth().padding(vertical = 2.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.SpaceBetween
- ) {
- BasicText(
- options.getOrElse(formatIndex) { "" },
- style = TextStyle(fg, 14.sp, fontWeight = FontWeight.SemiBold)
- )
- Icon(
- Icons.Rounded.KeyboardArrowDown,
- null,
- Modifier.size(20.dp).graphicsLayer { rotationZ = chevron },
- fgSoft
- )
- }
- }
- }
- }
-
- if (pdfSelected) {
- // Segmented Normal | Encrypted. Deterministic — a plain tap on `LiquidToggle`
- // fires both its clickable and its drag-stop, cancelling out, so it could get
- // stuck on and never prompt for a password. Two buttons set a definite value.
- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp)) {
- listOf(false to R.string.viewer_share_normal, true to R.string.viewer_share_encrypted)
- .forEach { (enc, labelRes) ->
- val sel = encrypt == enc
- LiquidButton(
- onClick = { encrypt = enc },
- backdrop = backdrop,
- tint = if (sel) LiquidGlassColors.Blue else Color.Unspecified,
- surfaceColor = if (sel) Color.Unspecified else field,
- modifier = Modifier.weight(1f)
- ) {
- BasicText(
- stringResource(labelRes),
- style = TextStyle(if (sel) Color.White else fg, 13.sp, fontWeight = FontWeight.SemiBold),
- modifier = Modifier.padding(vertical = 2.dp)
- )
- }
- }
- }
- if (encrypt) {
- Box(
- Modifier
- .fillMaxWidth()
- .clip(RoundedCornerShape(12.dp))
- .background(field)
- .border(1.dp, fg.copy(0.18f), RoundedCornerShape(12.dp))
- .padding(horizontal = 12.dp, vertical = 12.dp)
- ) {
- if (password.isEmpty()) {
- BasicText(
- stringResource(R.string.viewer_share_password_hint),
- style = TextStyle(fgSoft, 14.sp)
- )
- }
- BasicTextField(
- value = password,
- onValueChange = { password = it },
- singleLine = true,
- textStyle = TextStyle(fg, 14.sp),
- cursorBrush = SolidColor(fg),
- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
- modifier = Modifier.fillMaxWidth().focusRequester(passwordFocus)
- )
- }
- }
- }
-
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.End)
- ) {
- LiquidButton(onClick = onDismiss, backdrop = backdrop, surfaceColor = field) {
- BasicText(stringResource(R.string.cancel), style = TextStyle(fg, 13.sp, FontWeight.Medium))
- }
- LiquidButton(
- onClick = {
- if (canShare) onShare(
- if (pdfSelected) ShareFormat.PDF else ShareFormat.ORIGINAL,
- encrypt && pdfSelected,
- password
- )
- },
- backdrop = backdrop,
- tint = if (canShare) LiquidGlassColors.Blue else LiquidGlassColors.Blue.copy(0.4f)
- ) {
- BasicText(stringResource(R.string.viewer_share_button), style = TextStyle(Color.White, 13.sp, fontWeight = FontWeight.Bold))
- }
- }
- }
-
- // Tap-outside catcher for an open dropdown. `matchParentSize` reads the panel's size
- // without contributing to it, so it doesn't grow the dialog.
- if (dropdownOpen) {
- Box(
- Modifier
- .matchParentSize()
- .pointerInput(Unit) { detectTapGestures { dropdownOpen = false } }
- )
- }
-
- // Dropdown menu overlay — anchored under the trigger, drawn last (on top), and NOT
- // wrapped by the glass panel, so opening/closing it costs nothing on the panel. The
- // bounce is all draw-time (a `pop()` spring driving alpha + a translationY overshoot +
- // a small scaleY grow), so the menu's own glass never re-blurs while it springs.
- if (!pdfOnly && (dropdownOpen || trigSize != IntSize.Zero)) {
- val menuOffset = IntOffset(
- (trigWin.x - boxWin.x).roundToInt(),
- (trigWin.y - boxWin.y).roundToInt() + trigSize.height + with(density) { 6.dp.roundToPx() }
- )
- val menuWidth = with(density) { trigSize.width.toDp() }
AnimatedVisibility(
- visible = dropdownOpen,
- enter = fadeIn(tween(110)),
- exit = fadeOut(tween(90)),
- modifier = Modifier.align(Alignment.TopStart).offset { menuOffset }.zIndex(1f)
+ visible = encrypt,
+ enter = fadeIn(tween(160)) + expandVertically(GlassMotion.settle()),
+ exit = fadeOut(tween(120)) + shrinkVertically(GlassMotion.settle())
) {
- val reveal by transition.animateFloat(
- transitionSpec = {
- if (targetState == EnterExitState.Visible) GlassMotion.pop() else GlassMotion.settle()
- },
- label = "shareMenuReveal"
- ) { if (it == EnterExitState.Visible) 1f else 0f }
- Column(
- Modifier
- .width(menuWidth)
- .graphicsLayer {
- alpha = reveal.coerceIn(0f, 1f)
- translationY = (1f - reveal) * (-14.dp.toPx())
- scaleY = 0.9f + 0.1f * reveal
- transformOrigin = TransformOrigin(0.5f, 0f)
- }
- .liquidGlassPanel(backdrop, uiSensor, field)
- .padding(4.dp),
- verticalArrangement = Arrangement.spacedBy(2.dp)
- ) {
- options.forEachIndexed { i, opt ->
- val selected = i == formatIndex
- Row(
- Modifier
- .fillMaxWidth()
- .clip(RoundedCornerShape(12.dp))
- .clickable(
- interactionSource = remember { MutableInteractionSource() },
- indication = null
- ) { formatIndex = i; dropdownOpen = false }
- .padding(horizontal = 14.dp, vertical = 11.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.SpaceBetween
- ) {
- BasicText(
- opt,
- style = TextStyle(fg, 14.sp, fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Medium)
- )
- if (selected) Icon(Icons.Rounded.Check, null, Modifier.size(16.dp), fg)
- }
- }
- }
+ GlassDialogField(
+ value = password,
+ onValueChange = { password = it },
+ modifier = Modifier.fillMaxWidth(),
+ placeholder = stringResource(R.string.viewer_share_password_hint),
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
+ visualTransformation = PasswordVisualTransformation(),
+ focusRequester = passwordFocus
+ )
}
}
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt
index bed3bd6..b1c7d57 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt
@@ -451,8 +451,11 @@ internal fun PdfMarkup.hitTest(
internal fun expandedTextHighlightRect(rect: Rect, verticalScale: Float = 1f): Rect {
val padX = (rect.height * 0.05f).coerceIn(0.75f, 3f)
- val padTop = rect.height * 0.13f * verticalScale
- val padBottom = rect.height * 0.11f * verticalScale
+ // Line boxes now span the font's real ascent..descent (see PdfTextService), so only a hair of
+ // breathing room is added. The old 13%/11% padding compensated for boxes that stopped at the
+ // baseline and made adjacent lines' highlights overlap once the geometry was right.
+ val padTop = rect.height * 0.03f * verticalScale
+ val padBottom = rect.height * 0.03f * verticalScale
return Rect(rect.left - padX, rect.top - padTop, rect.right + padX, rect.bottom + padBottom)
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt
index 59e3019..8f0f747 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt
@@ -80,10 +80,7 @@ import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.icons.rounded.DarkMode
import androidx.compose.material.icons.rounded.LightMode
import androidx.compose.material.icons.rounded.UploadFile
-import androidx.compose.material.icons.rounded.PlayArrow
-import androidx.compose.material.icons.rounded.Pause
import androidx.compose.material.icons.rounded.Edit
-import androidx.compose.material.icons.automirrored.rounded.NoteAdd
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
@@ -237,7 +234,6 @@ fun PdfViewerScreen(
var passwordText by rememberSaveable { mutableStateOf("") }
val passwordFocusRequester = remember { FocusRequester() }
var showSignaturePad by remember { mutableStateOf(false) }
- var quickActionsOpen by remember { mutableStateOf(false) }
var showZoomHud by remember { mutableStateOf(false) }
var darkPageAppearance by rememberSaveable { mutableStateOf(false) }
var bookmarkedPages by remember { mutableStateOf<List<Int>>(emptyList()) }
@@ -905,23 +901,39 @@ fun PdfViewerScreen(
// midpoint doesn't strobe while scrolling. The colour crossfade below smooths the flip
// itself. The sampling runs in a coroutine off `snapshotFlow`, so scrolling recomputes the
// luminance every frame but only an actual light/dark flip ever recomposes the chrome.
- LaunchedEffect(containerHeightPx) {
+ LaunchedEffect(containerHeightPx, darkPageAppearance) {
+ var firstSample = true
snapshotFlow {
- bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, 0f, topBandBottomPx)
+ bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, 0f, topBandBottomPx, darkPageAppearance)
}.collect { lum ->
- if (lum > 0.62f) topBarLight = true else if (lum < 0.58f) topBarLight = false
+ if (firstSample) {
+ topBarLight = lum > 0.60f
+ firstSample = false
+ } else if (lum > 0.62f) topBarLight = true else if (lum < 0.58f) topBarLight = false
}
}
- LaunchedEffect(containerHeightPx) {
+ LaunchedEffect(containerHeightPx, darkPageAppearance) {
+ var firstSample = true
snapshotFlow {
val h = containerHeightPx.toFloat()
if (h <= 0f) 0f
- else bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, h - bottomBandDepthPx, h)
+ else bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, h - bottomBandDepthPx, h, darkPageAppearance)
}.collect { lum ->
- if (lum > 0.62f) bottomBarLight = true else if (lum < 0.58f) bottomBarLight = false
+ if (firstSample) {
+ bottomBarLight = lum > 0.60f
+ firstSample = false
+ } else if (lum > 0.62f) bottomBarLight = true else if (lum < 0.58f) bottomBarLight = false
}
}
val topFg by animateColorAsState(if (topBarLight) Color(0xFF15171C) else Color.White, tween(200), label = "topBarInk")
+ // The system status bar sits over the same band as the top chrome, so its icons follow the
+ // same sampling: dark clock/battery over a white page, light over a dark one (they were white
+ // on white over light pages). Restores the theme's appearance when the viewer leaves.
+ DisposableEffect(activity, view, topBarLight) {
+ val ctrl = activity?.let { WindowCompat.getInsetsController(it.window, view) }
+ ctrl?.isAppearanceLightStatusBars = topBarLight
+ onDispose { ctrl?.isAppearanceLightStatusBars = !isDarkMode }
+ }
val bottomFg by animateColorAsState(if (bottomBarLight) Color(0xFF15171C) else Color.White, tween(200), label = "bottomBarInk")
val topFgSoft = topFg.copy(alpha = 0.62f)
val bottomFgSoft = bottomFg.copy(alpha = 0.62f)
@@ -939,7 +951,7 @@ fun PdfViewerScreen(
if (h <= 0f) 0f
else {
val bottom = (h - imeInset.getBottom(density)).coerceAtLeast(bottomBandDepthPx)
- bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, bottom - bottomBandDepthPx, bottom)
+ bandLuminance(listState.layoutInfo, state.pageBitmaps, scale, bottom - bottomBandDepthPx, bottom, darkPageAppearance)
}
}.collect { lum ->
if (lum > 0.62f) findBarLight = true else if (lum < 0.58f) findBarLight = false
@@ -1024,7 +1036,14 @@ fun PdfViewerScreen(
onTap = {
// Tap outside clears a text selection (and does nothing else), like a
// TextView; otherwise it toggles the reading chrome.
+ // A selected markup (highlight / shape / note with its Edit bar) is
+ // dismissed the same way, from ANY page — the page-local tap layer only
+ // saw taps on its own page, so the bar could not be dismissed elsewhere.
if (textSelection.hasSelection) textSelection.clear()
+ else if (selectedAnnoIndex >= 0 || selectedMarkupGroup.isNotEmpty()) {
+ selectedAnnoPage = null; selectedAnnoIndex = -1
+ selectedMarkupGroupPage = null; selectedMarkupGroup = emptySet()
+ }
else if (activeTool == PdfEditTool.None) controlsVisible = !controlsVisible
lastInteractionAtMs = System.currentTimeMillis()
},
@@ -1185,35 +1204,19 @@ fun PdfViewerScreen(
)
AnimatedVisibility(
- visible = controlsVisible && state.document != null && safePageCount > 1 && scale <= 1.01f && activeTool == PdfEditTool.None,
+ visible = controlsVisible && autoScroll && state.document != null && safePageCount > 1 && scale <= 1.01f && activeTool == PdfEditTool.None,
enter = fadeIn(tween(180)) + scaleIn(initialScale = 0.94f),
exit = fadeOut(tween(120)) + scaleOut(targetScale = 0.96f),
- modifier = Modifier.align(Alignment.BottomCenter).navigationBarsPadding().padding(bottom = 92.dp)
+ modifier = Modifier.align(Alignment.BottomCenter).navigationBarsPadding().padding(bottom = 76.dp)
) {
Row(
Modifier
- .viewerGlass(contentBackdrop, chromeGlass, shape = { com.kyant.shapes.Capsule })
+ // Clear glass like every other floating control; the ink carries contrast.
+ .viewerGlass(contentBackdrop, Color.Transparent, shape = { com.kyant.shapes.Capsule })
.padding(horizontal = 7.dp, vertical = 6.dp),
verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(4.dp)
+ horizontalArrangement = Arrangement.spacedBy(2.dp)
) {
- LiquidIconButton(
- onClick = {
- autoScroll = !autoScroll
- controlsVisible = true
- lastInteractionAtMs = System.currentTimeMillis()
- },
- backdrop = contentBackdrop,
- tint = if (autoScroll) accent else Color.Unspecified,
- modifier = Modifier.size(38.dp)
- ) {
- Icon(
- if (autoScroll) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,
- stringResource(if (autoScroll) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),
- Modifier.size(20.dp),
- if (autoScroll) Color.White else bottomFg
- )
- }
BasicText(
text = "${autoScrollSpeed}×",
modifier = Modifier
@@ -1264,7 +1267,8 @@ fun PdfViewerScreen(
onPageChange = { page -> scrollToPage(page) },
onPageScrubbing = { page -> viewModel.renderPage(context, page, 400); lastInteractionAtMs = System.currentTimeMillis() },
onDraggingChange = { scrubberDragging = it },
- isScrolling = listState.isScrollInProgress
+ isScrolling = listState.isScrollInProgress,
+ darkPageAppearance = darkPageAppearance
)
}
@@ -1298,6 +1302,7 @@ fun PdfViewerScreen(
onBack = { requestExit() },
backdrop = contentBackdrop,
foreground = topFg,
+ surfaceColor = Color.Unspecified,
onLongPressBack = if (hasUnsavedEdits) ({ requestExit() }) else LocalBackToLibraryAction.current,
longPressLabel = if (hasUnsavedEdits) stringResource(R.string.back) else null
)
@@ -1437,7 +1442,7 @@ fun PdfViewerScreen(
drawingToolActive = drawingToolActive,
showFindBar = showFindBar,
showSignaturePad = showSignaturePad,
- quickActionsVisible = quickActionsOpen,
+ autoScrollActive = autoScroll,
activeImageId = activeImageId,
currentColor = currentColor,
currentColorLong = currentColorLong,
@@ -1515,9 +1520,8 @@ fun PdfViewerScreen(
// .docx used to always leave as the converted PDF, silently. The dialog lets the
// user pick the original file vs a PDF (and encrypt the PDF). See ExportShareDialog.
onShareDocument = { showShareDialog = true },
- onOpenQuickActions = {
- textSelection.clear()
- quickActionsOpen = true
+ onToggleAutoScroll = {
+ autoScroll = !autoScroll
controlsVisible = true
lastInteractionAtMs = System.currentTimeMillis()
},
@@ -1557,7 +1561,8 @@ fun PdfViewerScreen(
uiSensor = uiSensor,
fg = findFg,
fgSoft = findFgSoft,
- surface = chromeGlass,
+ // Clear, like the top bar's title pill and circles — only the ink adapts.
+ surface = Color.Transparent,
onQueryChange = { q -> findQuery = q; viewModel.searchText(q) },
onPrevMatch = { viewModel.prevMatch(); lastInteractionAtMs = System.currentTimeMillis() },
onNextMatch = { viewModel.nextMatch(); lastInteractionAtMs = System.currentTimeMillis() },
@@ -1583,11 +1588,20 @@ fun PdfViewerScreen(
context.startActivity(intent)
}
}
- fun applyToSelection(block: (page: Int, marks: MutableList<PdfMarkup>, range: OcrTextRange) -> Boolean) {
+ fun applyToSelection(
+ snapToWords: Boolean = false,
+ block: (page: Int, marks: MutableList<PdfMarkup>, range: OcrTextRange) -> Boolean
+ ) {
textSelection.rangesByPage().forEach { (page, ranges) ->
val marks = getPageMarks(page)
var changed = false
- ranges.forEach { r -> if (block(page, marks, r)) changed = true }
+ // Marking actions (highlight / underline / strike) cover whole words, like Acrobat:
+ // a handle dragged back a few characters must not leave "Engin|eering" half-marked.
+ val pageBlocks = if (snapToWords) state.ocrBlocksByPage[page].orEmpty().associateBy { it.id } else emptyMap()
+ ranges.forEach { raw ->
+ val r = if (snapToWords) pageBlocks[raw.blockId]?.let { raw.snappedToWords(it.text) } ?: raw else raw
+ if (block(page, marks, r)) changed = true
+ }
if (changed) recordEdit(page)
}
lastInteractionAtMs = System.currentTimeMillis()
@@ -1623,7 +1637,7 @@ fun PdfViewerScreen(
},
onHighlight = { colorLong ->
currentColorLong = colorLong
- applyToSelection { _, m, r ->
+ applyToSelection(snapToWords = true) { _, m, r ->
// Re-highlighting replaces (recolours) highlights inside the range instead of stacking.
m.removeAll { it is PdfMarkup.TextBlockHighlightMarkup && it.blockId == r.blockId && it.start >= r.start && it.end <= r.end }
m.add(PdfMarkup.TextBlockHighlightMarkup(r.blockId, Color(colorLong), 0.38f, r.start, r.end))
@@ -1632,14 +1646,14 @@ fun PdfViewerScreen(
textSelection.clear()
},
onUnderline = {
- applyToSelection { _, m, r ->
+ applyToSelection(snapToWords = true) { _, m, r ->
if (m.any { it is PdfMarkup.TextBlockLineMarkup && it.blockId == r.blockId && it.start == r.start && it.end == r.end && !it.strikeThrough }) false
else m.add(PdfMarkup.TextBlockLineMarkup(r.blockId, Color(currentColorLong), 3f, 1f, false, r.start, r.end))
}
textSelection.clear()
},
onStrike = {
- applyToSelection { _, m, r ->
+ applyToSelection(snapToWords = true) { _, m, r ->
if (m.any { it is PdfMarkup.TextBlockLineMarkup && it.blockId == r.blockId && it.start == r.start && it.end == r.end && it.strikeThrough }) false
else m.add(PdfMarkup.TextBlockLineMarkup(r.blockId, Color(currentColorLong), 3f, 1f, true, r.start, r.end))
}
@@ -1701,80 +1715,12 @@ fun PdfViewerScreen(
modifier = Modifier.align(Alignment.BottomCenter).navigationBarsPadding().padding(bottom = 112.dp)
)
- // Keep the reader action sheet on the screen's top overlay layer. It must cover the
- // selection toolbar and bottom controls, otherwise those floating controls intercept
- // taps on the sheet's lower actions.
- GlassBottomSheet(
- visible = quickActionsOpen,
- onDismiss = { quickActionsOpen = false },
- backdrop = contentBackdrop
- ) {
- BasicText(
- stringResource(R.string.viewer_quick_actions),
- modifier = Modifier.padding(start = 18.dp, top = 8.dp, bottom = 14.dp),
- style = TextStyle(quickActionFg, 20.sp, FontWeight.SemiBold)
- )
- LiquidButton(
- onClick = {
- quickActionsOpen = false
- showSignaturePad = true
- controlsVisible = true
- },
- backdrop = contentBackdrop,
- surfaceColor = quickActionField,
- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp)
- ) {
- Row(Modifier.fillMaxWidth().padding(vertical = 6.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
- Icon(Icons.Rounded.Edit, null, Modifier.size(20.dp), quickActionFg)
- BasicText(stringResource(R.string.viewer_sign), style = TextStyle(quickActionFg, 15.sp, FontWeight.Medium))
- }
- }
- LiquidButton(
- onClick = {
- quickActionsOpen = false
- activeTool = PdfEditTool.Note
- controlsVisible = true
- },
- backdrop = contentBackdrop,
- surfaceColor = quickActionField,
- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp)
- ) {
- Row(Modifier.fillMaxWidth().padding(vertical = 6.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
- Icon(Icons.AutoMirrored.Rounded.NoteAdd, null, Modifier.size(20.dp), quickActionFg)
- BasicText(stringResource(R.string.anno_note_title), style = TextStyle(quickActionFg, 15.sp, FontWeight.Medium))
- }
- }
- LiquidButton(
- onClick = {
- quickActionsOpen = false
- autoScroll = !autoScroll
- controlsVisible = true
- },
- backdrop = contentBackdrop,
- surfaceColor = quickActionField,
- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp)
- ) {
- Row(Modifier.fillMaxWidth().padding(vertical = 6.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
- Icon(if (autoScroll) Icons.Rounded.Pause else Icons.Rounded.PlayArrow, null, Modifier.size(20.dp), quickActionFg)
- BasicText(
- stringResource(if (autoScroll) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),
- style = TextStyle(quickActionFg, 15.sp, FontWeight.Medium)
- )
- }
- }
- }
-
// ── Page-jump popup (in-window, so it samples the liquid-glass backdrop) ──
LiquidPageJumpPopup(
visible = showPageJumpDialog,
currentPage = currentPageIndex,
pageCount = safePageCount,
backdrop = contentBackdrop,
- uiSensor = uiSensor,
- fg = panelFg,
- fgSoft = panelFgSoft,
- surface = chromePanel,
- field = chromeField,
bookmarkedPages = bookmarkedPages,
onDismiss = { showPageJumpDialog = false },
onJumpToPage = { targetPage -> showPageJumpDialog = false; scrollToPage(targetPage) },
@@ -1795,11 +1741,6 @@ fun PdfViewerScreen(
initialText = annotationDraft,
initialColor = editingAnnoColor,
backdrop = contentBackdrop,
- uiSensor = uiSensor,
- fg = panelFg,
- fgSoft = panelFgSoft,
- surface = chromePanel,
- field = chromeField,
onDismiss = {
getPageMarks(editingAnnoPage).removeAll { m -> matches(m) &&
((m is PdfMarkup.TextBoxMarkup && m.text.isBlank()) || (m is PdfMarkup.NoteMarkup && m.text.isBlank())) }
@@ -1899,11 +1840,6 @@ fun PdfViewerScreen(
visible = showShareDialog,
originalExt = if (shareExt.isNotBlank() && shareExt != "PDF") shareExt else null,
backdrop = contentBackdrop,
- uiSensor = uiSensor,
- fg = panelFg,
- fgSoft = panelFgSoft,
- surface = chromePanel,
- field = chromeField,
onDismiss = { showShareDialog = false },
onShare = { format, encrypt, password ->
showShareDialog = false
@@ -2084,7 +2020,11 @@ private fun bandLuminance(
pageBitmaps: List<Bitmap?>,
scale: Float,
screenTopPx: Float,
- screenBottomPx: Float
+ screenBottomPx: Float,
+ // Dark page appearance draws every page through an RGB-inverting colour matrix, so the pixels
+ // on screen are 1 - (bitmap). Sampling the bitmap as-is read a white page behind a black one and
+ // picked dark ink — the "icons invisible in dark mode" bug. Mirror the matrix here.
+ inverted: Boolean = false
): Float {
val s = scale.coerceAtLeast(0.01f)
val lTop = screenTopPx / s
@@ -2102,7 +2042,8 @@ private fun bandLuminance(
val bmp = pageBitmaps.getOrNull(item.index) ?: continue
val fTop = (interTop - io) / item.size
val fBottom = (interBottom - io) / item.size
- lum += regionLuminance(bmp, fTop, fBottom).toDouble() * cover
+ val l = regionLuminance(bmp, fTop, fBottom)
+ lum += (if (inverted) 1f - l else l).toDouble() * cover
weight += cover.toDouble()
}
return if (weight <= 0.0) 0f else (lum / weight).toFloat()
@@ -2124,3 +2065,21 @@ private fun averageLuminance(bitmap: Bitmap): Float = runCatching {
}
(sum / pixels.size).toFloat()
}.getOrDefault(0f)
+
+/**
+ * Grows a line-local `[start, end)` range to whole-word boundaries (letters, digits and in-word
+ * apostrophes/hyphens), after trimming surrounding spaces. Used by the marking actions only; copy and
+ * share keep the exact selection.
+ */
+internal fun OcrTextRange.snappedToWords(text: String): OcrTextRange {
+ if (text.isEmpty()) return this
+ fun inWord(c: Char) = c.isLetterOrDigit() || c == '\'' || c == '\u2019' || c == '-' || c == '_'
+ var a = start.coerceIn(0, text.length)
+ var b = end.coerceIn(a, text.length)
+ while (a < b && text[a].isWhitespace()) a++
+ while (b > a && text[b - 1].isWhitespace()) b--
+ if (a >= b) return this
+ while (a > 0 && inWord(text[a - 1]) && inWord(text[a])) a--
+ while (b < text.length && inWord(text[b]) && inWord(text[b - 1])) b++
+ return copy(start = a, end = b)
+}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
index b5e3554..944eaa3 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
@@ -279,7 +279,8 @@ fun SettingsScreen(
}
LazyColumn(
state = settingsListState,
- modifier = Modifier.fillMaxSize().padding(contentPadding),
+ modifier = Modifier.fillMaxSize(),
+ contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// ── Theme Mode Selector ──
@@ -853,8 +854,6 @@ fun SettingsScreen(
}
}
- // Clear the floating bottom navigation bar + system nav inset.
- item(key = "settings-bottom-inset") { Spacer(Modifier.height(120.dp)) }
}
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
index 52dee4a..0cfca37 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
@@ -116,6 +116,7 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalHapticFeedback
@@ -615,7 +616,7 @@ fun SpreadsheetViewerScreen(
glass = chromeGlass,
text = text, sub = sub, accent = accent,
onSelect = { i -> if (editing) commitDraft(); sheetIndex = i },
- modifier = Modifier.padding(top = 8.dp, end = if (!editMode && !showSearch) 64.dp else 0.dp)
+ modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 8.dp)
)
AnimatedVisibility(
visible = editMode,
@@ -908,11 +909,12 @@ private fun SheetTabs(
val scroll = rememberScrollState()
val selectedSlot = indices.indexOf(selected).coerceAtLeast(0)
val density = LocalDensity.current
+ val compactWidth = (LocalConfiguration.current.screenWidthDp.dp - 32.dp)
+ .coerceAtMost(320.dp)
+ .coerceAtLeast(104.dp)
BoxWithConstraints(
- modifier
- .fillMaxWidth()
- .height(64.dp),
- contentAlignment = Alignment.CenterStart
+ modifier.width(compactWidth).height(64.dp),
+ contentAlignment = Alignment.Center
) {
val tabWidth = (maxWidth / 3).coerceIn(104.dp, 136.dp)
val tabWidthPx = with(density) { tabWidth.toPx() }
@@ -929,7 +931,9 @@ private fun SheetTabs(
onTabSelected = { slot -> indices.getOrNull(slot)?.let(onSelect) },
backdrop = backdrop,
tabsCount = indices.size,
- modifier = Modifier.width(contentWidth).height(64.dp)
+ modifier = Modifier.width(contentWidth).height(48.dp),
+ barHeight = 48.dp,
+ surfaceColor = Color.Transparent
) {
indices.forEachIndexed { slot, sheetIndex ->
val sheet = wb.sheets[sheetIndex]
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index ea4a3e2..0e0b154 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -550,7 +550,8 @@
<string name="tour_next">Siguiente</string>
<string name="tour_done">Entendido</string>
<string name="tour_reader_tools_title">Herramientas de lectura</string>
- <string name="tour_reader_tools_message">Toca Herramientas para resaltar, dibujar, añadir notas o firmar.</string>
+ <string name="tour_reader_tools_message">Toca el icono de edición para resaltar, dibujar, añadir notas o firmar.</string>
+ <string name="tour_reader_tools_ppt_message">Toca el icono de notas para resaltar, dibujar, añadir notas o firmar.</string>
<string name="tour_reader_share_title">Compartir o abrir otro archivo</string>
<string name="tour_reader_share_message">Toca la cápsula para abrir otro archivo. Para compartir, mantenla pulsada y desliza hacia arriba.</string>
<string name="tour_sheet_title">Editar una hoja de cálculo</string>
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index d78c504..2214cc0 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -533,7 +533,8 @@
<string name="tour_next">Avançar</string>
<string name="tour_done">Entendi</string>
<string name="tour_reader_tools_title">Ferramentas de leitura</string>
- <string name="tour_reader_tools_message">Toque em Ferramentas para destacar, desenhar, adicionar notas ou assinar.</string>
+ <string name="tour_reader_tools_message">Toque no ícone de edição para destacar, desenhar, adicionar notas ou assinar.</string>
+ <string name="tour_reader_tools_ppt_message">Toque no ícone de notas para destacar, desenhar, adicionar notas ou assinar.</string>
<string name="tour_reader_share_title">Compartilhar ou abrir outro arquivo</string>
<string name="tour_reader_share_message">Toque na cápsula para abrir outro arquivo. Para compartilhar, mantenha-a pressionada e deslize para cima.</string>
<string name="tour_sheet_title">Editar uma planilha</string>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 87cd057..645addf 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -533,7 +533,8 @@
<string name="tour_next">Seguinte</string>
<string name="tour_done">Percebi</string>
<string name="tour_reader_tools_title">Ferramentas de leitura</string>
- <string name="tour_reader_tools_message">Toque em Ferramentas para realçar, desenhar, adicionar notas ou assinar.</string>
+ <string name="tour_reader_tools_message">Toque no ícone de edição para realçar, desenhar, adicionar notas ou assinar.</string>
+ <string name="tour_reader_tools_ppt_message">Toque no ícone de notas para realçar, desenhar, adicionar notas ou assinar.</string>
<string name="tour_reader_share_title">Partilhar ou abrir outro ficheiro</string>
<string name="tour_reader_share_message">Toque na cápsula para abrir outro ficheiro. Para partilhar, mantenha-a premida e deslize para cima.</string>
<string name="tour_sheet_title">Editar uma folha de cálculo</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b653cac..348d27e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -710,7 +710,8 @@
<string name="tour_next">Next</string>
<string name="tour_done">Got it</string>
<string name="tour_reader_tools_title">Reader tools</string>
- <string name="tour_reader_tools_message">Tap Editor Tools to highlight, draw, add notes, or sign.</string>
+ <string name="tour_reader_tools_message">Tap the edit icon to highlight, draw, add notes, or sign.</string>
+ <string name="tour_reader_tools_ppt_message">Tap the notes bubble to highlight, draw, add notes, or sign.</string>
<string name="tour_reader_share_title">Share or open another file</string>
<string name="tour_reader_share_message">Tap the capsule to open another file. To share, press and hold it, then swipe up.</string>
<string name="tour_sheet_title">Edit a spreadsheet</string>
diff --git a/app/src/test/java/com/chethan616/clearpdf/ui/screen/WordSnapTest.kt b/app/src/test/java/com/chethan616/clearpdf/ui/screen/WordSnapTest.kt
new file mode 100644
index 0000000..61d937b
--- /dev/null
+++ b/app/src/test/java/com/chethan616/clearpdf/ui/screen/WordSnapTest.kt
@@ -0,0 +1,43 @@
+package com.chethan616.clearpdf.ui.screen
+
+import com.chethan616.clearpdf.ui.viewmodel.OcrTextRange
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class WordSnapTest {
+ private val line = "Job Description Data Engineering"
+
+ private fun snap(start: Int, end: Int): String {
+ val r = OcrTextRange("b", start, end).snappedToWords(line)
+ return line.substring(r.start, r.end)
+ }
+
+ @Test fun partialWordGrowsToWholeWord() {
+ // "Engin" selected → whole "Engineering"
+ val s = line.indexOf("Engin")
+ assertEquals("Engineering", snap(s, s + 5))
+ }
+
+ @Test fun midWordStartAndEndGrowAcrossWords() {
+ // "cription Da" → "Description Data"
+ val s = line.indexOf("cription")
+ assertEquals("Description Data", snap(s, s + "cription Da".length))
+ }
+
+ @Test fun surroundingSpacesAreTrimmed() {
+ val s = line.indexOf(" Data ")
+ assertEquals("Data", snap(s, s + 6))
+ }
+
+ @Test fun wholeWordIsUnchanged() {
+ val s = line.indexOf("Job")
+ assertEquals("Job", snap(s, s + 3))
+ }
+
+ @Test fun apostropheAndHyphenStayInWord() {
+ val text = "it's a well-known fact"
+ val s = text.indexOf("know")
+ val r = OcrTextRange("b", s, s + 2).snappedToWords(text)
+ assertEquals("well-known", text.substring(r.start, r.end))
+ }
+}
diff --git a/pdf-core/src/main/java/com/kyant/pdfcore/text/PdfTextService.kt b/pdf-core/src/main/java/com/kyant/pdfcore/text/PdfTextService.kt
index e0e89f6..cd5f5b9 100644
--- a/pdf-core/src/main/java/com/kyant/pdfcore/text/PdfTextService.kt
+++ b/pdf-core/src/main/java/com/kyant/pdfcore/text/PdfTextService.kt
@@ -98,6 +98,42 @@ class PdfTextServiceImpl : PdfTextService {
return groupPositionsIntoLines(stripper.positions, pageW, pageH, pageIndex)
}
+ /** Per-font ascent/descent as fractions of the em, cached for the page being grouped. */
+ private val fontMetricsCache = java.util.IdentityHashMap<Any, FloatArray>()
+
+ private fun fontMetrics(tp: TextPosition): FloatArray {
+ val font = tp.font ?: return DefaultMetrics
+ return synchronized(fontMetricsCache) { fontMetricsCache[font] } ?: run {
+ runCatching {
+ val fd = font.fontDescriptor
+ var ascent = fd?.ascent ?: 0f
+ var descent = fd?.descent ?: 0f
+ if (ascent <= 0f) ascent = fd?.capHeight?.takeIf { it > 0f }?.times(1.18f) ?: 0f
+ if (ascent <= 0f || descent >= 0f) {
+ val bbox = font.boundingBox
+ if (ascent <= 0f && bbox != null) ascent = bbox.upperRightY
+ if (descent >= 0f && bbox != null) descent = bbox.lowerLeftY
+ }
+ // Glyph-space units are 1/1000 em for everything but Type 3 fonts. Clamp so a broken
+ // descriptor (some PDFs carry 0 or bbox-sized values) can't produce absurd boxes.
+ val a = (ascent / 1000f).takeIf { it.isFinite() && it > 0f }?.coerceIn(0.62f, 1.05f) ?: DefaultMetrics[0]
+ val d = (-descent / 1000f).takeIf { it.isFinite() && it > 0f }?.coerceIn(0.12f, 0.32f) ?: DefaultMetrics[1]
+ floatArrayOf(a, d)
+ }.getOrDefault(DefaultMetrics).also { m -> synchronized(fontMetricsCache) { fontMetricsCache[font] = m } }
+ }
+ }
+
+ /** Rendered font size in page units: the text rendering matrix's Y scale. */
+ private fun emSize(tp: TextPosition): Float {
+ val ys = tp.yScale
+ if (ys.isFinite() && ys > 0.5f) return ys
+ val pt = tp.fontSizeInPt
+ return if (pt.isFinite() && pt > 0.5f) pt else tp.height.coerceAtLeast(1f) / 0.7f
+ }
+
+ private fun glyphAscent(tp: TextPosition): Float = emSize(tp) * fontMetrics(tp)[0]
+ private fun glyphDescent(tp: TextPosition): Float = emSize(tp) * fontMetrics(tp)[1]
+
private fun groupPositionsIntoLines(
positions: List<TextPosition>,
pageWidth: Float,
@@ -105,6 +141,7 @@ class PdfTextServiceImpl : PdfTextService {
pageIndex: Int
): List<PdfTextBlock> {
if (positions.isEmpty()) return emptyList()
+ synchronized(fontMetricsCache) { fontMetricsCache.clear() }
val avgH = positions.map { it.height }.average().toFloat().coerceAtLeast(2f)
val lineGap = avgH * 0.6f
@@ -191,8 +228,12 @@ class PdfTextServiceImpl : PdfTextService {
val minX = byX.minOf { it.x }
val maxX = byX.maxOf { it.x + it.width }
- val minY = byX.minOf { it.y - it.height }.coerceAtLeast(0f)
- val maxY = byX.maxOf { it.y }
+ // Vertical extent from the FONT's ascent/descent at the rendered size, not
+ // TextPosition.height: PdfBox's height is often near the x-height and the old box ended
+ // at the baseline, so highlights sat low — clipping ascenders/caps above and leaving
+ // descenders (g, p, y) hanging out below.
+ val minY = byX.minOf { it.y - glyphAscent(it) }.coerceAtLeast(0f)
+ val maxY = byX.maxOf { it.y + glyphDescent(it) }
PdfTextBlock(
id = "$pageIndex-$lineIdx",
@@ -235,3 +276,6 @@ private class PositionCapturingStripper : PDFTextStripper() {
if (!text.unicode.isNullOrBlank()) positions.add(text)
}
}
+
+/** Typical Latin face: ascent 0.80 em, descent 0.20 em. */
+private val DefaultMetrics = floatArrayOf(0.80f, 0.20f)