Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ links are downloaded first when they point to a file.
(Direct Share), like AirDrop on an iPhone. Tap one and a small sheet sends it right there, with a
progress ring, then folds away. Or turn on the **edge panel**: a slim handle on the side of the
screen, over any app, that sends your clipboard, your latest photo, or whatever you drop on it.
While you drag something, the handle opens into a list of nearby devices: drop on one to send it
there. (Android then shows its own "displaying over other apps" notice; long-press it to hide it.)
Received photos show up as a preview in the notification.

<p align="center">
Expand All @@ -66,6 +68,10 @@ Received photos show up as a preview in the notification.
<img src="docs/screenshots/android-edgePanel.png" width="24%" alt="Edge panel over another app">
</p>

<p align="center">
<img src="docs/screenshots/android-dropTab.png" width="24%" alt="Dragging a photo to the screen edge: nearby devices, the one under the finger in blue">
</p>

<p align="center">
<img src="docs/screenshots/edge-drop-devices.png" width="60%" alt="Drop zone with several devices (light), and while looking for devices (dark)">
<img src="docs/screenshots/desktop-quickshare-pin.png" width="36%" alt="Quick Share request from an Android phone, with the PIN">
Expand Down Expand Up @@ -336,4 +342,5 @@ docs/ RESEARCH.md, screenshots
## License

MIT. See [LICENSE](LICENSE). AirBridge is not affiliated with Apple, Google or the LocalSend
project.
project. The Android app uses the [Inter](https://rsms.me/inter/) typeface, under the SIL Open
Font License ([android/third_party/inter/OFL.txt](android/third_party/inter/OFL.txt)).
4 changes: 2 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = "io.github.mdhaarith.airbridge"
minSdk = 29
targetSdk = 35
versionCode = 2
versionName = "0.1.1"
versionCode = 3
versionName = "0.1.2"
}

