Welcome to mirror list, hosted at ThFree Co, Russian Federation.

_HoloFragmentInflater.java « app « v4 « support « android « src « library « HoloEverywhere « 3rd_party « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2b9dbe84bd1e2cb2f802b6edc10757b0089e5a48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

package android.support.v4.app;

import org.holoeverywhere.LayoutInflater;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.support.v4.app.FragmentActivity.FragmentTag;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class _HoloFragmentInflater {
    private static View inflate(AttributeSet attrs, View parent, FragmentActivity activity,
            Fragment parentFragment) {
        String fname = attrs.getAttributeValue(null, "class");
        TypedArray a = activity.obtainStyledAttributes(attrs, FragmentTag.Fragment);
        if (fname == null) {
            fname = a.getString(FragmentTag.Fragment_name);
        }
        if (fname.startsWith(".")) {
            fname = activity.getPackageName() + fname;
        }
        int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
        String tag = a.getString(FragmentTag.Fragment_tag);
        a.recycle();
        int containerId = parent != null ? parent.getId() : 0;
        if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
            throw new IllegalArgumentException(
                    attrs.getPositionDescription()
                            + ": Must specify unique android:id, android:tag, or have a parent with an id for "
                            + fname);
        }
        final FragmentManagerImpl fm = obtainFragmentManager(activity, parentFragment);
        Fragment fragment = id != View.NO_ID ? fm.findFragmentById(id) : null;
        if (fragment == null && tag != null) {
            fragment = fm.findFragmentByTag(tag);
        }
        if (fragment == null && containerId != View.NO_ID) {
            fragment = fm.findFragmentById(containerId);
        }
        if (fragment == null) {
            fragment = Fragment.instantiate(activity, fname);
            fragment.mParentFragment = parentFragment;
            fragment.mFromLayout = true;
            fragment.mFragmentId = id != 0 ? id : containerId;
            fragment.mContainer = (ViewGroup) parent;
            fragment.mContainerId = containerId;
            fragment.mTag = tag;
            fragment.mInLayout = true;
            fragment.mFragmentManager = fm;
            fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
            fm.addFragment(fragment, false);
            fm.moveToState(fragment, Fragment.CREATED, 0, 0, false);
        } else if (fragment.mInLayout) {
            throw new IllegalArgumentException(attrs.getPositionDescription()
                    + ": Duplicate id 0x" + Integer.toHexString(id)
                    + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)
                    + " with another fragment for " + fname);
        } else {
            fragment.mInLayout = true;
            if (!fragment.mRetaining) {
                fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
            }
            fm.moveToState(fragment, Fragment.CREATED, 0, 0, false);
        }
        if (fragment.mView == null) {
            throw new IllegalStateException("Fragment " + fname
                    + " did not create a view.");
        }
        if (id != 0) {
            fragment.mView.setId(id);
        }
        if (fragment.mView.getTag() == null) {
            fragment.mView.setTag(tag);
        }
        return fragment.mView;
    }

    public static View inflate(LayoutInflater layoutInflater, AttributeSet attrs, View parent,
            Fragment fragment) {
        FragmentActivity activity = layoutInflater.getFragmentActivity();
        if (activity != null) {
            return inflate(attrs, parent, activity, fragment);
        }
        Context context = layoutInflater.getContext();
        while (context instanceof ContextWrapper) {
            if (context instanceof FragmentActivity) {
                activity = (FragmentActivity) context;
                break;
            }
            context = ((ContextWrapper) context).getBaseContext();
        }
        if (activity == null) {
            throw new IllegalStateException("Cannot find any reference to FragmentActivity");
        }
        return inflate(attrs, parent, activity, fragment);
    }

    private static FragmentManagerImpl obtainFragmentManager(FragmentActivity activity,
            Fragment fragment) {
        FragmentManagerImpl fm = null;
        if (fragment != null) {
            fm = fragment.mChildFragmentManager;
            if (fm == null) {
                try {
                    fm = (FragmentManagerImpl) fragment.getChildFragmentManager();
                } catch (ClassCastException e) {
                    fm = fragment.mChildFragmentManager;
                }
            }
        }
        if (fm == null && activity != null) {
            fm = activity.mFragments;
        }
        return fm;
    }
}