Compare commits
3 Commits
2eebb63122
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 83d188f21e | |||
| 9e00d69d35 | |||
| 003bbb9e63 |
@@ -12,7 +12,7 @@ android {
|
||||
minSdk = 24
|
||||
targetSdk = 34
|
||||
versionCode = 4
|
||||
versionName = "1.0.3"
|
||||
versionName = "1.0.4"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -50,8 +50,4 @@ dependencies {
|
||||
|
||||
// EasyWindow
|
||||
implementation("com.github.getActivity:EasyWindow:10.2")
|
||||
|
||||
// Glide
|
||||
implementation("com.github.bumptech.glide:glide:4.15.1")
|
||||
|
||||
}
|
||||
@@ -3,23 +3,25 @@ package com.ray650128.floatingwindow.ui
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.AdapterView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import com.bumptech.glide.Glide
|
||||
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.view.ValueEditor
|
||||
import java.io.File
|
||||
|
||||
|
||||
class SettingActivity : AppCompatActivity() {
|
||||
@@ -52,15 +54,18 @@ class SettingActivity : AppCompatActivity() {
|
||||
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)
|
||||
val returnUri = data?.data ?: return@registerForActivityResult
|
||||
imageUri = saveImageToCache(returnUri)
|
||||
Log.d(TAG, "imageUri=$imageUri")
|
||||
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||
binding.imgPreview.setImageBitmap(bitmap)
|
||||
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
|
||||
//checkPassButton()
|
||||
}
|
||||
}
|
||||
|
||||
private var imageUri: Uri? = null
|
||||
private var imageUri: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -72,8 +77,8 @@ 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)
|
||||
if (!PreferenceUtil.iconPath.isNullOrEmpty()) {
|
||||
imageUri = PreferenceUtil.iconPath
|
||||
}
|
||||
|
||||
binding.apply {
|
||||
@@ -94,7 +99,9 @@ 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, imageUri)
|
||||
if (imageUri != null) {
|
||||
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||
}
|
||||
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
|
||||
imgPreview.isVisible = true
|
||||
btnPickPhoto.isVisible = true
|
||||
@@ -189,13 +196,15 @@ class SettingActivity : AppCompatActivity() {
|
||||
}*/
|
||||
|
||||
if (imageUri != null) {
|
||||
Glide.with(this@SettingActivity).load(imageUri).into(imgPreview)
|
||||
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||
imgPreview.setImageBitmap(bitmap)
|
||||
}
|
||||
|
||||
btnPickPhoto.setOnClickListener {
|
||||
requestPermission.launch(
|
||||
arrayOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_MEDIA_IMAGES
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_MEDIA_IMAGES
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -205,7 +214,7 @@ class SettingActivity : AppCompatActivity() {
|
||||
PreferenceUtil.yOffset = yOffset
|
||||
PreferenceUtil.gravity = windowGravity.type
|
||||
PreferenceUtil.icon = windowIcon.value
|
||||
PreferenceUtil.iconPath = imageUri?.toString()
|
||||
PreferenceUtil.iconPath = imageUri
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -219,7 +228,7 @@ class SettingActivity : AppCompatActivity() {
|
||||
)
|
||||
FloatingWindowHelperUtils.setIcon(
|
||||
FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
|
||||
Uri.parse(PreferenceUtil.iconPath)
|
||||
PreferenceUtil.iconPath
|
||||
)
|
||||
finish()
|
||||
}
|
||||
@@ -230,4 +239,27 @@ class SettingActivity : AppCompatActivity() {
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
|
||||
galleryLauncher.launch(intent)
|
||||
}
|
||||
|
||||
private fun saveImageToCache(uri: Uri?): String? {
|
||||
if (uri == null) return null
|
||||
val inputStream = contentResolver.openInputStream(uri)
|
||||
inputStream?.use { input ->
|
||||
val extension = getFileExtension(uri.toString())
|
||||
val outputFile = File(cacheDir, "custom.$extension")
|
||||
outputFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
return outputFile.absolutePath
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getFileExtension(uri: String): String {
|
||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(Uri.parse(uri)))
|
||||
?: "jpg" // Default extension
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = SettingActivity::class.java.simpleName
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ray650128.floatingwindow.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
@@ -10,6 +11,7 @@ import android.view.WindowManager
|
||||
import com.hjq.window.EasyWindow
|
||||
import com.ray650128.floatingwindow.MyApp
|
||||
import com.ray650128.floatingwindow.R
|
||||
import java.io.File
|
||||
|
||||
object FloatingWindowHelperUtils {
|
||||
|
||||
@@ -38,10 +40,17 @@ object FloatingWindowHelperUtils {
|
||||
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)
|
||||
val iconPath = PreferenceUtil.iconPath
|
||||
if (iconPath?.contains("/data/user/0/com.ray650128.floatingwindow/cache/") == true) {
|
||||
val bitmap = BitmapFactory.decodeFile(iconPath)
|
||||
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
||||
setImageDrawable(android.R.id.icon, drawable)
|
||||
} 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)
|
||||
@@ -129,6 +138,21 @@ object FloatingWindowHelperUtils {
|
||||
window.update()
|
||||
}
|
||||
|
||||
fun setIcon(value: IconType, inputUri: String? = null) {
|
||||
if (value == IconType.CUSTOM) {
|
||||
if (inputUri == null) {
|
||||
window.setImageDrawable(android.R.id.icon, value.value)
|
||||
} else {
|
||||
val bitmap = BitmapFactory.decodeFile(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()
|
||||
}
|
||||
|
||||
enum class GravityType(val type: Int) {
|
||||
TOP_LEFT(0),
|
||||
BOTTOM_LEFT(1),
|
||||
|
||||
Reference in New Issue
Block a user