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