diff options
author | nchalko <nchalko@google.com> | 2018-02-23 15:14:25 -0800 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2018-02-26 15:42:12 -0800 |
commit | adcef7667a2fb24d830a37dc0356865f7618f5cd (patch) | |
tree | 23acc6e0250919f454dba3834338ad920f60f64c | |
parent | 931f61842005107fd487591708dd934b1316e2e3 (diff) | |
download | TV-adcef7667a2fb24d830a37dc0356865f7618f5cd.tar.gz |
FIX: dpad up and down should change channels even when talk back is on.
PiperOrigin-RevId: 186830435
Change-Id: I93d4d047654df6b3a6e98d29c79181cdd1668611
-rw-r--r-- | res/layout/tunable_tv_view.xml | 21 | ||||
-rw-r--r-- | src/com/android/tv/MainActivity.java | 37 | ||||
-rw-r--r-- | src/com/android/tv/ui/TunableTvView.java | 36 |
3 files changed, 83 insertions, 11 deletions
diff --git a/res/layout/tunable_tv_view.xml b/res/layout/tunable_tv_view.xml index 00c9908c..549d0535 100644 --- a/res/layout/tunable_tv_view.xml +++ b/res/layout/tunable_tv_view.xml @@ -17,6 +17,27 @@ <merge xmlns:android="http://schemas.android.com/apk/res/android" > + <View android:id="@+id/channel_up" + android:layout_width="wrap_content" + android:focusable="false" + android:focusableInTouchMode="true" + android:layout_height="1dp" + android:layout_gravity="top" /> + <View android:id="@+id/placeholder" + android:layout_width="1dp" + android:layout_height="1dp" + android:focusable="false" + android:focusableInTouchMode="true" + android:focusedByDefault="true" + android:layout_gravity="center" /> + + <View android:id="@+id/channel_down" + android:layout_width="wrap_content" + android:focusable="false" + android:focusableInTouchMode="true" + android:layout_height="1dp" + android:layout_gravity="bottom" /> + <com.android.tv.ui.AppLayerTvView android:id="@+id/tv_view" android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/src/com/android/tv/MainActivity.java b/src/com/android/tv/MainActivity.java index ab8fe714..94a86cce 100644 --- a/src/com/android/tv/MainActivity.java +++ b/src/com/android/tv/MainActivity.java @@ -488,6 +488,9 @@ public class MainActivity extends Activity implements OnActionClickListener, OnP new OnUnhandledInputEventListener() { @Override public boolean onUnhandledInputEvent(InputEvent event) { + if (DEBUG) { + Log.d(TAG, "onUnhandledInputEvent " + event); + } if (isKeyEventBlocked()) { return true; } @@ -508,6 +511,7 @@ public class MainActivity extends Activity implements OnActionClickListener, OnP return false; } }); + mTvView.setOnTalkBackDpadKeyListener(keycode -> handleUpDownKeys(keycode, null)); long channelId = Utils.getLastWatchedChannelId(this); String inputId = Utils.getLastWatchedTunerInputId(this); if (!isPassthroughInput @@ -2096,32 +2100,43 @@ public class MainActivity extends Activity implements OnActionClickListener, OnP if (!mChannelTuner.areAllChannelsLoaded()) { return false; } + if (handleUpDownKeys(keyCode, event)) { + return true; + } + return super.onKeyDown(keyCode, event); + } + + private boolean handleUpDownKeys(int keyCode, @Nullable KeyEvent event) { if (!mChannelTuner.isCurrentChannelPassthrough()) { switch (keyCode) { case KeyEvent.KEYCODE_CHANNEL_UP: case KeyEvent.KEYCODE_DPAD_UP: - if (event.getRepeatCount() == 0 + if ((event == null || event.getRepeatCount() == 0) && mChannelTuner.getBrowsableChannelCount() > 0) { // message sending should be done before moving channel, because we use the // existence of message to decide if users are switching channel. - mHandler.sendMessageDelayed( - mHandler.obtainMessage( - MSG_CHANNEL_UP_PRESSED, System.currentTimeMillis()), - CHANNEL_CHANGE_INITIAL_DELAY_MILLIS); + if (event != null) { + mHandler.sendMessageDelayed( + mHandler.obtainMessage( + MSG_CHANNEL_UP_PRESSED, System.currentTimeMillis()), + CHANNEL_CHANGE_INITIAL_DELAY_MILLIS); + } moveToAdjacentChannel(true, false); mTracker.sendChannelUp(); } return true; case KeyEvent.KEYCODE_CHANNEL_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN: - if (event.getRepeatCount() == 0 + if ((event == null || event.getRepeatCount() == 0) && mChannelTuner.getBrowsableChannelCount() > 0) { // message sending should be done before moving channel, because we use the // existence of message to decide if users are switching channel. - mHandler.sendMessageDelayed( - mHandler.obtainMessage( - MSG_CHANNEL_DOWN_PRESSED, System.currentTimeMillis()), - CHANNEL_CHANGE_INITIAL_DELAY_MILLIS); + if (event != null) { + mHandler.sendMessageDelayed( + mHandler.obtainMessage( + MSG_CHANNEL_DOWN_PRESSED, System.currentTimeMillis()), + CHANNEL_CHANGE_INITIAL_DELAY_MILLIS); + } moveToAdjacentChannel(false, false); mTracker.sendChannelDown(); } @@ -2129,7 +2144,7 @@ public class MainActivity extends Activity implements OnActionClickListener, OnP default: // fall out } } - return super.onKeyDown(keyCode, event); + return false; } @Override diff --git a/src/com/android/tv/ui/TunableTvView.java b/src/com/android/tv/ui/TunableTvView.java index 9c75bc80..bb98d974 100644 --- a/src/com/android/tv/ui/TunableTvView.java +++ b/src/com/android/tv/ui/TunableTvView.java @@ -96,6 +96,8 @@ public class TunableTvView extends FrameLayout implements StreamInfo, TunableTvV public static final int VIDEO_UNAVAILABLE_REASON_SCREEN_BLOCKED = -3; public static final int VIDEO_UNAVAILABLE_REASON_NONE = -100; + private OnTalkBackDpadKeyListener mOnTalkBackDpadKeyListener; + @Retention(RetentionPolicy.SOURCE) @IntDef({BLOCK_SCREEN_TYPE_NO_UI, BLOCK_SCREEN_TYPE_SHRUNKEN_TV_VIEW, BLOCK_SCREEN_TYPE_NORMAL}) public @interface BlockScreenType {} @@ -500,6 +502,30 @@ public class TunableTvView extends FrameLayout implements StreamInfo, TunableTvV } } }); + View placeholder = findViewById(R.id.placeholder); + placeholder.requestFocus(); + findViewById(R.id.channel_up) + .setOnFocusChangeListener( + (v, hasFocus) -> { + if (hasFocus) { + placeholder.requestFocus(); + if (mOnTalkBackDpadKeyListener != null) { + mOnTalkBackDpadKeyListener.onTalkBackDpadKey( + KeyEvent.KEYCODE_DPAD_UP); + } + } + }); + findViewById(R.id.channel_down) + .setOnFocusChangeListener( + (v, hasFocus) -> { + if (hasFocus) { + placeholder.requestFocus(); + if (mOnTalkBackDpadKeyListener != null) { + mOnTalkBackDpadKeyListener.onTalkBackDpadKey( + KeyEvent.KEYCODE_DPAD_DOWN); + } + } + }); } public void initialize( @@ -843,6 +869,10 @@ public class TunableTvView extends FrameLayout implements StreamInfo, TunableTvV mTvView.setOnUnhandledInputEventListener(listener); } + public void setOnTalkBackDpadKeyListener(OnTalkBackDpadKeyListener listener) { + mOnTalkBackDpadKeyListener = listener; + } + public void setClosedCaptionEnabled(boolean enabled) { mTvView.setCaptionEnabled(enabled); } @@ -1416,6 +1446,12 @@ public class TunableTvView extends FrameLayout implements StreamInfo, TunableTvV }; } + /** Listens for dpad actions that are otherwise trapped by talkback */ + public interface OnTalkBackDpadKeyListener { + + void onTalkBackDpadKey(int keycode); + } + /** A listener which receives the notification when the screen is blocked/unblocked. */ public abstract static class OnScreenBlockingChangedListener { /** Called when the screen is blocked/unblocked. */ |