1package org.robolectric.shadows;
2
3import android.content.Context;
4import android.util.AttributeSet;
5import android.view.LayoutInflater;
6import android.view.View;
7
8/**
9 * Robolectric implementation of {@link android.view.LayoutInflater}.
10 */
11public class RoboLayoutInflater extends LayoutInflater {
12  private static final String[] sClassPrefixList = {
13      "android.widget.",
14      "android.webkit."
15  };
16
17  /**
18   * Instead of instantiating directly, you should retrieve an instance
19   * through {@link android.content.Context#getSystemService}
20   *
21   * @param context The Context in which in which to find resources and other
22   *                application-specific things.
23   *
24   * @see android.content.Context#getSystemService
25   */
26  public RoboLayoutInflater(Context context) {
27    super(context);
28  }
29
30  RoboLayoutInflater(LayoutInflater original, Context newContext) {
31    super(original, newContext);
32  }
33
34  /** Override onCreateView to instantiate names that correspond to the
35   widgets known to the Widget factory. If we don't find a match,
36   call through to our super class.
37   */
38  @Override protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException {
39    for (String prefix : sClassPrefixList) {
40      try {
41        View view = createView(name, prefix, attrs);
42        if (view != null) {
43          return view;
44        }
45      } catch (ClassNotFoundException e) {
46        // In this case we want to let the base class take a crack
47        // at it.
48      }
49    }
50
51    return super.onCreateView(name, attrs);
52  }
53
54  @Override public LayoutInflater cloneInContext(Context newContext) {
55    return new RoboLayoutInflater(this, newContext);
56  }
57}
58