buildTypes {
Expand Down

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions android/app/src/main/java/io/github/mdhaarith/airbridge/ui/DropTab.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package io.github.mdhaarith.airbridge.ui

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Download
import androidx.compose.material.icons.rounded.Groups
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
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.graphicsLayer
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/** A place to drop on while dragging: one device, or everyone nearby. */
data class DropTarget(
val id: String,
val name: String,
val subtitle: String?,
val deviceType: String? = null,
val deviceModel: String? = null,
val everyone: Boolean = false,
)

data class DropTabUi(
val rightSide: Boolean,
val targets: List<DropTarget>,
/** The target under the finger, if any. */
val hovered: String? = null,
/** Something is being dragged over the tab. */
val over: Boolean = false,
val defaultId: String? = null,
)

/**
* The tab's geometry, in dp: the window is sized from it and the drag
* position is mapped back to a row with it, so both always agree.
*/
object DropTabLayout {
const val HEADER = 30
const val ROW = 68
const val FOOTER = 8
const val WIDTH = 196
const val COMPACT_WIDTH = 104
const val COMPACT_HEIGHT = 168

fun width(targets: Int) = if (targets == 0) COMPACT_WIDTH else WIDTH
fun height(targets: Int) = if (targets == 0) COMPACT_HEIGHT else HEADER + targets * ROW + FOOTER

/** Index of the row at [yDp] from the top of the tab, or null over the header. */
fun rowAt(yDp: Float, targets: Int): Int? =
if (yDp < HEADER) null else ((yDp - HEADER) / ROW).toInt().takeIf { it in 0 until targets }
}

/**
* What the edge handle becomes while something is dragged anywhere on the
* screen: a card against the edge listing nearby devices. The row under the
* finger lights up blue, like a device in the AirDrop sheet.
*/
@Composable
fun DropTab(ui: DropTabUi) {
val air = LocalAir.current
// Flat against the screen edge, rounded on the inside.
val shape = if (ui.rightSide) RoundedCornerShape(topStart = 22.dp, bottomStart = 22.dp) else RoundedCornerShape(topEnd = 22.dp, bottomEnd = 22.dp)
val edge = if (ui.rightSide) Modifier.padding(start = 4.dp) else Modifier.padding(end = 4.dp)
if (ui.targets.isEmpty()) return CompactTab(ui, shape, edge)

Column(
edge.fillMaxSize()
.clip(shape)
.background(air.elevated)
.border(0.5.dp, air.separator, shape)
.padding(horizontal = 6.dp),
) {
Text(
"DROP TO SEND",
color = air.muted, fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.6.sp,
modifier = Modifier.height(DropTabLayout.HEADER.dp).padding(start = 10.dp, top = 12.dp),
)
for (target in ui.targets) TargetRow(target, hovered = target.id == ui.hovered, isDefault = target.id == ui.defaultId)
}
}

@Composable
private fun TargetRow(target: DropTarget, hovered: Boolean, isDefault: Boolean) {
val air = LocalAir.current
val fill by animateColorAsState(if (hovered) air.accent else Color.Transparent, tween(140), label = "fill")
val scale by animateFloatAsState(if (hovered) 1.08f else 1f, tween(160), label = "scale")
Row(
Modifier.fillMaxWidth().height(DropTabLayout.ROW.dp).padding(vertical = 3.dp)
.clip(RoundedCornerShape(16.dp)).background(fill).padding(horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Box(Modifier.graphicsLayer { scaleX = scale; scaleY = scale }) {
if (target.everyone) {
Box(
Modifier.size(46.dp).clip(CircleShape).background(if (hovered) Color.White.copy(alpha = 0.22f) else air.accent.copy(alpha = 0.14f)),
contentAlignment = Alignment.Center,
) {
Icon(Icons.Rounded.Groups, null, tint = if (hovered) Color.White else air.accent, modifier = Modifier.size(24.dp))
}
} else {
Avatar(deviceIcon(target.deviceType, target.deviceModel), 46.dp, if (hovered) Modifier.border(2.dp, Color.White, CircleShape) else Modifier)
}
}
Spacer(Modifier.width(10.dp))
Column(Modifier.weight(1f)) {
Text(
target.name, color = if (hovered) Color.White else air.text, fontSize = 14.sp, fontWeight = FontWeight.SemiBold,
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
val subtitle = if (isDefault) "Default" else target.subtitle
if (subtitle != null) {
Text(
subtitle,
color = when {
hovered -> Color.White.copy(alpha = 0.85f)
isDefault -> air.accent
else -> air.muted
},
fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
}
}
}

/** No devices to choose from: a small "Drop here" tab that turns blue under the finger. */
@Composable
private fun CompactTab(ui: DropTabUi, shape: RoundedCornerShape, edge: Modifier) {
val air = LocalAir.current
val fill by animateColorAsState(if (ui.over) air.accent else air.elevated, tween(140), label = "fill")
val ink = if (ui.over) Color.White else air.accent
Column(
edge.fillMaxSize().clip(shape).background(fill).border(0.5.dp, air.separator, shape).padding(10.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
) {
Box(Modifier.size(42.dp).clip(CircleShape).background(if (ui.over) Color.White.copy(alpha = 0.22f) else air.accent.copy(alpha = 0.14f)), contentAlignment = Alignment.Center) {
Icon(Icons.Rounded.Download, null, tint = ink, modifier = Modifier.size(22.dp))
}
Spacer(Modifier.height(10.dp))
Text(
if (ui.over) "Release" else "Drop here",
color = if (ui.over) Color.White else air.text, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center,
)
Text(
if (ui.over) "to send" else "No devices yet",
color = if (ui.over) Color.White.copy(alpha = 0.85f) else air.muted, fontSize = 11.sp, textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 2.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ fun SettingsScreen(vm: AppViewModel) {
}
}

Group("Sending", footer = "Your devices also appear in Android's share sheet: share anything and tap your computer.") {
Group(
"Sending",
footer = "Your devices also appear in Android's share sheet: share anything and tap your computer." +
if (settings.edgePanel) "\n\nWhile the handle is on, Android shows an “AirBridge is displaying over other apps” notification. " +
"Long-press it to hide it; the handle keeps working." else "",
) {
ListRow("Edge Panel", subtitle = "A handle on the screen edge: send your clipboard, latest photo or anything you drop on it", icon = Icons.Rounded.VerticalSplit, chevron = false) {
AppleSwitch(settings.edgePanel, { on ->
engine.settings.update { it.copy(edgePanel = on) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package io.github.mdhaarith.airbridge.ui

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import io.github.mdhaarith.airbridge.R
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
Expand Down Expand Up @@ -93,6 +99,28 @@ fun AirBridgeTheme(dark: Boolean = isSystemInDarkTheme(), content: @Composable (
)
}
CompositionLocalProvider(LocalAir provides air) {
MaterialTheme(colorScheme = scheme, content = content)
MaterialTheme(colorScheme = scheme, typography = AirTypography, content = content)
}
}

/**
* Inter, the open typeface closest to Apple's SF, for every text in the app
* (Latin only; other scripts fall back to the system font).
*/
val Inter = FontFamily(
Font(R.font.inter_regular, FontWeight.Normal),
Font(R.font.inter_medium, FontWeight.Medium),
Font(R.font.inter_semibold, FontWeight.SemiBold),
Font(R.font.inter_bold, FontWeight.Bold),
)

private val AirTypography = Typography().run {
fun TextStyle.inter() = copy(fontFamily = Inter)
copy(
displayLarge = displayLarge.inter(), displayMedium = displayMedium.inter(), displaySmall = displaySmall.inter(),
headlineLarge = headlineLarge.inter(), headlineMedium = headlineMedium.inter(), headlineSmall = headlineSmall.inter(),
titleLarge = titleLarge.inter(), titleMedium = titleMedium.inter(), titleSmall = titleSmall.inter(),
bodyLarge = bodyLarge.inter(), bodyMedium = bodyMedium.inter(), bodySmall = bodySmall.inter(),
labelLarge = labelLarge.inter(), labelMedium = labelMedium.inter(), labelSmall = labelSmall.inter(),
)
}
Binary file added android/app/src/main/res/font/inter_bold.ttf
Binary file not shown.
Binary file added android/app/src/main/res/font/inter_medium.ttf
Binary file not shown.
Binary file added android/app/src/main/res/font/inter_regular.ttf
Binary file not shown.
Binary file added android/app/src/main/res/font/inter_semibold.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ContentPaste
Expand All @@ -16,6 +17,7 @@ import androidx.compose.material.icons.rounded.Image
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
Expand Down Expand Up @@ -113,6 +115,28 @@ class ShareScreenshotTest {
ShareSheetUi(preview, peers, targetId = imac.id, phase = SharePhase.FAILED, error = "Office iMac declined"),
)

/** The handle while something is dragged: the tab at its real window size, against the edge. */
private fun dropTab(ui: DropTabUi) = shoot {
Box(Modifier.fillMaxSize()) {
Box(
Modifier.align(if (ui.rightSide) Alignment.CenterEnd else Alignment.CenterStart)
.size(DropTabLayout.width(ui.targets.size).dp, DropTabLayout.height(ui.targets.size).dp),
) { DropTab(ui) }
}
}

private val dropTargets get() = listOf(DropTarget(DropTargets.ALL, "Send to all", "3 devices nearby", everyone = true)) +
peers.map { DropTarget(it.id, it.alias, if (it.id == laptop.id) "My device" else it.deviceModel, it.deviceType, it.deviceModel) }

@Test
fun dropTab() = dropTab(DropTabUi(true, dropTargets, hovered = laptop.id, over = true, defaultId = imac.id))

@Test
fun dropTabLeft() = dropTab(DropTabUi(false, dropTargets, defaultId = laptop.id))

@Test
fun dropTabNoDevices() = dropTab(DropTabUi(true, emptyList(), over = true))

private fun actions(selected: String) = listOf(
EdgeAction("clipboard", "Clipboard", "Flight AF 1234 lands 18:40, terminal 2E", Icons.Rounded.ContentPaste),
EdgeAction("photo", "Latest photo", "2 min ago", Icons.Rounded.Image, thumbnail = photo()),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading