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 {
TimelineGridView(Context context)26     public TimelineGridView(Context context) {
27         this(context, null);
28     }
29 
TimelineGridView(Context context, AttributeSet attrs)30     public TimelineGridView(Context context, AttributeSet attrs) {
31         this(context, attrs, 0);
32     }
33 
TimelineGridView(Context context, AttributeSet attrs, int defStyle)34     public TimelineGridView(Context context, AttributeSet attrs, int defStyle) {
35         super(context, attrs, defStyle);
36 
37         setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
38             @Override
39             public boolean onRequestChildFocus(RecyclerView parent, State state, View child,
40                     View focused) {
41                  // This disables the default scroll behavior for focus movement.
42                 return true;
43             }
44         });
45 
46         // RecyclerView is always focusable, however this is not desirable for us, so disable.
47         // See b/18863217 (ag/634046) for reasons to why RecyclerView is focusable.
48         setFocusable(false);
49 
50         // Don't cache anything that is off screen. Normally it is good to prefetch and prepopulate
51         // off screen views in order to reduce jank, however the program guide is capable to scroll
52         // in all four directions so not only would we prefetch views in the scrolling direction
53         // but also keep views in the perpendicular direction up to date.
54         // E.g. when scrolling horizontally we would have to update rows above and below the current
55         // view port even though they are not visible.
56         setItemViewCacheSize(0);
57     }
58 }
59