From 1470721399c7dcdde32e44e8182eb58d11b8e0bc Mon Sep 17 00:00:00 2001
From: lunaticbum <>
Date: Thu, 12 Sep 2024 18:22:11 +0900
Subject: [PATCH] ....
---
app/src/main/AndroidManifest.xml | 3 +
.../rasel/lunar/launcher/LauncherActivity.kt | 11 +--
.../rasel/lunar/launcher/feeds/Feeds.kt | 2 +-
.../rasel/lunar/launcher/home/LauncherHome.kt | 76 ++++++++++-----
.../lunar/launcher/utils/BitmapConverter.kt | 44 +++++++++
.../rasel/lunar/launcher/utils/NLService.kt | 5 +-
app/src/main/res/layout/launcher_home.xml | 95 ++++++++++---------
app/src/main/res/layout/list_item_with.xml | 2 +-
app/src/main/res/values/themes.xml | 2 +-
9 files changed, 159 insertions(+), 81 deletions(-)
create mode 100644 app/src/main/kotlin/rasel/lunar/launcher/utils/BitmapConverter.kt
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6c60b38d..320025fc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -33,6 +33,9 @@
+
+
diff --git a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt
index b55bf5bc..f1f4c797 100644
--- a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt
+++ b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt
@@ -159,7 +159,7 @@ internal class LauncherActivity : AppCompatActivity() {
@JvmStatic var lActivity: LauncherActivity? = null
@JvmStatic var appWidgetManager: AppWidgetManager? = null
@JvmStatic var appWidgetHost: WidgetHost? = null
- fun refreshSms() {
+ fun refreshDeviceData() {
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager?.cancelAllWorkByTag(SMS_WORK_TAG)
mWorkManager?.enqueueUniquePeriodicWork(
@@ -169,8 +169,6 @@ internal class LauncherActivity : AppCompatActivity() {
.addTag(SMS_WORK_TAG)
.build())
}, 1, TimeUnit.SECONDS)
- }
- fun refreshCalls() {
var delay = 1L
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager?.cancelAllWorkByTag(ContactInfoGetter.TAG)
@@ -442,8 +440,7 @@ internal class LauncherActivity : AppCompatActivity() {
}
if (!needAsk) {
- refreshSms()
- refreshCalls()
+ refreshDeviceData()
refreshFeeds()
}
}
@@ -575,14 +572,14 @@ internal class LauncherActivity : AppCompatActivity() {
BLog.LOGE("EndCallReceiver >>> ${intent}")
val phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE) ?: return
if (phoneState == TelephonyManager.EXTRA_STATE_IDLE) {
- refreshCalls()
+ refreshDeviceData()
}
}
}
class SMSReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
BLog.LOGE("SMSReceiver >>> ${intent}")
- refreshSms()
+ refreshDeviceData()
}
}
diff --git a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt
index ecdfe9c5..aed291b6 100644
--- a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt
+++ b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt
@@ -58,8 +58,8 @@ import rasel.lunar.launcher.CommadCallabck
import rasel.lunar.launcher.LauncherActivity.Companion.appWidgetHost
import rasel.lunar.launcher.LauncherActivity.Companion.appWidgetManager
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
-import rasel.lunar.launcher.LauncherActivity.Companion.refreshFeeds
import rasel.lunar.launcher.LauncherActivity.Companion.refreshDeviceData
+import rasel.lunar.launcher.LauncherActivity.Companion.refreshFeeds
import rasel.lunar.launcher.R
import rasel.lunar.launcher.databinding.FeedsBinding
import rasel.lunar.launcher.feeds.rss.RssAdapter
diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt
index ef108acd..8ff6bc5b 100644
--- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt
+++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt
@@ -20,18 +20,20 @@ package rasel.lunar.launcher.home
import android.annotation.SuppressLint
import android.content.ComponentName
-import android.content.ContentUris
+import android.content.Context.AUDIO_SERVICE
import android.content.DialogInterface
import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import android.graphics.Bitmap
+import android.media.AudioManager
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
+import android.os.SystemClock
import android.provider.AlarmClock
-import android.provider.MediaStore
+import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -41,7 +43,6 @@ import android.widget.TableRow
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.biometric.BiometricPrompt
-import androidx.core.net.toUri
import androidx.core.view.children
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
@@ -88,6 +89,7 @@ import rasel.lunar.launcher.todos.NotificationItemAdapter
import rasel.lunar.launcher.todos.RssItemAdapter
import rasel.lunar.launcher.todos.SmsLogsAdapter
import rasel.lunar.launcher.utils.BLog
+import rasel.lunar.launcher.utils.BitmapConverter
import rasel.lunar.launcher.utils.JamoUtils
import rasel.lunar.launcher.utils.SimpleFingerGestures
import rasel.lunar.launcher.utils.beforeDay
@@ -112,7 +114,7 @@ internal class LauncherHome : Fragment() {
companion object {
var home : LauncherHome? = null
var lastedFinishedPageUrl : String = ""
-// var recentCalls = arrayListOf()
+ // var recentCalls = arrayListOf()
var callList = arrayListOf()
var smsList = arrayListOf()
var listTags = arrayListOf()
@@ -212,32 +214,60 @@ internal class LauncherHome : Fragment() {
WorkersDb.getRealm().apply {
query().find().asFlow().collect { changes: ResultsChange ->
binding.currentMusic?.postDelayed({
- if (changes.list.size > 0) {
- changes.list?.first()?.let {
- binding.currentMusic.visibility = View.VISIBLE
- binding.artist.text = it.artists
- binding.title.text = it.title
+ if (changes.list.size > 0) {
+ changes.list?.first()?.let {
+ binding.currentMusic.visibility = View.VISIBLE
+ binding.nextPlay.visibility = View.GONE
+ binding.artist.text = it.artists
+ binding.title.text = it.title
- val albumArtUri = it.albumArt?.toUri()
- var bitmap: Bitmap? = null
- try {
- bitmap = MediaStore.Images.Media.getBitmap(
- requireContext().contentResolver,
- albumArtUri
- )
- binding.albumArt.setImageBitmap(bitmap)
- } catch (exception: java.lang.Exception) {
- // log error
+
+ var bitmap: Bitmap? = null
+ try {
+ bitmap = BitmapConverter.StringToBitmap(it.albumArt)
+ binding.albumArt.setImageBitmap(bitmap)
+ } catch (exception: java.lang.Exception) {
+ // log error
+ }
}
- }
- } else {
- binding.currentMusic.visibility = View.GONE
- }}, 150L)
+ } else {
+ binding.currentMusic.visibility = View.GONE
+ binding.nextPlay.visibility = View.VISIBLE
+ }}, 150L)
}
}
}
BLog.LOGE("onCreateView()")
+ binding.nextBtn.setOnClickListener {
+ val mAudioManager =
+ requireContext().getSystemService(AUDIO_SERVICE) as AudioManager
+
+ val eventtime: Long = SystemClock.uptimeMillis()
+
+ val downEvent =
+ KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
+ mAudioManager.dispatchMediaKeyEvent(downEvent)
+
+ val upEvent =
+ KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
+ mAudioManager.dispatchMediaKeyEvent(upEvent)
+ }
+ binding.nextPlay.setOnClickListener {
+ val mAudioManager =
+ requireContext().getSystemService(AUDIO_SERVICE) as AudioManager
+
+ val eventtime: Long = SystemClock.uptimeMillis()
+
+ val downEvent =
+ KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY, 0)
+ mAudioManager.dispatchMediaKeyEvent(downEvent)
+
+ val upEvent =
+ KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY, 0)
+ mAudioManager.dispatchMediaKeyEvent(upEvent)
+ }
+
queryInfos()
queryNotice()
diff --git a/app/src/main/kotlin/rasel/lunar/launcher/utils/BitmapConverter.kt b/app/src/main/kotlin/rasel/lunar/launcher/utils/BitmapConverter.kt
new file mode 100644
index 00000000..ca7992e1
--- /dev/null
+++ b/app/src/main/kotlin/rasel/lunar/launcher/utils/BitmapConverter.kt
@@ -0,0 +1,44 @@
+package rasel.lunar.launcher.utils
+
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.util.Base64
+import java.io.ByteArrayOutputStream
+
+
+object BitmapConverter {
+ /*
+ * String형을 BitMap으로 변환시켜주는 함수
+ * */
+ fun StringToBitmap(encodedString: String?): Bitmap? {
+ try {
+ val encodeByte: ByteArray = Base64.decode(encodedString, Base64.DEFAULT)
+ val bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.size)
+ return bitmap
+ } catch (e: Exception) {
+ e.message
+ return null
+ }
+ }
+
+ /*
+ * Bitmap을 String형으로 변환
+ * */
+ fun BitmapToString(bitmap: Bitmap?): String {
+ if (bitmap == null) return ""
+ val baos = ByteArrayOutputStream()
+ bitmap?.compress(Bitmap.CompressFormat.PNG, 70, baos)
+ val bytes = baos.toByteArray()
+ val temp: String = Base64.encodeToString(bytes, Base64.DEFAULT)
+ return temp
+ }
+
+ /*
+ * Bitmap을 byte배열로 변환
+ * */
+ fun BitmapToByteArray(bitmap: Bitmap): ByteArray {
+ val baos = ByteArrayOutputStream()
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 70, baos)
+ return baos.toByteArray()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/rasel/lunar/launcher/utils/NLService.kt b/app/src/main/kotlin/rasel/lunar/launcher/utils/NLService.kt
index edf0c1a3..6793dcc3 100644
--- a/app/src/main/kotlin/rasel/lunar/launcher/utils/NLService.kt
+++ b/app/src/main/kotlin/rasel/lunar/launcher/utils/NLService.kt
@@ -95,6 +95,9 @@ class NLService : NotificationListenerService() {
"Sessions",
"$session -- " + (session?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART))
)
+ current.albumArt = BitmapConverter.BitmapToString(session.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART))
+ } else {
+ current.albumArt = ""
}
BLog.LOGE(
"Sessions",
@@ -103,7 +106,7 @@ class NLService : NotificationListenerService() {
current.title = session?.metadata?.getString(MediaMetadata.METADATA_KEY_TITLE)
current.artists = session?.metadata?.getString(MediaMetadata.METADATA_KEY_ARTIST)
-// current.albumArt = session?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM)
+
} else {
delete(query().find())
}
diff --git a/app/src/main/res/layout/launcher_home.xml b/app/src/main/res/layout/launcher_home.xml
index 306ea443..1677f790 100644
--- a/app/src/main/res/layout/launcher_home.xml
+++ b/app/src/main/res/layout/launcher_home.xml
@@ -34,6 +34,16 @@
app:layout_constraintTop_toBottomOf="@+id/batteryProgress"
android:textSize="16sp"
tools:ignore="MissingConstraints" />
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ />
-
-
+
+
+
+
-
-
-
+
+
- rounded
- - 8dp
+ - 10dp
\ No newline at end of file