From ee612ab4c0d5b3b6f0825d6fb39325b1021c3d0f Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Thu, 3 Aug 2023 12:11:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=87XY=E5=81=8F=E7=A7=BB=E9=87=8F=E8=AA=BF?= =?UTF-8?q?=E6=95=B4UI=E5=85=83=E4=BB=B6=EF=BC=8C=E6=94=B9=E6=88=90?= =?UTF-8?q?=E5=AE=A2=E8=A3=BD=E5=8C=96=E5=85=83=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../floatingwindow/ui/SettingActivity.kt | 75 +++++++++++++++++-- app/src/main/res/layout/activity_setting.xml | 39 ++++------ 2 files changed, 85 insertions(+), 29 deletions(-) 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" />