Skip to content

Commit

Permalink
Dev (#189)
Browse files Browse the repository at this point in the history
[skip post]
  • Loading branch information
577fkj authored Apr 19, 2022
1 parent c9a978b commit c84a8b6
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 305 deletions.
48 changes: 24 additions & 24 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 132 additions & 29 deletions app/src/main/java/statusbar/lyric/activity/SettingsActivity.kt

Large diffs are not rendered by default.

152 changes: 142 additions & 10 deletions app/src/main/java/statusbar/lyric/config/Config.kt

Large diffs are not rendered by default.

138 changes: 0 additions & 138 deletions app/src/main/java/statusbar/lyric/config/IconConfig.kt

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/java/statusbar/lyric/hook/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class MainHook : IXposedHookLoadPackage {
LogUtils.e("start hook netease")
Netease()
}
"com.kugou.android" -> {
"com.kugou.android", "com.kugou.android.lite" -> {
LogUtils.e("start hook kugou")
Kugou()
Kugou(lpparam.packageName)
}
"cn.kuwo.player" -> {
LogUtils.e("start hook kuwo")
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/statusbar/lyric/hook/app/Kugou.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@
package statusbar.lyric.hook.app

import android.app.AndroidAppHelper
import de.robv.android.xposed.callbacks.XC_LoadPackage
import statusbar.lyric.hook.BaseHook
import statusbar.lyric.utils.LogUtils
import statusbar.lyric.utils.Utils
import statusbar.lyric.utils.ktx.findClassOrNull
import statusbar.lyric.utils.ktx.hookAfterMethod


class Kugou : BaseHook() {
class Kugou(private val packageName: String) : BaseHook() {
override fun hook() {
super.hook()
"android.media.AudioManager".hookAfterMethod("isBluetoothA2dpOn") {
it.result = true
}
"com.kugou.framework.player.c".hookAfterMethod("a", HashMap::class.java) {
var iconName="KuGou"
if (packageName!="com.kugou.android"){
iconName="KuGouLite"
}
LogUtils.e("酷狗音乐:" + (it.args[0] as HashMap<*, *>).values.toList()[0])
Utils.sendLyric(AndroidAppHelper.currentApplication(), "" + (it.args[0] as HashMap<*, *>).values.toList()[0], "KuGou")
Utils.sendLyric(AndroidAppHelper.currentApplication(), "" + (it.args[0] as HashMap<*, *>).values.toList()[0], iconName)
}
"com.tencent.tinker.loader.app.TinkerApplication".findClassOrNull()?.hookAfterMethod("getTinkerFlags") {
it.result = 0
Expand Down
85 changes: 46 additions & 39 deletions app/src/main/java/statusbar/lyric/hook/app/SystemUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ import de.robv.android.xposed.XposedHelpers
import statusbar.lyric.hook.BaseHook
import statusbar.lyric.utils.*
import statusbar.lyric.utils.XposedOwnSP.config
import statusbar.lyric.utils.XposedOwnSP.iconConfig
import statusbar.lyric.utils.ktx.*
import statusbar.lyric.view.LyricSwitchView
import java.io.File
import java.lang.reflect.Field
import java.util.*
import java.util.regex.Pattern
import kotlin.system.exitProcess

class SystemUI : BaseHook() {
private val lyricKey = "lyric"
var musicServer: ArrayList<String> = arrayListOf("com.kugou", "com.netease.cloudmusic", "com.tencent.qqmusic.service", "cn.kuwo", "remix.myplayer", "cmccwm.mobilemusic", "com.meizu.media.music", "com.tencent.qqmusicplayerprocess.service.QQPlayerServiceNew")

// base data
lateinit var application: Application
val application: Application by lazy { AndroidAppHelper.currentApplication() }
lateinit var clock: TextView
private lateinit var customizeView: TextView
lateinit var lyricSwitchView: LyricSwitchView
Expand All @@ -85,6 +85,7 @@ class SystemUI : BaseHook() {
private var isHook = false
var useSystemMusicActive = true
var test = false
private var pattern: Pattern? = null

// lyric click
private var showLyric = true
Expand All @@ -94,13 +95,10 @@ class SystemUI : BaseHook() {
// Handler
private lateinit var iconUpdate: Handler
private lateinit var updateIconColor: Handler
private lateinit var updateMarginsIcon: Handler
private lateinit var updateTextColor: Handler
private lateinit var updateLyricPos: Handler
private lateinit var updateLyric: Handler
private lateinit var offLyric: Handler
lateinit var updateMargins: Handler
private lateinit var updateMarginsLyric: Handler

// Color data
private var textColor: Int = 0
Expand Down Expand Up @@ -253,7 +251,7 @@ class SystemUI : BaseHook() {
}

private fun lyricInit(clock: TextView?) {
application = AndroidAppHelper.currentApplication() // Get Application
LogUtils.e(LogMultiLang.sendLog)

application.sendBroadcast(Intent().apply {
action = "App_Server"
Expand Down Expand Up @@ -289,7 +287,6 @@ class SystemUI : BaseHook() {

customizeView = TextView(application).apply {
height = clock.height
visibility = View.VISIBLE
text = config.getCustomizeText()
setTextSize(TypedValue.COMPLEX_UNIT_SHIFT, if (config.getLyricSize() == 0) clock.textSize else config.getLyricSize().toFloat())
isSingleLine = true
Expand All @@ -313,15 +310,13 @@ class SystemUI : BaseHook() {
}
}
lyricSwitchView = LyricSwitchView(application, config.getLyricStyle()).apply {
width = (displayWidth * 35) / 100
height = clock.height
setTextSize(TypedValue.COMPLEX_UNIT_SHIFT, if (config.getLyricSize() == 0) clock.textSize else config.getLyricSize().toFloat())
setMargins(config.getLyricPosition() + 10, config.getLyricHigh(), 0, 0)
setMarqueeRepeatLimit(if (config.getLyricStyle()) 1 else -1)
setSingleLine(true)
setMaxLines(1)
setLetterSpacings(if (config.getLyricSpacing() != 0) config.getLyricSpacing().toFloat() / 100 else clock.letterSpacing)

try {
val file = File(application.filesDir.path + "/font")
if (file.exists() && file.isFile && file.canRead()) {
Expand Down Expand Up @@ -351,7 +346,7 @@ class SystemUI : BaseHook() {
lyricLayout = LinearLayout(application).apply {
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).also { it.setMargins(config.getLyricPosition(), config.getLyricHigh(), 0, 0) }
addView(iconView)
if (config.getCustomizeViewPosition() == "first") {
if (config.getCustomizeViewPosition()) {
addView(customizeView)
addView(lyricSwitchView)
} else {
Expand Down Expand Up @@ -383,11 +378,9 @@ class SystemUI : BaseHook() {

iconUpdate = Handler(Looper.getMainLooper()) { message ->
if (message.obj == null) {
lyricSwitchView.setMargins(config.getLyricPosition(), config.getLyricHigh(), 0, 0)
iconView.visibility = View.GONE
iconView.setImageDrawable(null)
} else {
lyricSwitchView.setMargins(config.getLyricPosition() + 10, config.getLyricHigh(), 0, 0)
iconView.visibility = View.VISIBLE
iconView.setImageDrawable(message.obj as Drawable)
}
Expand All @@ -399,34 +392,45 @@ class SystemUI : BaseHook() {
true
}

updateMarginsLyric = Handler(Looper.getMainLooper()) { message ->
lyricSwitchView.setMargins(message.arg1, message.arg2, 0, 0)
true
}

updateMarginsIcon = Handler(Looper.getMainLooper()) { message ->
(iconView.layoutParams as LinearLayout.LayoutParams).setMargins(message.arg1, message.arg2, 0, 0)
true
}

updateTextColor = Handler(Looper.getMainLooper()) { message ->
lyricSwitchView.setTextColor(message.arg1)
customizeView.setTextColor(message.arg1)
true
}

updateLyricPos = Handler(Looper.getMainLooper()) {
(lyricSwitchView.layoutParams as LinearLayout.LayoutParams).setMargins(config.getLyricPosition(), config.getLyricHigh(), 0, 0)
true
}

updateIconColor = Handler(Looper.getMainLooper()) { message ->
iconView.setColorFilter(message.arg1)
true
}

updateLyric = Handler(Looper.getMainLooper()) { message ->
val lyric: String = message.data.getString(lyricKey) ?: ""
val block = config.getBlockLyric()
if (lyric == "") return@Handler true
if (block != "") {
if (pattern == null) {
if (lyric.contains(block)) {
if (config.getBlockLyricOff()) {
offLyric("BlockLyric")
return@Handler true
} else {
LogUtils.e("BlockLyric")
return@Handler true
}
}
} else {
if (pattern!!.matcher(lyric).matches()) {
if (config.getBlockLyricOff()) {
offLyric("BlockLyric")
return@Handler true
} else {
LogUtils.e("BlockLyric")
return@Handler true
}
}

}
}
LogUtils.e("${LogMultiLang.updateLyric}: $lyric")
val display = if (application.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) displayWidth else displayHeight
lyricSwitchView.width = if (config.getLyricWidth() == -1) getLyricWidth(lyricSwitchView.paint, lyric, display) else (display * config.getLyricWidth()) / 100
Expand Down Expand Up @@ -468,27 +472,24 @@ class SystemUI : BaseHook() {
gravity = Gravity.CENTER
orientation = LinearLayout.HORIZONTAL
(lyricLayout.parent as? ViewGroup)?.removeView(lyricLayout)
if (config.getLyricViewPosition() == "first") addView(lyricLayout, 1) else addView(lyricLayout)
if (config.getLyricViewPosition()) addView(lyricLayout, 1) else addView(lyricLayout)
}
updateConfig()
offLyric(LogMultiLang.initOk)
}, config.getDelayedLoading().toLong() * 1000)
LogUtils.e(LogMultiLang.sendLog)
}

private fun updateConfig() {
config.update()
iconConfig.update()
pattern = if (config.getBlockLyric() != "" && config.getBlockLyricMode()) Pattern.compile(config.getBlockLyric()) else null
if (!config.getLyricService()) offLyric(LogMultiLang.switchOff)
if (config.getLyricStyle()) lyricSwitchView.setSpeed((config.getLyricSpeed().toFloat() / 100))
if (config.getAnim() != "random") {
val anim = config.getAnim()
lyricSwitchView.inAnimation = Utils.inAnim(anim)
lyricSwitchView.outAnimation = Utils.outAnim(anim)
}
updateMarginsIcon.sendMessage(updateMarginsIcon.obtainMessage().also {
it.arg1 = 0
it.arg2 = config.getIconHigh()
})
if (config.getLyricColor() != "") {
textColor = Color.parseColor(config.getLyricColor())
updateTextColor.sendMessage(updateTextColor.obtainMessage().also {
Expand All @@ -501,14 +502,10 @@ class SystemUI : BaseHook() {
it.arg1 = iconColor
})
} else iconColor = 0
updateMarginsLyric.sendMessage(updateMarginsLyric.obtainMessage().also {
updateMargins.sendMessage(updateMargins.obtainMessage().also {
it.arg1 = config.getLyricPosition()
it.arg2 = config.getLyricHigh()
})
updateMarginsIcon.sendMessage(updateMarginsIcon.obtainMessage().also {
it.arg1 = 0
it.arg2 = config.getIconHigh()
})
if (config.getIconSize() != 0) {
(iconView.layoutParams as LinearLayout.LayoutParams).apply { // set icon size
width = config.getIconSize()
Expand All @@ -518,6 +515,16 @@ class SystemUI : BaseHook() {
if (config.getLyricSize() != 0) {
lyricSwitchView.setTextSize(TypedValue.COMPLEX_UNIT_SHIFT, config.getLyricSize().toFloat())
}
if (config.getCustomizeText() != "") {
customizeView.text = config.getCustomizeText()
}

if (config.getBackgroundColor() != "") {
lyricLayout.setBackgroundColor(Color.parseColor(config.getBackgroundColor()))
} else {
lyricLayout.setBackgroundColor(0)
}

}

private fun offLyric(info: String) { // off Lyric
Expand Down Expand Up @@ -555,7 +562,7 @@ class SystemUI : BaseHook() {
}
}
iconUpdate.sendMessage(iconUpdate.obtainMessage().also { // update icon
it.obj = BitmapDrawable(application.resources, Utils.stringToBitmap(iconConfig.getIcon(icon)))
it.obj = BitmapDrawable(application.resources, Utils.stringToBitmap(config.getIcon(icon)))
})
}

Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/statusbar/lyric/utils/ActivityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.json.JSONException
import org.json.JSONObject
import statusbar.lyric.BuildConfig
import statusbar.lyric.R
import statusbar.lyric.config.Config
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
Expand All @@ -60,9 +59,7 @@ object ActivityUtils {
//清除配置
@JvmStatic
fun cleanConfig(activity: Activity) {
for (name in arrayOf("Lyric_Config", "AppList_Config", "Icon_Config")) {
Utils.getSP(activity, name)?.let { Config(it) }?.clear()
}
ActivityOwnSP.ownSPConfig.clear()
showToastOnLooper(activity, activity.getString(R.string.ResetSuccess))
activity.finishActivity(0)
}
Expand Down
Loading

0 comments on commit c84a8b6

Please sign in to comment.