Add memory debug action window

This commit is contained in:
Aleksandras Kostarevas 2024-04-22 00:32:36 -04:00
parent cdb0bed56a
commit 9e0dc28848
5 changed files with 78 additions and 4 deletions

View File

@ -8,6 +8,7 @@
<string name="undo_action_title">Undo</string>
<string name="redo_action_title">Redo</string>
<string name="text_edit_action_title">Text Editor</string>
<string name="mem_debug_action_title">Debug Info</string>
<string name="amoled_dark_theme_name">AMOLED Dark Purple</string>
<string name="classic_material_dark_theme_name">AOSP Material Dark</string>

View File

@ -90,6 +90,7 @@ import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo.KIND_TYPED
import org.futo.inputmethod.latin.common.Constants
import org.futo.inputmethod.latin.suggestions.SuggestionStripView
import org.futo.inputmethod.latin.uix.actions.ActionRegistry
import org.futo.inputmethod.latin.uix.actions.DefaultActions
import org.futo.inputmethod.latin.uix.actions.DefaultActionsString
import org.futo.inputmethod.latin.uix.actions.ExpandableActionItems
import org.futo.inputmethod.latin.uix.actions.VoiceInputAction
@ -471,7 +472,7 @@ fun ActionItems(onSelect: (Action) -> Unit) {
val actions = useDataStoreValueNullable(key = ExpandableActionItems, default = DefaultActionsString)
if(actions != null) {
val actionItems = ActionRegistry.stringToActions(actions)
val actionItems = ActionRegistry.stringToActions(actions, DefaultActions)
LazyRow {
items(actionItems.size, key = { actionItems[it].name }) {

View File

@ -0,0 +1,65 @@
package org.futo.inputmethod.latin.uix.actions
import android.os.Debug
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource
import kotlinx.coroutines.delay
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action
import org.futo.inputmethod.latin.uix.ActionWindow
import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.latin.uix.theme.ThemeOptions
import org.futo.inputmethod.latin.uix.theme.Typography
val MemoryDebugAction = Action(
icon = R.drawable.code,
name = R.string.mem_debug_action_title,
simplePressImpl = null,
canShowKeyboard = true,
windowImpl = { manager, _ ->
object : ActionWindow {
@Composable
override fun windowName(): String {
return stringResource(R.string.mem_debug_action_title)
}
@Composable
override fun WindowContents(keyboardShown: Boolean) {
val state: MutableState<Map<String, String>> = remember { mutableStateOf(mapOf()) }
LaunchedEffect(Unit) {
while (true) {
delay(250)
val newInfo = Debug.MemoryInfo()
Debug.getMemoryInfo(newInfo)
state.value = newInfo.memoryStats
}
}
ScrollableList {
state.value.forEach {
val value = it.value.toInt().toFloat() / 1000.0f
Text("${it.key}: ${String.format("%.2f", value)}MB", style = Typography.labelSmall)
}
Button(onClick = {
manager.updateTheme(ThemeOptions.values.random())
}) {
Text("Randomize Theme")
}
}
}
override fun close() {
}
}
}
)

View File

@ -24,9 +24,15 @@ val AllActions = listOf(
object ActionRegistry {
fun stringToActions(string: String): List<Action> {
fun stringToActions(string: String, defaults: List<Action>): List<Action> {
return string.split(",").mapNotNull { idx ->
idx.toIntOrNull()?.let { AllActions.getOrNull(it) }
}.let { list ->
val notIncluded = defaults.filter { action ->
!list.contains(action)
}
list + notIncluded
}
}
@ -35,7 +41,7 @@ object ActionRegistry {
}
fun moveElement(string: String, action: Action, direction: Int): String {
val actions = stringToActions(string)
val actions = stringToActions(string, listOf())
val index = actions.indexOf(action)
val filtered = actions.filter { it != action }.toMutableList()
filtered.add((index + direction).coerceIn(0 .. filtered.size), action)
@ -64,6 +70,7 @@ val DefaultActions = listOf(
ClipboardAction,
SettingsAction,
ThemeAction,
MemoryDebugAction
)
val DefaultActionsString = ActionRegistry.actionsToString(DefaultActions)

View File

@ -64,7 +64,7 @@ namespace latinime {
if (i > 0) {
if (times[i] < times[i - 1]) {
AKLOGI("Invalid time sequence. %d, %d", times[i - 1], times[i]);
ASSERT(false);
//ASSERT(false);
}
}
}