mirror of https://github.com/FongMi/TV.git
parent
6d52b1820d
commit
70f006df8d
@ -0,0 +1,53 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.view.LayoutInflater; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
|
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.DialogSpeedBinding; |
||||
import com.fongmi.android.tv.impl.SpeedCallback; |
||||
import com.fongmi.android.tv.utils.KeyUtil; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class SpeedDialog { |
||||
|
||||
private final DialogSpeedBinding binding; |
||||
private final SpeedCallback callback; |
||||
private final AlertDialog dialog; |
||||
|
||||
public static SpeedDialog create(FragmentActivity activity) { |
||||
return new SpeedDialog(activity); |
||||
} |
||||
|
||||
public SpeedDialog(FragmentActivity activity) { |
||||
this.callback = (SpeedCallback) activity; |
||||
this.binding = DialogSpeedBinding.inflate(LayoutInflater.from(activity)); |
||||
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
binding.slider.setValue(Setting.getSpeed()); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.slider.addOnChangeListener((slider, value, fromUser) -> callback.setSpeed(value)); |
||||
binding.slider.setOnKeyListener((view, keyCode, event) -> { |
||||
boolean enter = KeyUtil.isEnterKey(event); |
||||
if (enter) dialog.dismiss(); |
||||
return enter; |
||||
}); |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@ |
||||
<?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" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:padding="48dp"> |
||||
|
||||
<com.google.android.material.slider.Slider |
||||
android:id="@+id/slider" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:stepSize="0.5" |
||||
android:valueFrom="2" |
||||
android:valueTo="5" |
||||
app:thumbColor="@color/blue_500" |
||||
app:tickVisible="false" |
||||
app:trackColorActive="@color/blue_500" |
||||
app:trackColorInactive="@color/blue_50" /> |
||||
|
||||
</FrameLayout> |
||||
@ -0,0 +1,6 @@ |
||||
package com.fongmi.android.tv.impl; |
||||
|
||||
public interface SpeedCallback { |
||||
|
||||
void setSpeed(float speed); |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.content.DialogInterface; |
||||
import android.view.LayoutInflater; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.Fragment; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.DialogSpeedBinding; |
||||
import com.fongmi.android.tv.impl.SpeedCallback; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class SpeedDialog { |
||||
|
||||
private final DialogSpeedBinding binding; |
||||
private final SpeedCallback callback; |
||||
private float value; |
||||
|
||||
public static SpeedDialog create(Fragment fragment) { |
||||
return new SpeedDialog(fragment); |
||||
} |
||||
|
||||
public SpeedDialog(Fragment fragment) { |
||||
this.callback = (SpeedCallback) fragment; |
||||
this.binding = DialogSpeedBinding.inflate(LayoutInflater.from(fragment.getContext())); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
AlertDialog dialog = new MaterialAlertDialogBuilder(binding.getRoot().getContext()).setTitle(R.string.player_speed).setView(binding.getRoot()).setPositiveButton(R.string.dialog_positive, this::onPositive).setNegativeButton(R.string.dialog_negative, this::onNegative).create(); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
binding.slider.setValue(value = Setting.getSpeed()); |
||||
} |
||||
|
||||
private void onPositive(DialogInterface dialog, int which) { |
||||
callback.setSpeed(binding.slider.getValue()); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private void onNegative(DialogInterface dialog, int which) { |
||||
callback.setSpeed(value); |
||||
dialog.dismiss(); |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
<?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:orientation="vertical" |
||||
android:paddingStart="12dp" |
||||
android:paddingTop="16dp" |
||||
android:paddingEnd="12dp"> |
||||
|
||||
<com.google.android.material.slider.Slider |
||||
android:id="@+id/slider" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:stepSize="0.5" |
||||
android:valueFrom="2" |
||||
android:valueTo="5" |
||||
app:tickVisible="false" |
||||
app:trackColorInactive="@color/blue_50" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue