diff --git a/app/src/main/java/com/ray650128/floatingwindow/ui/SettingActivity.kt b/app/src/main/java/com/ray650128/floatingwindow/ui/SettingActivity.kt
index 277af04..dee5d2d 100644
--- a/app/src/main/java/com/ray650128/floatingwindow/ui/SettingActivity.kt
+++ b/app/src/main/java/com/ray650128/floatingwindow/ui/SettingActivity.kt
@@ -1,13 +1,16 @@
package com.ray650128.floatingwindow.ui
-import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
-import androidx.core.widget.addTextChangedListener
+import androidx.appcompat.app.AppCompatActivity
+import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
+import com.ray650128.floatingwindow.dp
+import com.ray650128.floatingwindow.utils.DensityUtil
import com.ray650128.floatingwindow.utils.FloatingWindowHelperUtils
import com.ray650128.floatingwindow.utils.PreferenceUtil
-import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
+import com.ray650128.floatingwindow.view.ValueEditor
+
class SettingActivity : AppCompatActivity() {
@@ -55,7 +58,69 @@ class SettingActivity : AppCompatActivity() {
}
}
- etXOffset.apply {
+ edXOffset.apply {
+ value = xOffset
+ setOnValueChangeListener(object : ValueEditor.OnValueChangeListener {
+ override fun onValueAdd() {
+ if (xOffset in 0 .. (DensityUtil.getScreenWidth() - 52.dp)) {
+ xOffset += 1
+ }
+ value = xOffset
+ FloatingWindowHelperUtils.setXOffset(xOffset)
+ }
+
+ override fun onValueMinus() {
+ if (xOffset in 1 .. (DensityUtil.getScreenWidth() - 52.dp)) {
+ xOffset -= 1
+ }
+ value = xOffset
+ FloatingWindowHelperUtils.setXOffset(xOffset)
+ }
+
+ override fun onValueClick(result: Int?) {
+ if (result == null) return
+ if (xOffset in 0 .. (DensityUtil.getScreenWidth() - 52.dp)) {
+ xOffset = result
+ value = result
+ }
+ FloatingWindowHelperUtils.setXOffset(xOffset)
+ }
+
+ })
+ }
+
+ edYOffset.apply {
+ value = yOffset
+ setOnValueChangeListener(object : ValueEditor.OnValueChangeListener {
+ override fun onValueAdd() {
+ if (yOffset in 0 .. (DensityUtil.getScreenHeight() - 36.dp)) {
+ yOffset += 1
+ }
+ value = yOffset
+ FloatingWindowHelperUtils.setYOffset(yOffset)
+ }
+
+ override fun onValueMinus() {
+ if (yOffset in 1 .. (DensityUtil.getScreenHeight() - 36.dp)) {
+ yOffset -= 1
+ }
+ value = yOffset
+ FloatingWindowHelperUtils.setYOffset(yOffset)
+ }
+
+ override fun onValueClick(result: Int?) {
+ if (result == null) return
+ if (yOffset in 0 .. (DensityUtil.getScreenHeight() - 36.dp)) {
+ yOffset = result
+ value = result
+ }
+ FloatingWindowHelperUtils.setYOffset(yOffset)
+ }
+
+ })
+ }
+
+ /*etXOffset.apply {
setText("$xOffset")
addTextChangedListener {
if (it.isNullOrEmpty()) return@addTextChangedListener
@@ -71,7 +136,7 @@ class SettingActivity : AppCompatActivity() {
yOffset = it.toString().toIntOrNull() ?: return@addTextChangedListener
FloatingWindowHelperUtils.setYOffset(yOffset)
}
- }
+ }*/
btnOk.setOnClickListener {
PreferenceUtil.xOffset = xOffset
diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml
index fe385a1..6f5da0b 100644
--- a/app/src/main/res/layout/activity_setting.xml
+++ b/app/src/main/res/layout/activity_setting.xml
@@ -45,22 +45,17 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="水平偏移像素"
- app:layout_constraintBottom_toBottomOf="@+id/etXOffset"
- app:layout_constraintEnd_toStartOf="@+id/etXOffset"
- app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintBottom_toBottomOf="@+id/edXOffset"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="@+id/etXOffset" />
+ app:layout_constraintTop_toTopOf="@+id/edXOffset" />
-
@@ -69,25 +64,22 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
+ android:layout_marginTop="14dp"
+ android:layout_marginBottom="13dp"
android:text="垂直偏移像素"
- app:layout_constraintBottom_toBottomOf="@+id/etYOffset"
- app:layout_constraintEnd_toStartOf="@+id/etYOffset"
- app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintBottom_toBottomOf="@+id/edYOffset"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="@+id/etYOffset" />
+ app:layout_constraintTop_toTopOf="@+id/edYOffset" />
-
+ app:layout_constraintTop_toBottomOf="@+id/edXOffset" />
+ app:layout_constraintStart_toStartOf="parent" />
+ app:layout_constraintStart_toEndOf="@+id/btnOk" />
+ app:layout_constraintTop_toBottomOf="@+id/edYOffset" />
+
\ No newline at end of file