diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index bfb730d..bdd1c36 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -48,5 +48,10 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
+ // EasyWindow
implementation("com.github.getActivity:EasyWindow:10.2")
+
+ // Glide
+ implementation("com.github.bumptech.glide:glide:4.11.0")
+
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 16f3fe6..62ebc1d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,12 @@
+
+
+
+
+ permissions.entries.forEach {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
+ if (it.key == Manifest.permission.READ_EXTERNAL_STORAGE && it.value) {
+ pickImage()
+ }
+ } else {
+ if (it.key == Manifest.permission.READ_MEDIA_IMAGES && it.value) {
+ pickImage()
+ }
+ }
+ Log.e("DEBUG", "${it.key} = ${it.value}")
+ }
+ }
+
+ private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
+ if (result.resultCode == Activity.RESULT_OK) {
+ val data = result.data
+ imageUri = data?.data
+ Glide.with(this).load(imageUri).into(binding.imgPreview)
+ FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
+ //workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
+ //checkPassButton()
+ }
+ }
+
+ private var imageUri: Uri? = null
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySettingBinding.inflate(layoutInflater)
@@ -32,6 +71,9 @@ class SettingActivity : AppCompatActivity() {
yOffset = PreferenceUtil.yOffset
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
+ imageUri = if (PreferenceUtil.iconPath.isNullOrEmpty()) null else {
+ Uri.parse(PreferenceUtil.iconPath)
+ }
binding.apply {
spGravity.apply {
@@ -51,7 +93,14 @@ class SettingActivity : AppCompatActivity() {
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
windowIcon = FloatingWindowHelperUtils.IconType.fromIndex(position)
- FloatingWindowHelperUtils.setIcon(windowIcon)
+ FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
+ if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
+ imgPreview.isVisible = true
+ btnPickPhoto.isVisible = true
+ } else {
+ imgPreview.isVisible = false
+ btnPickPhoto.isVisible = false
+ }
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
@@ -138,11 +187,24 @@ class SettingActivity : AppCompatActivity() {
}
}*/
+ if (imageUri != null) {
+ Glide.with(this@SettingActivity).load(imageUri).into(imgPreview)
+ }
+
+ btnPickPhoto.setOnClickListener {
+ requestPermission.launch(
+ arrayOf(
+ Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_MEDIA_IMAGES
+ )
+ )
+ }
+
btnOk.setOnClickListener {
PreferenceUtil.xOffset = xOffset
PreferenceUtil.yOffset = yOffset
PreferenceUtil.gravity = windowGravity.type
PreferenceUtil.icon = windowIcon.value
+ PreferenceUtil.iconPath = imageUri?.toString()
finish()
}
@@ -155,10 +217,16 @@ class SettingActivity : AppCompatActivity() {
)
)
FloatingWindowHelperUtils.setIcon(
- FloatingWindowHelperUtils.IconType.fromInt(
- PreferenceUtil.icon))
+ FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
+ Uri.parse(PreferenceUtil.iconPath)
+ )
finish()
}
}
}
+
+ private fun pickImage() {
+ val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
+ galleryLauncher.launch(intent)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/ray650128/floatingwindow/utils/FloatingWindowHelperUtils.kt b/app/src/main/java/com/ray650128/floatingwindow/utils/FloatingWindowHelperUtils.kt
index 8ff83a7..db7975e 100644
--- a/app/src/main/java/com/ray650128/floatingwindow/utils/FloatingWindowHelperUtils.kt
+++ b/app/src/main/java/com/ray650128/floatingwindow/utils/FloatingWindowHelperUtils.kt
@@ -1,5 +1,9 @@
package com.ray650128.floatingwindow.utils
+import android.graphics.BitmapFactory
+import android.graphics.drawable.BitmapDrawable
+import android.net.Uri
+import android.provider.MediaStore
import android.view.Gravity
import android.view.MotionEvent
import android.view.WindowManager
@@ -30,7 +34,18 @@ object FloatingWindowHelperUtils {
})
setXOffset(xOffset)
setYOffset(yOffset)
- setImageDrawable(android.R.id.icon, windowIcon.value)
+ if (windowIcon == IconType.CUSTOM) {
+ if (PreferenceUtil.iconPath.isNullOrEmpty()) {
+ setImageDrawable(android.R.id.icon, windowIcon.value)
+ } else {
+ val uri = Uri.parse(PreferenceUtil.iconPath)
+ val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(uri))
+ val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
+ setImageDrawable(android.R.id.icon, drawable)
+ }
+ } else {
+ setImageDrawable(android.R.id.icon, windowIcon.value)
+ }
setOnTouchListener { window, view, event ->
var touch = false
when (event.action) {
@@ -99,8 +114,18 @@ object FloatingWindowHelperUtils {
window.update()
}
- fun setIcon(value: IconType) {
- window.setImageDrawable(android.R.id.icon, value.value)
+ fun setIcon(value: IconType, inputUri: Uri? = null) {
+ if (value == IconType.CUSTOM) {
+ if (inputUri == null) {
+ window.setImageDrawable(android.R.id.icon, value.value)
+ } else {
+ val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(inputUri))
+ val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
+ window.setImageDrawable(android.R.id.icon, drawable)
+ }
+ } else {
+ window.setImageDrawable(android.R.id.icon, value.value)
+ }
window.update()
}
@@ -126,7 +151,8 @@ object FloatingWindowHelperUtils {
GURA(R.drawable.ic_gura, 7),
RUSHIA2(R.drawable.ic_uruha_rushia2, 8),
RUSHIA3(R.drawable.ic_uruha_rushia3, 9),
- HOSHIMACHI_SUISEI(R.drawable.ic_hoshimachii_suisei, 10);
+ HOSHIMACHI_SUISEI(R.drawable.ic_hoshimachii_suisei, 10),
+ CUSTOM(R.mipmap.ic_launcher, 11);
companion object {
fun fromInt(value: Int) = IconType.values().first { it.value == value }