mirror of https://github.com/FongMi/TV.git
parent
eadd6b6f0d
commit
c01e0133cd
@ -0,0 +1,62 @@ |
||||
package com.fongmi.android.tv.ui.custom.dialog; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
|
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.DialogSubtitleBinding; |
||||
import com.fongmi.android.tv.impl.SubtitleCallback; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class SubtitleDialog { |
||||
|
||||
private final DialogSubtitleBinding binding; |
||||
private final SubtitleCallback callback; |
||||
private final AlertDialog dialog; |
||||
private int value; |
||||
|
||||
public static SubtitleDialog create(FragmentActivity activity) { |
||||
return new SubtitleDialog(activity); |
||||
} |
||||
|
||||
public SubtitleDialog(FragmentActivity activity) { |
||||
this.callback = (SubtitleCallback) activity; |
||||
this.binding = DialogSubtitleBinding.inflate(LayoutInflater.from(activity)); |
||||
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
binding.slider.setValue(value = Setting.getSubtitle()); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.positive.setOnClickListener(this::onPositive); |
||||
binding.negative.setOnClickListener(this::onNegative); |
||||
binding.slider.addOnChangeListener((slider, value, fromUser) -> callback.setSubtitle((int) value)); |
||||
} |
||||
|
||||
private void onPositive(View view) { |
||||
callback.setSubtitle((int) binding.slider.getValue()); |
||||
Setting.putSubtitle((int) binding.slider.getValue()); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private void onNegative(View view) { |
||||
callback.setSubtitle(value); |
||||
dialog.dismiss(); |
||||
} |
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="center" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<com.google.android.material.slider.Slider |
||||
android:id="@+id/slider" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:nextFocusDown="@id/positive" |
||||
android:stepSize="1" |
||||
android:valueFrom="16" |
||||
android:valueTo="60" |
||||
app:thumbColor="@color/blue_500" |
||||
app:trackColorActive="@color/blue_500" |
||||
app:trackColorInactive="@color/blue_50" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/positive" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:text="@string/dialog_positive" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/negative" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:text="@string/dialog_negative" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
@ -0,0 +1,6 @@ |
||||
package com.fongmi.android.tv.impl; |
||||
|
||||
public interface SubtitleCallback { |
||||
|
||||
void setSubtitle(int size); |
||||
} |
||||
@ -1,62 +0,0 @@ |
||||
package tv.danmaku.ijk.media.player.ui; |
||||
|
||||
import android.content.Context; |
||||
import android.graphics.Canvas; |
||||
import android.graphics.Color; |
||||
import android.graphics.Paint; |
||||
import android.text.Html; |
||||
import android.text.TextUtils; |
||||
import android.util.AttributeSet; |
||||
import android.widget.TextView; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
|
||||
public class SubtitleView extends TextView { |
||||
|
||||
private final float strokeWidth; |
||||
private boolean isDrawing; |
||||
|
||||
public SubtitleView(Context context) { |
||||
this(context, null); |
||||
} |
||||
|
||||
public SubtitleView(Context context, @Nullable AttributeSet attrs) { |
||||
this(context, attrs, 0); |
||||
} |
||||
|
||||
public SubtitleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
||||
super(context, attrs, defStyleAttr); |
||||
strokeWidth = Util.dp2px(getContext(), 0.8f); |
||||
} |
||||
|
||||
public void onSubtitleChanged(String text) { |
||||
if (TextUtils.isEmpty(text)) { |
||||
setText(""); |
||||
} else { |
||||
setText(Html.fromHtml(text.replaceAll("\r\n", "<br>").replaceAll("\r", "<br>").replaceAll("\n", "<br>").replaceAll("\\{\\\\.*?\\}", ""))); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void invalidate() { |
||||
if (isDrawing) return; |
||||
super.invalidate(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDraw(Canvas canvas) { |
||||
isDrawing = true; |
||||
Paint paint = getPaint(); |
||||
paint.setStyle(Paint.Style.FILL); |
||||
setTextColor(Color.WHITE); |
||||
super.onDraw(canvas); |
||||
paint.setStyle(Paint.Style.STROKE); |
||||
paint.setStrokeJoin(Paint.Join.ROUND); |
||||
paint.setStrokeWidth(strokeWidth); |
||||
setTextColor(Color.BLACK); |
||||
super.onDraw(canvas); |
||||
paint.setStyle(Paint.Style.FILL); |
||||
setTextColor(Color.WHITE); |
||||
isDrawing = false; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue