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

Commit

Permalink
add mutil-user ui support
Browse files Browse the repository at this point in the history
  • Loading branch information
jiesou committed Dec 18, 2023
1 parent 933b205 commit f699356
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.google.android.material.chip.Chip
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import top.jiecs.screener.databinding.FragmentResolutionBinding
Expand Down Expand Up @@ -64,7 +65,15 @@ class ResolutionFragment : Fragment() {
textWidth.setText(it["width"].toString())
textDpi.setText(it["dpi"].toString())
}

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
Expand All @@ -90,11 +99,16 @@ class ResolutionFragment : Fragment() {

fun applyResolution(height: Int, width: Int, dpi: Int) {
Log.d("screener", "apply")
// TODO: apply dpi for each user

HiddenApiBypass.invoke(iWindowManager::class.java, iWindowManager,
"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)


val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.success))
.setMessage(getString(R.string.reset_hint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.util.Log
import java.lang.reflect.Method
import java.lang.reflect.Field


import org.lsposed.hiddenapibypass.HiddenApiBypass
import top.jiecs.screener.ui.resolution.ResolutionFragment

Expand All @@ -24,22 +23,23 @@ class ResolutionViewModel : ViewModel() {
}
val text: LiveData<String> = _text

private val _resolutionMap = MutableLiveData<Map<String, Int>>()
val resolutionMap: LiveData<Map<String, Int>> = _resolutionMap


val resolutionMap: MutableLiveData<Map<String, Int>> by lazy {
MutableLiveData<Map<String, Int>>()
}
fun fetchScreenResolution(windowManager: WindowManager) {
val metrics = windowManager.currentWindowMetrics.bounds

// TODO: get now Physical and Override size
_resolutionMap.value = mapOf(
resolutionMap.value = mapOf(
"height" to metrics.height(),
"width" to metrics.width(),
"dpi" to 520)
}

private val _usersList = MutableLiveData<MutableList<*>>()
val usersList: LiveData<MutableList<*>> = _usersList

val usersList: MutableLiveData<Map<String, Any>> by lazy {
MutableLiveData<Map<String, Any>>()
}
fun fetchUsers() {
val userManager = ResolutionFragment.iUserManager

Expand All @@ -60,6 +60,15 @@ class ResolutionViewModel : ViewModel() {
// }

// TODO

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

}
21 changes: 15 additions & 6 deletions app/src/main/res/layout/fragment_resolution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,41 @@
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@+id/text_dpi"
app:layout_constraintBottom_toTopOf="@+id/bt_apply"
app:layout_constraintStart_toStartOf="@+id/text_resolution"
app:layout_constraintBottom_toTopOf="@+id/chip_group"
app:layout_constraintTop_toBottomOf="@+id/text_dpi"
android:id="@+id/text_scale"
android:text="@string/scale" />

<com.google.android.material.slider.Slider
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="@+id/text_scale"
app:layout_constraintBottom_toBottomOf="@+id/text_scale"
android:valueTo="200"
app:layout_constraintStart_toEndOf="@+id/text_scale"
app:layout_constraintEnd_toEndOf="@+id/text_resolution"
android:valueTo="200"
android:value="0"
android:valueFrom="-50"
app:layout_constraintBottom_toBottomOf="@+id/text_scale"
android:layout_marginTop="8dp"
android:stepSize="25"
android:id="@+id/silder_scale" />

<com.google.android.material.chip.ChipGroup
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="@+id/text_resolution"
app:layout_constraintEnd_toEndOf="@+id/text_resolution"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/silder_scale"
android:id="@+id/chip_group" />

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="@+id/text_resolution"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@+id/silder_scale"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/chip_group"
android:id="@+id/bt_apply"
android:text="@string/apply" />

Expand Down

0 comments on commit f699356

Please sign in to comment.