Redesign watch navigation with a shared icon menu
This commit is contained in:
25 files changed
+759
-149
No files matched your search
@@ -39,18 +39,18 @@ class BackupTest {
|
||||
editor.commit()
|
||||
}
|
||||
@Test fun backupPagesAreReachableAndAutomaticUploadsDefaultOff() {
|
||||
val activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
try {
|
||||
instrumentation.runOnMainSync {
|
||||
fun descendants(view: View): List<View> = listOf(view) + if (view is ViewGroup)
|
||||
(0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
fun button(label: String) = descendants(activity.window.decorView).filterIsInstance<Button>().first { it.text == label }
|
||||
listOf("Server", "Transfers", "Server recordings", "Automatic backup", "Advanced").forEach {
|
||||
button(it).performClick(); button("Back").performClick()
|
||||
listOf("overview", "server", "transfers", "remote", "automatic", "advanced").forEach { page ->
|
||||
val activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java)
|
||||
.putExtra(BackupActivity.EXTRA_PAGE, page).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
try {
|
||||
instrumentation.runOnMainSync {
|
||||
fun descendants(view: View): List<View> = listOf(view) + if (view is ViewGroup)
|
||||
(0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
assertTrue(descendants(activity.window.decorView).filterIsInstance<Button>().any { it.contentDescription == "Open all sections" })
|
||||
}
|
||||
}
|
||||
assertFalse(settings.automatic)
|
||||
} finally { instrumentation.runOnMainSync { activity.finish() } }
|
||||
} finally { instrumentation.runOnMainSync { activity.finish() } }
|
||||
}
|
||||
assertFalse(settings.automatic)
|
||||
}
|
||||
@Test fun encryptedWatchKeyPersistsWithoutPlaintextPrivateKeyInPreferences() {
|
||||
val public = settings.generateKey()
|
||||
@@ -107,8 +107,8 @@ class BackupTest {
|
||||
try {
|
||||
settings.save(pending)
|
||||
settings.preferences.edit().remove("key").remove("public_key").commit()
|
||||
activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
press("Server")
|
||||
activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java)
|
||||
.putExtra(BackupActivity.EXTRA_PAGE, "server").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
instrumentation.runOnMainSync {
|
||||
assertEquals("Fingerprint must not require typing", 4, descendants(activity!!.window.decorView).filterIsInstance<EditText>().size)
|
||||
}
|
||||
@@ -214,7 +214,7 @@ class BackupTest {
|
||||
settings.generateKey()
|
||||
instrumentation.uiAutomation.grantRuntimePermission(context.packageName, Manifest.permission.RECORD_AUDIO)
|
||||
try {
|
||||
activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java).putExtra(BackupActivity.EXTRA_PAGE, "remote").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
val recorder = MediaRecorder(context)
|
||||
try {
|
||||
recorder.setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
@@ -239,9 +239,13 @@ class BackupTest {
|
||||
}
|
||||
assertTrue("Remote playback did not reach expected state", ready)
|
||||
}
|
||||
click("Server recordings"); click("Refresh")
|
||||
await { descendants(activity!!.window.decorView).filterIsInstance<Button>().any { it.text.startsWith(clip.title) } }
|
||||
click(clip.title); click("Download & play")
|
||||
click("Refresh")
|
||||
await { descendants(activity!!.window.decorView).filterIsInstance<android.widget.TextView>().any { it.text == clip.title } }
|
||||
instrumentation.runOnMainSync {
|
||||
descendants(activity!!.window.decorView).filterIsInstance<android.widget.TextView>().first { it.text == clip.title }
|
||||
.let { (it.parent.parent as View).performClick() }
|
||||
}
|
||||
click("Download & play")
|
||||
val playerField = BackupActivity::class.java.getDeclaredField("player").apply { isAccessible = true }
|
||||
val readyField = BackupActivity::class.java.getDeclaredField("playbackReady").apply { isAccessible = true }
|
||||
await { readyField.getBoolean(activity) && (playerField.get(activity) as? MediaPlayer)?.isPlaying == true }
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.junit.Assert.*
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class LaunchTest {
|
||||
@Test fun homeLaunchesWithAccessibleRecordAndLibraryControls() {
|
||||
@Test fun homeLaunchesWithRecordAndSharedMenuControls() {
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
val activity = instrumentation.startActivitySync(
|
||||
Intent(instrumentation.targetContext, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -23,7 +23,8 @@ class LaunchTest {
|
||||
if (view is ViewGroup) (0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
val buttons = descendants(activity.window.decorView).filterIsInstance<Button>()
|
||||
assertTrue(buttons.any { it.contentDescription == "Start recording" && it.isEnabled })
|
||||
assertTrue(buttons.any { it.text.startsWith("Moments") })
|
||||
assertTrue(buttons.any { it.contentDescription == "Open all sections" && it.isEnabled })
|
||||
assertFalse(buttons.any { it.text.startsWith("Moments") })
|
||||
}
|
||||
} finally { instrumentation.runOnMainSync { activity.finish() } }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package meghdad.remember
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.os.SystemClock
|
||||
import android.view.InputDevice
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ScrollView
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isRoot
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MenuVisibilityTest {
|
||||
@Test fun bottomMenuStartsHiddenRevealsWithoutOpeningAndWaitsUntilTouchEndsToHide() {
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
val context = instrumentation.targetContext
|
||||
fun descendants(view: View): List<View> = listOf(view) + if (view is ViewGroup)
|
||||
(0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
fun send(activity: Activity, action: Int, x: Float, y: Float, downTime: Long) = instrumentation.runOnMainSync {
|
||||
MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, x, y, 0).also {
|
||||
it.source = InputDevice.SOURCE_TOUCHSCREEN
|
||||
activity.dispatchTouchEvent(it); it.recycle()
|
||||
}
|
||||
}
|
||||
for (type in listOf(MainActivity::class.java, BackupActivity::class.java)) {
|
||||
val activity = instrumentation.startActivitySync(Intent(context, type).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
try {
|
||||
onView(isRoot()).check(matches(isDisplayed()))
|
||||
lateinit var menu: Button
|
||||
var x = 0f; var y = 0f
|
||||
instrumentation.runOnMainSync {
|
||||
val root = activity.window.decorView
|
||||
menu = descendants(root).filterIsInstance<Button>().single { it.contentDescription == "Open all sections" }
|
||||
val location = IntArray(2); menu.getLocationInWindow(location)
|
||||
assertEquals(root.width / 2, location[0] + menu.width / 2)
|
||||
assertEquals(root.height, location[1] + menu.height)
|
||||
assertEquals(root.height, descendants(root).filterIsInstance<ScrollView>().single().height)
|
||||
assertEquals(View.INVISIBLE, menu.visibility)
|
||||
x = location[0] + menu.width / 2f; y = location[1] + menu.height / 2f
|
||||
}
|
||||
val down = SystemClock.uptimeMillis()
|
||||
// The reveal tap must reach the old content target, never the newly shown menu.
|
||||
send(activity, MotionEvent.ACTION_DOWN, x, y, down)
|
||||
SystemClock.sleep(3300)
|
||||
instrumentation.runOnMainSync {
|
||||
assertEquals("Do not hide under a held finger", View.VISIBLE, menu.visibility)
|
||||
assertFalse(descendants(activity.window.decorView).filterIsInstance<Button>().any { it.contentDescription == "Recorder" })
|
||||
}
|
||||
send(activity, MotionEvent.ACTION_UP, x, y, down)
|
||||
instrumentation.runOnMainSync {
|
||||
assertTrue("Reveal must not open the menu", menu.isAttachedToWindow)
|
||||
assertFalse(descendants(activity.window.decorView).filterIsInstance<Button>().any { it.contentDescription == "Recorder" })
|
||||
}
|
||||
SystemClock.sleep(2000)
|
||||
instrumentation.runOnMainSync { assertEquals("Leave time to tap the revealed menu", View.VISIBLE, menu.visibility) }
|
||||
var hidden = false
|
||||
val deadline = SystemClock.elapsedRealtime() + 2500
|
||||
while (!hidden && SystemClock.elapsedRealtime() < deadline) {
|
||||
instrumentation.runOnMainSync { hidden = menu.visibility == View.INVISIBLE }
|
||||
if (!hidden) SystemClock.sleep(50)
|
||||
}
|
||||
assertTrue("Menu must hide after idle time", hidden)
|
||||
// Ordinary content touches reveal it too, without swallowing that gesture.
|
||||
val tap = SystemClock.uptimeMillis()
|
||||
send(activity, MotionEvent.ACTION_DOWN, activity.window.decorView.width / 2f, activity.window.decorView.height * .12f, tap)
|
||||
send(activity, MotionEvent.ACTION_UP, activity.window.decorView.width / 2f, activity.window.decorView.height * .12f, tap)
|
||||
instrumentation.runOnMainSync { assertEquals(View.VISIBLE, menu.visibility) }
|
||||
if (type == MainActivity::class.java && InstrumentationRegistry.getArguments().getString("saveDesignScreenshots") == "true") {
|
||||
instrumentation.waitForIdleSync()
|
||||
SystemClock.sleep(100)
|
||||
instrumentation.uiAutomation.takeScreenshot()?.let { bitmap ->
|
||||
File(context.cacheDir, "home-menu-visible.png").outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
bitmap.recycle()
|
||||
}
|
||||
}
|
||||
if (type == MainActivity::class.java) {
|
||||
val open = SystemClock.uptimeMillis()
|
||||
send(activity, MotionEvent.ACTION_DOWN, x, y, open)
|
||||
send(activity, MotionEvent.ACTION_UP, x, y, open)
|
||||
instrumentation.runOnMainSync {
|
||||
assertTrue("A second tap opens the visible menu", descendants(activity.window.decorView).filterIsInstance<Button>().any { it.contentDescription == "Recorder" })
|
||||
}
|
||||
}
|
||||
} finally { instrumentation.runOnMainSync { activity.finish() } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package meghdad.remember
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import org.junit.Assert.assertEquals
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.Espresso.pressBack
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
|
||||
import androidx.test.runner.lifecycle.Stage
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class NavigationTest {
|
||||
/** Exercise the real activity stack, the fixed menu shortcut, and scrollable grid tiles. */
|
||||
@Test fun oneMenuOpensEverySectionAndBackReturnsWithoutNestedMenus() {
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
val context = instrumentation.targetContext
|
||||
val activity = instrumentation.startActivitySync(Intent(context, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
fun descendants(view: View): List<View> = listOf(view) + if (view is ViewGroup)
|
||||
(0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
fun revealMenu(open: Boolean = false) {
|
||||
// Run the gesture and assertion together: an idle-waiting test runner must not
|
||||
// wait out the very timeout this control is meant to have.
|
||||
instrumentation.runOnMainSync {
|
||||
val current = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED)
|
||||
.single { it.window.decorView.hasWindowFocus() }
|
||||
val root = current.window.decorView
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
listOf(MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP).forEach { action ->
|
||||
MotionEvent.obtain(now, now, action, root.width * .5f, root.height * .2f, 0).also {
|
||||
it.source = android.view.InputDevice.SOURCE_TOUCHSCREEN
|
||||
current.dispatchTouchEvent(it); it.recycle()
|
||||
}
|
||||
}
|
||||
val button = descendants(root).filterIsInstance<Button>().single { it.contentDescription == "Open all sections" }
|
||||
assertEquals(View.VISIBLE, button.visibility)
|
||||
if (open) button.performClick()
|
||||
}
|
||||
}
|
||||
fun screenshot(name: String) {
|
||||
if (InstrumentationRegistry.getArguments().getString("saveDesignScreenshots") != "true") return
|
||||
onView(isRoot()).check(matches(isDisplayed()))
|
||||
instrumentation.waitForIdleSync()
|
||||
android.os.SystemClock.sleep(350)
|
||||
instrumentation.uiAutomation.takeScreenshot()?.let { bitmap ->
|
||||
File(context.cacheDir, "$name.png").outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
bitmap.recycle()
|
||||
}
|
||||
}
|
||||
try {
|
||||
screenshot("home")
|
||||
revealMenu(open = true)
|
||||
screenshot("menu")
|
||||
listOf("Moments", "Storage", "Recording limit", "Backup", "Server", "Transfers", "Server recordings", "Automatic backup", "Advanced").forEach { destination ->
|
||||
android.util.Log.i("RememberNavigation", "Opening $destination")
|
||||
onView(withContentDescription(destination)).perform(scrollTo())
|
||||
instrumentation.waitForIdleSync()
|
||||
android.os.SystemClock.sleep(250)
|
||||
onView(withContentDescription(destination)).perform(click())
|
||||
val expected = if (destination in listOf("Moments", "Storage", "Recording limit")) MainActivity::class.java else BackupActivity::class.java
|
||||
var ready = false
|
||||
val deadline = android.os.SystemClock.elapsedRealtime() + 5000
|
||||
while (!ready && android.os.SystemClock.elapsedRealtime() < deadline) {
|
||||
instrumentation.runOnMainSync {
|
||||
ready = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED)
|
||||
.any { expected.isInstance(it) && it.window.decorView.hasWindowFocus() }
|
||||
}
|
||||
if (!ready) android.os.SystemClock.sleep(50)
|
||||
}
|
||||
assertTrue("Section must be foreground before testing its touch menu", ready)
|
||||
revealMenu()
|
||||
screenshot(when (destination) {
|
||||
"Recording limit" -> "recording-limit"
|
||||
"Backup" -> "backup-overview"
|
||||
"Server" -> "backup-server"
|
||||
"Automatic backup" -> "backup-automatic"
|
||||
else -> destination.lowercase().replace(' ', '-')
|
||||
})
|
||||
// Both ways out must return to the same shared grid across activity boundaries.
|
||||
if (destination in listOf("Storage", "Backup", "Automatic backup")) {
|
||||
revealMenu(open = true)
|
||||
} else pressBack()
|
||||
instrumentation.waitForIdleSync()
|
||||
android.os.SystemClock.sleep(350)
|
||||
onView(withContentDescription("Recorder")).check(matches(isEnabled()))
|
||||
}
|
||||
onView(withContentDescription("Recorder")).perform(scrollTo(), click())
|
||||
onView(withContentDescription("Start recording")).check(matches(isDisplayed()))
|
||||
} finally { instrumentation.runOnMainSync { activity.finish() } }
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,18 @@ class SettingsTest {
|
||||
fun descendants(view: View): List<View> = listOf(view) + if (view is ViewGroup)
|
||||
(0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList()
|
||||
fun button(prefix: String) = descendants(activity.window.decorView).filterIsInstance<Button>().first { it.text.startsWith(prefix) }
|
||||
button("Settings").performClick()
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
listOf(android.view.MotionEvent.ACTION_DOWN, android.view.MotionEvent.ACTION_UP).forEach { action ->
|
||||
android.view.MotionEvent.obtain(now, now, action, activity.window.decorView.width / 2f,
|
||||
activity.window.decorView.height * .12f, 0).also { event -> activity.dispatchTouchEvent(event); event.recycle() }
|
||||
}
|
||||
descendants(activity.window.decorView).filterIsInstance<Button>().first { it.contentDescription == "Open all sections" }.performClick()
|
||||
button("Recording limit").performClick()
|
||||
descendants(activity.window.decorView).filterIsInstance<Switch>().single().isChecked = true
|
||||
button("Length").performClick()
|
||||
descendants(activity.window.decorView).filterIsInstance<NumberPicker>().single().value = 137
|
||||
button("Save").performClick()
|
||||
button("At the limit").performClick()
|
||||
descendants(activity.window.decorView).filterIsInstance<android.widget.TextView>().first { it.text == "At the limit" }.let { (it.parent.parent as View).performClick() }
|
||||
button("Save & start next").performClick()
|
||||
button("Back").performClick()
|
||||
assertEquals(RecordingLimit(true, 137, LimitAction.NEXT_CLIP), preferences.read())
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".RecordingService" android:exported="false" android:foregroundServiceType="microphone" />
|
||||
<activity android:name=".BackupActivity" android:exported="false" android:taskAffinity="" />
|
||||
<activity android:name=".BackupActivity" android:exported="false" android:taskAffinity="" android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
|
||||
<service android:name=".BackupWorker" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -28,6 +28,10 @@ class BackupActivity : Activity() {
|
||||
private lateinit var body: LinearLayout
|
||||
private lateinit var scroll: ScrollView
|
||||
private var page = "overview"
|
||||
private var floatingMenu: FloatingMenuController? = null
|
||||
companion object { const val EXTRA_PAGE = "backup_page" }
|
||||
private var backupDial: StatusDialView? = null
|
||||
private var waitingCount: TextView? = null
|
||||
private var busy = false
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
@@ -48,7 +52,10 @@ class BackupActivity : Activity() {
|
||||
private var localClips: List<Clip> = emptyList()
|
||||
private val tick = object : Runnable {
|
||||
override fun run() {
|
||||
if (page == "overview") summary?.text = settings.preferences.getString("summary", "Ready when you are")
|
||||
if (page == "overview") {
|
||||
summary?.text = settings.preferences.getString("summary", "Ready when you are")
|
||||
updateBackupDial()
|
||||
}
|
||||
if (page == "transfers") rows.forEach { (id, view) ->
|
||||
val clip = localClips.find { it.id == id }
|
||||
if (clip != null) view.text = transferState(clip)
|
||||
@@ -64,23 +71,43 @@ class BackupActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
settings = BackupSettings(this)
|
||||
page = intent.getStringExtra(EXTRA_PAGE)?.takeIf { it in listOf("overview", "server", "transfers", "remote", "automatic", "advanced") } ?: "overview"
|
||||
if (Build.VERSION.SDK_INT >= 33) onBackInvokedDispatcher.registerOnBackInvokedCallback(0) { back() }
|
||||
render()
|
||||
}
|
||||
override fun onResume() { super.onResume(); resumed = true; handler.post(tick) }
|
||||
override fun onPause() { resumed = false; handler.removeCallbacks(tick); if (playbackReady) player?.pause(); super.onPause() }
|
||||
override fun onDestroy() { trustProbe?.close(); client?.close(); executor.shutdownNow(); player?.release(); super.onDestroy() }
|
||||
override fun onResume() { super.onResume(); resumed = true; floatingMenu?.resume(); handler.post(tick) }
|
||||
override fun onPause() { resumed = false; floatingMenu?.pause(); handler.removeCallbacks(tick); if (playbackReady) player?.pause(); super.onPause() }
|
||||
override fun onDestroy() { floatingMenu?.dispose(); trustProbe?.close(); client?.close(); executor.shutdownNow(); player?.release(); super.onDestroy() }
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
val handled = super.dispatchTouchEvent(event)
|
||||
floatingMenu?.onTouch(event.actionMasked)
|
||||
return handled
|
||||
}
|
||||
override fun dispatchKeyEvent(event: android.view.KeyEvent): Boolean {
|
||||
val handled = super.dispatchKeyEvent(event)
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.keyCode in listOf(
|
||||
android.view.KeyEvent.KEYCODE_DPAD_UP, android.view.KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
android.view.KeyEvent.KEYCODE_DPAD_LEFT, android.view.KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
android.view.KeyEvent.KEYCODE_DPAD_CENTER, android.view.KeyEvent.KEYCODE_TAB)) floatingMenu?.interact()
|
||||
return handled
|
||||
}
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
val handled = super.dispatchGenericMotionEvent(event)
|
||||
if (event.action == MotionEvent.ACTION_SCROLL) floatingMenu?.interact()
|
||||
return handled
|
||||
}
|
||||
private fun dp(value: Int) = (value * resources.displayMetrics.density).roundToInt()
|
||||
private fun text(value: String, size: Float = 12f, color: Int = Color.WHITE): TextView = TextView(this).apply {
|
||||
text = value; textSize = size; setTextColor(color); gravity = Gravity.CENTER
|
||||
setPadding(dp(3), dp(5), dp(3), dp(5)); body.addView(this, LinearLayout.LayoutParams(-1, -2))
|
||||
}
|
||||
private fun button(label: String, action: () -> Unit): Button = Button(this).apply {
|
||||
text = label; textSize = 12f; isAllCaps = false; setTextColor(Color.WHITE)
|
||||
background = GradientDrawable().apply { setColor(Color.rgb(43, 52, 32)); cornerRadius = dp(24).toFloat() }
|
||||
stateListAnimator = null
|
||||
setOnClickListener { action() }
|
||||
body.addView(this, LinearLayout.LayoutParams(-1, dp(48)).apply { setMargins(0, dp(4), 0, dp(4)) })
|
||||
private fun button(label: String, action: () -> Unit): Button = WatchDesign.action(this, label, action = action).also { body.addView(it) }
|
||||
private fun primary(label: String, action: () -> Unit): Button = WatchDesign.action(this, label, true, action).also { body.addView(it) }
|
||||
private fun menu() {
|
||||
if (busy) { toast(getString(R.string.backup_wait_for_the_current_action_or_cancel_it)); return }
|
||||
startActivity(Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra(MainActivity.EXTRA_SCREEN, "menu"))
|
||||
finish()
|
||||
}
|
||||
private fun navigate(target: String) {
|
||||
if (busy) { toast(getString(R.string.backup_wait_for_the_current_action_or_cancel_it)); return }
|
||||
@@ -89,15 +116,29 @@ class BackupActivity : Activity() {
|
||||
page = target; render()
|
||||
}
|
||||
private fun render() {
|
||||
rows.clear(); summary = null; progress = null; playbackButton = null; seek = null
|
||||
val menuWasVisible = floatingMenu?.button?.visibility == View.VISIBLE
|
||||
floatingMenu?.dispose(); floatingMenu = null
|
||||
rows.clear(); summary = null; progress = null; playbackButton = null; seek = null; backupDial = null; waitingCount = null
|
||||
scroll = ScrollView(this).apply { isFillViewport = true; isVerticalScrollBarEnabled = false; setBackgroundColor(Color.rgb(13, 17, 11)) }
|
||||
body = LinearLayout(this).apply {
|
||||
orientation = LinearLayout.VERTICAL; gravity = Gravity.CENTER_HORIZONTAL
|
||||
// Keep controls inside a round watch's usable area even on emulator images
|
||||
// that omit the round configuration qualifier.
|
||||
setPadding(dp(28), dp(28), dp(28), dp(36))
|
||||
setPadding(dp(28), dp(14), dp(28), dp(24))
|
||||
}
|
||||
scroll.addView(body); setContentView(scroll)
|
||||
val layers = FrameLayout(this).apply { setBackgroundColor(WatchDesign.ink) }
|
||||
scroll.addView(body); layers.addView(scroll, FrameLayout.LayoutParams(-1, -1))
|
||||
if (page !in listOf("trust", "trust_fingerprint")) {
|
||||
val menuButton = WatchDesign.menuDock(this) { menu() }
|
||||
layers.addView(menuButton, FrameLayout.LayoutParams(dp(48), dp(48), Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL))
|
||||
floatingMenu = FloatingMenuController(menuButton).also {
|
||||
if (resumed) { it.resume(); if (menuWasVisible) it.interact() }
|
||||
}
|
||||
}
|
||||
setContentView(layers)
|
||||
window.decorView.windowInsetsController?.hide(android.view.WindowInsets.Type.systemBars())
|
||||
scroll.descendantFocusability = android.view.ViewGroup.FOCUS_BEFORE_DESCENDANTS
|
||||
scroll.isFocusableInTouchMode = true
|
||||
scroll.setOnGenericMotionListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_SCROLL) {
|
||||
scroll.smoothScrollBy(0, (-event.getAxisValue(MotionEvent.AXIS_SCROLL) * dp(35)).toInt()); true
|
||||
@@ -119,28 +160,27 @@ class BackupActivity : Activity() {
|
||||
"licenses" -> { title(getString(R.string.backup_open_source_licenses)); text(listOf("JSch.txt", "Bouncy-Castle.txt").joinToString("\n\n") { name -> assets.open("licenses/$name").bufferedReader().use { it.readText() } }, 10f, muted); button(getString(R.string.backup_back)) { navigate("advanced") } }
|
||||
else -> overview()
|
||||
}
|
||||
scroll.requestFocus()
|
||||
}
|
||||
private fun title(value: String) { WatchDesign.heading(body, value, "Remember") }
|
||||
private fun updateBackupDial() {
|
||||
val backed = localClips.count { settings.receipt(it.id) == backupVersion(it, Recordings(this).audio(it.id)) }
|
||||
backupDial?.update(backed.toString(), "backed up / ${localClips.size}", if (localClips.isEmpty()) 0f else backed.toFloat() / localClips.size)
|
||||
waitingCount?.text = getString(R.string.backup_waiting_count, localClips.size - backed)
|
||||
}
|
||||
private fun title(value: String) { text(value.uppercase(), 10f, lime) }
|
||||
private fun overview() {
|
||||
title(getString(R.string.backup_backup))
|
||||
text(getString(R.string.backup_keep_your_moments), 16f)
|
||||
val clips = Recordings(this).list()
|
||||
val backed = clips.count { settings.receipt(it.id) == backupVersion(it, Recordings(this).audio(it.id)) }
|
||||
text("$backed backed up\n${clips.size - backed} waiting", 16f, lime)
|
||||
button(getString(R.string.backup_back_up_now)) { startBackup() }.apply {
|
||||
background = GradientDrawable().apply {
|
||||
setColor(Color.rgb(35, 44, 20)); cornerRadius = dp(24).toFloat(); setStroke(dp(1), lime)
|
||||
}
|
||||
}
|
||||
val time = settings.preferences.getLong("last_success", 0)
|
||||
text(if (time == 0L) "No completed backup yet" else "Last backup\n${DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(Date(time))}", 10f, muted)
|
||||
body.addView(WatchDesign.label(this, getString(R.string.backup_backup).uppercase(), 10f, lime).apply { letterSpacing = .16f })
|
||||
localClips = Recordings(this).list()
|
||||
backupDial = StatusDialView(this).also { body.addView(it, LinearLayout.LayoutParams(-1, dp(92))) }
|
||||
primary(getString(R.string.backup_back_up_now)) { startBackup() }
|
||||
waitingCount = text("", 11f, lime)
|
||||
updateBackupDial()
|
||||
summary = text(settings.preferences.getString("summary", "Ready when you are")!!, 11f, muted)
|
||||
button(getString(R.string.backup_server)) { navigate("server") }
|
||||
button(getString(R.string.backup_transfers)) { navigate("transfers") }
|
||||
button(getString(R.string.backup_server_recordings)) { navigate("remote") }
|
||||
button(getString(R.string.backup_automatic_backup)) { navigate("automatic") }
|
||||
button(getString(R.string.backup_advanced)) { navigate("advanced") }
|
||||
button(getString(R.string.backup_back)) { finish() }
|
||||
val time = settings.preferences.getLong("last_success", 0)
|
||||
WatchDesign.card(body, getString(R.string.backup_last), if (time == 0L) getString(R.string.backup_none_completed) else DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(Date(time)), WatchIcon.BACKUP)
|
||||
val server = settings.server()
|
||||
WatchDesign.card(body, getString(R.string.backup_destination), server.host.ifBlank { getString(R.string.backup_no_destination) }, WatchIcon.SERVER)
|
||||
text(getString(if (settings.automatic) R.string.backup_automatic_on else R.string.backup_automatic_off), 10f, muted)
|
||||
}
|
||||
private fun field(label: String, value: String, type: Int = InputType.TYPE_CLASS_TEXT): EditText {
|
||||
text(label, 11f, muted)
|
||||
@@ -152,6 +192,7 @@ class BackupActivity : Activity() {
|
||||
}
|
||||
private fun serverPage() {
|
||||
title(getString(R.string.backup_server))
|
||||
text("01 / CONNECTION", 9f, lime)
|
||||
val server = serverDraft?.withRememberedTrust(settings.server()) ?: settings.server()
|
||||
val host = field(getString(R.string.backup_address), server.host, InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
|
||||
val port = field(getString(R.string.backup_port), server.port.toString(), InputType.TYPE_CLASS_NUMBER)
|
||||
@@ -169,7 +210,7 @@ class BackupActivity : Activity() {
|
||||
host.addTextChangedListener(endpointWatcher); port.addTextChangedListener(endpointWatcher)
|
||||
fun save(candidate: BackupServer): Boolean = persistServer(candidate).also { if (it) updateTrustStatus() }
|
||||
fun testConnection() { runRemote("Connecting…") { it.test(); "Connected. Backup folder is accessible." } }
|
||||
button(getString(R.string.backup_connect_trust)) {
|
||||
primary(getString(R.string.backup_connect_trust)) {
|
||||
val candidate = draft()
|
||||
runCatching { candidate.validateConfiguration() }.onSuccess {
|
||||
serverDraft = candidate
|
||||
@@ -197,7 +238,7 @@ class BackupActivity : Activity() {
|
||||
button(getString(R.string.backup_save_server)) {
|
||||
if (save(draft())) {
|
||||
if (settings.server().fingerprint.isNotEmpty()) BackupWork.schedule(this)
|
||||
navigate("overview")
|
||||
menu()
|
||||
}
|
||||
}
|
||||
button(getString(R.string.backup_test_connection)) {
|
||||
@@ -205,6 +246,7 @@ class BackupActivity : Activity() {
|
||||
runCatching { candidate.validate() }.onSuccess { if (save(candidate)) testConnection() }
|
||||
.onFailure { toast(it.message ?: "Use Connect & trust first") }
|
||||
}
|
||||
text("02 / WATCH IDENTITY", 9f, lime)
|
||||
button(if (settings.publicKey() == null) "Create watch key" else "Show watch key") {
|
||||
runTask("Preparing key…", { settings.generateKey() }) { key ->
|
||||
showPublicKey(key)
|
||||
@@ -223,7 +265,7 @@ class BackupActivity : Activity() {
|
||||
}
|
||||
}
|
||||
progress = text("", 10f, muted)
|
||||
button(getString(R.string.backup_back)) { navigate("overview") }
|
||||
button(getString(R.string.backup_back)) { back() }
|
||||
}
|
||||
private fun persistServer(candidate: BackupServer): Boolean = try {
|
||||
candidate.validateConfiguration()
|
||||
@@ -277,48 +319,51 @@ class BackupActivity : Activity() {
|
||||
title(getString(R.string.backup_transfers))
|
||||
val clips = Recordings(this).list()
|
||||
localClips = clips
|
||||
if (clips.isEmpty()) text(getString(R.string.backup_save_a_recording_to_begin), 14f)
|
||||
clips.forEach { clip ->
|
||||
text(clip.title, 14f)
|
||||
rows[clip.id] = text(transferState(clip), 11f, lime)
|
||||
}
|
||||
button(getString(R.string.backup_back_up_retry)) { startBackup() }
|
||||
button(getString(R.string.backup_pause_all_backups)) {
|
||||
BackupWork.cancel(this)
|
||||
clips.forEach { if (transferState(it) != "Backed up") settings.status(it.id, "Waiting") }
|
||||
toast(getString(R.string.backup_backups_paused_automatic_backup_is_off))
|
||||
text("${clips.size} moments · one safe copy at a time", 10f, muted)
|
||||
WatchDesign.pair(body,
|
||||
WatchDesign.action(this, getString(R.string.backup_back_up_retry), true) { startBackup() },
|
||||
WatchDesign.action(this, getString(R.string.pause_all)) {
|
||||
BackupWork.cancel(this)
|
||||
clips.forEach { if (transferState(it) != "Backed up") settings.status(it.id, "Waiting") }
|
||||
toast(getString(R.string.backup_backups_paused_automatic_backup_is_off))
|
||||
})
|
||||
if (clips.isEmpty()) {
|
||||
body.addView(ImageView(this).apply { setImageDrawable(WatchGlyph(WatchIcon.TRANSFERS, lime)); importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO }, LinearLayout.LayoutParams(dp(60), dp(72)))
|
||||
text(getString(R.string.backup_save_a_recording_to_begin), 14f)
|
||||
}
|
||||
clips.forEach { clip -> rows[clip.id] = WatchDesign.card(body, clip.title, transferState(clip), WatchIcon.TRANSFERS) }
|
||||
text(getString(R.string.backup_copies_stay_on_the_server_when_you_delete_local_recordings), 10f, muted)
|
||||
button(getString(R.string.backup_back)) { navigate("overview") }
|
||||
button(getString(R.string.backup_back)) { back() }
|
||||
}
|
||||
private fun startBackup() {
|
||||
runCatching { BackupWork.start(this) }.onSuccess { toast(getString(R.string.backup_backup_queued_opens_when_connected)) }
|
||||
.onFailure { toast(it.message ?: "Configure the server first") }
|
||||
}
|
||||
private fun remotePage() {
|
||||
title(getString(R.string.backup_server_recordings))
|
||||
WatchDesign.heading(body, getString(R.string.on_your_server), getString(R.string.backup_server_recordings))
|
||||
button(getString(R.string.backup_refresh)) {
|
||||
runTask("Loading recordings…", { withRemote { it.list() } }) { remoteClips = it; render() }
|
||||
}
|
||||
if (remoteClips.isEmpty()) text(getString(R.string.backup_tap_refresh_to_browse_your_backups), 12f, muted)
|
||||
if (remoteClips.isEmpty()) {
|
||||
body.addView(ImageView(this).apply { setImageDrawable(WatchGlyph(WatchIcon.REMOTE, Color.rgb(143, 204, 217))); importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO }, LinearLayout.LayoutParams(dp(72), dp(88)))
|
||||
text(getString(R.string.backup_tap_refresh_to_browse_your_backups), 12f, muted)
|
||||
}
|
||||
remoteClips.forEach { remote ->
|
||||
val date = DateFormat.getDateInstance(DateFormat.SHORT).format(Date(remote.clip.created))
|
||||
button("${remote.clip.title}\n$date · ${timeLabel(remote.clip.duration)}") { selected = remote; navigate("playback") }.apply {
|
||||
maxLines = 2; ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
}
|
||||
WatchDesign.card(body, remote.clip.title, "$date · ${timeLabel(remote.clip.duration)}", WatchIcon.PLAY) { selected = remote; navigate("playback") }
|
||||
}
|
||||
progress = text("", 10f, muted)
|
||||
button(getString(R.string.backup_back)) { navigate("overview") }
|
||||
button(getString(R.string.backup_back)) { back() }
|
||||
}
|
||||
private fun playbackPage() {
|
||||
val remote = selected ?: return
|
||||
title(getString(R.string.backup_server_playback))
|
||||
text(remote.clip.title, 17f)
|
||||
text("${timeLabel(remote.clip.duration)} · ${remote.clip.marks.size} bookmarks", 11f, muted)
|
||||
text(getString(R.string.backup_audio_downloads_to_a_temporary_watch_cache_before_playing), 10f, muted)
|
||||
body.addView(StatusDialView(this).apply { update((remote.clip.duration / 60_000).toString(), "minutes on server", 1f) }, LinearLayout.LayoutParams(-1, dp(104)))
|
||||
progress = text(getString(R.string.backup_ready_to_download), 11f, lime)
|
||||
playbackButton = button(getString(R.string.backup_download_play)) {
|
||||
if (player != null) { if (playbackReady) player!!.let { if (it.isPlaying) it.pause() else it.start() }; return@button }
|
||||
playbackButton = primary(getString(R.string.backup_download_play)) {
|
||||
if (player != null) { if (playbackReady) player!!.let { if (it.isPlaying) it.pause() else it.start() }; return@primary }
|
||||
val file = File(cacheDir, "server-playback.m4a")
|
||||
runTask("Preparing audio…", {
|
||||
require(StatFs(cacheDir.absolutePath).availableBytes > remote.bytes + 16 * 1024 * 1024) { "Not enough free space for playback" }
|
||||
@@ -351,43 +396,50 @@ class BackupActivity : Activity() {
|
||||
}); body.addView(this, LinearLayout.LayoutParams(-1, dp(40)))
|
||||
}
|
||||
remote.clip.marks.forEach { mark -> button("Bookmark · ${timeLabel(mark)}") { runCatching { player?.seekTo(mark.coerceAtMost(Int.MAX_VALUE.toLong()).toInt()) } } }
|
||||
text(getString(R.string.backup_audio_downloads_to_a_temporary_watch_cache_before_playing), 10f, muted)
|
||||
button(getString(R.string.backup_cancel_download)) { client?.close() }
|
||||
button(getString(R.string.backup_back)) { navigate("remote") }
|
||||
}
|
||||
private fun toggle(label: String, value: Boolean, change: (Boolean) -> Unit) {
|
||||
Switch(this).apply {
|
||||
background = WatchDesign.shape(this@BackupActivity)
|
||||
setPadding(dp(12), 0, dp(12), 0)
|
||||
thumbTintList = WatchDesign.switchTint()
|
||||
text = label; textSize = 12f; setTextColor(Color.WHITE); isChecked = value
|
||||
setOnCheckedChangeListener { _, checked -> change(checked) }
|
||||
body.addView(this, LinearLayout.LayoutParams(-1, dp(52)))
|
||||
body.addView(this, LinearLayout.LayoutParams(-1, dp(52)).apply { topMargin = dp(4); bottomMargin = dp(4) })
|
||||
}
|
||||
}
|
||||
private fun automaticPage() {
|
||||
title(getString(R.string.backup_automatic_backup))
|
||||
WatchDesign.heading(body, getString(R.string.autopilot), getString(R.string.backup_automatic_backup))
|
||||
body.addView(StatusDialView(this).apply { update(settings.hours.toString(), if (settings.automatic) "hours / check" else "hours · off", if (settings.automatic) 1f else 0f) }, LinearLayout.LayoutParams(-1, dp(112)))
|
||||
toggle("Enable", settings.automatic) {
|
||||
settings.preferences.edit().putBoolean("automatic", it).apply()
|
||||
runCatching { BackupWork.schedule(this) }.onFailure { error ->
|
||||
runCatching { BackupWork.schedule(this) }.onSuccess { render() }.onFailure { error ->
|
||||
settings.preferences.edit().putBoolean("automatic", false).apply(); toast(error.message ?: "Configure server first"); render()
|
||||
}
|
||||
}
|
||||
toggle("While charging", settings.charging) { updateOption("charging", it) }
|
||||
toggle("Unmetered only", settings.unmetered) { updateOption("unmetered", it) }
|
||||
button("Check every ${settings.hours} hours") {
|
||||
choose("Backup interval", arrayOf("Every hour", "Every 6 hours", "Daily")) { index ->
|
||||
settings.preferences.edit().putInt("hours", intArrayOf(1, 6, 24)[index]).apply(); BackupWork.schedule(this); render()
|
||||
}
|
||||
text(getString(R.string.check_interval), 9f, lime)
|
||||
optionStrip(listOf(1, 6, 24), settings.hours, { if (it == 24) "Daily" else "${it}h" }) {
|
||||
settings.preferences.edit().putInt("hours", it).apply(); BackupWork.schedule(this); render()
|
||||
}
|
||||
text(getString(R.string.backup_runs_when_conditions_allow_the_watch_may_delay_background), 10f, muted)
|
||||
button(getString(R.string.backup_back)) { navigate("overview") }
|
||||
button(getString(R.string.backup_back)) { back() }
|
||||
}
|
||||
private fun updateOption(key: String, value: Boolean) { settings.preferences.edit().putBoolean(key, value).apply(); BackupWork.schedule(this) }
|
||||
private fun advancedPage() {
|
||||
title(getString(R.string.backup_advanced))
|
||||
button("Retry attempts · ${settings.attempts}") { choose("Retry attempts", arrayOf("1", "3", "5")) { index ->
|
||||
settings.preferences.edit().putInt("attempts", intArrayOf(1, 3, 5)[index]).apply(); render()
|
||||
} }
|
||||
button("Connection timeout · ${settings.timeout}s") { choose("Connection timeout", arrayOf("20 seconds", "40 seconds", "60 seconds")) { index ->
|
||||
settings.preferences.edit().putInt("timeout", intArrayOf(20, 40, 60)[index]).apply(); render()
|
||||
} }
|
||||
WatchDesign.heading(body, getString(R.string.fine_tune), getString(R.string.backup_advanced))
|
||||
text(getString(R.string.retry_attempts), 9f, lime)
|
||||
optionStrip(listOf(1, 3, 5), settings.attempts, { it.toString() }) {
|
||||
settings.preferences.edit().putInt("attempts", it).apply(); render()
|
||||
}
|
||||
text(getString(R.string.connection_timeout), 9f, lime)
|
||||
optionStrip(listOf(20, 40, 60), settings.timeout, { "${it}s" }) {
|
||||
settings.preferences.edit().putInt("timeout", it).apply(); render()
|
||||
}
|
||||
text(getString(R.string.on_this_watch), 9f, lime)
|
||||
button(getString(R.string.backup_clear_playback_cache)) {
|
||||
player?.release(); player = null; playbackReady = false
|
||||
File(cacheDir, "server-playback.m4a").delete(); File(cacheDir, "server-playback.m4a.download").delete()
|
||||
@@ -411,9 +463,18 @@ class BackupActivity : Activity() {
|
||||
}.setNegativeButton(android.R.string.cancel, null).show()
|
||||
}
|
||||
button(getString(R.string.backup_open_source_licenses)) { navigate("licenses") }
|
||||
button(getString(R.string.backup_back)) { navigate("overview") }
|
||||
button(getString(R.string.backup_back)) { back() }
|
||||
}
|
||||
private fun optionStrip(values: List<Int>, selected: Int, label: (Int) -> String, action: (Int) -> Unit) {
|
||||
val row = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL }
|
||||
values.forEach { value ->
|
||||
row.addView(WatchDesign.action(this, label(value), value == selected) { action(value) }.apply {
|
||||
isSelected = value == selected
|
||||
if (Build.VERSION.SDK_INT >= 30) stateDescription = if (isSelected) "Selected" else "Not selected"
|
||||
}, LinearLayout.LayoutParams(0, dp(48), 1f).apply { setMargins(dp(2), dp(4), dp(2), dp(8)) })
|
||||
}
|
||||
body.addView(row)
|
||||
}
|
||||
private fun choose(title: String, values: Array<String>, action: (Int) -> Unit) { AlertDialog.Builder(this).setTitle(title).setItems(values) { _, index -> action(index) }.show() }
|
||||
private fun <T> runTask(message: String, task: () -> T, done: (T) -> Unit) {
|
||||
if (busy) { toast(getString(R.string.backup_an_action_is_already_running)); return }
|
||||
busy = true; progress?.text = message
|
||||
@@ -450,7 +511,9 @@ class BackupActivity : Activity() {
|
||||
private fun toast(message: String) { Toast.makeText(this, message, Toast.LENGTH_LONG).show() }
|
||||
private fun back() {
|
||||
when (page) {
|
||||
"overview" -> finish()
|
||||
"overview", "server", "transfers", "remote", "automatic", "advanced" -> {
|
||||
if (busy) toast(getString(R.string.backup_wait_for_the_current_action_or_cancel_it)) else finish()
|
||||
}
|
||||
"trust" -> cancelTrust()
|
||||
"trust_fingerprint" -> navigate("trust")
|
||||
else -> navigate(when (page) { "playback" -> "remote"; "licenses" -> "advanced"; else -> "overview" })
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package meghdad.remember
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.accessibility.AccessibilityManager
|
||||
import android.widget.Button
|
||||
|
||||
/** One idle callback per visible menu; never polls or intercepts the content's gestures. */
|
||||
class FloatingMenuController(val button: Button) {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val accessibility = button.context.getSystemService(AccessibilityManager::class.java)
|
||||
private var active = false
|
||||
private var touching = false
|
||||
private val hide = Runnable {
|
||||
if (active && !touching && !keepVisible()) button.visibility = View.INVISIBLE
|
||||
}
|
||||
private val explorationListener = AccessibilityManager.TouchExplorationStateChangeListener {
|
||||
if (active) {
|
||||
if (accessibility.isTouchExplorationEnabled) reveal() else scheduleHide()
|
||||
}
|
||||
}
|
||||
init {
|
||||
button.visibility = View.INVISIBLE
|
||||
button.onFocusChangeListener = View.OnFocusChangeListener { _, focused ->
|
||||
if (active) { if (focused) reveal() else scheduleHide() }
|
||||
}
|
||||
accessibility.addTouchExplorationStateChangeListener(explorationListener, handler)
|
||||
}
|
||||
fun resume() {
|
||||
active = true; touching = false
|
||||
if (keepVisible()) reveal() else button.visibility = View.INVISIBLE
|
||||
}
|
||||
fun pause() {
|
||||
active = false; touching = false
|
||||
handler.removeCallbacks(hide)
|
||||
button.visibility = View.INVISIBLE
|
||||
}
|
||||
fun dispose() {
|
||||
pause()
|
||||
button.onFocusChangeListener = null
|
||||
accessibility.removeTouchExplorationStateChangeListener(explorationListener)
|
||||
}
|
||||
/** Called AFTER normal dispatch so a reveal cannot become a menu click in the same gesture. */
|
||||
fun onTouch(action: Int) {
|
||||
if (!active) return
|
||||
when (action) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> { touching = true; reveal() }
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { touching = false; interact() }
|
||||
}
|
||||
}
|
||||
fun interact() {
|
||||
if (!active) return
|
||||
reveal(); scheduleHide()
|
||||
}
|
||||
private fun keepVisible() = accessibility.isTouchExplorationEnabled || button.hasFocus()
|
||||
private fun reveal() {
|
||||
handler.removeCallbacks(hide)
|
||||
button.visibility = View.VISIBLE
|
||||
}
|
||||
private fun scheduleHide() {
|
||||
handler.removeCallbacks(hide)
|
||||
if (active && !touching && !keepVisible()) {
|
||||
val timeout = accessibility.getRecommendedTimeoutMillis(3000, AccessibilityManager.FLAG_CONTENT_CONTROLS)
|
||||
handler.postDelayed(hide, timeout.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ class MainActivity : Activity() {
|
||||
private lateinit var scroll: ScrollView
|
||||
private lateinit var store: Recordings
|
||||
private var screen = "home"
|
||||
private var menuOffset = 0
|
||||
private var foreground = false
|
||||
private var floatingMenu: FloatingMenuController? = null
|
||||
companion object { const val EXTRA_SCREEN = "screen" }
|
||||
private var clip: Clip? = null
|
||||
private var player: MediaPlayer? = null
|
||||
private var minutes: MinuteCounterView? = null
|
||||
@@ -73,16 +77,40 @@ class MainActivity : Activity() {
|
||||
store = Recordings(this)
|
||||
store.recover()
|
||||
active = RecordingService.activeId != null
|
||||
if (intent.getStringExtra(EXTRA_SCREEN) == "menu") screen = "menu"
|
||||
render()
|
||||
}
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent.getStringExtra(EXTRA_SCREEN) == "menu") { releasePlayer(); screen = "menu"; render() }
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
foreground = true; floatingMenu?.resume()
|
||||
motionAllowed = android.animation.ValueAnimator.areAnimatorsEnabled() && !getSystemService(PowerManager::class.java).isPowerSaveMode
|
||||
minutes?.setFloating(motionAllowed && !RecordingService.paused && minutes?.visibility == View.VISIBLE)
|
||||
handler.post(ticker)
|
||||
}
|
||||
override fun onPause() { handler.removeCallbacks(ticker); minutes?.setFloating(false); player?.pause(); super.onPause() }
|
||||
override fun onDestroy() { releasePlayer(); storageWorker.shutdown(); super.onDestroy() }
|
||||
override fun onPause() { foreground = false; floatingMenu?.pause(); handler.removeCallbacks(ticker); minutes?.setFloating(false); player?.pause(); super.onPause() }
|
||||
override fun onDestroy() { floatingMenu?.dispose(); releasePlayer(); storageWorker.shutdown(); super.onDestroy() }
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
val handled = super.dispatchTouchEvent(event)
|
||||
floatingMenu?.onTouch(event.actionMasked)
|
||||
return handled
|
||||
}
|
||||
override fun dispatchKeyEvent(event: android.view.KeyEvent): Boolean {
|
||||
val handled = super.dispatchKeyEvent(event)
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.keyCode in listOf(
|
||||
android.view.KeyEvent.KEYCODE_DPAD_UP, android.view.KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
android.view.KeyEvent.KEYCODE_DPAD_LEFT, android.view.KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
android.view.KeyEvent.KEYCODE_DPAD_CENTER, android.view.KeyEvent.KEYCODE_TAB)) floatingMenu?.interact()
|
||||
return handled
|
||||
}
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
val handled = super.dispatchGenericMotionEvent(event)
|
||||
if (event.action == MotionEvent.ACTION_SCROLL) floatingMenu?.interact()
|
||||
return handled
|
||||
}
|
||||
private fun dp(value: Int) = (value * resources.displayMetrics.density).roundToInt()
|
||||
private fun background(color: Int, radius: Float = 28f) = GradientDrawable().apply { setColor(color); cornerRadius = dp(radius.toInt()).toFloat() }
|
||||
private fun text(value: String, size: Float, color: Int = Color.WHITE): TextView {
|
||||
@@ -108,6 +136,8 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
private fun render() {
|
||||
val menuWasVisible = floatingMenu?.button?.visibility == View.VISIBLE
|
||||
floatingMenu?.dispose(); floatingMenu = null
|
||||
minutes?.setFloating(false)
|
||||
minutes = null; status = null; pause = null; play = null; seek = null; limitPicker = null
|
||||
storageRequest++; storageChart = null; storageAvailable = null; storageApp = null
|
||||
@@ -118,10 +148,17 @@ class MainActivity : Activity() {
|
||||
body = LinearLayout(this).apply {
|
||||
orientation = LinearLayout.VERTICAL; gravity = Gravity.CENTER_HORIZONTAL
|
||||
val round = resources.configuration.isScreenRound
|
||||
setPadding(dp(if (round) 30 else 20), dp(16), dp(if (round) 30 else 20), dp(20))
|
||||
setPadding(dp(if (round) 30 else 28), dp(if (screen == "home") 16 else 14), dp(if (round) 30 else 28), dp(24))
|
||||
}
|
||||
scroll.addView(body)
|
||||
layers.addView(scroll, FrameLayout.LayoutParams(-1, -1))
|
||||
if (screen != "menu") {
|
||||
val menuButton = WatchDesign.menuDock(this) { releasePlayer(); screen = "menu"; render() }
|
||||
layers.addView(menuButton, FrameLayout.LayoutParams(dp(48), dp(48), Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL))
|
||||
floatingMenu = FloatingMenuController(menuButton).also {
|
||||
if (foreground) { it.resume(); if (menuWasVisible) it.interact() }
|
||||
}
|
||||
}
|
||||
setContentView(layers)
|
||||
window.decorView.windowInsetsController?.hide(WindowInsets.Type.systemBars())
|
||||
window.decorView.windowInsetsController?.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
@@ -158,7 +195,7 @@ class MainActivity : Activity() {
|
||||
} else false
|
||||
}
|
||||
when {
|
||||
screen == "settings" -> settings()
|
||||
screen == "menu" -> menu()
|
||||
screen == "storage" -> storage()
|
||||
screen == "limits" -> limits()
|
||||
screen == "limit_minutes" -> limitMinutes()
|
||||
@@ -212,13 +249,6 @@ class MainActivity : Activity() {
|
||||
// Saved total has no running seconds; the sweep starts when capture starts.
|
||||
dial.elapsed = 0
|
||||
button("● Record", mint) { startRecording() }.contentDescription = "Start recording"
|
||||
val row = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL }
|
||||
val moments = button("Moments · ${clips.size}") { screen = "library"; render() }.apply { textSize = 11f }
|
||||
val settings = button("Settings") { screen = "settings"; render() }.apply { textSize = 11f }
|
||||
body.removeView(moments); body.removeView(settings)
|
||||
row.addView(moments, LinearLayout.LayoutParams(0, dp(44), 1f).apply { marginEnd = dp(3) })
|
||||
row.addView(settings, LinearLayout.LayoutParams(dp(64), dp(44)).apply { marginStart = dp(3) })
|
||||
body.addView(row, LinearLayout.LayoutParams(-1, dp(44)).apply { topMargin = dp(3) })
|
||||
}
|
||||
private fun recording() {
|
||||
status = text(if (RecordingService.paused) "PAUSED" else "● RECORDING", 10f, mint)
|
||||
@@ -235,20 +265,60 @@ class MainActivity : Activity() {
|
||||
row.addView(mark, LinearLayout.LayoutParams(0, dp(44), 1f).apply { marginStart = dp(3) })
|
||||
body.addView(row)
|
||||
button("■ Save", mint) { command(RecordingService.SAVE) }
|
||||
button("Settings") { screen = "settings"; render() }
|
||||
}
|
||||
private fun settings() {
|
||||
private fun menu() {
|
||||
updateDial(0)
|
||||
text("SETTINGS", 10f, mint)
|
||||
text("Make it yours.", 17f)
|
||||
button("Storage") { screen = "storage"; render() }.apply { layoutParams.height = dp(56) }
|
||||
button("Recording limit") { screen = "limits"; render() }.apply { layoutParams.height = dp(56) }
|
||||
button("Backup") { startActivity(Intent(this, BackupActivity::class.java)) }.apply { layoutParams.height = dp(56) }
|
||||
text("REMEMBER", 9f, mint).apply { letterSpacing = .16f }
|
||||
text(getString(R.string.menu), 18f)
|
||||
data class Destination(val label: String, val icon: WatchIcon, val target: String, val backup: Boolean = false)
|
||||
val destinations = listOf(
|
||||
Destination(getString(R.string.recorder), WatchIcon.RECORD, "home"),
|
||||
Destination(getString(R.string.moments), WatchIcon.MOMENTS, "library"),
|
||||
Destination(getString(R.string.storage), WatchIcon.STORAGE, "storage"),
|
||||
Destination(getString(R.string.recording_limit), WatchIcon.LIMIT, "limits"),
|
||||
Destination(getString(R.string.backup_backup), WatchIcon.BACKUP, "overview", true),
|
||||
Destination(getString(R.string.backup_server), WatchIcon.SERVER, "server", true),
|
||||
Destination(getString(R.string.backup_transfers), WatchIcon.TRANSFERS, "transfers", true),
|
||||
Destination(getString(R.string.backup_server_recordings), WatchIcon.REMOTE, "remote", true),
|
||||
Destination(getString(R.string.backup_automatic_backup), WatchIcon.AUTOMATIC, "automatic", true),
|
||||
Destination(getString(R.string.backup_advanced), WatchIcon.ADVANCED, "advanced", true)
|
||||
)
|
||||
destinations.chunked(3).forEach { pair ->
|
||||
val row = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL }
|
||||
pair.forEach { destination ->
|
||||
val tile = WatchDesign.action(this, destination.label) {
|
||||
menuOffset = scroll.scrollY
|
||||
if (destination.backup) startActivity(Intent(this, BackupActivity::class.java).putExtra(BackupActivity.EXTRA_PAGE, destination.target))
|
||||
else { screen = destination.target; render() }
|
||||
}.apply {
|
||||
background = WatchDesign.touch(this@MainActivity, Color.TRANSPARENT, 16)
|
||||
textSize = 9f; gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
|
||||
setPadding(dp(3), dp(4), dp(3), 0); maxLines = 2
|
||||
val colors = when (destination.icon) {
|
||||
WatchIcon.MOMENTS, WatchIcon.REMOTE -> Color.rgb(143, 204, 217)
|
||||
WatchIcon.SERVER, WatchIcon.ADVANCED -> Color.rgb(197, 190, 234)
|
||||
else -> mint
|
||||
}
|
||||
val icon = WatchGlyph(destination.icon, colors, true).apply { setBounds(0, 0, dp(44), dp(44)) }
|
||||
setCompoundDrawables(null, icon, null, null); compoundDrawablePadding = dp(4)
|
||||
contentDescription = destination.label
|
||||
}
|
||||
row.addView(tile, LinearLayout.LayoutParams(0, dp(84), 1f))
|
||||
}
|
||||
repeat(3 - pair.size) { row.addView(Space(this), LinearLayout.LayoutParams(0, dp(84), 1f)) }
|
||||
body.addView(row, LinearLayout.LayoutParams(-1, -2))
|
||||
}
|
||||
button(if (active) "Back to recording" else "Back") { screen = "home"; render() }
|
||||
scroll.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
scroll.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
scroll.scrollTo(0, menuOffset)
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun storage() {
|
||||
updateDial(0)
|
||||
body.setPadding(dp(12), dp(8), dp(12), dp(20))
|
||||
body.setPadding(dp(12), dp(8), dp(12), dp(24))
|
||||
text("STORAGE", 10f, mint)
|
||||
storageChart = StorageChartView(this).also {
|
||||
// Center a large chart in the initial viewport; details and actions follow below it.
|
||||
@@ -258,7 +328,7 @@ class MainActivity : Activity() {
|
||||
storageAvailable = text("● Available · …", 11f, mint)
|
||||
storageApp = text("● Remember · …", 11f)
|
||||
button("Refresh") { loadStorage() }
|
||||
button("Back") { screen = "settings"; render() }
|
||||
button("Back") { screen = "menu"; render() }
|
||||
loadStorage()
|
||||
}
|
||||
private fun loadStorage() {
|
||||
@@ -286,30 +356,30 @@ class MainActivity : Activity() {
|
||||
private fun limits() {
|
||||
updateDial(0)
|
||||
val limit = preferences.read()
|
||||
text("RECORDING LIMIT", 10f, mint)
|
||||
val toggle = Switch(this).apply {
|
||||
WatchDesign.heading(body, getString(R.string.your_pace), getString(R.string.recording_limit))
|
||||
val face = StatusDialView(this).apply {
|
||||
update(if (limit.enabled) limit.minutes.toString() else "∞", if (limit.enabled) "minutes / clip" else "unlimited", if (limit.enabled) 1f else 0f)
|
||||
}
|
||||
body.addView(face, LinearLayout.LayoutParams(-1, dp(116)))
|
||||
Switch(this).apply {
|
||||
text = "Minute limit"; textSize = 12f; setTextColor(Color.WHITE)
|
||||
isChecked = limit.enabled
|
||||
thumbTintList = android.content.res.ColorStateList(
|
||||
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
|
||||
intArrayOf(mint, Color.rgb(116, 129, 96))
|
||||
)
|
||||
setPadding(dp(5), 0, dp(5), 0)
|
||||
body.addView(this, LinearLayout.LayoutParams(-1, dp(44)))
|
||||
thumbTintList = WatchDesign.switchTint()
|
||||
background = WatchDesign.shape(this@MainActivity)
|
||||
setPadding(dp(12), 0, dp(12), 0)
|
||||
body.addView(this, LinearLayout.LayoutParams(-1, dp(48)))
|
||||
setOnCheckedChangeListener { _, checked -> preferences.write(preferences.read().copy(enabled = checked)); render() }
|
||||
}
|
||||
text(if (toggle.isChecked) "Enabled" else "Unlimited recording", 10f, muted)
|
||||
button("Length · ${limit.minutes} min") { screen = "limit_minutes"; render() }
|
||||
button("At the limit\n${if (limit.action == LimitAction.STOP) "Save & stop" else "Save & start next"}") {
|
||||
WatchDesign.card(body, "At the limit", if (limit.action == LimitAction.STOP) "Save & stop" else "Save & start next", WatchIcon.LIMIT) {
|
||||
screen = "limit_action"; render()
|
||||
}.apply { layoutParams.height = dp(54); textSize = 11f }
|
||||
text("Applies to your next recording session.\nPaused time doesn't count.", 10f, muted)
|
||||
button("Back") { screen = "settings"; render() }
|
||||
}
|
||||
text("Applies to your next session.\nPaused time doesn't count.", 10f, muted)
|
||||
button("Back") { screen = "menu"; render() }
|
||||
}
|
||||
private fun limitMinutes() {
|
||||
updateDial(0)
|
||||
text("CLIP LENGTH", 10f, mint)
|
||||
text("Minutes", 13f)
|
||||
WatchDesign.heading(body, "Minutes", "Clip length")
|
||||
limitPicker = NumberPicker(this).apply {
|
||||
minValue = 1; maxValue = 1440; value = preferences.read().minutes; wrapSelectorWheel = false
|
||||
contentDescription = "Recording limit in minutes"
|
||||
@@ -325,7 +395,7 @@ class MainActivity : Activity() {
|
||||
}
|
||||
private fun limitAction() {
|
||||
updateDial(0)
|
||||
text("AT THE LIMIT", 10f, mint)
|
||||
WatchDesign.heading(body, "At the limit", "Recording limit")
|
||||
val action = preferences.read().action
|
||||
button("${if (action == LimitAction.STOP) "✓ " else ""}Save & stop", if (action == LimitAction.STOP) mint else Color.rgb(43, 52, 32)) {
|
||||
preferences.write(preferences.read().copy(action = LimitAction.STOP)); render()
|
||||
@@ -338,7 +408,7 @@ class MainActivity : Activity() {
|
||||
}
|
||||
private fun library() {
|
||||
updateDial(0)
|
||||
text("YOUR MOMENTS", 10f, mint)
|
||||
WatchDesign.heading(body, getString(R.string.moments), getString(R.string.on_your_wrist))
|
||||
val clips = store.list()
|
||||
if (clips.isEmpty()) {
|
||||
text("A little space\nfor big ideas.", 20f)
|
||||
@@ -347,16 +417,13 @@ class MainActivity : Activity() {
|
||||
} else {
|
||||
text("${clips.size} saved", 12f, muted)
|
||||
clips.forEach { item ->
|
||||
button("${item.title}\n${SimpleDateFormat("MMM d", Locale.getDefault()).format(Date(item.created))} · ${timeLabel(item.duration)}") {
|
||||
WatchDesign.card(body, item.title,
|
||||
"${SimpleDateFormat("MMM d", Locale.getDefault()).format(Date(item.created))} · ${timeLabel(item.duration)}", WatchIcon.PLAY) {
|
||||
clip = item; screen = "detail"; render()
|
||||
}.apply {
|
||||
textSize = 11f
|
||||
layoutParams.height = dp(54)
|
||||
maxLines = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
button("Back") { screen = "home"; render() }
|
||||
button("Back") { screen = "menu"; render() }
|
||||
}
|
||||
private fun detail() {
|
||||
val item = clip ?: run { screen = "library"; render(); return }
|
||||
@@ -454,7 +521,7 @@ class MainActivity : Activity() {
|
||||
releasePlayer()
|
||||
screen = when (screen) {
|
||||
"detail" -> "library"
|
||||
"storage", "limits" -> "settings"
|
||||
"storage", "limits", "library" -> "menu"
|
||||
"limit_minutes", "limit_action" -> "limits"
|
||||
else -> "home"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package meghdad.remember
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.graphics.drawable.RippleDrawable
|
||||
import android.view.Gravity
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import kotlin.math.*
|
||||
|
||||
/** Shared watch controls: native focus and spoken labels, with original vector artwork. */
|
||||
object WatchDesign {
|
||||
val ink = Color.rgb(13, 17, 11)
|
||||
val lime = Color.rgb(199, 234, 24)
|
||||
val muted = Color.rgb(164, 175, 143)
|
||||
val surface = Color.rgb(30, 39, 25)
|
||||
fun dp(context: Context, value: Int) = (context.resources.displayMetrics.density * value).roundToInt()
|
||||
fun switchTint() = ColorStateList(arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()), intArrayOf(lime, muted))
|
||||
fun shape(context: Context, color: Int = surface, radius: Int = 22, stroke: Int? = null) = GradientDrawable().apply {
|
||||
setColor(color); cornerRadius = dp(context, radius).toFloat()
|
||||
stroke?.let { setStroke(dp(context, 1), it) }
|
||||
}
|
||||
fun touch(context: Context, color: Int = surface, radius: Int = 22) = RippleDrawable(
|
||||
ColorStateList.valueOf(Color.argb(60, 199, 234, 24)), shape(context, color, radius), shape(context, Color.WHITE, radius))
|
||||
fun label(context: Context, value: String, size: Float = 12f, color: Int = Color.WHITE) = TextView(context).apply {
|
||||
text = value; textSize = size; setTextColor(color); gravity = Gravity.CENTER
|
||||
includeFontPadding = false
|
||||
layoutParams = LinearLayout.LayoutParams(-1, -2)
|
||||
}
|
||||
fun heading(body: LinearLayout, title: String, eyebrow: String) {
|
||||
body.addView(label(body.context, eyebrow.uppercase(), 9f, lime).apply { letterSpacing = .16f })
|
||||
body.addView(label(body.context, title, 21f).apply {
|
||||
typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
|
||||
setPadding(0, dp(context, 4), 0, dp(context, 8))
|
||||
})
|
||||
}
|
||||
fun action(context: Context, label: String, primary: Boolean = false, action: () -> Unit) = Button(context).apply {
|
||||
text = label; textSize = 12f; isAllCaps = false; setTextColor(if (primary) ink else Color.WHITE)
|
||||
background = touch(context, if (primary) lime else surface)
|
||||
minHeight = 0; minimumHeight = 0; stateListAnimator = null
|
||||
setPadding(dp(context, 8), 0, dp(context, 8), 0)
|
||||
layoutParams = LinearLayout.LayoutParams(-1, dp(context, 48)).apply { setMargins(0, dp(context, 4), 0, dp(context, 4)) }
|
||||
setOnClickListener { performHapticFeedback(HapticFeedbackConstants.CONFIRM); action() }
|
||||
}
|
||||
fun pair(body: LinearLayout, first: Button, second: Button) {
|
||||
val row = LinearLayout(body.context).apply { orientation = LinearLayout.HORIZONTAL }
|
||||
row.addView(first, LinearLayout.LayoutParams(0, dp(body.context, 48), 1f).apply { marginEnd = dp(body.context, 3) })
|
||||
row.addView(second, LinearLayout.LayoutParams(0, dp(body.context, 48), 1f).apply { marginStart = dp(body.context, 3) })
|
||||
body.addView(row, LinearLayout.LayoutParams(-1, -2).apply { topMargin = dp(body.context, 6); bottomMargin = dp(body.context, 6) })
|
||||
}
|
||||
fun card(body: LinearLayout, title: String, subtitle: String, icon: WatchIcon, action: (() -> Unit)? = null): TextView {
|
||||
val context = body.context
|
||||
val row = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.HORIZONTAL; gravity = Gravity.CENTER_VERTICAL
|
||||
background = touch(context); setPadding(dp(context, 12), dp(context, 12), dp(context, 10), dp(context, 12))
|
||||
minimumHeight = dp(context, 60)
|
||||
}
|
||||
val image = ImageView(context).apply { setImageDrawable(WatchGlyph(icon, lime)); importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO }
|
||||
row.addView(image, LinearLayout.LayoutParams(dp(context, 24), dp(context, 24)).apply { marginEnd = dp(context, 10) })
|
||||
val copy = LinearLayout(context).apply { orientation = LinearLayout.VERTICAL }
|
||||
copy.addView(label(context, title, 13f).apply { gravity = Gravity.START; maxLines = 2; ellipsize = android.text.TextUtils.TruncateAt.END })
|
||||
val detail = label(context, subtitle, 10f, muted).apply { gravity = Gravity.START; setPadding(0, dp(context, 4), 0, 0) }
|
||||
copy.addView(detail); row.addView(copy, LinearLayout.LayoutParams(0, -2, 1f))
|
||||
if (action != null) {
|
||||
row.contentDescription = "$title. $subtitle"
|
||||
image.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
|
||||
copy.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
||||
row.isFocusable = true; row.setOnClickListener { row.performHapticFeedback(HapticFeedbackConstants.CONFIRM); action() }
|
||||
row.accessibilityDelegate = object : View.AccessibilityDelegate() {
|
||||
override fun onInitializeAccessibilityNodeInfo(host: View, info: android.view.accessibility.AccessibilityNodeInfo) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info); info.className = Button::class.java.name
|
||||
}
|
||||
}
|
||||
}
|
||||
body.addView(row, LinearLayout.LayoutParams(-1, -2).apply { topMargin = dp(context, 4); bottomMargin = dp(context, 4) })
|
||||
return detail
|
||||
}
|
||||
fun menuDock(context: Context, action: () -> Unit) = action(context, "", false, action).apply {
|
||||
background = touch(context, Color.TRANSPARENT, 24)
|
||||
setPadding(dp(context, 10), dp(context, 10), dp(context, 10), dp(context, 10))
|
||||
val icon = WatchGlyph(WatchIcon.MENU, lime).apply { setBounds(0, 0, dp(context, 28), dp(context, 28)) }
|
||||
setCompoundDrawables(icon, null, null, null); compoundDrawablePadding = 0
|
||||
contentDescription = context.getString(R.string.open_menu)
|
||||
}
|
||||
}
|
||||
|
||||
enum class WatchIcon { RECORD, MOMENTS, STORAGE, LIMIT, BACKUP, SERVER, TRANSFERS, REMOTE, AUTOMATIC, ADVANCED, MENU, PLAY }
|
||||
|
||||
/** Each destination has an identifiable silhouette, without fonts or bitmap assets. */
|
||||
class WatchGlyph(private val icon: WatchIcon, private val tint: Int, private val orb: Boolean = false) : Drawable() {
|
||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
override fun draw(canvas: Canvas) {
|
||||
canvas.save(); canvas.translate(bounds.left.toFloat(), bounds.top.toFloat()); canvas.scale(bounds.width() / 48f, bounds.height() / 48f)
|
||||
if (orb) {
|
||||
paint.style = Paint.Style.FILL
|
||||
paint.shader = LinearGradient(5f, 3f, 40f, 48f, Color.rgb(47, 61, 34), Color.rgb(21, 29, 17), Shader.TileMode.CLAMP)
|
||||
canvas.drawCircle(24f, 24f, 23f, paint); paint.shader = null
|
||||
paint.color = Color.argb(90, Color.red(tint), Color.green(tint), Color.blue(tint)); paint.style = Paint.Style.STROKE; paint.strokeWidth = .7f
|
||||
canvas.drawArc(RectF(1f, 1f, 47f, 47f), 210f, 130f, false, paint)
|
||||
canvas.translate(9f, 9f); canvas.scale(.625f, .625f)
|
||||
}
|
||||
paint.color = tint; paint.style = Paint.Style.STROKE; paint.strokeWidth = 2.5f; paint.strokeCap = Paint.Cap.ROUND; paint.strokeJoin = Paint.Join.ROUND
|
||||
fun line(x: Float, y: Float, xx: Float, yy: Float) = canvas.drawLine(x, y, xx, yy, paint)
|
||||
fun box(x: Float, y: Float, xx: Float, yy: Float, r: Float = 4f) = canvas.drawRoundRect(RectF(x, y, xx, yy), r, r, paint)
|
||||
fun arrow() { line(24f, 33f, 24f, 15f); line(18f, 21f, 24f, 15f); line(24f, 15f, 30f, 21f) }
|
||||
when (icon) {
|
||||
WatchIcon.RECORD -> { box(18f, 7f, 30f, 29f, 6f); canvas.drawArc(RectF(12f, 15f, 36f, 36f), 0f, 180f, false, paint); line(24f, 36f, 24f, 42f); line(18f, 42f, 30f, 42f) }
|
||||
WatchIcon.MOMENTS -> { line(10f, 20f, 10f, 28f); line(17f, 12f, 17f, 36f); line(24f, 6f, 24f, 42f); line(31f, 15f, 31f, 33f); line(38f, 20f, 38f, 28f) }
|
||||
WatchIcon.STORAGE -> { canvas.drawCircle(24f, 24f, 16f, paint); paint.strokeWidth = 6f; canvas.drawArc(RectF(8f, 8f, 40f, 40f), -90f, 235f, false, paint); paint.style = Paint.Style.FILL; canvas.drawCircle(24f, 24f, 3f, paint) }
|
||||
WatchIcon.LIMIT -> { canvas.drawCircle(24f, 26f, 16f, paint); line(24f, 26f, 24f, 16f); line(24f, 26f, 31f, 30f); line(20f, 5f, 28f, 5f); line(24f, 5f, 24f, 10f) }
|
||||
WatchIcon.BACKUP, WatchIcon.REMOTE -> {
|
||||
val path = Path().apply { moveTo(12f, 35f); cubicTo(-1f, 31f, 5f, 15f, 15f, 18f); cubicTo(17f, 3f, 37f, 5f, 37f, 20f); cubicTo(48f, 20f, 48f, 35f, 37f, 35f) }
|
||||
canvas.drawPath(path, paint)
|
||||
if (icon == WatchIcon.BACKUP) arrow() else { val play = Path().apply { moveTo(21f, 24f); lineTo(29f, 29f); lineTo(21f, 34f); close() }; canvas.drawPath(play, paint) }
|
||||
}
|
||||
WatchIcon.SERVER -> { box(8f, 7f, 40f, 22f); box(8f, 27f, 40f, 42f); line(14f, 14f, 15f, 14f); line(14f, 34f, 15f, 34f); line(27f, 14f, 34f, 14f); line(27f, 34f, 34f, 34f) }
|
||||
WatchIcon.TRANSFERS -> { line(15f, 37f, 15f, 10f); line(9f, 16f, 15f, 10f); line(15f, 10f, 21f, 16f); line(33f, 11f, 33f, 38f); line(27f, 32f, 33f, 38f); line(33f, 38f, 39f, 32f) }
|
||||
WatchIcon.AUTOMATIC -> { canvas.drawArc(RectF(7f, 7f, 41f, 41f), -60f, 290f, false, paint); line(35f, 5f, 40f, 12f); line(40f, 12f, 31f, 13f); line(24f, 14f, 24f, 24f); line(24f, 24f, 31f, 29f) }
|
||||
WatchIcon.ADVANCED -> { for (i in 0..2) { val y = 12f + i * 12; line(7f, y, 41f, y); box(if (i == 1) 26f else 12f, y - 4, if (i == 1) 32f else 18f, y + 4, 2f) } }
|
||||
WatchIcon.MENU -> { paint.style = Paint.Style.FILL; for (x in listOf(15f, 33f)) for (y in listOf(15f, 33f)) canvas.drawCircle(x, y, 5f, paint) }
|
||||
WatchIcon.PLAY -> { val path = Path().apply { moveTo(17f, 9f); lineTo(38f, 24f); lineTo(17f, 39f); close() }; canvas.drawPath(path, paint) }
|
||||
}
|
||||
canvas.restore()
|
||||
}
|
||||
override fun setAlpha(alpha: Int) { paint.alpha = alpha; invalidateSelf() }
|
||||
override fun setColorFilter(colorFilter: ColorFilter?) { paint.colorFilter = colorFilter; invalidateSelf() }
|
||||
@Deprecated("Drawable opacity") override fun getOpacity() = PixelFormat.TRANSLUCENT
|
||||
}
|
||||
|
||||
/** A quiet, static dial: progress for backups, or tick marks for a configured duration. */
|
||||
class StatusDialView(context: Context) : View(context) {
|
||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private var value = "0"
|
||||
private var caption = ""
|
||||
private var fraction = 0f
|
||||
private val ring = RectF()
|
||||
fun update(number: String, label: String, progress: Float) {
|
||||
value = number; caption = label; fraction = progress.coerceIn(0f, 1f)
|
||||
contentDescription = "$number $label"; invalidate()
|
||||
}
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val size = min(width, height).toFloat(); val cx = width / 2f; val cy = height / 2f; val r = size * .42f
|
||||
paint.style = Paint.Style.STROKE; paint.strokeWidth = size * .035f; paint.strokeCap = Paint.Cap.ROUND; paint.color = WatchDesign.surface
|
||||
ring.set(cx - r, cy - r, cx + r, cy + r)
|
||||
canvas.drawArc(ring, 135f, 270f, false, paint)
|
||||
paint.color = WatchDesign.lime
|
||||
if (fraction > 0) canvas.drawArc(ring, 135f, 270f * fraction, false, paint)
|
||||
paint.strokeWidth = size * .008f
|
||||
for (i in 0..24) {
|
||||
val angle = Math.toRadians(135.0 + i * 270.0 / 24)
|
||||
val outer = r - size * .05f; val inner = outer - if (i % 6 == 0) size * .05f else size * .024f
|
||||
paint.color = if (i / 24f <= fraction && fraction > 0) WatchDesign.lime else Color.rgb(67, 80, 54)
|
||||
canvas.drawLine(cx + cos(angle).toFloat() * inner, cy + sin(angle).toFloat() * inner, cx + cos(angle).toFloat() * outer, cy + sin(angle).toFloat() * outer, paint)
|
||||
}
|
||||
paint.style = Paint.Style.FILL; paint.color = Color.WHITE; paint.textAlign = Paint.Align.CENTER
|
||||
paint.typeface = Typeface.create("sans-serif-condensed", Typeface.BOLD)
|
||||
paint.textSize = size * if (value.length > 3) .26f else .36f
|
||||
canvas.drawText(value, cx, cy + size * .09f, paint)
|
||||
paint.color = WatchDesign.muted; paint.typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL); paint.textSize = size * .075f
|
||||
val displayCaption = caption.uppercase()
|
||||
val captionWidth = paint.measureText(displayCaption)
|
||||
if (captionWidth > size * .68f) paint.textSize *= size * .68f / captionWidth
|
||||
canvas.drawText(displayCaption, cx, cy + size * .23f, paint)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,27 @@
|
||||
<resources>
|
||||
<string name="menu">Menu</string>
|
||||
<string name="open_menu">Open all sections</string>
|
||||
<string name="recorder">Recorder</string>
|
||||
<string name="moments">Moments</string>
|
||||
<string name="storage">Storage</string>
|
||||
<string name="recording_limit">Recording limit</string>
|
||||
<string name="autopilot">Autopilot</string>
|
||||
<string name="on_your_server">On your server</string>
|
||||
<string name="fine_tune">Fine tune</string>
|
||||
<string name="your_pace">Your pace</string>
|
||||
<string name="on_your_wrist">On your wrist</string>
|
||||
<string name="retry_attempts">RETRY ATTEMPTS</string>
|
||||
<string name="connection_timeout">CONNECTION TIMEOUT</string>
|
||||
<string name="on_this_watch">ON THIS WATCH</string>
|
||||
<string name="check_interval">CHECK INTERVAL</string>
|
||||
<string name="pause_all">Pause all</string>
|
||||
<string name="backup_waiting_count">%1$d waiting on your wrist</string>
|
||||
<string name="backup_last">Last backup</string>
|
||||
<string name="backup_destination">Destination</string>
|
||||
<string name="backup_no_destination">Choose Server in the menu</string>
|
||||
<string name="backup_none_completed">No completed backup yet</string>
|
||||
<string name="backup_automatic_on">Automatic backups are on</string>
|
||||
<string name="backup_automatic_off">Automatic backups are off</string>
|
||||
<string name="app_name">Remember</string>
|
||||
<string name="backup_download_progress">Downloading · %1$d%%</string>
|
||||
<string name="backup_address">Address</string>
|
||||
|
||||
Reference in new issue
Block a user