From ebb3126523adfe8f819f115f0d8741ae1e141d11 Mon Sep 17 00:00:00 2001 From: klosw <> Date: Tue, 5 Mar 2024 19:55:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=B9=95=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20=E4=BB=8EApplication=20=E7=A7=BB=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=20SubtitleHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/github/tvbox/osc/base/App.java | 16 +++------------- .../github/tvbox/osc/util/SubtitleHelper.java | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/github/tvbox/osc/base/App.java b/app/src/main/java/com/github/tvbox/osc/base/App.java index ce5c1b89d3..bee97c0478 100644 --- a/app/src/main/java/com/github/tvbox/osc/base/App.java +++ b/app/src/main/java/com/github/tvbox/osc/base/App.java @@ -4,6 +4,7 @@ import androidx.multidex.MultiDexApplication; +import com.github.catvod.crawler.JarLoader; import com.github.catvod.crawler.JsLoader; import com.github.tvbox.osc.R; import com.github.tvbox.osc.callback.EmptyCallback; @@ -17,6 +18,7 @@ import com.github.tvbox.osc.util.LOG; import com.github.tvbox.osc.util.OkGoHelper; import com.github.tvbox.osc.util.PlayerHelper; +import com.github.tvbox.osc.util.SubtitleHelper; import com.hjq.permissions.XXPermissions; import com.kingja.loadsir.core.LoadSir; import com.orhanobut.hawk.Hawk; @@ -42,15 +44,13 @@ public class App extends MultiDexApplication { public static String burl; private static String dashData; public static ViewPump viewPump = null; - private int[][] subtitleTextColor = null; - @Override public void onCreate() { super.onCreate(); instance = this; - initSubtitleColor(); + SubtitleHelper.initSubtitleColor(this); initParams(); // takagen99 : Initialize Locale initLocale(); @@ -169,14 +169,4 @@ public void setDashData(String data) { public String getDashData() { return dashData; } - - private void initSubtitleColor() { - int[] subtitleColor = getResources().getIntArray(R.array.subtitle_text_color); - int[] shadowColor = getResources().getIntArray(R.array.subtitle_text_shadow_color); - this.subtitleTextColor = new int[][]{subtitleColor, shadowColor}; - } - - public int[][] getSubtitleTextColor() { - return subtitleTextColor; - } } diff --git a/app/src/main/java/com/github/tvbox/osc/util/SubtitleHelper.java b/app/src/main/java/com/github/tvbox/osc/util/SubtitleHelper.java index 0c8fb53732..9eaef00334 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/SubtitleHelper.java +++ b/app/src/main/java/com/github/tvbox/osc/util/SubtitleHelper.java @@ -1,12 +1,27 @@ package com.github.tvbox.osc.util; import android.app.Activity; +import android.app.Application; +import android.content.Context; +import com.github.tvbox.osc.R; import com.github.tvbox.osc.base.App; import com.github.tvbox.osc.subtitle.widget.SimpleSubtitleView; import com.orhanobut.hawk.Hawk; public class SubtitleHelper { + private static int[][] subtitleTextColor = null; + + //初始化字幕颜色 + public static void initSubtitleColor(Context context) { + int[] subtitleColor = context.getApplicationContext().getResources().getIntArray(R.array.subtitle_text_color); + int[] shadowColor = context.getApplicationContext().getResources().getIntArray(R.array.subtitle_text_shadow_color); + SubtitleHelper.subtitleTextColor = new int[][]{subtitleColor, shadowColor}; + } + + public static int[][] getSubtitleTextColor() { + return subtitleTextColor; + } public static int getSubtitleTextAutoSize(Activity activity) { double screenSqrt = ScreenUtils.getSqrt(activity); @@ -51,7 +66,7 @@ public static void upTextStyle(SimpleSubtitleView mSubtitleView, int style) { } else { Hawk.put(HawkConfig.SUBTITLE_TEXT_STYLE, style); } - int[][] subtitleTextColor = App.getInstance().getSubtitleTextColor(); + int[][] subtitleTextColor = getSubtitleTextColor(); mSubtitleView.setTextColor(subtitleTextColor[0][colorIndex]); mSubtitleView.setShadowLayer(10, 0, 0, subtitleTextColor[1][colorIndex]); // mSubtitleView.setBackGroundTextColor(subtitleTextColor[1][colorIndex]); @@ -62,7 +77,7 @@ public static int getTextStyle() { } public static int getTextStyleSize() { - int[][] subtitleTextColor = App.getInstance().getSubtitleTextColor(); + int[][] subtitleTextColor = getSubtitleTextColor(); return Math.min(subtitleTextColor[0].length, subtitleTextColor[1].length); } } \ No newline at end of file