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 17package com.android.settings.applications; 18 19import android.content.Context; 20import android.content.res.TypedArray; 21import android.preference.Preference; 22import android.util.AttributeSet; 23import android.view.LayoutInflater; 24import android.view.View; 25import android.view.ViewGroup; 26 27import com.android.settings.R; 28import com.android.settings.Utils; 29 30public class LayoutPreference extends Preference { 31 32 private View mRootView; 33 34 public LayoutPreference(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 setSelectable(false); 37 final TypedArray a = context.obtainStyledAttributes( 38 attrs, com.android.internal.R.styleable.Preference, 0, 0); 39 int layoutResource = a.getResourceId(com.android.internal.R.styleable.Preference_layout, 40 0); 41 if (layoutResource == 0) { 42 throw new IllegalArgumentException("LayoutPreference requires a layout to be defined"); 43 } 44 // Need to create view now so that findViewById can be called immediately. 45 final View view = LayoutInflater.from(getContext()) 46 .inflate(layoutResource, null, false); 47 48 final ViewGroup allDetails = (ViewGroup) view.findViewById(R.id.all_details); 49 if (allDetails != null) { 50 Utils.forceCustomPadding(allDetails, true /* additive padding */); 51 } 52 mRootView = view; 53 setShouldDisableView(false); 54 } 55 56 @Override 57 protected View onCreateView(ViewGroup parent) { 58 return mRootView; 59 } 60 61 @Override 62 protected void onBindView(View view) { 63 // Do nothing. 64 } 65 66 public View findViewById(int id) { 67 return mRootView.findViewById(id); 68 } 69 70} 71