-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8fd438
commit 8b328d3
Showing
7 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/me/iacn/biliroaming/hook/SubtitleHook.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.iacn.biliroaming.hook | ||
|
||
import android.graphics.Rect | ||
import android.text.SpannableString | ||
import android.text.style.ForegroundColorSpan | ||
import android.text.style.LineBackgroundSpan | ||
import me.iacn.biliroaming.BiliBiliPackage.Companion.instance | ||
import me.iacn.biliroaming.utils.* | ||
import kotlin.math.roundToInt | ||
|
||
|
||
class SubtitleHook(classLoader: ClassLoader) : BaseHook(classLoader) { | ||
override fun startHook() { | ||
if (!sPrefs.getBoolean("custom_subtitle", false)) return | ||
Log.d("startHook: Subtitle") | ||
|
||
instance.chronosSwitchClass?.hookAfterConstructor { param -> | ||
param.thisObject.javaClass.declaredFields.forEach { | ||
if (it.type == Boolean::class.javaObjectType) { | ||
param.thisObject.setObjectField(it.name, false) | ||
} | ||
} | ||
} | ||
|
||
val rect = Rect() | ||
val margin = 3 | ||
val backgroundColor = 0x7f000000 | ||
val backgroundSpan = | ||
LineBackgroundSpan { canvas, paint, left, right, top, _, bottom, text, start, end, _ -> | ||
val width = paint.measureText(text, start, end).roundToInt() | ||
val textLeft = (right - left - width) / 2 | ||
val color = paint.color | ||
rect.set(textLeft - margin, top, textLeft + width + margin, bottom) | ||
paint.color = backgroundColor | ||
canvas.drawRect(rect, paint) | ||
paint.color = color | ||
} | ||
|
||
android.text.SpannableString::class.java.hookBeforeMethod( | ||
"setSpan", | ||
Object::class.java, | ||
Int::class.java, | ||
Int::class.java, | ||
Int::class.java | ||
) { param -> | ||
if (instance.subtitleSpanClass?.isInstance(param.args[0]) != true) return@hookBeforeMethod | ||
val (start, end, flags) = listOf( | ||
param.args[1] as Int, | ||
param.args[2] as Int, | ||
param.args[3] as Int | ||
) | ||
(param.thisObject as SpannableString).run { | ||
setSpan( | ||
ForegroundColorSpan(sPrefs.getInt("subtitle_font_color", 0x7fffffff)), | ||
start, | ||
end, | ||
flags | ||
) | ||
param.result = null | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:rowCount="4" | ||
android:columnCount="2" | ||
android:orientation="horizontal" | ||
android:paddingStart="25dp" | ||
android:paddingEnd="20dp"> | ||
|
||
|
||
<TextView | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_columnWeight="1" | ||
android:text="字体颜色" | ||
android:singleLine="true" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<EditText | ||
android:id="@+id/font_color" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_columnWeight="4" | ||
android:hint="00000000" | ||
android:tag="subtitle_font_color" | ||
android:inputType="number" | ||
android:autofillHints="no" | ||
tools:ignore="HardcodedText" /> | ||
</GridLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters