Skip to content

Commit

Permalink
字幕相关代码 从Application 移动到 SubtitleHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
klosw committed Mar 5, 2024
1 parent 5b34300 commit ebb3126
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
16 changes: 3 additions & 13 deletions app/src/main/java/com/github/tvbox/osc/base/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
19 changes: 17 additions & 2 deletions app/src/main/java/com/github/tvbox/osc/util/SubtitleHelper.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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);
}
}

0 comments on commit ebb3126

Please sign in to comment.