Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Nov 29, 2019
1 parent 900cc4c commit 6eb0ad1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1674,12 +1674,18 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
return true;
} else if (flMenu.getVisibility() != View.VISIBLE) {
if (keyCode == preferences.getInt("pageKeyCode", 0)) {
if (keyCode == preferences.getInt("nextKeyCode", 0)) {
if (mPageLoader != null) {
mPageLoader.skipToNextPage();
}
return true;
}
if (keyCode == preferences.getInt("prevKeyCode", 0)) {
if (mPageLoader != null) {
mPageLoader.skipToPrePage();
}
return true;
}
if (readBookControl.getCanKeyTurn(aloudStatus == ReadAloudService.Status.PLAY) && keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (mPageLoader != null) {
mPageLoader.skipToNextPage();
Expand All @@ -1705,7 +1711,8 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
if (readBookControl.getCanKeyTurn(aloudStatus == ReadAloudService.Status.PLAY)
&& (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == preferences.getInt("pageKeyCode", 0))) {
|| keyCode == preferences.getInt("nextKeyCode", 0)
|| keyCode == preferences.getInt("prevKeyCode", 0))) {
return true;
}
}
Expand Down Expand Up @@ -1821,7 +1828,7 @@ public void onMediaButton(String cmd) {
readBottomMenu.setFabReadAloudText(getString(R.string.read_aloud));
} else if (cmd.equals(ReadAloudService.ActionMediaPrev)) {
//停止倒计时
ReadAloudService.setTimer(getContext(), ReadAloudService.maxTimeMinute+1);
ReadAloudService.setTimer(getContext(), ReadAloudService.maxTimeMinute + 1);
//语音提示倒计时结束
ReadAloudService.tts_ui_timer_stop(this);
} else if (cmd.equals(ReadAloudService.ActionMediaNext)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.widget.CompoundButton
import android.widget.FrameLayout
import androidx.appcompat.app.AlertDialog
import com.hwangjr.rxbus.RxBus
import com.kunfei.bookshelf.MApplication
import com.kunfei.bookshelf.R
import com.kunfei.bookshelf.constant.RxBusTag
import com.kunfei.bookshelf.help.ReadBookControl
Expand Down Expand Up @@ -176,16 +175,7 @@ class MoreSettingPop : FrameLayout {
}
}
ll_click_key_code.onClick {
PageKeyDialog.builder(context)
.setDefaultValue("")
.setTitle("请按需要录入的按键")
.setCallback { inputText: String? ->
MApplication.getConfigPreferences()
.edit()
.putInt("pageKeyCode", Integer.valueOf(inputText))
.apply()
}
.show()
PageKeyDialog(context).show()
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.kunfei.bookshelf.widget.modialog

import android.content.Context
import android.view.KeyEvent
import com.kunfei.bookshelf.MApplication
import com.kunfei.bookshelf.R
import com.kunfei.bookshelf.utils.SoftInputUtil
import kotlinx.android.synthetic.main.dialog_page_key.*
import org.jetbrains.anko.sdk27.listeners.onClick


class PageKeyDialog(context: Context) : BaseDialog(context) {

init {
setContentView(R.layout.dialog_page_key)
et_prev.setText(MApplication.getConfigPreferences().getInt("prevKeyCode", 0).toString())
et_next.setText(MApplication.getConfigPreferences().getInt("nextKeyCode", 0).toString())
tv_ok.onClick {
val edit = MApplication.getConfigPreferences().edit()
et_prev.text?.let {
edit.putInt("prevKeyCode", it.toString().toInt())
}
et_next.text?.let {
edit.putInt("nextKeyCode", it.toString().toInt())
}
edit.apply()
dismiss()
}
}

override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode != KeyEvent.KEYCODE_BACK) {
if (et_prev.hasFocus()) {
et_prev.setText(keyCode.toString())
} else if (et_next.hasFocus()) {
et_next.setText(keyCode.toString())
}
return true
}
return super.onKeyDown(keyCode, event)
}

override fun dismiss() {
super.dismiss()
SoftInputUtil.hideIMM(currentFocus)
}

}
60 changes: 60 additions & 0 deletions app/src/main/res/layout/dialog_page_key.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/custom_page_key" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="@string/prev_page_key">

<EditText
android:id="@+id/et_prev"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="@string/next_page_key">

<EditText
android:id="@+id/et_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" />

</com.google.android.material.textfield.TextInputLayout>

<TextView
android:id="@+id/tv_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/selector_fillet_btn_bg"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="@string/ok"
android:textColor="@color/tv_text_default" />
</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,8 @@
<string name="select_local_image">选择本地图片</string>
<string name="refresh_cover">刷新封面</string>
<string name="c_page_key">自定义翻页按键</string>

<string name="custom_page_key">自定义翻页按键</string>
<string name="prev_page_key">上一页按键</string>
<string name="next_page_key">下一页按键</string>
</resources>

0 comments on commit 6eb0ad1

Please sign in to comment.