Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Initial support for dpi changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jiesou committed Dec 21, 2023
1 parent f699356 commit e3fdbfa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class ResolutionFragment : Fragment() {

private lateinit var windowManager: WindowManager

private var userId = 0

companion object {
lateinit var iWindowManager: Any
lateinit var iUserManager: Any
lateinit var iUserManager: Any
}

override fun onCreateView(
Expand All @@ -57,6 +59,10 @@ class ResolutionFragment : Fragment() {
resolutionViewModel.fetchScreenResolution(windowManager)
resolutionViewModel.fetchUsers()

val textView = binding.textResolution
resolutionViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}
val textHeight = binding.textHeight.editText!!
val textWidth = binding.textWidth.editText!!
val textDpi = binding.textDpi.editText!!
Expand All @@ -68,17 +74,20 @@ class ResolutionFragment : Fragment() {
val chipGroup = binding.chipGroup
resolutionViewModel.usersList.observe(viewLifecycleOwner) {
Log.d("usersRecved", it.toString())
chipGroup.addView(Chip(chipGroup.context).apply {
text = "${it["name"]} (${it["id"]})"
isCheckable = true
isCheckedIconVisible = true
})
}
val textView = binding.textResolution
resolutionViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
for (user in it) {
chipGroup.addView(Chip(chipGroup.context).apply {
text = "${user["name"]} (${user["id"]})"
isCheckable = true
isCheckedIconVisible = true
})
}
}

chipGroup.setOnCheckedChangeListener { group, index ->
Log.d("index", index.toString())
val currentUser = resolutionViewModel.usersList.value!![index] as Map<String, Any>
userId = currentUser["id"] as Int
}
binding.btApply.setOnClickListener {
applyResolution(textHeight.text.toString().toInt(),
textWidth.text.toString().toInt(),
Expand All @@ -104,7 +113,6 @@ class ResolutionFragment : Fragment() {
"setForcedDisplaySize", Display.DEFAULT_DISPLAY, width, height)

// TODO: apply dpi for each user
val userId = 0
HiddenApiBypass.invoke(iWindowManager::class.java, iWindowManager,
"setForcedDisplayDensityForUser", Display.DEFAULT_DISPLAY, dpi, userId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class ResolutionViewModel : ViewModel() {
"dpi" to 520)
}

val usersList: MutableLiveData<Map<String, Any>> by lazy {
MutableLiveData<Map<String, Any>>()
val usersList: MutableLiveData<List<Map<String, Any>>> by lazy {
MutableLiveData<List<Map<String, Any>>>()
}
fun fetchUsers() {
val userManager = ResolutionFragment.iUserManager
Expand All @@ -61,14 +61,15 @@ class ResolutionViewModel : ViewModel() {

// TODO

usersList.setValue(mapOf(
"id" to 0,
"name" to "jiesou"
))
usersList.setValue(mapOf(
"id" to 10,
"name" to "second user"
))
usersList.setValue(
listOf(mapOf(
"id" to 0,
"name" to "jiesou"
), mapOf(
"id" to 10,
"name" to "second user")
)
)
}

}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
}

Expand Down

0 comments on commit e3fdbfa

Please sign in to comment.