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