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 android.support.v17.preference;
18 
19 import android.app.Fragment;
20 import android.os.Bundle;
21 import android.support.v14.preference.PreferenceFragment;
22 import android.support.v17.leanback.widget.VerticalGridView;
23 import android.support.v7.widget.RecyclerView;
24 import android.view.LayoutInflater;
25 import android.view.ViewGroup;
26 
27 /**
28  * This fragment provides a preference fragment with leanback-style behavior, suitable for
29  * embedding into broader UI elements.
30  */
31 public abstract class BaseLeanbackPreferenceFragment extends PreferenceFragment {
32 
33     @Override
onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)34     public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
35             Bundle savedInstanceState) {
36         VerticalGridView verticalGridView = (VerticalGridView) inflater
37                 .inflate(R.layout.leanback_preferences_list, parent, false);
38         verticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
39         verticalGridView.setFocusScrollStrategy(VerticalGridView.FOCUS_SCROLL_ALIGNED);
40         return verticalGridView;
41     }
42 
43     /**
44      * @hide
45      */
46     @Override
getCallbackFragment()47     public Fragment getCallbackFragment() {
48         return getParentFragment();
49     }
50 }
51