Home | History | Annotate | Download | only in guide
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.tv.guide;
     18 
     19 import android.content.Context;
     20 import android.support.v7.widget.LinearLayoutManager;
     21 import android.support.v7.widget.RecyclerView;
     22 import android.util.AttributeSet;
     23 import android.view.View;
     24 
     25 public class TimelineGridView extends RecyclerView {
     26     public TimelineGridView(Context context) {
     27         this(context, null);
     28     }
     29 
     30     public TimelineGridView(Context context, AttributeSet attrs) {
     31         this(context, attrs, 0);
     32     }
     33 
     34     public TimelineGridView(Context context, AttributeSet attrs, int defStyle) {
     35         super(context, attrs, defStyle);
     36 
     37         setLayoutManager(
     38                 new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
     39                     @Override
     40                     public boolean onRequestChildFocus(
     41                             RecyclerView parent, State state, View child, View focused) {
     42                         // This disables the default scroll behavior for focus movement.
     43                         return true;
     44                     }
     45                 });
     46 
     47         // RecyclerView is always focusable, however this is not desirable for us, so disable.
     48         // See b/18863217 (ag/634046) for reasons to why RecyclerView is focusable.
     49         setFocusable(false);
     50 
     51         // Don't cache anything that is off screen. Normally it is good to prefetch and prepopulate
     52         // off screen views in order to reduce jank, however the program guide is capable to scroll
     53         // in all four directions so not only would we prefetch views in the scrolling direction
     54         // but also keep views in the perpendicular direction up to date.
     55         // E.g. when scrolling horizontally we would have to update rows above and below the current
     56         // view port even though they are not visible.
     57         setItemViewCacheSize(0);
     58     }
     59 }
     60