mirror of
https://git.citron-emu.org/citron/emulator
synced 2026-01-08 10:47:56 +00:00
feat: Add compact overlay system with FPS, thermal, and RAM indicators
- Replace old text-based FPS/thermal overlays with custom views - Add new FpsIndicatorView with color-coded performance display - Add ThermalIndicatorView showing battery temperature in °C/°F - Add RamMeterView with usage percentage and visual progress bar - Arrange all overlays horizontally at top center of screen - Add native configuration support for show_ram_meter setting - Update overlay options menu to include RAM meter toggle - Implement proper battery temperature reading via BatteryManager - Use compact 120x60 (FPS/thermal) and 140x60 (RAM) dimensions - Add color coding: green (good), orange (moderate), red (poor/hot) - Include appropriate icons and shadows for better visibility (WIP) Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.citron.citron_emu.features.settings.model
|
||||
@@ -26,7 +27,8 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting {
|
||||
SHOW_PERFORMANCE_OVERLAY("show_performance_overlay"),
|
||||
SHOW_INPUT_OVERLAY("show_input_overlay"),
|
||||
TOUCHSCREEN("touchscreen"),
|
||||
SHOW_THERMAL_OVERLAY("show_thermal_overlay");
|
||||
SHOW_THERMAL_OVERLAY("show_thermal_overlay"),
|
||||
SHOW_RAM_METER("show_ram_meter");
|
||||
|
||||
override fun getBoolean(needsGlobal: Boolean): Boolean =
|
||||
NativeConfig.getBoolean(key, needsGlobal)
|
||||
|
||||
@@ -8,9 +8,12 @@ import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.BatteryManager
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@@ -66,6 +69,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
private var emulationActivity: EmulationActivity? = null
|
||||
private var perfStatsUpdater: (() -> Unit)? = null
|
||||
private var thermalStatsUpdater: (() -> Unit)? = null
|
||||
private var ramStatsUpdater: (() -> Unit)? = null
|
||||
|
||||
private var _binding: FragmentEmulationBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
@@ -374,6 +378,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
// Setup overlays
|
||||
updateShowFpsOverlay()
|
||||
updateThermalOverlay()
|
||||
updateRamMeterOverlay()
|
||||
}
|
||||
}
|
||||
emulationViewModel.isEmulationStopping.collect(viewLifecycleOwner) {
|
||||
@@ -381,7 +386,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
binding.loadingText.setText(R.string.shutting_down)
|
||||
ViewUtils.showView(binding.loadingIndicator)
|
||||
ViewUtils.hideView(binding.inputContainer)
|
||||
ViewUtils.hideView(binding.showFpsText)
|
||||
ViewUtils.hideView(binding.fpsIndicatorView)
|
||||
ViewUtils.hideView(binding.thermalIndicatorView)
|
||||
ViewUtils.hideView(binding.ramMeterView)
|
||||
}
|
||||
}
|
||||
emulationViewModel.drawerOpen.collect(viewLifecycleOwner) {
|
||||
@@ -486,22 +493,16 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
|
||||
private fun updateShowFpsOverlay() {
|
||||
val showOverlay = BooleanSetting.SHOW_PERFORMANCE_OVERLAY.getBoolean()
|
||||
binding.showFpsText.setVisible(showOverlay)
|
||||
binding.fpsIndicatorView.setVisible(showOverlay)
|
||||
if (showOverlay) {
|
||||
val SYSTEM_FPS = 0
|
||||
val FPS = 1
|
||||
val FRAMETIME = 2
|
||||
val SPEED = 3
|
||||
perfStatsUpdater = {
|
||||
if (emulationViewModel.emulationStarted.value &&
|
||||
!emulationViewModel.isEmulationStopping.value
|
||||
) {
|
||||
val perfStats = NativeLibrary.getPerfStats()
|
||||
val cpuBackend = NativeLibrary.getCpuBackend()
|
||||
val gpuDriver = NativeLibrary.getGpuDriver()
|
||||
if (_binding != null) {
|
||||
binding.showFpsText.text =
|
||||
String.format("FPS: %.1f\n%s/%s", perfStats[FPS], cpuBackend, gpuDriver)
|
||||
binding.fpsIndicatorView.updateFps(perfStats[FPS].toFloat())
|
||||
}
|
||||
perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 800)
|
||||
}
|
||||
@@ -516,26 +517,17 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
|
||||
private fun updateThermalOverlay() {
|
||||
val showOverlay = BooleanSetting.SHOW_THERMAL_OVERLAY.getBoolean()
|
||||
binding.showThermalsText.setVisible(showOverlay)
|
||||
binding.thermalIndicatorView.setVisible(showOverlay)
|
||||
if (showOverlay) {
|
||||
thermalStatsUpdater = {
|
||||
if (emulationViewModel.emulationStarted.value &&
|
||||
!emulationViewModel.isEmulationStopping.value
|
||||
) {
|
||||
val thermalStatus = when (powerManager.currentThermalStatus) {
|
||||
PowerManager.THERMAL_STATUS_LIGHT -> "😥"
|
||||
PowerManager.THERMAL_STATUS_MODERATE -> "🥵"
|
||||
PowerManager.THERMAL_STATUS_SEVERE -> "🔥"
|
||||
PowerManager.THERMAL_STATUS_CRITICAL,
|
||||
PowerManager.THERMAL_STATUS_EMERGENCY,
|
||||
PowerManager.THERMAL_STATUS_SHUTDOWN -> "☢️"
|
||||
|
||||
else -> "🙂"
|
||||
}
|
||||
if (_binding != null) {
|
||||
binding.showThermalsText.text = thermalStatus
|
||||
val temperature = getBatteryTemperature(requireContext())
|
||||
binding.thermalIndicatorView.updateTemperature(temperature)
|
||||
}
|
||||
thermalStatsUpdateHandler.postDelayed(thermalStatsUpdater!!, 1000)
|
||||
thermalStatsUpdateHandler.postDelayed(thermalStatsUpdater!!, 2000)
|
||||
}
|
||||
}
|
||||
thermalStatsUpdateHandler.post(thermalStatsUpdater!!)
|
||||
@@ -546,6 +538,42 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateRamMeterOverlay() {
|
||||
val showOverlay = BooleanSetting.SHOW_RAM_METER.getBoolean()
|
||||
binding.ramMeterView.setVisible(showOverlay)
|
||||
if (showOverlay) {
|
||||
ramStatsUpdater = {
|
||||
if (emulationViewModel.emulationStarted.value &&
|
||||
!emulationViewModel.isEmulationStopping.value
|
||||
) {
|
||||
if (_binding != null) {
|
||||
binding.ramMeterView.updateRamUsage()
|
||||
}
|
||||
ramStatsUpdateHandler.postDelayed(ramStatsUpdater!!, 1500)
|
||||
}
|
||||
}
|
||||
ramStatsUpdateHandler.post(ramStatsUpdater!!)
|
||||
} else {
|
||||
if (ramStatsUpdater != null) {
|
||||
ramStatsUpdateHandler.removeCallbacks(ramStatsUpdater!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBatteryTemperature(context: Context): Float {
|
||||
return try {
|
||||
val batteryIntent = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
||||
if (batteryIntent != null) {
|
||||
val temperature = batteryIntent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 250)
|
||||
temperature / 10f // Convert from tenths of degrees to degrees
|
||||
} else {
|
||||
25f // Fallback temperature
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
25f // Fallback temperature
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
private fun updateOrientation() {
|
||||
emulationActivity?.let {
|
||||
@@ -676,6 +704,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
BooleanSetting.SHOW_PERFORMANCE_OVERLAY.getBoolean()
|
||||
findItem(R.id.thermal_indicator).isChecked =
|
||||
BooleanSetting.SHOW_THERMAL_OVERLAY.getBoolean()
|
||||
findItem(R.id.ram_meter).isChecked =
|
||||
BooleanSetting.SHOW_RAM_METER.getBoolean()
|
||||
findItem(R.id.menu_rel_stick_center).isChecked =
|
||||
BooleanSetting.JOYSTICK_REL_CENTER.getBoolean()
|
||||
findItem(R.id.menu_dpad_slide).isChecked = BooleanSetting.DPAD_SLIDE.getBoolean()
|
||||
@@ -702,6 +732,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
true
|
||||
}
|
||||
|
||||
R.id.ram_meter -> {
|
||||
it.isChecked = !it.isChecked
|
||||
BooleanSetting.SHOW_RAM_METER.setBoolean(it.isChecked)
|
||||
updateRamMeterOverlay()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_edit_overlay -> {
|
||||
binding.drawerLayout.close()
|
||||
binding.surfaceInputOverlay.requestFocus()
|
||||
@@ -1046,5 +1083,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
companion object {
|
||||
private val perfStatsUpdateHandler = Handler(Looper.myLooper()!!)
|
||||
private val thermalStatsUpdateHandler = Handler(Looper.myLooper()!!)
|
||||
private val ramStatsUpdateHandler = Handler(Looper.myLooper()!!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.citron.citron_emu.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class FpsIndicatorView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr) {
|
||||
|
||||
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.parseColor("#80000000") // Semi-transparent black
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
private val borderPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = 2f
|
||||
}
|
||||
|
||||
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 22f
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val smallTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 16f
|
||||
typeface = Typeface.DEFAULT
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val iconPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 24f
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private var currentFps: Float = 0f
|
||||
private val fpsIcon: String = "📊"
|
||||
|
||||
private val backgroundRect = RectF()
|
||||
|
||||
fun updateFps(fps: Float) {
|
||||
try {
|
||||
currentFps = fps
|
||||
Log.d("FpsIndicator", "FPS updated: $currentFps")
|
||||
|
||||
// Update color based on FPS performance
|
||||
val fpsColor = when {
|
||||
currentFps >= 55f -> Color.parseColor("#4CAF50") // Green - Good performance
|
||||
currentFps >= 45f -> Color.parseColor("#FF9800") // Orange - Moderate performance
|
||||
currentFps >= 30f -> Color.parseColor("#FF5722") // Red orange - Poor performance
|
||||
else -> Color.parseColor("#F44336") // Red - Very poor performance
|
||||
}
|
||||
|
||||
textPaint.color = fpsColor
|
||||
smallTextPaint.color = fpsColor
|
||||
borderPaint.color = fpsColor
|
||||
|
||||
// Always invalidate to trigger a redraw
|
||||
invalidate()
|
||||
Log.d("FpsIndicator", "View invalidated, FPS: $currentFps")
|
||||
} catch (e: Exception) {
|
||||
// Fallback in case of any errors
|
||||
currentFps = 0f
|
||||
Log.e("FpsIndicator", "Error updating FPS", e)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val desiredWidth = 120
|
||||
val desiredHeight = 60
|
||||
|
||||
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||
|
||||
val width = when (widthMode) {
|
||||
MeasureSpec.EXACTLY -> widthSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredWidth, widthSize)
|
||||
else -> desiredWidth
|
||||
}
|
||||
|
||||
val height = when (heightMode) {
|
||||
MeasureSpec.EXACTLY -> heightSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredHeight, heightSize)
|
||||
else -> desiredHeight
|
||||
}
|
||||
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
backgroundRect.set(4f, 4f, w - 4f, h - 4f)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
|
||||
// Draw background with rounded corners
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, backgroundPaint)
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, borderPaint)
|
||||
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
|
||||
// Draw FPS icon on the left
|
||||
canvas.drawText(fpsIcon, 18f, centerY - 8f, iconPaint)
|
||||
|
||||
// Draw FPS value (main text)
|
||||
val fpsText = "${currentFps.roundToInt()}"
|
||||
canvas.drawText(fpsText, centerX, centerY - 8f, textPaint)
|
||||
|
||||
// Draw "FPS" label (smaller text below)
|
||||
canvas.drawText("FPS", centerX, centerY + 12f, smallTextPaint)
|
||||
|
||||
Log.d("FpsIndicator", "onDraw called - FPS: $fpsText")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.citron.citron_emu.views
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class RamMeterView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr) {
|
||||
|
||||
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.parseColor("#80000000") // Semi-transparent black
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
private val borderPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = 2f
|
||||
}
|
||||
|
||||
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 20f
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val smallTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 14f
|
||||
typeface = Typeface.DEFAULT
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val iconPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 24f
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val meterBackgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.parseColor("#40FFFFFF") // Semi-transparent white
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
private val meterFillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.GREEN
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
private var ramUsagePercent: Float = 0f
|
||||
private var usedRamMB: Long = 0L
|
||||
private var totalRamMB: Long = 0L
|
||||
private var ramIcon: String = "🧠"
|
||||
|
||||
private val backgroundRect = RectF()
|
||||
private val meterBackgroundRect = RectF()
|
||||
private val meterFillRect = RectF()
|
||||
|
||||
fun updateRamUsage() {
|
||||
try {
|
||||
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val memoryInfo = ActivityManager.MemoryInfo()
|
||||
activityManager.getMemoryInfo(memoryInfo)
|
||||
|
||||
totalRamMB = memoryInfo.totalMem / (1024 * 1024)
|
||||
val availableRamMB = memoryInfo.availMem / (1024 * 1024)
|
||||
usedRamMB = totalRamMB - availableRamMB
|
||||
ramUsagePercent = (usedRamMB.toFloat() / totalRamMB.toFloat()) * 100f
|
||||
|
||||
// Update meter color based on usage
|
||||
val meterColor = when {
|
||||
ramUsagePercent < 50f -> Color.parseColor("#4CAF50") // Green
|
||||
ramUsagePercent < 75f -> Color.parseColor("#FF9800") // Orange
|
||||
ramUsagePercent < 90f -> Color.parseColor("#FF5722") // Red orange
|
||||
else -> Color.parseColor("#F44336") // Red
|
||||
}
|
||||
|
||||
meterFillPaint.color = meterColor
|
||||
textPaint.color = meterColor
|
||||
smallTextPaint.color = meterColor
|
||||
borderPaint.color = meterColor
|
||||
|
||||
// Update icon based on usage
|
||||
ramIcon = when {
|
||||
ramUsagePercent < 50f -> "🧠" // Normal brain
|
||||
ramUsagePercent < 75f -> "⚡" // Warning
|
||||
ramUsagePercent < 90f -> "🔥" // Hot
|
||||
else -> "💥" // Critical
|
||||
}
|
||||
|
||||
invalidate()
|
||||
Log.d("RamMeter", "RAM usage updated: ${ramUsagePercent.roundToInt()}% (${usedRamMB}MB/${totalRamMB}MB)")
|
||||
} catch (e: Exception) {
|
||||
Log.e("RamMeter", "Error updating RAM usage", e)
|
||||
ramUsagePercent = 0f
|
||||
usedRamMB = 0L
|
||||
totalRamMB = 0L
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val desiredWidth = 140
|
||||
val desiredHeight = 60
|
||||
|
||||
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||
|
||||
val width = when (widthMode) {
|
||||
MeasureSpec.EXACTLY -> widthSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredWidth, widthSize)
|
||||
else -> desiredWidth
|
||||
}
|
||||
|
||||
val height = when (heightMode) {
|
||||
MeasureSpec.EXACTLY -> heightSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredHeight, heightSize)
|
||||
else -> desiredHeight
|
||||
}
|
||||
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
backgroundRect.set(4f, 4f, w - 4f, h - 4f)
|
||||
|
||||
// Setup meter rectangles - compact horizontal bar at the bottom
|
||||
val meterLeft = 30f
|
||||
val meterTop = h - 18f
|
||||
val meterRight = w - 10f
|
||||
val meterBottom = h - 10f
|
||||
|
||||
meterBackgroundRect.set(meterLeft, meterTop, meterRight, meterBottom)
|
||||
meterFillRect.set(meterLeft, meterTop, meterRight, meterBottom)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
|
||||
// Draw background with rounded corners
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, backgroundPaint)
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, borderPaint)
|
||||
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
|
||||
// Draw RAM icon on the left
|
||||
canvas.drawText(ramIcon, 18f, centerY - 8f, iconPaint)
|
||||
|
||||
// Draw percentage text at the top center
|
||||
val percentText = "${ramUsagePercent.roundToInt()}%"
|
||||
canvas.drawText(percentText, centerX, centerY - 8f, textPaint)
|
||||
|
||||
// Draw memory usage text below percentage
|
||||
val usedGB = usedRamMB / 1024f
|
||||
val totalGB = totalRamMB / 1024f
|
||||
val memoryText = if (totalGB >= 1.0f) {
|
||||
"%.1fGB/%.1fGB".format(usedGB, totalGB)
|
||||
} else {
|
||||
"${usedRamMB}MB/${totalRamMB}MB"
|
||||
}
|
||||
canvas.drawText(memoryText, centerX, centerY + 8f, smallTextPaint)
|
||||
|
||||
// Draw RAM meter background at the bottom
|
||||
canvas.drawRoundRect(meterBackgroundRect, 4f, 4f, meterBackgroundPaint)
|
||||
|
||||
// Draw RAM meter fill
|
||||
val fillWidth = meterBackgroundRect.width() * (ramUsagePercent / 100f)
|
||||
meterFillRect.right = meterBackgroundRect.left + fillWidth
|
||||
canvas.drawRoundRect(meterFillRect, 4f, 4f, meterFillPaint)
|
||||
|
||||
Log.d("RamMeter", "onDraw called - Usage: $percentText, Memory: $memoryText")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.citron.citron_emu.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Typeface
|
||||
import android.os.BatteryManager
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.citron.citron_emu.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class ThermalIndicatorView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr) {
|
||||
|
||||
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.parseColor("#80000000") // Semi-transparent black
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
private val borderPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = 2f
|
||||
}
|
||||
|
||||
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 22f
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val smallTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 16f
|
||||
typeface = Typeface.DEFAULT
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private val iconPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 24f
|
||||
textAlign = Paint.Align.CENTER
|
||||
setShadowLayer(2f, 1f, 1f, Color.BLACK)
|
||||
}
|
||||
|
||||
private var batteryTemperature: Float = 0f
|
||||
private var thermalStatus: String = "🌡️"
|
||||
|
||||
private val backgroundRect = RectF()
|
||||
|
||||
fun updateTemperature(temperature: Float) {
|
||||
try {
|
||||
batteryTemperature = temperature
|
||||
Log.d("ThermalIndicator", "Battery temperature updated: ${batteryTemperature}°C")
|
||||
|
||||
// Update thermal status icon based on temperature
|
||||
thermalStatus = when {
|
||||
batteryTemperature < 20f -> "❄️" // Cold
|
||||
batteryTemperature < 30f -> "🌡️" // Normal
|
||||
batteryTemperature < 40f -> "🔥" // Warm
|
||||
batteryTemperature < 50f -> "🥵" // Hot
|
||||
else -> "☢️" // Critical
|
||||
}
|
||||
|
||||
// Update text color based on temperature
|
||||
val tempColor = when {
|
||||
batteryTemperature < 20f -> Color.parseColor("#87CEEB") // Sky blue
|
||||
batteryTemperature < 30f -> Color.WHITE // White
|
||||
batteryTemperature < 40f -> Color.parseColor("#FFA500") // Orange
|
||||
batteryTemperature < 50f -> Color.parseColor("#FF4500") // Red orange
|
||||
else -> Color.parseColor("#FF0000") // Red
|
||||
}
|
||||
|
||||
textPaint.color = tempColor
|
||||
smallTextPaint.color = tempColor
|
||||
borderPaint.color = tempColor
|
||||
|
||||
// Always invalidate to trigger a redraw
|
||||
invalidate()
|
||||
Log.d("ThermalIndicator", "View invalidated, temperature: ${batteryTemperature}°C, status: $thermalStatus")
|
||||
} catch (e: Exception) {
|
||||
// Fallback in case of any errors
|
||||
batteryTemperature = 25f
|
||||
thermalStatus = "🌡️"
|
||||
Log.e("ThermalIndicator", "Error updating temperature", e)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val desiredWidth = 120
|
||||
val desiredHeight = 60
|
||||
|
||||
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||
|
||||
val width = when (widthMode) {
|
||||
MeasureSpec.EXACTLY -> widthSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredWidth, widthSize)
|
||||
else -> desiredWidth
|
||||
}
|
||||
|
||||
val height = when (heightMode) {
|
||||
MeasureSpec.EXACTLY -> heightSize
|
||||
MeasureSpec.AT_MOST -> minOf(desiredHeight, heightSize)
|
||||
else -> desiredHeight
|
||||
}
|
||||
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
backgroundRect.set(4f, 4f, w - 4f, h - 4f)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
|
||||
// Draw background with rounded corners
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, backgroundPaint)
|
||||
canvas.drawRoundRect(backgroundRect, 12f, 12f, borderPaint)
|
||||
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
|
||||
// Draw thermal icon on the left
|
||||
canvas.drawText(thermalStatus, 18f, centerY - 8f, iconPaint)
|
||||
|
||||
// Draw temperature in Celsius (main temperature)
|
||||
val celsiusText = "${batteryTemperature.roundToInt()}°C"
|
||||
canvas.drawText(celsiusText, centerX, centerY - 8f, textPaint)
|
||||
|
||||
// Draw temperature in Fahrenheit (smaller, below)
|
||||
val fahrenheit = (batteryTemperature * 9f / 5f + 32f).roundToInt()
|
||||
val fahrenheitText = "${fahrenheit}°F"
|
||||
canvas.drawText(fahrenheitText, centerX, centerY + 12f, smallTextPaint)
|
||||
|
||||
Log.d("ThermalIndicator", "onDraw called - Celsius: $celsiusText, Fahrenheit: $fahrenheitText")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
@@ -69,6 +70,8 @@ struct Values {
|
||||
Settings::Category::Overlay};
|
||||
Settings::Setting<bool> show_thermal_overlay{linkage, false, "show_thermal_overlay",
|
||||
Settings::Category::Overlay};
|
||||
Settings::Setting<bool> show_ram_meter{linkage, false, "show_ram_meter",
|
||||
Settings::Category::Overlay};
|
||||
Settings::Setting<bool> show_input_overlay{linkage, true, "show_input_overlay",
|
||||
Settings::Category::Overlay};
|
||||
Settings::Setting<bool> touchscreen{linkage, true, "touchscreen", Settings::Category::Overlay};
|
||||
|
||||
@@ -143,31 +143,41 @@
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/show_fps_text"
|
||||
style="@style/TextAppearance.Material3.BodySmall"
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:textColor="@android:color/white"
|
||||
android:shadowColor="@android:color/black"
|
||||
android:shadowRadius="3"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
android:layout_gravity="center_horizontal|top"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/show_thermals_text"
|
||||
style="@style/TextAppearance.Material3.BodySmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:textColor="@android:color/white"
|
||||
android:shadowColor="@android:color/black"
|
||||
android:shadowRadius="3"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
<org.citron.citron_emu.views.FpsIndicatorView
|
||||
android:id="@+id/fps_indicator_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<org.citron.citron_emu.views.ThermalIndicatorView
|
||||
android:id="@+id/thermal_indicator_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<org.citron.citron_emu.views.RamMeterView
|
||||
android:id="@+id/ram_meter_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
android:title="@string/emulation_thermal_indicator"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/ram_meter"
|
||||
android:title="@string/emulation_ram_meter"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit_overlay"
|
||||
android:title="@string/emulation_touch_overlay_edit" />
|
||||
|
||||
@@ -479,7 +479,8 @@
|
||||
<string name="emulation_exit">Exit emulation</string>
|
||||
<string name="emulation_done">Done</string>
|
||||
<string name="emulation_fps_counter">FPS counter</string>
|
||||
<string name="emulation_thermal_indicator">Thermal indicator</string>
|
||||
<string name="emulation_thermal_indicator">Battery temperature</string>
|
||||
<string name="emulation_ram_meter">RAM usage meter</string>
|
||||
<string name="emulation_toggle_controls">Toggle controls</string>
|
||||
<string name="emulation_rel_stick_center">Relative stick center</string>
|
||||
<string name="emulation_dpad_slide">D-pad slide</string>
|
||||
|
||||
Reference in New Issue
Block a user