Compare commits
4 Commits
c1f37845b4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 83d188f21e | |||
| 9e00d69d35 | |||
| 003bbb9e63 | |||
| 2eebb63122 |
@@ -5,14 +5,14 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.ray650128.floatingwindow"
|
namespace = "com.ray650128.floatingwindow"
|
||||||
compileSdk = 33
|
compileSdk = 34
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.ray650128.floatingwindow"
|
applicationId = "com.ray650128.floatingwindow"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 33
|
targetSdk = 34
|
||||||
versionCode = 4
|
versionCode = 4
|
||||||
versionName = "1.0.3-beta"
|
versionName = "1.0.4"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -40,9 +40,9 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation("androidx.core:core-ktx:1.9.0")
|
implementation("androidx.core:core-ktx:1.12.0")
|
||||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||||
implementation("com.google.android.material:material:1.9.0")
|
implementation("com.google.android.material:material:1.11.0")
|
||||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||||
testImplementation("junit:junit:4.13.2")
|
testImplementation("junit:junit:4.13.2")
|
||||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||||
@@ -50,8 +50,4 @@ dependencies {
|
|||||||
|
|
||||||
// EasyWindow
|
// EasyWindow
|
||||||
implementation("com.github.getActivity:EasyWindow:10.2")
|
implementation("com.github.getActivity:EasyWindow:10.2")
|
||||||
|
|
||||||
// Glide
|
|
||||||
implementation("com.github.bumptech.glide:glide:4.11.0")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,23 +3,25 @@ package com.ray650128.floatingwindow.ui
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
|
import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
|
||||||
import com.ray650128.floatingwindow.dp
|
import com.ray650128.floatingwindow.dp
|
||||||
import com.ray650128.floatingwindow.utils.DensityUtil
|
import com.ray650128.floatingwindow.utils.DensityUtil
|
||||||
import com.ray650128.floatingwindow.utils.FloatingWindowHelperUtils
|
import com.ray650128.floatingwindow.utils.FloatingWindowHelperUtils
|
||||||
import com.ray650128.floatingwindow.utils.PreferenceUtil
|
import com.ray650128.floatingwindow.utils.PreferenceUtil
|
||||||
import com.ray650128.floatingwindow.view.ValueEditor
|
import com.ray650128.floatingwindow.view.ValueEditor
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
class SettingActivity : AppCompatActivity() {
|
class SettingActivity : AppCompatActivity() {
|
||||||
@@ -52,15 +54,18 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
if (result.resultCode == Activity.RESULT_OK) {
|
if (result.resultCode == Activity.RESULT_OK) {
|
||||||
val data = result.data
|
val data = result.data
|
||||||
imageUri = data?.data
|
val returnUri = data?.data ?: return@registerForActivityResult
|
||||||
Glide.with(this).load(imageUri).into(binding.imgPreview)
|
imageUri = saveImageToCache(returnUri)
|
||||||
|
Log.d(TAG, "imageUri=$imageUri")
|
||||||
|
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||||
|
binding.imgPreview.setImageBitmap(bitmap)
|
||||||
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||||
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
|
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
|
||||||
//checkPassButton()
|
//checkPassButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var imageUri: Uri? = null
|
private var imageUri: String? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -72,8 +77,8 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
yOffset = PreferenceUtil.yOffset
|
yOffset = PreferenceUtil.yOffset
|
||||||
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
|
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
|
||||||
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
|
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
|
||||||
imageUri = if (PreferenceUtil.iconPath.isNullOrEmpty()) null else {
|
if (!PreferenceUtil.iconPath.isNullOrEmpty()) {
|
||||||
Uri.parse(PreferenceUtil.iconPath)
|
imageUri = PreferenceUtil.iconPath
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
@@ -94,7 +99,9 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
windowIcon = FloatingWindowHelperUtils.IconType.fromIndex(position)
|
windowIcon = FloatingWindowHelperUtils.IconType.fromIndex(position)
|
||||||
|
if (imageUri != null) {
|
||||||
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||||
|
}
|
||||||
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
|
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
|
||||||
imgPreview.isVisible = true
|
imgPreview.isVisible = true
|
||||||
btnPickPhoto.isVisible = true
|
btnPickPhoto.isVisible = true
|
||||||
@@ -189,13 +196,15 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (imageUri != null) {
|
if (imageUri != null) {
|
||||||
Glide.with(this@SettingActivity).load(imageUri).into(imgPreview)
|
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||||
|
imgPreview.setImageBitmap(bitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
btnPickPhoto.setOnClickListener {
|
btnPickPhoto.setOnClickListener {
|
||||||
requestPermission.launch(
|
requestPermission.launch(
|
||||||
arrayOf(
|
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.yOffset = yOffset
|
||||||
PreferenceUtil.gravity = windowGravity.type
|
PreferenceUtil.gravity = windowGravity.type
|
||||||
PreferenceUtil.icon = windowIcon.value
|
PreferenceUtil.icon = windowIcon.value
|
||||||
PreferenceUtil.iconPath = imageUri?.toString()
|
PreferenceUtil.iconPath = imageUri
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +228,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
FloatingWindowHelperUtils.setIcon(
|
FloatingWindowHelperUtils.setIcon(
|
||||||
FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
|
FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
|
||||||
Uri.parse(PreferenceUtil.iconPath)
|
PreferenceUtil.iconPath
|
||||||
)
|
)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
@@ -230,4 +239,27 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
|
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
|
||||||
galleryLauncher.launch(intent)
|
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
|
package com.ray650128.floatingwindow.utils
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@@ -10,6 +11,7 @@ import android.view.WindowManager
|
|||||||
import com.hjq.window.EasyWindow
|
import com.hjq.window.EasyWindow
|
||||||
import com.ray650128.floatingwindow.MyApp
|
import com.ray650128.floatingwindow.MyApp
|
||||||
import com.ray650128.floatingwindow.R
|
import com.ray650128.floatingwindow.R
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
object FloatingWindowHelperUtils {
|
object FloatingWindowHelperUtils {
|
||||||
|
|
||||||
@@ -37,12 +39,19 @@ object FloatingWindowHelperUtils {
|
|||||||
if (windowIcon == IconType.CUSTOM) {
|
if (windowIcon == IconType.CUSTOM) {
|
||||||
if (PreferenceUtil.iconPath.isNullOrEmpty()) {
|
if (PreferenceUtil.iconPath.isNullOrEmpty()) {
|
||||||
setImageDrawable(android.R.id.icon, windowIcon.value)
|
setImageDrawable(android.R.id.icon, windowIcon.value)
|
||||||
|
} else {
|
||||||
|
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 {
|
} else {
|
||||||
val uri = Uri.parse(PreferenceUtil.iconPath)
|
val uri = Uri.parse(PreferenceUtil.iconPath)
|
||||||
val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(uri))
|
val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(uri))
|
||||||
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
||||||
setImageDrawable(android.R.id.icon, drawable)
|
setImageDrawable(android.R.id.icon, drawable)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setImageDrawable(android.R.id.icon, windowIcon.value)
|
setImageDrawable(android.R.id.icon, windowIcon.value)
|
||||||
}
|
}
|
||||||
@@ -129,6 +138,21 @@ object FloatingWindowHelperUtils {
|
|||||||
window.update()
|
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) {
|
enum class GravityType(val type: Int) {
|
||||||
TOP_LEFT(0),
|
TOP_LEFT(0),
|
||||||
BOTTOM_LEFT(1),
|
BOTTOM_LEFT(1),
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 166 KiB |
@@ -6,15 +6,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.MainActivity">
|
tools:context=".ui.MainActivity">
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:alpha="0.125"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:srcCompat="@drawable/bg_winnie_the_pooh" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/textView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -6,15 +6,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.SettingActivity">
|
tools:context=".ui.SettingActivity">
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView2"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:alpha="0.125"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:srcCompat="@drawable/bg_winnie_the_pooh" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView6"
|
android:id="@+id/textView6"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application") version "8.1.0-rc01" apply false
|
id("com.android.application") version "8.3.1" apply false
|
||||||
id("org.jetbrains.kotlin.android") version "1.8.0" apply false
|
id("org.jetbrains.kotlin.android") version "1.8.0" apply false
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#Mon Jul 03 09:29:45 CST 2023
|
#Mon Jul 03 09:29:45 CST 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
Reference in New Issue
Block a user