Merge branch 'main' into glanceboard-tilt-angle-and-glance-down

This commit is contained in:
James Babcock committed 2026-11-15 22:38:39 -08:00
commit 37d81d0308
416 files changed
+34629 -3885

No files matched your search

+13 -4
View File
@@ -19,6 +19,9 @@ dependencies {
// app's captions (translation models download on demand, per language).
implementation 'com.google.mlkit:language-id:17.0.6'
implementation 'com.google.mlkit:translate:17.0.3'
// Pure-Java Opus decoder for the RayNeo iO's microphone (16 kHz mono Opus over
// BLE); the same one Glassly uses. See AndroidSpeechEngines.OpusDecoderAdapter.
implementation 'io.github.jaredmdobson:concentus:1.0.1'
}
def faceclawSherpaOnnxVersion = "1.13.0"
@@ -261,15 +264,21 @@ if (faceclawVersionFile.exists()) {
faceclawVersionName = faceclawVersionMatch.group(1)
}
}
def faceclawBuildRevision = System.getenv("FACECLAW_ANDROID_BUILD_REVISION") ?: "0"
if (!(faceclawBuildRevision ==~ /[0-4]/)) {
throw new GradleException("FACECLAW_ANDROID_BUILD_REVISION must be an integer from 0 to 4")
}
def faceclawVersionCode = {
// Prerelease labels belong in versionName, not the numeric versionCode.
def parts = (faceclawVersionName.split('-')[0].tokenize('.') + ["0", "0"]).take(3)*.toInteger()
return parts[0] * 10000 + parts[1] * 100 + parts[2]
// Last digit: build revision * 2, plus form factor (phone 0, Wear OS 1).
// Play requires distinct version codes even on separate form-factor tracks.
return (parts[0] * 10000 + parts[1] * 100 + parts[2]) * 10 + faceclawBuildRevision.toInteger() * 2
}()
android {
compileSdkVersion 35
buildToolsVersion "35"
compileSdkVersion 36
buildToolsVersion "36.0.0"
// ndkVersion ""
sourceSets.main {
@@ -279,7 +288,7 @@ android {
defaultConfig {
minSdkVersion 24
targetSdkVersion 35
targetSdkVersion 36
ndk {
// The NativeScript platform build.gradle has already added all four
// ABIs by the time app.gradle is applied, and abiFilters is additive,
@@ -46,6 +46,15 @@ class AndroidSessionLink(private val bleManager: FaceclawBleManager) : SessionLi
override fun isBonded(address: String): Boolean = bleManager.isBonded(address)
override fun requestBond(address: String) = bleManager.requestBond(address)
override fun removeBond(address: String): Boolean = bleManager.removeBond(address)
override fun hasCharacteristic(address: String, characteristicUuid: String): Boolean =
bleManager.hasCharacteristic(address, characteristicUuid)
override fun refreshServices(address: String, timeoutMs: Int): Boolean = bleManager.refreshServices(address, timeoutMs)
override fun prepareBenchmarkLink(address: String, mode: Int) = bleManager.prepareBenchmarkLink(address, mode)
override fun recordDisplayFrameSent() = FaceclawBleManager.recordDisplayFrameSent()
@@ -94,6 +94,44 @@ internal object AndroidSpeechEngines {
override fun close() = decoder.close()
}
/**
* The RayNeo iO's microphone: one 16 kHz mono Opus packet per BLE message (its remote
* audio stream, GlassesSessionIo), decoded with Concentus. No G2 DSP metadata; packets
* carry no counter, so "missing" stays 0 and a lost one is just a gap.
*/
class OpusDecoderAdapter : AudioPacketDecoder {
private val decoder = io.github.jaredmdobson.OpusDecoder(RayNeoIoProtocol.VOICE_SAMPLE_RATE, 1)
private var packets = 0L
private var errors = 0L
override fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int {
if (packet == null || packet.isEmpty() || pcmOut == null) return 0
return try {
val count = decoder.decode(packet, 0, packet.size, pcmOut, 0, pcmOut.size, false)
packets++
count
} catch (e: io.github.jaredmdobson.OpusException) {
errors++
if (errors == 1L || errors % 100 == 0L) {
android.util.Log.w("FaceclawVoice", "Opus decode error ($errors so far): ${e.message}")
}
0
}
}
/** 120 ms, Opus's longest frame. */
override val maxSamplesPerPacket: Int get() = RayNeoIoProtocol.VOICE_SAMPLE_RATE * 120 / 1000
override val hasFrameMeta: Boolean get() = false
override val lastAngleDegrees: Int get() = 0
override val lastSsr: Int get() = 0
override val realPackets: Long get() = packets
override val duplicatePackets: Long get() = 0
override val missingPackets: Long get() = 0
override val decodeErrors: Long get() = errors
override fun close() = decoder.resetState()
}
/**
* Open the phone's own microphone at the pipeline's native format (16 kHz
* mono PCM16), or null when it cannot start — the permission is missing
@@ -48,6 +48,17 @@ class AndroidStockLink(context: Context) : StockLink, FaceclawBleListener {
else -> BondState.UNKNOWN
}
override fun negotiatedMtu(address: String): Int = bleManager.getNegotiatedMtu(address)
override fun requestBond(address: String) = bleManager.requestBond(address)
override fun removeBond(address: String): Boolean = bleManager.removeBond(address)
override fun hasCharacteristic(address: String, characteristicUuid: String): Boolean =
bleManager.hasCharacteristic(address, characteristicUuid)
override fun refreshServices(address: String, timeoutMs: Int): Boolean = bleManager.refreshServices(address, timeoutMs)
override fun disconnect(address: String) = bleManager.disconnect(address)
override fun close() = bleManager.close()
@@ -189,6 +189,28 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun setRequiredFirmwareRevision(revision: Int) = core.setRequiredFirmwareRevision(revision)
/**
* Drive a RayNeo iO (constructed with its address as both arms and no ring). The phone's
* protocol identity is derived from ANDROID_ID so it survives reinstalls: the glasses bind
* to the first identity that authenticates and refuse others until put in pairing mode.
*/
fun useRayNeoIo() {
val androidId = try {
android.provider.Settings.Secure.getString(appContext.contentResolver, android.provider.Settings.Secure.ANDROID_ID)
} catch (_: Exception) {
null
}
val seed = "faceclaw-rayneo-phone-id:" + (androidId ?: android.os.Build.FINGERPRINT)
val phoneId = java.security.MessageDigest.getInstance("SHA-256").digest(seed.toByteArray(Charsets.UTF_8)).copyOf(6)
val model = android.os.Build.MODEL ?: "Android"
core.useRayNeoIo(phoneId, model, android.os.Build.MANUFACTURER ?: "Android", model)
}
fun isRayNeoIo(): Boolean = core.isRayNeoIo()
/** Drive an Even G1 on g1v0 (two arms, as a G2 pair's addresses). */
fun useG1() = core.useG1()
fun start() {
if (core.start()) {
activeInstance = this
@@ -235,6 +257,9 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled)
/** See [GlassesSessionCore.setVoiceWakeEnabled]. */
fun setVoiceWakeEnabled(enabled: Boolean) = core.setVoiceWakeEnabled(enabled)
fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean = core.awaitEvenHubSessionReady(timeoutMs)
fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq)
@@ -304,6 +329,13 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun sendFaceclawMicControl(record: ByteArray?, label: String, rightTemple: Boolean, leftTemple: Boolean): Boolean =
core.sendFaceclawMicControl(record, label, rightTemple, leftTemple)
fun addKeyboardEventListener(listener: FaceclawKeyboardEventListener?) = core.addKeyboardEventListener(listener)
fun removeKeyboardEventListener(listener: FaceclawKeyboardEventListener?) = core.removeKeyboardEventListener(listener)
fun sendFaceclawKeyboardControl(record: ByteArray?, label: String): Boolean =
core.sendFaceclawKeyboardControl(record, label)
fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean = core.startG2AudioForwarding(listener)
fun stopG2AudioForwarding() = core.stopG2AudioForwarding()
@@ -27,6 +27,11 @@ import java.util.concurrent.atomic.AtomicLong
class FaceclawBleManager(context: Context) {
companion object {
private const val TAG = "FaceclawBle"
/** Not public API, but long stable, and the only way short of sending the user to Settings. */
fun removeBond(device: BluetoothDevice): Boolean =
device.bondState == BluetoothDevice.BOND_NONE || device.javaClass.getMethod("removeBond").invoke(device) == true
private val WRITE_RETRY_DELAYS_MS = intArrayOf(1, 1, 1, 2, 4, 8, 12, 20, 35, 100, 200)
// Gap after each LE 2M PHY request before checking whether it landed and asking
@@ -160,6 +165,36 @@ class FaceclawBleManager(context: Context) {
}
}
/**
* Remove this phone's half of a pairing the other side no longer has. False when the platform refused.
*/
fun removeBond(address: String?): Boolean {
if (address == null || address.trim().isEmpty()) {
return false
}
return try {
removeBond(bluetoothAdapter.getRemoteDevice(address))
} catch (t: Throwable) {
Log.w(TAG, "removeBond failed: $address", t)
false
}
}
/** Start bonding, without waiting: the OS may ask the user, and [isBonded] tells when it is done. */
fun requestBond(address: String?) {
if (address == null || address.trim().isEmpty()) {
return
}
try {
val device = bluetoothAdapter.getRemoteDevice(address)
if (device.bondState == BluetoothDevice.BOND_NONE) {
Log.i(TAG, "requestBond " + address + ": " + device.createBond())
}
} catch (t: Throwable) {
Log.w(TAG, "requestBond failed: " + address, t)
}
}
/**
* Android's bond state for this address (BluetoothDevice.BOND_NONE /
* BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined.
@@ -364,6 +399,31 @@ class FaceclawBleManager(context: Context) {
return status == BluetoothGatt.GATT_SUCCESS
}
/** After discovery: whether the service table has this characteristic. */
fun hasCharacteristic(address: String, characteristicUuid: String): Boolean {
synchronized(bluetoothApiLock) {
val gatt = links[address]?.gatt ?: return false
val target = UUID.fromString(characteristicUuid)
return gatt.services.any { it.getCharacteristic(target) != null }
}
}
/**
* Forget the service table Android remembers for a bonded device and read it again. A G1 arm keeps its address across an
* install that changes its services, and a cached table would make new firmware look like the old one.
*/
fun refreshServices(address: String, timeoutMs: Int): Boolean {
synchronized(bluetoothApiLock) {
val gatt = links[address]?.gatt ?: return false
try {
gatt.javaClass.getMethod("refresh").invoke(gatt)
} catch (t: Throwable) {
Log.w(TAG, "refresh failed: $address", t)
}
}
return discoverServices(address, timeoutMs)
}
fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean {
synchronized(bluetoothApiLock) {
val gatt = requireGatt(address)
@@ -129,13 +129,21 @@ class FaceclawDeviceDiscovery(context: Context) {
&& manufacturerData[0] == 0x45.toByte() && manufacturerData[1] == 0x52.toByte()) {
return true
}
// RayNeo iO: manufacturer company 0x5716 ([07][MAC]...) outside pairing mode;
// in pairing mode only the "RayNeo iO-xxxx" name identifies it.
if (manufacturerData != null && manufacturerData.size >= 2
&& manufacturerData[0] == 0x16.toByte() && manufacturerData[1] == 0x57.toByte()) {
return true
}
if (name == null) {
return false
}
val upper = name.uppercase()
// A bare "R1" substring also matches unrelated hardware ("Oppo Enco
// R1"), and TS only classifies rings from the stock name prefix.
return upper.contains("G2") || upper.startsWith("EVEN R1")
// Even G1: its stock name, or g1v0's G1CFW_L_XXXXXX (before 0.5.66: G1v0_L, G1v0S_R).
return upper.contains("G2") || upper.startsWith("EVEN R1") || upper.startsWith("RAYNEO") ||
upper.startsWith("EVEN G1") || upper.startsWith("G1CFW_") || upper.startsWith("G1V0")
}
private fun buildJson(
@@ -0,0 +1,106 @@
package com.faceclaw.app
import android.content.Context
import android.os.Handler
import android.os.Looper
/**
* Android host for the shared [G1ArmFlashFlow]: owns the GATT link and the worker thread for one G1 arm's install, its
* restore to Even's firmware, or a question about what it runs, and delivers listener callbacks on the main thread. For app/native/g1-flasher.ts.
*/
class FaceclawG1Flasher(
context: Context,
address: String?,
side: String?,
firmwarePath: String?,
netCorePath: String?,
mode: String?,
connectWindowMs: Int,
) {
private val link = AndroidStockLink(context.applicationContext)
private val mainHandler = Handler(Looper.getMainLooper())
private val lock = Any()
@Volatile
private var listener: FaceclawFirmwareFlasherListener? = null
@Volatile
private var worker: Thread? = null
private val flow =
G1ArmFlashFlow(
link,
address ?: "",
side ?: "",
firmwarePath ?: "",
netCorePath ?: "",
G1ArmFlashFlow.mode(mode ?: ""),
connectWindowMs,
object : FaceclawFirmwareFlasherListener {
override fun onLog(line: String?) {
android.util.Log.i(G1ArmFlashFlow.TAG, line ?: "")
post { it.onLog(line) }
}
override fun onProgress(
lens: String?,
componentIndex: Int,
componentCount: Int,
blockIndex: Int,
blockCount: Int,
bytesSent: Long,
bytesTotal: Long,
) = post { it.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) }
override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") }
override fun onComplete(success: Boolean, detail: String?) = post { it.onComplete(success, detail ?: "") }
},
)
fun setListener(listener: FaceclawFirmwareFlasherListener?) {
this.listener = listener
}
fun start() {
synchronized(lock) {
if (worker != null) {
return
}
val w = Thread({ flow.run() }, "faceclaw-g1-flash")
worker = w
w.start()
}
}
fun cancel() {
flow.cancel()
}
fun close() {
cancel()
try {
link.close()
} catch (ignored: Exception) {
}
}
companion object {
/** The phone's pairing with an address these glasses no longer use. */
@JvmStatic
fun forgetPairing(context: Context, address: String?) {
if (address == null) return
val manager = context.applicationContext.getSystemService(Context.BLUETOOTH_SERVICE) as android.bluetooth.BluetoothManager
FaceclawBleManager.removeBond(manager.adapter.getRemoteDevice(address))
}
}
private fun post(action: (FaceclawFirmwareFlasherListener) -> Unit) {
mainHandler.post {
val current = listener
if (current != null) {
action(current)
}
}
}
}
@@ -114,7 +114,24 @@ class FaceclawVoiceController(context: Context) {
}
}
override fun createPacketDecoder(): AudioPacketDecoder = AndroidSpeechEngines.Lc3DecoderAdapter()
override fun micArrayLink(): MicArrayLink? {
val currentCommunicator = communicator ?: return null
return object : MicArrayLink {
override fun startForwarding(listener: FaceclawAudioPacketListener): Boolean =
currentCommunicator.startG2AudioForwarding(listener)
override fun stopForwarding() = currentCommunicator.stopG2AudioForwarding()
override fun isForwarding(): Boolean = currentCommunicator.isAudioCaptureActive()
override fun sendControl(record: ByteArray, label: String, rightTemple: Boolean, leftTemple: Boolean): Boolean =
currentCommunicator.sendFaceclawMicControl(record, label, rightTemple, leftTemple)
}
}
override fun createPacketDecoder(): AudioPacketDecoder =
if (communicator?.isRayNeoIo() == true) AndroidSpeechEngines.OpusDecoderAdapter()
else AndroidSpeechEngines.Lc3DecoderAdapter()
override fun openPhoneMic(): PcmAudioSource? = AndroidSpeechEngines.openPhoneMic(PHONE_MIC_CHUNK_SAMPLES)
@@ -134,12 +151,15 @@ class FaceclawVoiceController(context: Context) {
override fun release() {}
}
}
override fun recordingSink(): RecordingSink = RecordingSink { pcmBytes, sampleRate -> saveRecording(pcmBytes, sampleRate) }
}
private val session = VoiceCaptureSession(host)
// The recording of this controller's live captures (see startRecording). It outlives any one
// capture, and is only handed to the session while recording is enabled.
private var recording: MicRecordingWriter? = null
private var recordingEnabled = true
fun setListener(listener: FaceclawVoiceControllerListener?) {
session.setListener(listener)
}
@@ -153,11 +173,6 @@ class FaceclawVoiceController(context: Context) {
session.setUsePhoneMic(usePhoneMic)
}
/** When true, the decoded mic PCM for each session is saved as a WAV. */
fun setSaveRecordings(saveRecordings: Boolean) {
session.setSaveRecordings(saveRecordings)
}
/**
* Which on-device model {@link #start}("onboard") should load: "whisper"
* selects the second on-device model (sherpa-onnx offline Whisper); any
@@ -206,6 +221,88 @@ class FaceclawVoiceController(context: Context) {
session.setBeamFilter(enabled, centerDeg, halfWidthDeg)
}
/**
* Capture glasses sessions from the temples' own microphones (the custom firmware's
* mic_control stream) instead of the stock mixed stream. [configureRecord] is the CONFIGURE
* record to arm both temples with; null goes back to the mixed stream. Must be set before
* {@link #start}.
*/
fun setMicArray(configureRecord: ByteArray?) {
session.setMicArray(configureRecord)
}
/**
* Have the next {@link #start} play the recording at [path] (a .mka file) from [startMs] in
* place of any microphone; null goes back to the microphones. Progress arrives through the
* listener's onReplay.
*/
fun setReplay(path: String?, startMs: Long) {
session.setReplay(path, startMs)
}
/** Continue the running replay from [positionMs] into its recording. */
fun seekReplay(positionMs: Long) {
session.seekReplay(positionMs)
}
fun setReplayPaused(paused: Boolean) {
session.setReplayPaused(paused)
}
/**
* Record live captures to a new Matroska audio file at [path], from now until
* {@link #stopRecording}, across however many captures run in between: every source's audio
* as it arrives, before any processing. [configJson] describes the capture and is stored in
* the file. Returns false when the file cannot be created.
*/
@Synchronized
fun startRecording(path: String, configJson: String?): Boolean {
stopRecording()
return try {
val parent = File(path).parentFile
if (parent != null && !parent.exists()) parent.mkdirs()
recording = MicRecordingWriter(openFileOutput(path), configJson, System.currentTimeMillis())
session.setRecorder(if (recordingEnabled) recording else null)
true
} catch (t: Throwable) {
Log.w(TAG, "could not create recording $path", t)
recording = null
false
}
}
/**
* Whether captures are written to the recording right now: off while the capture running
* isn't one that is to be recorded.
*/
@Synchronized
fun setRecordingEnabled(enabled: Boolean) {
recordingEnabled = enabled
session.setRecorder(if (enabled) recording else null)
}
/** Whether a recording is open and still being written (false once writing to it failed). */
@Synchronized
fun isRecording(): Boolean = recording?.failed == false
/**
* Note a change in what is being captured (a JSON object) at the recording's current
* position; the audio after it is placed afresh on the recording's timeline.
*/
@Synchronized
fun noteRecordingEvent(json: String) {
recording?.event(json)
}
/** Complete the recording's file. Returns its length in ms, or -1 when none was open. */
@Synchronized
fun stopRecording(): Long {
val current = recording ?: return -1
recording = null
session.setRecorder(null)
return current.finish()
}
fun start(requestedMode: String?) {
session.start(requestedMode, 0)
}
@@ -231,29 +328,6 @@ class FaceclawVoiceController(context: Context) {
stop()
}
/** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */
private fun saveRecording(pcmBytes: ByteArray, sampleRate: Int) {
try {
val dir = File(appContext.getExternalFilesDir(null), "voice-recordings")
if (!dir.exists() && !dir.mkdirs()) {
Log.w(TAG, "could not create voice-recordings dir")
return
}
val stamp = java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US)
.format(java.util.Date())
val file = File(dir, "voice-$stamp.wav")
java.io.FileOutputStream(file).use { fos ->
fos.write(BinaryEncoding.wavHeader(pcmBytes.size, sampleRate, 1))
fos.write(pcmBytes)
}
Log.i(TAG, "saved voice recording " + file.absolutePath
+ " samples=" + (pcmBytes.size / 2)
+ " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / sampleRate))
} catch (t: Throwable) {
Log.w(TAG, "failed to save voice recording", t)
}
}
/**
* The on-device model directory for the given kind, populated by the
* download flow in asr-model.ts (releases before 0.5.0 copied the
@@ -167,6 +167,7 @@ class FontFileRenderer private constructor() {
* [width u16][height u16]
* [width*height coverage bytes, gamma-mapped]
* An ink-free glyph (space) has width = height = 0 but a valid advance.
* A color glyph (emoji) carries its ColorGlyphArt shade as its coverage.
* Empty array when the font cannot be loaded or the render fails.
*/
@JvmStatic
@@ -196,11 +197,16 @@ class FontFileRenderer private constructor() {
}
val penX = pad - bounds.left
val baselineY = pad - bounds.top
val bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ALPHA_8)
// Drawn in color: an emoji the system fallback supplies from a color font
// would keep only its silhouette in an alpha-only bitmap. ColorGlyphArt shades
// color glyphs and passes white ones through as their alpha.
val bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawText(text, penX.toFloat(), baselineY.toFloat(), paint)
val pixels = alpha8Pixels(bitmap, bw, bh)
val argb = IntArray(bw * bh)
bitmap.getPixels(argb, 0, bw, 0, 0, bw, bh)
bitmap.recycle()
val pixels = ColorGlyphArt.coverage(argb)
// Trim to the tight ink box; bearing/inkTop become pen- and
// line-relative inside the shared packer.
@@ -108,6 +108,64 @@ class ImageFileLoader private constructor() {
}
}
/** Longest side decodeRgbaFromBytes decodes at; larger images are subsampled. */
private const val MAX_RGBA_SIDE = 4096
/**
* Decode encoded image bytes (JPEG, PNG, WebP, GIF's first frame, BMP)
* to [widthLo, widthHi, heightLo, heightHi, R, G, B, A, ...] at native
* size, not premultiplied, so a transparent pixel keeps its colour;
* empty when undecodable. The EvenHub host converts these to grey the
* way the Even app does (app/apps/evenhub/image-pipeline.ts).
*/
@JvmStatic
fun decodeRgbaFromBytes(buffer: java.nio.ByteBuffer?): ByteArray {
if (buffer == null) return ByteArray(0)
try {
val source = buffer.duplicate()
source.rewind()
val data = ByteArray(source.remaining())
source.get(data)
if (data.isEmpty()) return ByteArray(0)
val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }
BitmapFactory.decodeByteArray(data, 0, data.size, bounds)
if (bounds.outWidth <= 0 || bounds.outHeight <= 0) return ByteArray(0)
var sample = 1
while (maxOf(bounds.outWidth, bounds.outHeight) / sample > MAX_RGBA_SIDE) sample *= 2
val options = BitmapFactory.Options().apply {
inPreferredConfig = Bitmap.Config.ARGB_8888
inPremultiplied = false
inSampleSize = sample
}
val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size, options) ?: return ByteArray(0)
val width = bitmap.width
val height = bitmap.height
val argb = IntArray(width * height)
bitmap.getPixels(argb, 0, width, 0, 0, width, height)
bitmap.recycle()
val packet = ByteArray(4 + argb.size * 4)
packet[0] = (width and 0xff).toByte()
packet[1] = ((width shr 8) and 0xff).toByte()
packet[2] = (height and 0xff).toByte()
packet[3] = ((height shr 8) and 0xff).toByte()
for (i in argb.indices) {
val pixel = argb[i]
val o = 4 + i * 4
packet[o] = (pixel shr 16).toByte()
packet[o + 1] = (pixel shr 8).toByte()
packet[o + 2] = pixel.toByte()
packet[o + 3] = (pixel ushr 24).toByte()
}
return packet
} catch (e: Exception) {
Log.w(TAG, "RGBA image decode failed", e)
return ByteArray(0)
} catch (e: OutOfMemoryError) {
Log.w(TAG, "RGBA image decode failed", e)
return ByteArray(0)
}
}
/**
* Scale a bitmap to fit within maxWidth x maxHeight (preserving aspect,
* never upscaling) and convert it to the grayscale packet format.
@@ -62,7 +62,7 @@ class PreviewBitmapUtil private constructor() {
/**
* A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes
* alpha; black, which the glasses show as unlit, is transparent), for
* showing glasses artwork on the phone's dark action bar.
* showing glasses artwork in the phone UI, which tints it to suit.
*/
@JvmStatic
fun whiteIconFromGray(gray: ByteBuffer?, width: Int, height: Int): Bitmap {
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Keyboard icon for the main page's tab-bar keyboard-dialog button (beside
the mic button). Material Design "keyboard" glyph (Apache 2.0); base fill
is overridden by tint-color in app.css. -->
<!-- Keyboard icon for the main page's keyboard-dialog button (beside the mic
button). Material Design "keyboard" glyph (Apache 2.0); base fill is
overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Microphone icon for the main page's tab-bar wakeword button.
<!-- Microphone icon for the main page's voice-input (wakeword) button.
Converted from ~/Downloads/noun-microphone-1368757.svg (Noun Project
icon #1368757); base fill is overridden by tint-color in app.css. -->
icon #1368757); base fill is overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Gear icon for the main page's Settings button (beside the mic and keyboard
buttons). Material Design "settings" glyph (Apache 2.0); base fill is
overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF333333"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
</vector>