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