Move to Android N-MR1 SDK.
[android_tools.git] / sdk / sources / android-25 / com / android / setupwizardlib / GlifPreferenceLayout.java
blobd334d7dc1f3c5ae8153ef163e4a62c5dd780b24a
1 /*
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;
27 /**
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}.
32 * <p />Example:
33 * <pre>{@code
34 * &lt;style android:name="MyActivityTheme">
35 * &lt;item android:name="preferenceTheme">@style/MyPreferenceTheme&lt;/item>
36 * &lt;/style>
38 * &lt;style android:name="MyPreferenceTheme">
39 * &lt;item android:name="preferenceFragmentStyle">@style/MyPreferenceFragmentStyle&lt;/item>
40 * &lt;/style>
42 * &lt;style android:name="MyPreferenceFragmentStyle">
43 * &lt;item android:name="android:layout">@layout/my_preference_layout&lt;/item>
44 * &lt;/style>
45 * }</pre>
47 * where {@code my_preference_layout} is a layout that contains
48 * {@link com.android.setupwizardlib.GlifPreferenceLayout}.
50 * <p />Example:
51 * <pre>{@code
52 * &lt;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" />
57 * }</pre>
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,
62 * android.os.Bundle)}
64 public class GlifPreferenceLayout extends GlifRecyclerLayout {
66 private RecyclerView mRecyclerView;
68 public GlifPreferenceLayout(Context context) {
69 super(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() {
85 return mRecyclerView;
88 @Override
89 protected ViewGroup findContainer(int containerId) {
90 if (containerId == 0) {
91 containerId = R.id.suw_layout_content;
93 return super.findContainer(containerId);
96 /**
97 * This method must be called in {@code PreferenceFragment#onCreateRecyclerView}.
99 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
100 Bundle savedInstanceState) {
101 return mRecyclerView;
104 @Override
105 protected View onInflateTemplate(LayoutInflater inflater, int template) {
106 if (template == 0) {
107 template = R.layout.suw_glif_preference_template;
109 return super.onInflateTemplate(inflater, template);
112 @Override
113 protected void onTemplateInflated() {
114 // Inflate the recycler view here, so attributes on the decoration views can be applied
115 // immediately.
116 final LayoutInflater inflater = LayoutInflater.from(getContext());
117 mRecyclerView = (RecyclerView) inflater.inflate(R.layout.suw_glif_preference_recycler_view,
118 this, false);
119 initRecyclerView(mRecyclerView);