mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-23 17:05:37 +00:00
android: Make MemoryUtil an object
This commit is contained in:
parent
217e958a95
commit
a1dd5dfba5
|
@ -106,13 +106,12 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||
inputHandler = InputHandler()
|
||||
inputHandler.initialize()
|
||||
|
||||
val memoryUtil = MemoryUtil(this)
|
||||
if (memoryUtil.isLessThan(8, MemoryUtil.Gb)) {
|
||||
if (MemoryUtil.isLessThan(8, MemoryUtil.Gb)) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(
|
||||
R.string.device_memory_inadequate,
|
||||
memoryUtil.getDeviceRAM(),
|
||||
MemoryUtil.getDeviceRAM(),
|
||||
"8 ${getString(R.string.memory_gigabyte)}"
|
||||
),
|
||||
Toast.LENGTH_LONG
|
||||
|
|
|
@ -6,13 +6,22 @@ package org.yuzu.yuzu_emu.utils
|
|||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import java.util.Locale
|
||||
|
||||
class MemoryUtil(val context: Context) {
|
||||
object MemoryUtil {
|
||||
private val context get() = YuzuApplication.appContext
|
||||
|
||||
private val Long.floatForm: String
|
||||
get() = String.format(Locale.ROOT, "%.2f", this.toDouble())
|
||||
|
||||
const val Kb: Long = 1024
|
||||
const val Mb = Kb * 1024
|
||||
const val Gb = Mb * 1024
|
||||
const val Tb = Gb * 1024
|
||||
const val Pb = Tb * 1024
|
||||
const val Eb = Pb * 1024
|
||||
|
||||
private fun bytesToSizeUnit(size: Long): String {
|
||||
return when {
|
||||
size < Kb -> "${size.floatForm} ${context.getString(R.string.memory_byte)}"
|
||||
|
@ -47,13 +56,4 @@ class MemoryUtil(val context: Context) {
|
|||
fun getDeviceRAM(): String {
|
||||
return bytesToSizeUnit(totalMemory)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Kb: Long = 1024
|
||||
const val Mb = Kb * 1024
|
||||
const val Gb = Mb * 1024
|
||||
const val Tb = Gb * 1024
|
||||
const val Pb = Tb * 1024
|
||||
const val Eb = Pb * 1024
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue