2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com
.android
.setupwizardlib
;
19 import android
.content
.Context
;
20 import android
.os
.Bundle
;
21 import android
.support
.v7
.widget
.RecyclerView
;
22 import android
.util
.AttributeSet
;
23 import android
.view
.LayoutInflater
;
24 import android
.view
.View
;
25 import android
.view
.ViewGroup
;
28 * A layout to be used with {@code PreferenceFragment} in v14 support library. This can be specified
29 * as the {@code android:layout} in the {@code app:preferenceFragmentStyle} in
30 * {@code app:preferenceTheme}.
34 * <style android:name="MyActivityTheme">
35 * <item android:name="preferenceTheme">@style/MyPreferenceTheme</item>
38 * <style android:name="MyPreferenceTheme">
39 * <item android:name="preferenceFragmentStyle">@style/MyPreferenceFragmentStyle</item>
42 * <style android:name="MyPreferenceFragmentStyle">
43 * <item android:name="android:layout">@layout/my_preference_layout</item>
47 * where {@code my_preference_layout} is a layout that contains
48 * {@link com.android.setupwizardlib.GlifPreferenceLayout}.
52 * <com.android.setupwizardlib.GlifPreferenceLayout
53 * xmlns:android="http://schemas.android.com/apk/res/android"
54 * android:id="@id/list_container"
55 * android:layout_width="match_parent"
56 * android:layout_height="match_parent" />
59 * <p />Fragments using this layout <em>must</em> delegate {@code onCreateRecyclerView} to the
60 * implementation in this class:
61 * {@link #onCreateRecyclerView(android.view.LayoutInflater, android.view.ViewGroup,
64 public class GlifPreferenceLayout
extends GlifRecyclerLayout
{
66 private RecyclerView mRecyclerView
;
68 public GlifPreferenceLayout(Context context
) {
72 public GlifPreferenceLayout(Context context
, int template
, int containerId
) {
73 super(context
, template
, containerId
);
76 public GlifPreferenceLayout(Context context
, AttributeSet attrs
) {
77 super(context
, attrs
);
80 public GlifPreferenceLayout(Context context
, AttributeSet attrs
, int defStyleAttr
) {
81 super(context
, attrs
, defStyleAttr
);
84 public RecyclerView
getRecyclerView() {
89 protected ViewGroup
findContainer(int containerId
) {
90 if (containerId
== 0) {
91 containerId
= R
.id
.suw_layout_content
;
93 return super.findContainer(containerId
);
97 * This method must be called in {@code PreferenceFragment#onCreateRecyclerView}.
99 public RecyclerView
onCreateRecyclerView(LayoutInflater inflater
, ViewGroup parent
,
100 Bundle savedInstanceState
) {
101 return mRecyclerView
;
105 protected View
onInflateTemplate(LayoutInflater inflater
, int template
) {
107 template
= R
.layout
.suw_glif_preference_template
;
109 return super.onInflateTemplate(inflater
, template
);
113 protected void onTemplateInflated() {
114 // Inflate the recycler view here, so attributes on the decoration views can be applied
116 final LayoutInflater inflater
= LayoutInflater
.from(getContext());
117 mRecyclerView
= (RecyclerView
) inflater
.inflate(R
.layout
.suw_glif_preference_recycler_view
,
119 initRecyclerView(mRecyclerView
);