这是在我的 EPG 上滚动和导航的方法,但我需要在 AndroidTV 上使用 Remote 进行导航。
我已经阅读了一些关于 setClickable、setFocusable 的内容,但它只在主屏幕上工作,我需要在里面访问每个单元格。
所以基本上,我需要在 EPG 内的单元格之间导航。
有人有什么想法吗?
EPG 项目在那里 -> https://github.com/korre/android-tv-epg
private class OnGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapUp(MotionEvent e) {
// This is absolute coordinate on screen not taking scroll into account.
int x = (int) e.getX();
int y = (int) e.getY();
// Adding scroll to clicked coordinate
int scrollX = getScrollX() + x;
int scrollY = getScrollY() + y;
int channelPosition = getChannelPosition(scrollY);
if (channelPosition != -1 && mClickListener != null) {
if (calculateResetButtonHitArea().contains(scrollX,scrollY)) {
// Reset button clicked
mClickListener.onResetButtonClicked();
} else if (calculateChannelsHitArea().contains(x, y)) {
// Channel area is clicked
/*mClickListener.onChannelClicked(channelPosition, epgData.getChannel(channelPosition));*/
} else if (calculateProgramsHitArea().contains(x, y)) {
// Event area is clicked
int programPosition = getProgramPosition(channelPosition, getTimeFrom(getScrollX() + x - calculateProgramsHitArea().left));
if (programPosition != -1) {
/*mClickListener.onEventClicked(channelPosition, programPosition, epgData.getEvent(channelPosition, programPosition));*/
}
}
}
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
int dx = (int) distanceX;
int dy = (int) distanceY;
int x = getScrollX();
int y = getScrollY();
// Avoid over scrolling
if (x + dx < 0) {
dx = 0 - x;
}
if (y + dy < 0) {
dy = 0 - y;
}
if (x + dx > mMaxHorizontalScroll) {
dx = mMaxHorizontalScroll - x;
}
if (y + dy > mMaxVerticalScroll) {
dy = mMaxVerticalScroll - y;
}
scrollBy(dx, dy);
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float vX, float vY) {
mScroller.fling(getScrollX(), getScrollY(), -(int) vX,
-(int) vY, 0, mMaxHorizontalScroll, 0, mMaxVerticalScroll);
redraw();
return true;
}
@Override
public boolean onDown(MotionEvent e) {
if (!mScroller.isFinished()) {
mScroller.forceFinished(true);
return true;
}
return true;
}
}
}