110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta/* 210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * Copyright (C) 2014 The Android Open Source Project 310bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * 410bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * Licensed under the Apache License, Version 2.0 (the "License"); 510bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * you may not use this file except in compliance with the License. 610bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * You may obtain a copy of the License at 710bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * 810bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * http://www.apache.org/licenses/LICENSE-2.0 910bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * 1010bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * Unless required by applicable law or agreed to in writing, software 1110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * distributed under the License is distributed on an "AS IS" BASIS, 1210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1310bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * See the License for the specific language governing permissions and 1410bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta * limitations under the License. 1510bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta */ 1610bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 1710bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Guptapackage android.preference; 1810bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 190ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Guptaimport com.android.layoutlib.bridge.android.BridgeContext; 2010bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Guptaimport com.android.layoutlib.bridge.android.BridgeXmlBlockParser; 2110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 2210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Guptaimport android.content.Context; 2310bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Guptaimport android.util.AttributeSet; 2410bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 2510bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Guptapublic class BridgePreferenceInflater extends PreferenceInflater { 2610bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 270ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta public BridgePreferenceInflater(Context context, PreferenceManager preferenceManager) { 2810bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta super(context, preferenceManager); 2910bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta } 3010bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta 3110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta @Override 3210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta protected Preference onCreateItem(String name, AttributeSet attrs) 3310bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta throws ClassNotFoundException { 340ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta Object viewKey = null; 350ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta BridgeContext bc = null; 360ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta 370ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta Context context = getContext(); 380ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta if (context instanceof BridgeContext) { 390ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta bc = (BridgeContext) context; 400ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta } 4110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta if (attrs instanceof BridgeXmlBlockParser) { 4210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie(); 4310bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta } 440ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta 4510bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta Preference preference = super.onCreateItem(name, attrs); 460ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta 470ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta if (viewKey != null && bc != null) { 480ff4568ca07c16f2ad4c61872995200115292ecfDeepanshu Gupta bc.addCookie(preference, viewKey); 4910bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta } 5010bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta return preference; 5110bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta } 5210bb1371dca38b5b59f083ee963f7987da6511f2Deepanshu Gupta} 53