....
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<RecentCall>()
|
||||
// var recentCalls = arrayListOf<RecentCall>()
|
||||
var callList = arrayListOf<RecentCall>()
|
||||
var smsList = arrayListOf<RecentSms>()
|
||||
var listTags = arrayListOf<RssDataInterface>()
|
||||
@@ -212,32 +214,60 @@ internal class LauncherHome : Fragment() {
|
||||
WorkersDb.getRealm().apply {
|
||||
query<CurrentPlayItem>().find().asFlow().collect { changes: ResultsChange<CurrentPlayItem> ->
|
||||
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()
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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<CurrentPlayItem>().find())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user