parent
1bd7030621
commit
065cd6ee49
@ -0,0 +1,97 @@ |
||||
package io.legado.app.ui.book.read.config |
||||
|
||||
import android.os.Bundle |
||||
import android.util.DisplayMetrics |
||||
import android.view.Gravity |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import android.widget.SeekBar |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseDialogFragment |
||||
import io.legado.app.help.ReadBookConfig |
||||
import io.legado.app.lib.theme.bottomBackground |
||||
import io.legado.app.service.BaseReadAloudService |
||||
import io.legado.app.service.help.ReadAloud |
||||
import io.legado.app.ui.book.read.Help |
||||
import kotlinx.android.synthetic.main.dialog_auto_read.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class AutoReadDialog : BaseDialogFragment() { |
||||
var callBack: CallBack? = null |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
val dm = DisplayMetrics() |
||||
activity?.let { |
||||
Help.upSystemUiVisibility(it) |
||||
it.windowManager?.defaultDisplay?.getMetrics(dm) |
||||
} |
||||
dialog?.window?.let { |
||||
it.setBackgroundDrawableResource(R.color.background) |
||||
it.decorView.setPadding(0, 0, 0, 0) |
||||
val attr = it.attributes |
||||
attr.dimAmount = 0.0f |
||||
attr.gravity = Gravity.BOTTOM |
||||
it.attributes = attr |
||||
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) |
||||
} |
||||
} |
||||
|
||||
override fun onCreateView( |
||||
inflater: LayoutInflater, |
||||
container: ViewGroup?, |
||||
savedInstanceState: Bundle? |
||||
): View? { |
||||
callBack = activity as? CallBack |
||||
return inflater.inflate(R.layout.dialog_auto_read, container) |
||||
} |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||
root_view.setBackgroundColor(requireContext().bottomBackground) |
||||
initOnChange() |
||||
initData() |
||||
initEvent() |
||||
} |
||||
|
||||
private fun initData() { |
||||
seek_auto_read.progress = ReadBookConfig.autoReadSpeed |
||||
} |
||||
|
||||
private fun initOnChange() { |
||||
seek_auto_read.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { |
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { |
||||
} |
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit |
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) { |
||||
ReadBookConfig.autoReadSpeed = seek_auto_read.progress |
||||
upTtsSpeechRate() |
||||
} |
||||
}) |
||||
} |
||||
|
||||
private fun initEvent() { |
||||
ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() } |
||||
ll_setting.onClick { |
||||
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") |
||||
} |
||||
ll_catalog.onClick { callBack?.openChapterList() } |
||||
ll_auto_page_stop.onClick { callBack?.autoPageStop() } |
||||
} |
||||
|
||||
private fun upTtsSpeechRate() { |
||||
ReadAloud.upTtsSpeechRate(requireContext()) |
||||
if (!BaseReadAloudService.pause) { |
||||
ReadAloud.pause(requireContext()) |
||||
ReadAloud.resume(requireContext()) |
||||
} |
||||
} |
||||
|
||||
interface CallBack { |
||||
fun showMenuBar() |
||||
fun openChapterList() |
||||
fun autoPageStop() |
||||
} |
||||
} |
@ -0,0 +1,198 @@ |
||||
<?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" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/root_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@color/background_menu" |
||||
android:paddingLeft="16dp" |
||||
android:paddingRight="16dp" |
||||
android:paddingTop="6dp" |
||||
android:paddingBottom="6dp" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/ll_tts_SpeechRate" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_vertical" |
||||
android:orientation="horizontal" |
||||
android:padding="8dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:layout_weight="1" |
||||
android:text="@string/auto_page_speed" |
||||
android:textColor="@color/tv_text_default" |
||||
android:textSize="14sp" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<io.legado.app.lib.theme.view.ATESeekBar |
||||
android:id="@+id/seek_auto_read" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="15dp" |
||||
android:layout_marginEnd="15dp" |
||||
android:max="45" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:layout_marginTop="8dp" |
||||
android:baselineAligned="false" |
||||
android:orientation="horizontal"> |
||||
|
||||
<!--目录按钮--> |
||||
<LinearLayout |
||||
android:id="@+id/ll_catalog" |
||||
android:layout_width="50dp" |
||||
android:layout_height="50dp" |
||||
android:background="?android:attr/selectableItemBackgroundBorderless" |
||||
android:clickable="true" |
||||
android:contentDescription="@string/chapter_list" |
||||
android:focusable="true" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="7dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1" |
||||
android:contentDescription="@string/chapter_list" |
||||
android:src="@drawable/ic_toc" |
||||
app:tint="@color/tv_text_default" |
||||
tools:ignore="NestedWeights" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_horizontal" |
||||
android:layout_marginTop="3dp" |
||||
android:text="@string/chapter_list" |
||||
android:maxLines="1" |
||||
android:textColor="@color/tv_text_default" |
||||
android:textSize="12sp" /> |
||||
</LinearLayout> |
||||
|
||||
<View |
||||
android:layout_width="0dp" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="2" /> |
||||
<!--调节按钮--> |
||||
<LinearLayout |
||||
android:id="@+id/ll_main_menu" |
||||
android:layout_width="50dp" |
||||
android:layout_height="50dp" |
||||
android:background="?android:attr/selectableItemBackgroundBorderless" |
||||
android:clickable="true" |
||||
android:contentDescription="@string/read_aloud" |
||||
android:focusable="true" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="7dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1" |
||||
android:contentDescription="@string/main_menu" |
||||
android:src="@drawable/ic_menu" |
||||
app:tint="@color/tv_text_default" |
||||
tools:ignore="NestedWeights" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_horizontal" |
||||
android:layout_marginTop="3dp" |
||||
android:text="@string/main_menu" |
||||
android:maxLines="1" |
||||
android:textColor="@color/tv_text_default" |
||||
android:textSize="12sp" /> |
||||
</LinearLayout> |
||||
|
||||
<View |
||||
android:layout_width="0dp" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="2" /> |
||||
<!--界面按钮--> |
||||
<LinearLayout |
||||
android:id="@+id/ll_auto_page_stop" |
||||
android:layout_width="50dp" |
||||
android:layout_height="50dp" |
||||
android:background="?android:attr/selectableItemBackgroundBorderless" |
||||
android:clickable="true" |
||||
android:contentDescription="@string/stop" |
||||
android:focusable="true" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="7dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1" |
||||
android:contentDescription="@string/stop" |
||||
android:src="@drawable/ic_auto_page_stop" |
||||
app:tint="@color/tv_text_default" |
||||
tools:ignore="NestedWeights" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_horizontal" |
||||
android:layout_marginTop="3dp" |
||||
android:text="@string/stop" |
||||
android:maxLines="1" |
||||
android:textColor="@color/tv_text_default" |
||||
android:textSize="12sp" /> |
||||
</LinearLayout> |
||||
|
||||
<View |
||||
android:layout_width="0dp" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="2" /> |
||||
<!--设置按钮--> |
||||
<LinearLayout |
||||
android:id="@+id/ll_setting" |
||||
android:layout_width="50dp" |
||||
android:layout_height="50dp" |
||||
android:background="?android:attr/selectableItemBackgroundBorderless" |
||||
android:clickable="true" |
||||
android:contentDescription="@string/setting" |
||||
android:focusable="true" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="7dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1" |
||||
android:contentDescription="@string/aloud_config" |
||||
android:src="@drawable/ic_settings" |
||||
app:tint="@color/tv_text_default" |
||||
tools:ignore="NestedWeights" /> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_horizontal" |
||||
android:layout_marginTop="3dp" |
||||
android:text="@string/setting" |
||||
android:maxLines="1" |
||||
android:textColor="@color/tv_text_default" |
||||
android:textSize="12sp" /> |
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue