1/*
2 * Copyright (C) 2014 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 android.support.v4.view;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.LayoutInflater;
22import android.view.View;
23
24class LayoutInflaterCompatBase {
25
26    static class FactoryWrapper implements LayoutInflater.Factory {
27
28        final LayoutInflaterFactory mDelegateFactory;
29
30        FactoryWrapper(LayoutInflaterFactory delegateFactory) {
31            mDelegateFactory = delegateFactory;
32        }
33
34        @Override
35        public View onCreateView(String name, Context context, AttributeSet attrs) {
36            return mDelegateFactory.onCreateView(null, name, context, attrs);
37        }
38
39        public String toString() {
40            return getClass().getName() + "{" + mDelegateFactory + "}";
41        }
42    }
43
44    static void setFactory(LayoutInflater inflater, LayoutInflaterFactory factory) {
45        inflater.setFactory(factory != null ? new FactoryWrapper(factory) : null);
46    }
47
48    static LayoutInflaterFactory getFactory(LayoutInflater inflater) {
49        LayoutInflater.Factory factory = inflater.getFactory();
50        if (factory instanceof FactoryWrapper) {
51            return ((FactoryWrapper) factory).mDelegateFactory;
52        }
53        return null;
54    }
55
56}
57