13885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam/* 23885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * Copyright (C) 2016 The Android Open Source Project 33885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 43885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 53885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * you may not use this file except in compliance with the License. 63885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * You may obtain a copy of the License at 73885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 83885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * http://www.apache.org/licenses/LICENSE-2.0 93885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 103885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * Unless required by applicable law or agreed to in writing, software 113885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 123885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * See the License for the specific language governing permissions and 143885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * limitations under the License. 153885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam */ 163885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 173885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lampackage com.android.setupwizardlib; 183885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 193885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.content.Context; 203885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.os.Bundle; 213885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.support.v7.widget.RecyclerView; 223885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.util.AttributeSet; 233885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.view.LayoutInflater; 243885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.view.View; 253885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lamimport android.view.ViewGroup; 263885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 2703b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lamimport com.android.setupwizardlib.template.RecyclerMixin; 2803b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lam 293885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam/** 303885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * A layout to be used with {@code PreferenceFragment} in v14 support library. This can be specified 313885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * as the {@code android:layout} in the {@code app:preferenceFragmentStyle} in 323885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * {@code app:preferenceTheme}. 333885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 343885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <p />Example: 353885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <pre>{@code 363885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <style android:name="MyActivityTheme"> 373885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <item android:name="preferenceTheme">@style/MyPreferenceTheme</item> 383885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * </style> 393885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 403885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <style android:name="MyPreferenceTheme"> 413885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <item android:name="preferenceFragmentStyle">@style/MyPreferenceFragmentStyle</item> 423885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * </style> 433885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 443885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <style android:name="MyPreferenceFragmentStyle"> 453885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <item android:name="android:layout">@layout/my_preference_layout</item> 463885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * </style> 473885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * }</pre> 483885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 493885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * where {@code my_preference_layout} is a layout that contains 503885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * {@link com.android.setupwizardlib.SetupWizardPreferenceLayout}. 513885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 523885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <p />Example: 533885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <pre>{@code 543885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <com.android.setupwizardlib.SetupWizardPreferenceLayout 553885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * xmlns:android="http://schemas.android.com/apk/res/android" 563885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * android:id="@id/list_container" 573885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * android:layout_width="match_parent" 583885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * android:layout_height="match_parent" /> 593885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * }</pre> 603885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * 613885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * <p />Fragments using this layout <em>must</em> delegate {@code onCreateRecyclerView} to the 623885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * implementation in this class: 633885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * {@link #onCreateRecyclerView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)} 643885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam */ 653885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lampublic class SetupWizardPreferenceLayout extends SetupWizardRecyclerLayout { 663885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 673885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam public SetupWizardPreferenceLayout(Context context) { 683885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam super(context); 693885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 703885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 713885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam public SetupWizardPreferenceLayout(Context context, int template, int containerId) { 723885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam super(context, template, containerId); 733885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 743885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 753885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam public SetupWizardPreferenceLayout(Context context, AttributeSet attrs) { 763885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam super(context, attrs); 773885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 783885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 793885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam public SetupWizardPreferenceLayout(Context context, AttributeSet attrs, int defStyleAttr) { 803885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam super(context, attrs, defStyleAttr); 813885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 823885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 833885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam @Override 843885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam protected ViewGroup findContainer(int containerId) { 853885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam if (containerId == 0) { 863885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam containerId = R.id.suw_layout_content; 873885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 883885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam return super.findContainer(containerId); 893885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 903885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 913885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam /** 923885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam * This method must be called in {@code PreferenceFragment#onCreateRecyclerView}. 933885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam */ 943885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 953885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam Bundle savedInstanceState) { 9603b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lam return mRecyclerMixin.getRecyclerView(); 973885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 983885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 993885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam @Override 1003885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam protected View onInflateTemplate(LayoutInflater inflater, int template) { 1013885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam if (template == 0) { 1023885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam template = R.layout.suw_preference_template; 1033885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 1043885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam return super.onInflateTemplate(inflater, template); 1053885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 1063885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam 1073885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam @Override 1083885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam protected void onTemplateInflated() { 1093885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam // Inflate the recycler view here, so attributes on the decoration views can be applied 1103885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam // immediately. 1113885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam final LayoutInflater inflater = LayoutInflater.from(getContext()); 11203b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lam RecyclerView recyclerView = (RecyclerView) inflater.inflate( 11303b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lam R.layout.suw_preference_recycler_view, this, false); 11403b52ec3584d8f5fd25d73bd933226a150b85642Maurice Lam mRecyclerMixin = new RecyclerMixin(this, recyclerView); 1153885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam } 1163885d8491a008281d18ddbbabc5b8e26848fadccMaurice Lam} 117