Java 类android.support.v4.app.FragmentActivity.FragmentTag 实例源码

项目:gloomy-dungeons-2    文件:_HoloFragmentInflater.java   
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() : View.NO_ID;
    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);
    }
    FragmentManagerImpl impl = obtainFragmentManager(activity, parentFragment);
    Fragment fragment = id != View.NO_ID ? impl.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = impl.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = impl.findFragmentById(containerId);
    }
    if (fragment == null) {
        fragment = Fragment.instantiate(activity, fname);
        fragment.mParentFragment = parentFragment;
        fragment.mActivity = activity;
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainer = (ViewGroup) parent;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = impl;
        fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        impl.addFragment(fragment, true);
    } 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);
        }
        impl.moveToState(fragment);
    }
    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;
}
项目:laposte-android    文件:_HoloFragmentInflater.java   
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);
    }
    FragmentManagerImpl impl = obtainFragmentManager(activity, parentFragment);
    Fragment fragment = id != View.NO_ID ? impl.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = impl.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = impl.findFragmentById(containerId);
    }
    if (fragment == null) {
        fragment = Fragment.instantiate(activity, fname);
        fragment.mParentFragment = parentFragment;
        fragment.mActivity = activity;
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainer = (ViewGroup) parent;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = impl;
        fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        impl.addFragment(fragment, true);
    } 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);
        }
        impl.moveToState(fragment);
    }
    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;
}
项目:TflTravelAlerts    文件:_HoloFragmentInflater.java   
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);
    }
    FragmentManagerImpl impl = obtainFragmentManager(activity, parentFragment);
    Fragment fragment = id != View.NO_ID ? impl.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = impl.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = impl.findFragmentById(containerId);
    }
    if (fragment == null) {
        fragment = Fragment.instantiate(activity, fname);
        fragment.mParentFragment = parentFragment;
        fragment.mActivity = activity;
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainer = (ViewGroup) parent;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = impl;
        fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        impl.addFragment(fragment, true);
    } 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);
        }
        impl.moveToState(fragment);
    }
    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;
}