加入icon選擇功能
@ -15,6 +15,7 @@ object FloatingWindowHelper {
|
|||||||
private var yOffset = PreferenceUtil.yOffset
|
private var yOffset = PreferenceUtil.yOffset
|
||||||
|
|
||||||
private var windowGravity = GravityType.fromInt(PreferenceUtil.gravity)
|
private var windowGravity = GravityType.fromInt(PreferenceUtil.gravity)
|
||||||
|
private var windowIcon = IconType.fromInt(PreferenceUtil.icon)
|
||||||
|
|
||||||
private val window by lazy {
|
private val window by lazy {
|
||||||
EasyWindow<EasyWindow<*>>(MyApp.instance).apply {
|
EasyWindow<EasyWindow<*>>(MyApp.instance).apply {
|
||||||
@ -27,7 +28,7 @@ object FloatingWindowHelper {
|
|||||||
})
|
})
|
||||||
setXOffset(xOffset)
|
setXOffset(xOffset)
|
||||||
setYOffset(yOffset)
|
setYOffset(yOffset)
|
||||||
setImageDrawable(android.R.id.icon, R.drawable.ic_chicken)
|
setImageDrawable(android.R.id.icon, windowIcon.value)
|
||||||
setOnTouchListener { window, view, event ->
|
setOnTouchListener { window, view, event ->
|
||||||
var touch = false
|
var touch = false
|
||||||
when (event.action) {
|
when (event.action) {
|
||||||
@ -96,6 +97,11 @@ object FloatingWindowHelper {
|
|||||||
window.update()
|
window.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setIcon(value: IconType) {
|
||||||
|
window.setImageDrawable(android.R.id.icon, value.value)
|
||||||
|
window.update()
|
||||||
|
}
|
||||||
|
|
||||||
enum class GravityType(val type: Int) {
|
enum class GravityType(val type: Int) {
|
||||||
TOP_LEFT(0),
|
TOP_LEFT(0),
|
||||||
BOTTOM_LEFT(1),
|
BOTTOM_LEFT(1),
|
||||||
@ -106,4 +112,25 @@ object FloatingWindowHelper {
|
|||||||
fun fromInt(value: Int) = GravityType.values().first { it.type == value }
|
fun fromInt(value: Int) = GravityType.values().first { it.type == value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class IconType(val value: Int, val index: Int) {
|
||||||
|
CHICKEN(R.drawable.ic_chicken, 0),
|
||||||
|
PEPE(R.drawable.ic_pepe, 1),
|
||||||
|
WEED(R.drawable.ic_weed, 2),
|
||||||
|
RUSHIA(R.drawable.ic_uruha_rushia, 3),
|
||||||
|
ISSHIKI_IROHA(R.drawable.ic_isshiki_iroha, 4),
|
||||||
|
AYAME(R.drawable.ic_nakiri_ayame, 5),
|
||||||
|
AQUA(R.drawable.ic_minato_aqua, 6),
|
||||||
|
GURA(R.drawable.ic_gura, 7);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromInt(value: Int) = IconType.values().first { it.value == value }
|
||||||
|
|
||||||
|
fun fromIndex(value: Int) = IconType.values().first { it.index == value }
|
||||||
|
|
||||||
|
fun getIndex(value: Int) = IconType.values().indexOf(
|
||||||
|
IconType.values().first { it.value == value }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -11,6 +11,7 @@ object PreferenceUtil {
|
|||||||
private const val X_AXIS_OFFSET = "X_AXIS_OFFSET"
|
private const val X_AXIS_OFFSET = "X_AXIS_OFFSET"
|
||||||
private const val Y_AXIS_OFFSET = "Y_AXIS_OFFSET"
|
private const val Y_AXIS_OFFSET = "Y_AXIS_OFFSET"
|
||||||
private const val GRAVITY = "GRAVITY"
|
private const val GRAVITY = "GRAVITY"
|
||||||
|
private const val ICON = "ICON"
|
||||||
|
|
||||||
private val sharedPreferences = MyApp.appContext.getSharedPreferences(MAIN_KEY, Context.MODE_PRIVATE)
|
private val sharedPreferences = MyApp.appContext.getSharedPreferences(MAIN_KEY, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
@ -25,4 +26,8 @@ object PreferenceUtil {
|
|||||||
var gravity: Int
|
var gravity: Int
|
||||||
get() = sharedPreferences.getInt(GRAVITY, 0)
|
get() = sharedPreferences.getInt(GRAVITY, 0)
|
||||||
set(value) = sharedPreferences.edit().putInt(GRAVITY, value).apply()
|
set(value) = sharedPreferences.edit().putInt(GRAVITY, value).apply()
|
||||||
|
|
||||||
|
var icon: Int
|
||||||
|
get() = sharedPreferences.getInt(ICON, R.drawable.ic_chicken)
|
||||||
|
set(value) = sharedPreferences.edit().putInt(ICON, value).apply()
|
||||||
}
|
}
|
||||||
@ -16,6 +16,8 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private var windowGravity = FloatingWindowHelper.GravityType.TOP_LEFT
|
private var windowGravity = FloatingWindowHelper.GravityType.TOP_LEFT
|
||||||
|
|
||||||
|
private var windowIcon = FloatingWindowHelper.IconType.CHICKEN
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivitySettingBinding.inflate(layoutInflater)
|
binding = ActivitySettingBinding.inflate(layoutInflater)
|
||||||
@ -24,6 +26,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
xOffset = PreferenceUtil.xOffset
|
xOffset = PreferenceUtil.xOffset
|
||||||
yOffset = PreferenceUtil.yOffset
|
yOffset = PreferenceUtil.yOffset
|
||||||
windowGravity = FloatingWindowHelper.GravityType.fromInt(PreferenceUtil.gravity)
|
windowGravity = FloatingWindowHelper.GravityType.fromInt(PreferenceUtil.gravity)
|
||||||
|
windowIcon = FloatingWindowHelper.IconType.fromInt(PreferenceUtil.icon)
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
spGravity.apply {
|
spGravity.apply {
|
||||||
@ -38,6 +41,18 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spIcon.apply {
|
||||||
|
setSelection(FloatingWindowHelper.IconType.getIndex(PreferenceUtil.icon) )
|
||||||
|
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
windowIcon = FloatingWindowHelper.IconType.fromIndex(position)
|
||||||
|
FloatingWindowHelper.setIcon(windowIcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
etXOffset.apply {
|
etXOffset.apply {
|
||||||
setText("$xOffset")
|
setText("$xOffset")
|
||||||
addTextChangedListener {
|
addTextChangedListener {
|
||||||
@ -60,6 +75,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
PreferenceUtil.xOffset = xOffset
|
PreferenceUtil.xOffset = xOffset
|
||||||
PreferenceUtil.yOffset = yOffset
|
PreferenceUtil.yOffset = yOffset
|
||||||
PreferenceUtil.gravity = windowGravity.type
|
PreferenceUtil.gravity = windowGravity.type
|
||||||
|
PreferenceUtil.icon = windowIcon.value
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +83,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
FloatingWindowHelper.setXOffset(PreferenceUtil.xOffset)
|
FloatingWindowHelper.setXOffset(PreferenceUtil.xOffset)
|
||||||
FloatingWindowHelper.setYOffset(PreferenceUtil.yOffset)
|
FloatingWindowHelper.setYOffset(PreferenceUtil.yOffset)
|
||||||
FloatingWindowHelper.setGravity(FloatingWindowHelper.GravityType.fromInt(PreferenceUtil.gravity))
|
FloatingWindowHelper.setGravity(FloatingWindowHelper.GravityType.fromInt(PreferenceUtil.gravity))
|
||||||
|
FloatingWindowHelper.setIcon(FloatingWindowHelper.IconType.fromInt(PreferenceUtil.icon))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/ic_gura.png
Normal file
|
After Width: | Height: | Size: 99 KiB |
BIN
app/src/main/res/drawable/ic_isshiki_iroha.png
Normal file
|
After Width: | Height: | Size: 151 KiB |
BIN
app/src/main/res/drawable/ic_minato_aqua.png
Normal file
|
After Width: | Height: | Size: 147 KiB |
BIN
app/src/main/res/drawable/ic_nakiri_ayame.png
Normal file
|
After Width: | Height: | Size: 400 KiB |
BIN
app/src/main/res/drawable/ic_pepe.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/res/drawable/ic_uruha_rushia.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
app/src/main/res/drawable/ic_weed.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
@ -105,4 +105,28 @@
|
|||||||
app:layout_constraintHorizontal_bias="0.5"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toEndOf="@+id/btnOk"
|
app:layout_constraintStart_toEndOf="@+id/btnOk"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView7"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="懸浮窗圖案"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/spIcon"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/spIcon"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/spIcon" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spIcon"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:entries="@array/item_window_icon"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/textView7"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/etYOffset" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@ -7,4 +7,15 @@
|
|||||||
<item>右上角</item>
|
<item>右上角</item>
|
||||||
<item>右下角</item>
|
<item>右下角</item>
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
|
<array name="item_window_icon">
|
||||||
|
<item>鐮刀雞雞</item>
|
||||||
|
<item>Pepe分窩</item>
|
||||||
|
<item>吃草</item>
|
||||||
|
<item>露西亞</item>
|
||||||
|
<item>一色</item>
|
||||||
|
<item>百鬼</item>
|
||||||
|
<item>阿夸</item>
|
||||||
|
<item>Gura</item>
|
||||||
|
</array>
|
||||||
</resources>
|
</resources>
|
||||||