aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/guide/ProgramGrid.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/tv/guide/ProgramGrid.java')
-rw-r--r--src/com/android/tv/guide/ProgramGrid.java60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/com/android/tv/guide/ProgramGrid.java b/src/com/android/tv/guide/ProgramGrid.java
index 1339ddf8..77de5827 100644
--- a/src/com/android/tv/guide/ProgramGrid.java
+++ b/src/com/android/tv/guide/ProgramGrid.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.support.v17.leanback.widget.VerticalGridView;
+import android.support.v7.widget.RecyclerView.LayoutManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -66,6 +67,16 @@ public class ProgramGrid extends VerticalGridView {
}
};
+ private final ViewTreeObserver.OnPreDrawListener mPreDrawListener =
+ new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ getViewTreeObserver().removeOnPreDrawListener(this);
+ updateInputLogo();
+ return true;
+ }
+ };
+
private ProgramManager mProgramManager;
private View mNextFocusByUpDown;
@@ -83,7 +94,7 @@ public class ProgramGrid extends VerticalGridView {
private boolean mKeepCurrentProgram;
private ChildFocusListener mChildFocusListener;
- private OnRepeatedKeyInterceptListener mOnRepeatedKeyInterceptListener;
+ private final OnRepeatedKeyInterceptListener mOnRepeatedKeyInterceptListener;
interface ChildFocusListener {
/**
@@ -332,6 +343,10 @@ public class ProgramGrid extends VerticalGridView {
return contains((View) v.getParent());
}
+ public void onItemSelectionReset() {
+ getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
+ }
+
@Override
public boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
if (mLastFocusedView != null && mLastFocusedView.isShown()) {
@@ -359,6 +374,49 @@ public class ProgramGrid extends VerticalGridView {
int maxY = (mSelectionRow + 1) * mRowHeight + mDetailHeight;
if (y > maxY) scrollBy(0, y - maxY);
}
+ updateInputLogo();
+ }
+
+ @Override
+ public void onViewRemoved(View view) {
+ // It is required to ensure input logo showing when the scroll is moved to most bottom.
+ updateInputLogo();
+ }
+
+ private int getFirstVisibleChildIndex() {
+ final LayoutManager mLayoutManager = getLayoutManager();
+ int top = mLayoutManager.getPaddingTop();
+ int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ View childView = getChildAt(i);
+ int childTop = mLayoutManager.getDecoratedTop(childView);
+ int childBottom = mLayoutManager.getDecoratedBottom(childView);
+ if ((childTop + childBottom) / 2 > top) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public void updateInputLogo() {
+ int childCount = getChildCount();
+ if (childCount == 0) {
+ return;
+ }
+ int firstVisibleChildIndex = getFirstVisibleChildIndex();
+ if (firstVisibleChildIndex == -1) {
+ return;
+ }
+ View childView = getChildAt(firstVisibleChildIndex);
+ int childAdapterPosition = getChildAdapterPosition(childView);
+ ((ProgramTableAdapter.ProgramRowHolder) getChildViewHolder(childView))
+ .updateInputLogo(childAdapterPosition, true);
+ for (int i = firstVisibleChildIndex + 1; i < childCount; i++) {
+ childView = getChildAt(i);
+ ((ProgramTableAdapter.ProgramRowHolder) getChildViewHolder(childView))
+ .updateInputLogo(childAdapterPosition, false);
+ childAdapterPosition = getChildAdapterPosition(childView);
+ }
}
private static void findFocusables(View v, ArrayList<View> outFocusable) {