Fix search can't back bug

pull/102/head
FongMi 3 years ago
parent 5358236248
commit 3eae35a60e
  1. 13
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomMic.java
  2. 2
      app/src/leanback/res/layout/activity_search.xml

@ -23,6 +23,7 @@ public class CustomMic extends AppCompatImageView {
private SpeechRecognizer recognizer;
private Animation flicker;
private boolean listen;
public CustomMic(@NonNull Context context) {
super(context);
@ -38,6 +39,14 @@ public class CustomMic extends AppCompatImageView {
recognizer = SpeechRecognizer.createSpeechRecognizer(context);
}
public boolean isListen() {
return listen;
}
public void setListen(boolean listen) {
this.listen = listen;
}
public void setListener(CustomListener listener) {
recognizer.setRecognitionListener(listener);
}
@ -47,12 +56,14 @@ public class CustomMic extends AppCompatImageView {
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
setColorFilter(MDColor.RED_500, PorterDuff.Mode.SRC_IN);
recognizer.startListening(intent);
setListen(true);
}
public boolean stop() {
setColorFilter(MDColor.WHITE, PorterDuff.Mode.SRC_IN);
recognizer.stopListening();
clearAnimation();
setListen(false);
return true;
}
@ -65,7 +76,7 @@ public class CustomMic extends AppCompatImageView {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (Utils.isBackKey(event) && event.getAction() == KeyEvent.ACTION_UP) return stop();
if (isListen() && Utils.isBackKey(event)) return stop();
else return super.dispatchKeyEvent(event);
}
}

@ -13,7 +13,7 @@
<LinearLayout
android:id="@+id/historyLayout"
android:layout_width="150dp"
android:layout_width="128dp"
android:layout_height="match_parent"
android:layout_marginEnd="36dp"
android:orientation="vertical">

Loading…
Cancel
Save