將XY偏移量調整UI元件,改成客製化元件
This commit is contained in:
parent
b6e9d9483c
commit
ee612ab4c0
@ -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
|
||||
|
||||
@ -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" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etXOffset"
|
||||
<com.ray650128.floatingwindow.view.ValueEditor
|
||||
android:id="@+id/edXOffset"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:ems="10"
|
||||
android:inputType="number"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/textView4"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spGravity" />
|
||||
|
||||
@ -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" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etYOffset"
|
||||
<com.ray650128.floatingwindow.view.ValueEditor
|
||||
android:id="@+id/edYOffset"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:ems="10"
|
||||
android:inputType="number"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/textView5"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etXOffset" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/edXOffset" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnOk"
|
||||
@ -99,8 +91,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btnCancel"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel"
|
||||
@ -112,8 +103,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/btnOk"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
||||
app:layout_constraintStart_toEndOf="@+id/btnOk" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
@ -137,5 +127,6 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/textView7"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/edYOffset" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user