BridgePreferenceInflater.java revision 10bb1371dca38b5b59f083ee963f7987da6511f2
1/* 2 * Copyright (C) 2014 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 android.preference; 18 19import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; 20 21import android.content.Context; 22import android.util.AttributeSet; 23 24import java.util.Map; 25 26public class BridgePreferenceInflater extends PreferenceInflater { 27 28 private final Map<Preference, Object> mViewCookieMap; 29 30 public BridgePreferenceInflater(Context context, PreferenceManager preferenceManager, 31 Map<Preference, Object> viewCookieMap) { 32 super(context, preferenceManager); 33 mViewCookieMap = viewCookieMap; 34 } 35 36 @Override 37 protected Preference onCreateItem(String name, AttributeSet attrs) 38 throws ClassNotFoundException { 39 Object viewKey; 40 if (attrs instanceof BridgeXmlBlockParser) { 41 viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie(); 42 } else { 43 viewKey = null; 44 } 45 Preference preference = super.onCreateItem(name, attrs); 46 if (viewKey != null) { 47 mViewCookieMap.put(preference, viewKey); 48 } 49 return preference; 50 } 51} 52