新增硬件GPU,display

This commit is contained in:
yuqian 2025-12-29 10:16:04 +08:00
parent f8483bdbb2
commit a59073b0af
2 changed files with 93 additions and 18 deletions

View File

@ -1,5 +1,7 @@
package com.xyzshell.myphoneinfo.custom
import kotlin.math.abs
object SetNumberOrWordUtils {
fun setDecimal1(double: Double): String{
return "%.1f".format(double)
@ -37,4 +39,53 @@ object SetNumberOrWordUtils {
return (Integer.parseInt(string) + 1).toString()
}
/**
* 智能宽高比转换
* 输入width=1080, height=2800
* 输出20:9近似值
*/
fun convertToApproximateAspectRatio(width: Int, height: Int): String {
val isPortrait = height > width
// 总是按横屏计算(宽>高)
val displayWidth = if (isPortrait) height else width
val displayHeight = if (isPortrait) width else height
// 计算实际比例
val actualRatio = displayWidth.toDouble() / displayHeight
// 常见宽高比映射表(比例值 -> 宽高比字符串)
val commonRatios = mapOf(
1.333 to "4:3", // 4:3 = 1.333
1.5 to "3:2", // 3:2 = 1.5
1.6 to "16:10", // 16:10 = 1.6
1.667 to "5:3", // 5:3 = 1.667
1.778 to "16:9", // 16:9 = 1.778
2.0 to "18:9", // 18:9 = 2.0
2.111 to "19:9", // 19:9 = 2.111
2.222 to "20:9", // 20:9 = 2.222 ← 您要的
2.333 to "21:9", // 21:9 = 2.333
2.4 to "24:10", // 24:10 = 2.4
2.5 to "25:10", // 25:10 = 2.5
)
// 找到最接近的常见比例
var closestRatio = "16:9"
var minDifference = Double.MAX_VALUE
for ((ratioValue, ratioStr) in commonRatios) {
val difference = abs(actualRatio - ratioValue)
if (difference < minDifference) {
minDifference = difference
closestRatio = ratioStr
}
}
return closestRatio
}
}

View File

@ -10,6 +10,7 @@ import android.view.ViewGroup
import com.xyzshell.andinfo.AndInfo
import com.xyzshell.andinfo.libs.CpuInfo
import com.xyzshell.myphoneinfo.R
import com.xyzshell.myphoneinfo.custom.SetNumberOrWordUtils.convertToApproximateAspectRatio
import com.xyzshell.myphoneinfo.databinding.FragmentHardWareBinding
import com.xyzshell.myphoneinfo.dialog.DialogBlueTooth
import com.xyzshell.myphoneinfo.dialog.DialogDiskPart
@ -120,46 +121,69 @@ class HardWareFragment : Fragment() {
binding.gpuText3.textTitle.text=getString(R.string.max_frequency)
binding.gpuText4.textTitle.text=getString(R.string.architecture)
binding.gpuText5.textTitle.text=getString(R.string.cores)
binding.gpuText5.textContent.text=gpu.getOpenGLExtensionCount().toString()
binding.gpuText6.textTitle.text=getString(R.string.total_l2)
binding.gpuText7.textTitle.text=getString(R.string.bus_width)
binding.gpuText8.textTitle.text=getString(R.string.vulkan_support)
binding.gpuText8.textContent.text=gpu.isVulkanSupported().toString()
binding.gpuText9.textTitle.text=getString(R.string.vulkan_API)
binding.gpuText9.textContent.text=gpu.getVulkanApiVersion()
binding.open1.text=getString(R.string.opengl)
// gpuInfo.eglInformation?.let { eglInfo ->
// eglInfo.eglExtensions?.let {
// dialogExtension?.setContent(it.joinToString())
// }
// eglInfo.glInformation?.let{glInfo ->
// binding.openItem1.text=glInfo.glVendor
// binding.openItem2.text=glInfo.glRenderer
// binding.openItem3.text=glInfo.glVersion
// }
// }
gpu.getGpuInformation().eglInformation?.let { eglInfo ->
eglInfo.eglExtensions?.let {
dialogExtension?.setContent(it.joinToString())
}
}
binding.openItem1.text=gpu.getVendorName()
binding.openItem2.text=gpu.getRendererName()
binding.openItem3.text=gpu.getOpenGLVersion()
//display
val defaultDisplayInfo = AndInfo.instance.display.getDefaultDisplayInfo()
val display=AndInfo.instance.display//显示信息
val defaultDisplayInfo = display.getDefaultDisplayInfo()
val width = defaultDisplayInfo?.widthPixels.toString()
val height = defaultDisplayInfo?.heightPixels.toString()
if(defaultDisplayInfo!=null){
binding.disText1.textContent.text=defaultDisplayInfo.widthPixels.toString()+"x"+defaultDisplayInfo.heightPixels.toString()
binding.disText1.textContent.text=width+"x"+height
}
binding.disText1.textTitle.text=getString(R.string.resolution)
binding.disText2.textTitle.text=getString(R.string.screen_density)//这个是px
binding.disText2.textContent.text=defaultDisplayInfo?.ppi.toString()
binding.disText3.textTitle.text=getString(R.string.screen_density_d)
val dpiStr=defaultDisplayInfo?.densityDpi.toString()+"(xxhdpi)\n"+defaultDisplayInfo?.xdpi?.roundToInt()+"dp"+defaultDisplayInfo?.ydpi?.roundToInt()+"dp"
val dpiStr=defaultDisplayInfo?.densityDpi.toString()+"(xxhdpi)\n"+defaultDisplayInfo?.xdpi?.roundToInt()+"dpx"+defaultDisplayInfo?.ydpi?.roundToInt()+"dp"
binding.disText3.textContent.text=dpiStr
binding.disText4.textTitle.text=getString(R.string.screen_size_e)
binding.disText5.textTitle.text=getString(R.string.aspect_ratio)
binding.disText5.textContent.text=convertToApproximateAspectRatio(width = width.toInt(), height = height.toInt()).toString()
binding.disText6.textTitle.text=getString(R.string.refresh_rate)
binding.disText6.textContent.text=defaultDisplayInfo?.refreshRate.toString()+"HZ"
binding.disText7.textTitle.text=getString(R.string.wide_color_gamut)
binding.disText7.textContent.text=defaultDisplayInfo?.isWideColorGamut.toString()
binding.disText8.textTitle.text=getString(R.string.hdr_support)
binding.disText8.textContent.text=defaultDisplayInfo?.isHdr.toString()
if(defaultDisplayInfo?.isHdr == true){
defaultDisplayInfo.hdrTypes.joinToString()
binding.disText8.textContent.text= defaultDisplayInfo.hdrTypes.joinToString()
}else{
binding.disText8.textContent.text= "No"
}
//memory
val storageInfo = AndInfo.instance.storage//存储信息
val used=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.internalStorageUsedSpace)
val free=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.internalStorageAvailableSpace)
val total=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.internalStorageTotalSpace)
val outused=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.externalStorageUsedSpace?: 0)
val outfree=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.externalStorageAvailableSpace?: 0)
val outtotal=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.externalStorageTotalSpace?: 0)
binding.memoryLayout.memText1.textTitle.text=getString(R.string.ram_size)
binding.memoryLayout.memText1.textContent.text=total
binding.memoryLayout.ram1.text=used+" used"
@ -169,9 +193,9 @@ class HardWareFragment : Fragment() {
//storage
binding.memoryLayout.memText3.textTitle.text=getString(R.string.zram)
binding.memoryLayout.memText3.textContent.text=Formatter.formatFileSize(AndInfo.instance.context, storageInfo.internalStorageTotalSpace)
binding.memoryLayout.ram3.text=used+" used"
binding.memoryLayout.ram4.text=free+" free"
binding.memoryLayout.seekbar2.progress=(used.substring(0,used.indexOf(" ")).toDouble() / total.substring(0,total.indexOf(" ")).toDouble() *100).toInt()
binding.memoryLayout.ram3.text=outused+" used"
binding.memoryLayout.ram4.text=outfree+" free"
binding.memoryLayout.seekbar2.progress=(outused.substring(0,outused.indexOf(" ")).toDouble() / outtotal.substring(0,outtotal.indexOf(" ")).toDouble() *100).toInt()
//fileSystem
binding.memoryLayout.storText1.textTitle.text=getString(R.string.filesystem)