parent
f0da98bc7b
commit
c4a9e142eb
@ -0,0 +1,68 @@ |
||||
package com.github.tvbox.osc.ui.dialog; |
||||
|
||||
import android.content.Context; |
||||
import android.view.View; |
||||
import android.widget.TextView; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.github.tvbox.osc.R; |
||||
import com.github.tvbox.osc.util.FastClickCheckUtil; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
public class SubtitleDialog extends BaseDialog { |
||||
|
||||
private TextView selectLocal; |
||||
private TextView selectRemote; |
||||
|
||||
private SearchSubtitleListener mSearchSubtitleListener; |
||||
private LocalFileChooserListener mLocalFileChooserListener; |
||||
|
||||
public SubtitleDialog(@NonNull @NotNull Context context) { |
||||
super(context, R.style.CustomDialogStyleDim); |
||||
setCanceledOnTouchOutside(false); |
||||
setCancelable(true); |
||||
setContentView(R.layout.dialog_subtitle); |
||||
init(context); |
||||
} |
||||
|
||||
private void init(Context context) { |
||||
selectLocal = findViewById(R.id.selectLocal); |
||||
selectRemote = findViewById(R.id.selectRemote); |
||||
|
||||
selectLocal.setOnClickListener(new View.OnClickListener() { |
||||
@Override |
||||
public void onClick(View view) { |
||||
FastClickCheckUtil.check(view); |
||||
dismiss(); |
||||
mLocalFileChooserListener.openLocalFileChooserDialog(); |
||||
} |
||||
}); |
||||
|
||||
selectRemote.setOnClickListener(new View.OnClickListener() { |
||||
@Override |
||||
public void onClick(View view) { |
||||
FastClickCheckUtil.check(view); |
||||
dismiss(); |
||||
mSearchSubtitleListener.openSearchSubtitleDialog(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public void setLocalFileChooserListener(LocalFileChooserListener localFileChooserListener) { |
||||
mLocalFileChooserListener = localFileChooserListener; |
||||
} |
||||
|
||||
public interface LocalFileChooserListener { |
||||
void openLocalFileChooserDialog(); |
||||
} |
||||
|
||||
public void setSearchSubtitleListener(SearchSubtitleListener searchSubtitleListener) { |
||||
mSearchSubtitleListener = searchSubtitleListener; |
||||
} |
||||
|
||||
public interface SearchSubtitleListener { |
||||
void openSearchSubtitleDialog(); |
||||
} |
||||
} |
||||
@ -0,0 +1,109 @@ |
||||
package com.github.tvbox.osc.util; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
import java.io.PushbackInputStream; |
||||
import java.io.Reader; |
||||
|
||||
public class UnicodeReader extends Reader { |
||||
private InputStreamReader internalIn = null; |
||||
private String encoding; |
||||
private static final int BOM_SIZE = 4; |
||||
|
||||
public UnicodeReader(String file) |
||||
throws IOException, FileNotFoundException, SecurityException { |
||||
this(new File(file)); |
||||
} |
||||
|
||||
public UnicodeReader(File file) |
||||
throws IOException, FileNotFoundException, SecurityException { |
||||
this(new FileInputStream(file)); |
||||
} |
||||
|
||||
public UnicodeReader(File file, String defaultEncoding) |
||||
throws IOException, FileNotFoundException, SecurityException { |
||||
this(new FileInputStream(file), defaultEncoding); |
||||
} |
||||
|
||||
public UnicodeReader(InputStream in) |
||||
throws IOException { |
||||
this(in, null); |
||||
} |
||||
|
||||
public UnicodeReader(InputStream in, String defaultEncoding) |
||||
throws IOException { |
||||
init(in, defaultEncoding); |
||||
} |
||||
|
||||
public void close() |
||||
throws IOException { |
||||
this.internalIn.close(); |
||||
} |
||||
|
||||
public String getEncoding() { |
||||
return this.encoding; |
||||
} |
||||
|
||||
protected void init(InputStream in, String defaultEncoding) |
||||
throws IOException { |
||||
PushbackInputStream tempIn = new PushbackInputStream(in, 4); |
||||
|
||||
byte[] bom = new byte[4]; |
||||
|
||||
int n = tempIn.read(bom, 0, bom.length); |
||||
int unread; |
||||
if ((bom[0] == 0) && (bom[1] == 0) && |
||||
(bom[2] == -2) && (bom[3] == -1)) { |
||||
this.encoding = "UTF-32BE"; |
||||
unread = n - 4; |
||||
} else { |
||||
if (n == 4) { |
||||
if ((bom[0] == -1) && (bom[1] == -2) && |
||||
(bom[2] == 0) && (bom[3] == 0)) { |
||||
this.encoding = "UTF-32LE"; |
||||
unread = n - 4; |
||||
//break label240;
|
||||
} |
||||
} |
||||
if ((bom[0] == -17) && (bom[1] == -69) && |
||||
(bom[2] == -65)) { |
||||
this.encoding = "UTF-8"; |
||||
unread = n - 3; |
||||
} else { |
||||
if ((bom[0] == -2) && (bom[1] == -1)) { |
||||
this.encoding = "UTF-16BE"; |
||||
unread = n - 2; |
||||
} else { |
||||
if ((bom[0] == -1) && (bom[1] == -2)) { |
||||
this.encoding = "UTF-16LE"; |
||||
unread = n - 2; |
||||
} else { |
||||
this.encoding = defaultEncoding; |
||||
unread = n; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (unread > 0) |
||||
tempIn.unread(bom, n - unread, unread); |
||||
else if (unread < -1) { |
||||
tempIn.unread(bom, 0, 0); |
||||
} |
||||
|
||||
if (this.encoding == null) { |
||||
this.internalIn = new InputStreamReader(tempIn); |
||||
this.encoding = this.internalIn.getEncoding(); |
||||
} else { |
||||
this.internalIn = new InputStreamReader(tempIn, this.encoding); |
||||
} |
||||
} |
||||
|
||||
public int read(char[] cbuf, int off, int len) |
||||
throws IOException { |
||||
return this.internalIn.read(cbuf, off, len); |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="@dimen/vs_640" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:background="@drawable/shape_dialog_bg_main" |
||||
android:orientation="vertical" |
||||
android:padding="@dimen/vs_30"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:orientation="vertical"> |
||||
|
||||
|
||||
<TextView |
||||
android:id="@+id/selectLocal" |
||||
android:layout_width="@dimen/vs_480" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:background="@drawable/button_dialog_main" |
||||
android:focusable="true" |
||||
android:gravity="center" |
||||
android:padding="@dimen/vs_10" |
||||
android:text="选择本地字幕" |
||||
android:textColor="@color/color_FFFFFF" |
||||
android:textSize="@dimen/ts_22" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/selectRemote" |
||||
android:layout_width="@dimen/vs_480" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:layout_marginTop="@dimen/vs_10" |
||||
android:background="@drawable/button_dialog_main" |
||||
android:focusable="true" |
||||
android:gravity="center" |
||||
android:visibility="gone" |
||||
android:padding="@dimen/vs_10" |
||||
android:text="在线搜索字幕" |
||||
android:textColor="@color/color_FFFFFF" |
||||
android:textSize="@dimen/ts_22" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</FrameLayout> |
||||
Loading…
Reference in new issue