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