mirror of https://github.com/FongMi/TV.git
parent
ac89d2b3e8
commit
7d7e6c9849
@ -1,83 +0,0 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.WindowManager; |
||||
|
||||
import androidx.annotation.Dimension; |
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
import androidx.media3.common.text.Cue; |
||||
|
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.DialogSubtitleBinding; |
||||
import com.fongmi.android.tv.impl.SubtitleCallback; |
||||
import com.fongmi.android.tv.player.exo.ExoUtil; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
public class SubtitleDialog { |
||||
|
||||
private final DialogSubtitleBinding binding; |
||||
private final SubtitleCallback callback; |
||||
private final AlertDialog dialog; |
||||
private boolean listen; |
||||
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 SubtitleDialog listen(boolean listen) { |
||||
this.listen = listen; |
||||
return this; |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); |
||||
params.width = (int) (ResUtil.getScreenWidth() * 0.45f); |
||||
dialog.getWindow().setAttributes(params); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
binding.slider.setValue(Setting.getSubtitle()); |
||||
binding.preview.setStyle(ExoUtil.getCaptionStyle()); |
||||
binding.preview.setVisibility(listen ? View.GONE : View.VISIBLE); |
||||
binding.preview.setFixedTextSize(Dimension.SP, value = Setting.getSubtitle()); |
||||
binding.preview.setCues(Arrays.asList(new Cue.Builder().setText("影視天下第一").build())); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.positive.setOnClickListener(this::onPositive); |
||||
binding.negative.setOnClickListener(this::onNegative); |
||||
if (listen) binding.slider.addOnChangeListener((slider, value, fromUser) -> callback.setSubtitle((int) value)); |
||||
else binding.slider.addOnChangeListener((slider, value, fromUser) -> binding.preview.setFixedTextSize(Dimension.SP, 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,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/grey_600" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M440,160L440,647L216,423L160,480L480,800L800,480L744,423L520,647L520,160L440,160Z" /> |
||||
</vector> |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/grey_600" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M440,520L200,520L200,440L440,440L440,200L520,200L520,440L760,440L760,520L520,520L520,760L440,760L440,520Z" /> |
||||
</vector> |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/grey_600" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M440,838Q319,823 239.5,732.5Q160,642 160,520Q160,454 186,393.5Q212,333 260,288L317,345Q279,379 259.5,424Q240,469 240,520Q240,608 296,675.5Q352,743 440,758L440,838ZM520,838L520,758Q607,742 663.5,675Q720,608 720,520Q720,420 650,350Q580,280 480,280L477,280L521,324L465,380L325,240L465,100L521,156L477,200L480,200Q614,200 707,293Q800,386 800,520Q800,641 720.5,731.5Q641,822 520,838Z" /> |
||||
</vector> |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/grey_600" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M200,520L200,440L760,440L760,520L200,520Z" /> |
||||
</vector> |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="@color/grey_600" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M440,800L440,313L216,537L160,480L480,160L800,480L744,537L520,313L520,800L440,800Z" /> |
||||
</vector> |
||||
@ -1,74 +1,53 @@ |
||||
<?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_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
android:orientation="horizontal" |
||||
android:padding="8dp"> |
||||
|
||||
<FrameLayout |
||||
android:layout_width="match_parent" |
||||
<ImageView |
||||
android:id="@+id/large" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/shape_subtitle"> |
||||
|
||||
<androidx.media3.ui.SubtitleView |
||||
android:id="@+id/preview" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="76dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginBottom="8dp" /> |
||||
|
||||
</FrameLayout> |
||||
|
||||
<com.google.android.material.slider.Slider |
||||
android:id="@+id/slider" |
||||
android:layout_width="match_parent" |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:focusable="true" |
||||
android:padding="8dp" |
||||
android:src="@drawable/ic_subtitle_large" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/small" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:nextFocusDown="@id/positive" |
||||
android:stepSize="1" |
||||
android:valueFrom="14" |
||||
android:valueTo="48" |
||||
app:labelBehavior="gone" |
||||
app:thumbColor="@color/blue_500" |
||||
app:tickVisible="false" |
||||
app:trackColorActive="@color/blue_500" |
||||
app:trackColorInactive="@color/blue_50" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:focusable="true" |
||||
android:padding="8dp" |
||||
android:src="@drawable/ic_subtitle_small" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/up" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
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" /> |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:focusable="true" |
||||
android:padding="8dp" |
||||
android:src="@drawable/ic_subtitle_up" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/down" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:focusable="true" |
||||
android:padding="8dp" |
||||
android:src="@drawable/ic_subtitle_down" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/reset" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="?attr/selectableItemBackgroundBorderless" |
||||
android:focusable="true" |
||||
android:padding="8dp" |
||||
android:src="@drawable/ic_subtitle_reset" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
Loading…
Reference in new issue