1/* 2 * Copyright (C) 2006 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.internal.policy.impl; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.view.View; 22import android.view.LayoutInflater; 23 24public class PhoneLayoutInflater extends LayoutInflater { 25 private static final String[] sClassPrefixList = { 26 "android.widget.", 27 "android.webkit.", 28 "android.app." 29 }; 30 31 /** 32 * Instead of instantiating directly, you should retrieve an instance 33 * through {@link Context#getSystemService} 34 * 35 * @param context The Context in which in which to find resources and other 36 * application-specific things. 37 * 38 * @see Context#getSystemService 39 */ 40 public PhoneLayoutInflater(Context context) { 41 super(context); 42 } 43 44 protected PhoneLayoutInflater(LayoutInflater original, Context newContext) { 45 super(original, newContext); 46 } 47 48 /** Override onCreateView to instantiate names that correspond to the 49 widgets known to the Widget factory. If we don't find a match, 50 call through to our super class. 51 */ 52 @Override protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException { 53 for (String prefix : sClassPrefixList) { 54 try { 55 View view = createView(name, prefix, attrs); 56 if (view != null) { 57 return view; 58 } 59 } catch (ClassNotFoundException e) { 60 // In this case we want to let the base class take a crack 61 // at it. 62 } 63 } 64 65 return super.onCreateView(name, attrs); 66 } 67 68 public LayoutInflater cloneInContext(Context newContext) { 69 return new PhoneLayoutInflater(this, newContext); 70 } 71} 72 73