diff --git a/wallet-native/android/build.gradle b/wallet-native/android/build.gradle index bf41263..5d7213c 100644 --- a/wallet-native/android/build.gradle +++ b/wallet-native/android/build.gradle @@ -10,6 +10,22 @@ plugins { group = 'com.principlezerolabs.wizard' version = '0.0.1' +// The five faces from the same packages React Native loads (mobile/src/theme.ts). +// Copied at build time so the binaries stay out of git. +def wizardFaceFiles = [ + "../../node_modules/@expo-google-fonts/fraunces/400Regular/Fraunces_400Regular.ttf", + "../../node_modules/@expo-google-fonts/figtree/400Regular/Figtree_400Regular.ttf", + "../../node_modules/@expo-google-fonts/figtree/500Medium/Figtree_500Medium.ttf", + "../../node_modules/@expo-google-fonts/figtree/600SemiBold/Figtree_600SemiBold.ttf", + "../../node_modules/@expo-google-fonts/ibm-plex-mono/400Regular/IBMPlexMono_400Regular.ttf", +] +def wizardFaceAssets = layout.buildDirectory.dir("generated/wizard-faces").get().asFile + +tasks.register("copyWizardFaces", Copy) { + into(new File(wizardFaceAssets, "fonts")) + from(wizardFaceFiles) +} + android { namespace "com.principlezerolabs.wizard.wallet" defaultConfig { @@ -18,6 +34,18 @@ android { versionCode 1 versionName "0.0.1" } + sourceSets { + main { + assets.srcDir(wizardFaceAssets) + } + } +} + +tasks.named("preBuild").configure { dependsOn("copyWizardFaces") } +afterEvaluate { + tasks.matching { it.name ==~ /(?i).*(merge|package).*[Aa]ssets.*/ }.configureEach { + dependsOn("copyWizardFaces") + } } dependencies { diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt index d100195..9c95522 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt @@ -2,7 +2,6 @@ package com.principlezerolabs.wizard.wallet import android.app.Activity import android.app.Dialog -import android.graphics.Color import android.graphics.Typeface import android.graphics.drawable.GradientDrawable import android.view.Gravity @@ -97,7 +96,12 @@ object ConfirmSheet { addFlags(WindowManager.LayoutParams.FLAG_SECURE) } - fun text(s: String, size: Float, color: Int, typeface: Typeface = Typeface.DEFAULT): TextView = + val bodyFace = Face.of(activity, Face.BODY) + val strong = Face.of(activity, Face.BUTTON) + val labelFace = Face.of(activity, Face.LABEL) + val mono = Face.of(activity, Face.MONO) + + fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace): TextView = TextView(activity).apply { text = s textSize = size @@ -109,30 +113,17 @@ object ConfirmSheet { fun add(v: View, top: Int = 12) = body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) }) - fun button(label: String, primary: Boolean, onClick: () -> Unit) = Button(activity).apply { - text = label - isAllCaps = false - textSize = if (primary) 17f else 16f - setTextColor(if (primary) Theme.buttonText else STAR) - background = if (primary) { - GradientDrawable().apply { - setColor(Theme.buttonBackground) - cornerRadius = dp(28).toFloat() - } - } else { - null - } - if (!primary) setBackgroundColor(Color.TRANSPARENT) - setOnClickListener { onClick() } - } + fun button(label: String, primary: Boolean, onClick: () -> Unit) = + Face.button(activity, label, filled = primary, onClick) fun header(title: String) { val row = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL gravity = Gravity.CENTER_VERTICAL - addView(text(title, 20f, STAR, Typeface.DEFAULT_BOLD), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) + addView(text(title, 28f, STAR, Face.of(activity, Face.TITLE)), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) // Only the test network is named (issue #10): mainnet is the default people never need to see. - if (WalletSettings.testnet) addView(text("TESTNET", 12f, NIGHT, Typeface.DEFAULT_BOLD).apply { + if (WalletSettings.testnet) addView(text("TESTNET", 11f, NIGHT, strong).apply { + letterSpacing = 0.05f setPadding(dp(8), dp(3), dp(8), dp(3)) background = GradientDrawable().apply { setColor(GOLD) @@ -144,7 +135,7 @@ object ConfirmSheet { } fun field(name: String, value: View) { - add(text(name, 13f, DUST), 14) + add(text(name, 13f, DUST, labelFace), 14) add(value, 2) } @@ -178,49 +169,49 @@ object ConfirmSheet { val d = Format.usd(z, usdPerZec) return if (usdFirst) "$d · $zz" else "$zz · $d" } - if (isShield) add(text("Arrived at your exchange address", 16f, DUST, Typeface.DEFAULT_BOLD), 16) + if (isShield) add(text("Arrived at your exchange address", 15f, DUST), 16) // The payment in the unit the person chose; the other one under it. A request's is its fee. - add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount, 36f, STAR, if (WalletSettings.serifAmount) Typeface.SERIF else Typeface.DEFAULT), 16) + add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount, 40f, STAR, Face.display(activity)), 16) if (usdPerZec != null && !isRequest) { val small = if (usdFirst) zecAmount else usdAmount!! - add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", 16f, DUST, Typeface.DEFAULT_BOLD), 2) + add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", 15f, DUST), 2) } if (isShield) { field("From", text("Your public exchange address", 16f, STAR)) field("To", text("Your private balance", 16f, STAR)) field("Fee", text(both(proposal.fee), 16f, STAR)) - field("Private after", text(both(proposal.shielded), 16f, STAR, Typeface.DEFAULT_BOLD)) - add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", 13f, DUST), 12) + field("Private after", text(both(proposal.shielded), 17f, STAR, strong)) + add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", 15f, DUST), 12) } else { val to = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL } - if (label != null) to.addView(text(label, 16f, STAR, Typeface.DEFAULT_BOLD)) - for (a in proposal.to) to.addView(text(Format.grouped(a), 13f, STAR, Typeface.MONOSPACE).apply { setTextIsSelectable(true) }) + if (label != null) to.addView(text(label, 17f, STAR, strong)) + for (a in proposal.to) to.addView(text(Format.grouped(a), 13f, STAR, mono).apply { setTextIsSelectable(true) }) // A public address says so (#54). when (proposal.recipient) { WalletRecipientKind.PUBLIC -> "Public address" WalletRecipientKind.TEX -> "Exchange address for public payments only" WalletRecipientKind.PRIVATE -> null - }?.let { to.addView(text(it, 13f, GOLD, Typeface.DEFAULT_BOLD)) } + }?.let { to.addView(text(it, 13f, GOLD, strong)) } field("To", to) if (isRequest) { memoLines.firstOrNull()?.let { field("Request", text(it, 16f, STAR)) } - add(text("Only the fee leaves your wallet. They pay the request if they choose to.", 13f, DUST), 12) + add(text("Only the fee leaves your wallet. They pay the request if they choose to.", 15f, DUST), 12) } else { proposal.memo?.takeIf { it.isNotEmpty() }?.let { field("Note", text(it, 16f, STAR)) } field("Fee", text(both(proposal.fee), 16f, STAR)) - field("Total", text(both(proposal.total), 16f, STAR, Typeface.DEFAULT_BOLD)) + field("Total", text(both(proposal.total), 17f, STAR, strong)) } val seen = "This payment is public. Anyone can see the amount and the address it goes to. The rest of your money stays private." when (proposal.recipient) { WalletRecipientKind.PUBLIC -> seen WalletRecipientKind.TEX -> "$seen It goes in two steps, through a one-time public address of yours, so the fee covers two transactions." WalletRecipientKind.PRIVATE -> null - }?.let { add(text(it, 13f, STAR), 12) } + }?.let { add(text(it, 16f, STAR), 12) } } if (usdPerZec != null && !isRequest && !isShield) { - add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", 13f, DUST), 12) + add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", 15f, DUST), 12) } - if (error != null) add(text(error, 15f, CINNABAR), 16) + if (error != null) add(text(error, 16f, CINNABAR), 16) val spinner = ProgressBar(activity).apply { visibility = View.GONE } add(spinner, 16) if (!canSend) { diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt index 5745017..d75b5ff 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt @@ -2,7 +2,6 @@ package com.principlezerolabs.wizard.wallet import android.app.Activity import android.app.Dialog -import android.graphics.Color import android.graphics.Typeface import android.graphics.drawable.GradientDrawable import android.view.Gravity @@ -10,7 +9,6 @@ import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.WindowManager -import android.widget.Button import android.widget.LinearLayout import android.widget.TextView @@ -61,7 +59,10 @@ object ContactSheet { addFlags(WindowManager.LayoutParams.FLAG_SECURE) } - fun text(s: String, size: Float, color: Int, typeface: Typeface = Typeface.DEFAULT) = TextView(activity).apply { + val bodyFace = Face.of(activity, Face.BODY) + val strong = Face.of(activity, Face.BUTTON) + + fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace) = TextView(activity).apply { text = s textSize = size setTextColor(color) @@ -73,11 +74,11 @@ object ContactSheet { body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) }) fun field(label: String, value: View) { - add(text(label, 13f, Theme.muted), 14) + add(text(label, 13f, Theme.muted, Face.of(activity, Face.LABEL)), 14) add(value, 2) } - fun mono(s: String) = text(Format.grouped(s), 13f, Theme.text, Typeface.MONOSPACE).apply { setTextIsSelectable(true) } + fun mono(s: String) = text(Format.grouped(s), 13f, Theme.text, Face.of(activity, Face.MONO)).apply { setTextIsSelectable(true) } var done = false fun finish(ok: Boolean) { @@ -87,39 +88,16 @@ object ContactSheet { onResult(ok) } - add(text(change.title, 20f, Theme.text, Typeface.DEFAULT_BOLD), 0) - field("Name", text(change.name, 18f, Theme.text, Typeface.DEFAULT_BOLD)) + add(text(change.title, 28f, Theme.text, Face.of(activity, Face.TITLE)), 0) + field("Name", text(change.name, 17f, Theme.text, strong)) change.was?.let { (label, value) -> field(label, if (change.wasAddress) mono(value) else text(value, 16f, Theme.muted)) } change.zcashName?.let { field(".zcash name", text(it, 16f, Theme.text)) } field(change.addressLabel, mono(change.address)) - change.note?.let { add(text(it, 14f, Theme.muted), 14) } - add( - Button(activity).apply { - text = change.confirm - isAllCaps = false - textSize = 17f - setTextColor(Theme.buttonText) - background = GradientDrawable().apply { - setColor(Theme.buttonBackground) - cornerRadius = dp(28).toFloat() - } - setOnClickListener { finish(true) } - }, - 20, - ) - add( - Button(activity).apply { - text = "Cancel" - isAllCaps = false - textSize = 16f - setTextColor(Theme.text) - setBackgroundColor(Color.TRANSPARENT) - setOnClickListener { finish(false) } - }, - 4, - ) + change.note?.let { add(text(it, 15f, Theme.muted), 14) } + add(Face.button(activity, change.confirm, filled = true) { finish(true) }, 20) + add(Face.button(activity, "Cancel", filled = false) { finish(false) }, 4) dialog.show() } } diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt new file mode 100644 index 0000000..f1c2357 --- /dev/null +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt @@ -0,0 +1,76 @@ +package com.principlezerolabs.wizard.wallet + +import android.app.Activity +import android.graphics.Color +import android.graphics.Typeface +import android.graphics.drawable.GradientDrawable +import android.util.Log +import android.widget.Button + +/** + * The same faces as `mobile/src/theme.ts`. Gradle copies those files into this + * module's assets (`copyWizardFaces`). [Typeface.create] does not see Expo's + * JavaScript names, and this library does not compile against React Native. + */ +object Face { + const val TITLE = "Fraunces_400Regular" + const val BODY = "Figtree_400Regular" + const val LABEL = "Figtree_500Medium" + const val BUTTON = "Figtree_600SemiBold" + const val MONO = "IBMPlexMono_400Regular" + + private const val TAG = "WizardFace" + + private val files = mapOf( + TITLE to "fonts/Fraunces_400Regular.ttf", + BODY to "fonts/Figtree_400Regular.ttf", + LABEL to "fonts/Figtree_500Medium.ttf", + BUTTON to "fonts/Figtree_600SemiBold.ttf", + MONO to "fonts/IBMPlexMono_400Regular.ttf", + ) + private val loaded = mutableMapOf() + + fun of(activity: Activity, name: String): Typeface { + loaded[name]?.let { return it } + val path = files.getValue(name) + val face = try { + Typeface.createFromAsset(activity.assets, path) + } catch (e: Exception) { + Log.e(TAG, "could not load $path", e) + Typeface.DEFAULT + } + loaded[name] = face + return face + } + + /** Fraunces when the amount setting is serif, otherwise Figtree. */ + fun display(activity: Activity): Typeface = + of(activity, if (WalletSettings.serifAmount) TITLE else BODY) + + fun dp(activity: Activity, v: Int) = (v * activity.resources.displayMetrics.density).toInt() + + fun capsule(activity: Activity, color: Int) = GradientDrawable().apply { + setColor(color) + cornerRadius = dp(activity, 999).toFloat() + } + + /** A full-width action: Figtree SemiBold 17, 52dp tall, a capsule when filled. */ + fun button(activity: Activity, label: String, filled: Boolean, onClick: () -> Unit) = + Button(activity).apply { + text = label + isAllCaps = false + textSize = 17f + typeface = of(activity, BUTTON) + includeFontPadding = false + minimumHeight = dp(activity, 52) + setPadding(dp(activity, 20), 0, dp(activity, 20), 0) + setTextColor(if (filled) Theme.buttonText else Theme.text) + if (filled) { + background = capsule(activity, Theme.buttonBackground) + } else { + background = null + setBackgroundColor(Color.TRANSPARENT) + } + setOnClickListener { onClick() } + } +} diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt index c5f269d..4d13a6a 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt @@ -7,7 +7,6 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint -import android.graphics.Typeface import android.graphics.drawable.GradientDrawable import android.text.Editable import android.text.InputType @@ -26,7 +25,6 @@ import android.widget.EditText import android.widget.GridLayout import android.widget.LinearLayout import android.widget.NumberPicker -import android.widget.ProgressBar import android.widget.ScrollView import android.widget.Switch import android.widget.TextView @@ -146,14 +144,27 @@ object PhraseScreens { fun clear() = body.removeAllViews() - fun title(s: String) = text(s, 24f, STAR, bold = true) + fun title(s: String) = TextView(activity).apply { + text = s + textSize = 28f + setTextColor(STAR) + typeface = Face.of(activity, Face.TITLE) + setPadding(0, dp(6), 0, dp(6)) + }.also { body.addView(it) } fun text(s: String, size: Float = 16f, color: Int = DUST, bold: Boolean = false): TextView = TextView(activity).apply { text = s textSize = size setTextColor(color) - if (bold) typeface = Typeface.DEFAULT_BOLD + typeface = Face.of( + activity, + when { + bold -> Face.BUTTON + size <= 14f -> Face.LABEL + else -> Face.BODY + }, + ) setPadding(0, dp(6), 0, dp(6)) }.also { body.addView(it) } @@ -162,40 +173,44 @@ object PhraseScreens { cornerRadius = dp(radius).toFloat() } - fun primary(label: String, onClick: () -> Unit): Button = Button(activity).apply { - text = label - isAllCaps = false - textSize = 17f - setTextColor(Theme.buttonText) - background = rounded(Theme.buttonBackground, 14) - setOnClickListener { onClick() } - }.also { addSpaced(it) } - - fun secondary(label: String, onClick: () -> Unit): Button = Button(activity).apply { - text = label - isAllCaps = false - textSize = 16f - setTextColor(STAR) - setBackgroundColor(Color.TRANSPARENT) - setOnClickListener { onClick() } - }.also { addSpaced(it) } + fun primary(label: String, onClick: () -> Unit): Button = + Face.button(activity, label, filled = true, onClick).also { addSpaced(it) } + + fun secondary(label: String, onClick: () -> Unit): Button = + Face.button(activity, label, filled = false, onClick).also { addSpaced(it) } fun addSpaced(v: View) { body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(12) }) } + /** One phrase word: the index in muted mono, the word in mono, on a raised ground. */ + fun wordCell(index: Int, word: String) = LinearLayout(activity).apply { + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + background = rounded(RAISED, 14) + setPadding(dp(12), dp(12), dp(12), dp(12)) + minimumHeight = dp(48) + addView(TextView(activity).apply { + text = "${index + 1}" + typeface = Face.of(activity, Face.MONO) + textSize = 13f + setTextColor(DUST) + gravity = Gravity.END + minWidth = dp(24) + }) + addView(TextView(activity).apply { + text = word + typeface = Face.of(activity, Face.MONO) + textSize = 16f + setTextColor(STAR) + setPadding(dp(8), 0, 0, 0) + }) + } + fun wordGrid(words: List) { val grid = GridLayout(activity).apply { columnCount = 2 } words.forEachIndexed { i, w -> - val cell = TextView(activity).apply { - text = "${i + 1} $w" - typeface = Typeface.MONOSPACE - textSize = 16f - setTextColor(STAR) - background = rounded(RAISED, 10) - setPadding(dp(10), dp(8), dp(10), dp(8)) - } - grid.addView(cell, GridLayout.LayoutParams( + grid.addView(wordCell(i, w), GridLayout.LayoutParams( GridLayout.spec(i / 2), GridLayout.spec(i % 2, 1f)).apply { width = 0 setMargins(dp(4), dp(4), dp(4), dp(4)) @@ -217,7 +232,7 @@ object PhraseScreens { s.title("Your recovery phrase") s.text("Write these 24 words on paper, in order, and keep it somewhere safe. Anyone who has them can take your money, and ${WalletSettings.appName} can't recover them for you.") s.wordGrid(words) - s.text("Screenshots are blocked here. Don't save the words in notes, email or a password app that syncs.", 13f) + s.text("Screenshots are blocked here. Don't save the words in notes, email or a password app that syncs.", 15f) if (backup) { s.primary("I've written them down") { checkStep(s, words, onBack = { wordsStep() }, onPassed = { finish(true) }) } s.secondary("Not now") { finish(false) } @@ -254,9 +269,9 @@ object PhraseScreens { topMargin = s.dp(12) bottomMargin = s.dp(12) }) - s.text("On the other phone: ${WalletSettings.appName} → I have a wallet → Viewing key → Scan.", 13f) + s.text("On the other phone: ${WalletSettings.appName} → I have a wallet → Viewing key → Scan.", 15f) val keyText = s.text(key, 13f, STAR).apply { - typeface = Typeface.MONOSPACE + typeface = Face.of(activity, Face.MONO) visibility = View.GONE } lateinit var reveal: Button @@ -267,7 +282,7 @@ object PhraseScreens { // The text sits under its button. s.body.removeView(keyText) s.body.addView(keyText) - s.text("Screenshots are blocked here.", 13f) + s.text("Screenshots are blocked here.", 15f) s.primary("Done") { finish() } s.dialog.setOnKeyListener { _, code, e -> if (code == KeyEvent.KEYCODE_BACK && e.action == KeyEvent.ACTION_UP) finish() @@ -283,7 +298,7 @@ object PhraseScreens { s.clear() s.title("Check your copy") val pos = positions[step] - s.text("Which is word ${pos + 1}?", 20f, STAR) + s.text("Which is word ${pos + 1}?", 16f, STAR) s.text("${step + 1} of ${positions.size}", 13f) val answer = words[pos] val choices = (listOf(answer) + words.toSet().minus(answer).shuffled().take(5)).shuffled() @@ -292,9 +307,12 @@ object PhraseScreens { val b = Button(s.activity).apply { text = w isAllCaps = false - typeface = Typeface.MONOSPACE + typeface = Face.of(s.activity, Face.MONO) + textSize = 16f setTextColor(STAR) - background = s.rounded(RAISED, 10) + background = s.rounded(RAISED, 14) + minimumHeight = s.dp(48) + setPadding(s.dp(16), s.dp(12), s.dp(16), s.dp(12)) setOnClickListener { if (w == answer) { step += 1 @@ -310,7 +328,7 @@ object PhraseScreens { }) } s.addSpaced(grid) - if (wrong) s.text("That's not word ${pos + 1}. Look at what you wrote down and try again.", 15f, CINNABAR) + if (wrong) s.text("That's not word ${pos + 1}. Look at what you wrote down and try again.", 16f, CINNABAR) s.secondary("Back to the words") { onBack() } } render(false) @@ -380,11 +398,15 @@ object PhraseScreens { lateinit var keyStep: () -> Unit // Recovery phrase | Viewing key, at the top of both entry steps. + // Same choice as the React Native pill tabs: a sheet track, a raised pill, + // the chosen word in the text colour, the other muted. fun tabs() { val row = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL - background = s.rounded(RAISED, 10) - setPadding(s.dp(3), s.dp(3), s.dp(3), s.dp(3)) + gravity = Gravity.CENTER_VERTICAL + background = s.rounded(Theme.sheet, 999) + setPadding(s.dp(4), s.dp(4), s.dp(4), s.dp(4)) + minimumHeight = s.dp(48) } for ((label, isKey) in listOf("Recovery phrase" to false, "Viewing key" to true)) { val on = isKey == viewingKey @@ -392,8 +414,11 @@ object PhraseScreens { text = label isAllCaps = false textSize = 15f - setTextColor(if (on) NIGHT else STAR) - background = if (on) s.rounded(STAR, 8) else null + typeface = Face.of(activity, Face.BUTTON) + includeFontPadding = false + setTextColor(if (on) STAR else DUST) + background = if (on) s.rounded(RAISED, 999) else null + minimumHeight = s.dp(40) isFocusable = false contentDescription = if (on) "$label, selected" else label setOnClickListener { @@ -411,7 +436,7 @@ object PhraseScreens { s.clear() s.title("Roughly when did you create this wallet?") s.text("${WalletSettings.appName} looks for your payments from then on. If you're not sure, pick an earlier month.") - if (viewingKey && keyNetworkFound == "testnet") s.text("This key is for the test network. Test coins have no value.", 13f) + if (viewingKey && keyNetworkFound == "testnet") s.text("This key is for the test network. Test coins have no value.") val now = Calendar.getInstance() val months = DateFormatSymbols.getInstance().months.take(12).toTypedArray() val month = NumberPicker(activity).apply { @@ -439,6 +464,7 @@ object PhraseScreens { val olderSwitch = Switch(activity).apply { text = "Look for older funds" textSize = 16f + typeface = Face.of(activity, Face.BODY) setTextColor(STAR) isChecked = true } @@ -451,7 +477,8 @@ object PhraseScreens { "If you used this phrase in another wallet before August 2026, some of your ZEC may be in an older " + "part of Zcash. Looking for it takes longer and uses more data." } - textSize = 13f + textSize = 16f + typeface = Face.of(activity, Face.BODY) setTextColor(DUST) setPadding(0, s.dp(6), 0, s.dp(6)) }) @@ -464,9 +491,7 @@ object PhraseScreens { month.setOnValueChangedListener { _, _, _ -> showOlder() } year.setOnValueChangedListener { _, _, _ -> showOlder() } showOlder() - val status = s.text("", 15f, CINNABAR) - val spinner = ProgressBar(activity).apply { visibility = View.GONE } - s.addSpaced(spinner) + val status = s.text("", 16f, CINNABAR) lateinit var restoreButton: Button lateinit var unknownButton: Button lateinit var backButton: Button @@ -475,7 +500,7 @@ object PhraseScreens { unknownButton.isEnabled = false backButton.isEnabled = false olderSwitch.isEnabled = false - spinner.visibility = View.VISIBLE + // The restore screen never moves (design guide §6). The words are the signal. status.setTextColor(DUST) status.text = "Restoring…" // Read on the UI thread, before the work moves off it. @@ -489,7 +514,6 @@ object PhraseScreens { closed = true s.dialog.dismiss() } else { - spinner.visibility = View.GONE status.setTextColor(CINNABAR) status.text = problem restoreButton.isEnabled = true @@ -517,15 +541,17 @@ object PhraseScreens { if (network in viewOnlyNetworks) { s.text( "${WalletSettings.appName} can show this wallet’s money, but paying from it isn’t ready yet. Your " + - "phrase stays on this phone, so the wallet can pay once it is.", 13f) + "phrase stays on this phone, so the wallet can pay once it is.") } val counter = s.text("", 13f) val field = EditText(activity).apply { setHintTextColor(DUST) setTextColor(STAR) - typeface = Typeface.MONOSPACE - background = s.rounded(RAISED, 10) - setPadding(s.dp(12), s.dp(12), s.dp(12), s.dp(12)) + typeface = Face.of(activity, Face.MONO) + textSize = 16f + background = s.rounded(RAISED, 14) + minimumHeight = s.dp(48) + setPadding(s.dp(16), s.dp(14), s.dp(16), s.dp(14)) // No suggestions or learning: the keyboard must not remember the words. inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS @@ -535,7 +561,7 @@ object PhraseScreens { s.addSpaced(field) val suggestions = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL } s.addSpaced(suggestions) - val errorText = s.text("", 15f, CINNABAR) + val errorText = s.text("", 16f, CINNABAR) lateinit var removeButton: Button lateinit var nextButton: Button // Added after the buttons below, so the field never moves down the screen. @@ -544,14 +570,7 @@ object PhraseScreens { fun refresh() { grid.removeAllViews() entered.forEachIndexed { i, w -> - grid.addView(TextView(activity).apply { - text = "${i + 1} $w" - typeface = Typeface.MONOSPACE - textSize = 16f - setTextColor(STAR) - background = s.rounded(RAISED, 10) - setPadding(s.dp(10), s.dp(8), s.dp(10), s.dp(8)) - }, GridLayout.LayoutParams(GridLayout.spec(i / 2), GridLayout.spec(i % 2, 1f)).apply { + grid.addView(s.wordCell(i, w), GridLayout.LayoutParams(GridLayout.spec(i / 2), GridLayout.spec(i % 2, 1f)).apply { width = 0 setMargins(s.dp(4), s.dp(4), s.dp(4), s.dp(4)) }) @@ -595,13 +614,16 @@ object PhraseScreens { suggestions.addView(Button(activity).apply { text = w isAllCaps = false - typeface = Typeface.MONOSPACE - setTextColor(NIGHT) - background = s.rounded(STAR, 16) + typeface = Face.of(activity, Face.MONO) + textSize = 16f + setTextColor(STAR) + background = s.rounded(RAISED, 999) + minimumHeight = s.dp(48) + setPadding(s.dp(16), 0, s.dp(16), 0) // Tapping a suggestion must not take focus from the field. isFocusable = false setOnClickListener { accept(w) } - }, LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { marginEnd = s.dp(6) }) + }, LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { marginEnd = s.dp(8) }) } } }) @@ -637,6 +659,7 @@ object PhraseScreens { val toggle = Switch(activity).apply { text = "Restore on the test network" textSize = 16f + typeface = Face.of(activity, Face.BODY) setTextColor(STAR) isChecked = network == "testnet" isFocusable = false @@ -649,7 +672,8 @@ object PhraseScreens { advanced.addView(toggle, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)) advanced.addView(TextView(activity).apply { text = "For developers. Test coins have no value." - textSize = 13f + textSize = 16f + typeface = Face.of(activity, Face.BODY) setTextColor(DUST) setPadding(0, s.dp(6), 0, s.dp(6)) }) @@ -663,6 +687,8 @@ object PhraseScreens { showAdvanced() } advancedButton.setTextColor(DUST) + advancedButton.textSize = 13f + advancedButton.typeface = Face.of(activity, Face.LABEL) advancedButton.isFocusable = false s.addSpaced(advanced) showAdvanced() @@ -682,10 +708,10 @@ object PhraseScreens { hint = "uview1…" setHintTextColor(DUST) setTextColor(STAR) - typeface = Typeface.MONOSPACE - textSize = 13f - background = s.rounded(RAISED, 10) - setPadding(s.dp(12), s.dp(12), s.dp(12), s.dp(12)) + typeface = Face.of(activity, Face.MONO) + textSize = 16f + background = s.rounded(RAISED, 14) + setPadding(s.dp(16), s.dp(14), s.dp(16), s.dp(14)) // No suggestions or learning: the keyboard must not remember the key. inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS @@ -696,7 +722,7 @@ object PhraseScreens { setText(key) } s.addSpaced(field) - val errorText = s.text("", 15f, CINNABAR) + val errorText = s.text("", 16f, CINNABAR) lateinit var nextButton: Button fun showNext() { nextButton.visibility = if (key.isBlank()) View.GONE else View.VISIBLE @@ -710,21 +736,53 @@ object PhraseScreens { showNext() } }) - s.secondary("Paste") { + fun chip(label: String, onClick: () -> Unit) = Button(activity).apply { + text = label + isAllCaps = false + textSize = 17f + typeface = Face.of(activity, Face.BUTTON) + includeFontPadding = false + setTextColor(STAR) + background = s.rounded(RAISED, 999) + minimumHeight = s.dp(48) + setPadding(s.dp(16), 0, s.dp(16), 0) + isFocusable = false + setOnClickListener { onClick() } + } + val actions = LinearLayout(activity).apply { + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + } + actions.addView(chip("Paste") { val clip = activity.getSystemService(ClipboardManager::class.java)?.primaryClip val text = clip?.takeIf { it.itemCount > 0 }?.getItemAt(0)?.coerceToText(activity)?.toString()?.trim() if (!text.isNullOrEmpty()) field.setText(text) - }.isFocusable = false + }) if (scan != null) { - s.secondary("Scan") { + actions.addView(chip("Scan") { scan { text, problem -> when { text != null -> field.setText(text) problem != null -> errorText.text = problem } } - }.isFocusable = false + }, LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { marginStart = s.dp(8) }) + } + actions.addView(View(activity), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) + val helpButton = Button(activity).apply { + text = "Where do I find it?" + isAllCaps = false + textSize = 17f + typeface = Face.of(activity, Face.BUTTON) + includeFontPadding = false + setTextColor(Theme.accent) + background = null + setBackgroundColor(Color.TRANSPARENT) + minimumHeight = s.dp(48) + isFocusable = false } + actions.addView(helpButton) + s.addSpaced(actions) nextButton = s.primary("Next") { val found = keyNetwork(key) if (found == null) { @@ -743,19 +801,14 @@ object PhraseScreens { val help = s.text( "In ${WalletSettings.appName} on another phone: Me → Show viewing key, then tap Scan here. In another " + "wallet, look in its settings for “Export viewing key” or “Unified full viewing key”. It’s one long line that starts with “uview”. Never enter a spending key here, and never give " + - "your recovery phrase to anyone.", 13f) + "your recovery phrase to anyone.") help.visibility = View.GONE - val helpButton = s.secondary("Where do I find it? ▾") {} - helpButton.setTextColor(DUST) - helpButton.isFocusable = false helpButton.setOnClickListener { - val open = help.visibility != View.VISIBLE - help.visibility = if (open) View.VISIBLE else View.GONE - helpButton.text = if (open) "Where do I find it? ▴" else "Where do I find it? ▾" + help.visibility = if (help.visibility != View.VISIBLE) View.VISIBLE else View.GONE } - // The help line sits under its button. + // The help line sits under the link, above Next. s.body.removeView(help) - s.body.addView(help) + s.body.addView(help, s.body.indexOfChild(actions) + 1) s.secondary("Cancel") { cancel() }.isFocusable = false showNext() field.requestFocus()