Skip to content

Commit

Permalink
perf: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Jul 4, 2023
1 parent 3607adc commit 09fc163
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package top.limuyang2.photolibrary.activity

import android.content.Intent
import android.content.res.Configuration
import android.graphics.Point
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -32,34 +30,35 @@ abstract class LBaseActivity<V : ViewBinding> : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(intentTheme)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

val display = window.windowManager.defaultDisplay

val nowPoint = Point()
display.getRealSize(nowPoint)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
this.display
} else {
@Suppress("DEPRECATION")
windowManager.defaultDisplay
}

val modes = display.supportedModes
if (display != null) {
val mode = display.mode
val currentWidth = mode.physicalWidth
val currentHeight = mode.physicalHeight

modes.sortBy {
it.refreshRate
}
val modes = display.supportedModes

// 只找90Hz的
val filterModes = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
modes.filter { m ->
m.refreshRate == 90f && m.physicalWidth == nowPoint.x && m.physicalHeight == nowPoint.y
modes.sortBy { m ->
m.refreshRate
}
} else {
modes.filter { m ->
m.refreshRate == 90f && m.physicalWidth == nowPoint.y && m.physicalHeight == nowPoint.x

// 只找90Hz的
val filterModes = modes.filter { m ->
m.refreshRate == 90f && m.physicalWidth == currentWidth && m.physicalHeight == currentHeight
}
}

filterModes.lastOrNull()?.let {
val lp = window.attributes
lp.preferredDisplayModeId = it.modeId
window.attributes = lp
filterModes.lastOrNull()?.let { m ->
val lp = window.attributes
lp.preferredDisplayModeId = m.modeId
window.attributes = lp
}
}
}

Expand Down

0 comments on commit 09fc163

Please sign in to comment.