import java.io.FileDescriptor;
import java.io.PrintWriter;
-final class FragmentState implements Parcelable {
- final String mClassName;
- final int mIndex;
- final boolean mFromLayout;
- final int mFragmentId;
- final int mContainerId;
- final String mTag;
- final boolean mRetainInstance;
- final boolean mDetached;
- final Bundle mArguments;
- final boolean mHidden;
-
- Bundle mSavedFragmentState;
-
- Fragment mInstance;
-
- public FragmentState(Fragment frag) {
- mClassName = frag.getClass().getName();
- mIndex = frag.mIndex;
- mFromLayout = frag.mFromLayout;
- mFragmentId = frag.mFragmentId;
- mContainerId = frag.mContainerId;
- mTag = frag.mTag;
- mRetainInstance = frag.mRetainInstance;
- mDetached = frag.mDetached;
- mArguments = frag.mArguments;
- mHidden = frag.mHidden;
- }
-
- public FragmentState(Parcel in) {
- mClassName = in.readString();
- mIndex = in.readInt();
- mFromLayout = in.readInt() != 0;
- mFragmentId = in.readInt();
- mContainerId = in.readInt();
- mTag = in.readString();
- mRetainInstance = in.readInt() != 0;
- mDetached = in.readInt() != 0;
- mArguments = in.readBundle();
- mHidden = in.readInt() != 0;
- mSavedFragmentState = in.readBundle();
- }
-
- public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
- Fragment parent, FragmentManagerNonConfig childNonConfig) {
- if (mInstance == null) {
- final Context context = host.getContext();
- if (mArguments != null) {
- mArguments.setClassLoader(context.getClassLoader());
- }
-
- if (container != null) {
- mInstance = container.instantiate(context, mClassName, mArguments);
- } else {
- mInstance = Fragment.instantiate(context, mClassName, mArguments);
- }
-
- if (mSavedFragmentState != null) {
- mSavedFragmentState.setClassLoader(context.getClassLoader());
- mInstance.mSavedFragmentState = mSavedFragmentState;
- }
- mInstance.setIndex(mIndex, parent);
- mInstance.mFromLayout = mFromLayout;
- mInstance.mRestored = true;
- mInstance.mFragmentId = mFragmentId;
- mInstance.mContainerId = mContainerId;
- mInstance.mTag = mTag;
- mInstance.mRetainInstance = mRetainInstance;
- mInstance.mDetached = mDetached;
- mInstance.mHidden = mHidden;
- mInstance.mFragmentManager = host.mFragmentManager;
- if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG,
- "Instantiated fragment " + mInstance);
- }
- mInstance.mChildNonConfig = childNonConfig;
- return mInstance;
- }
-
- public int describeContents() {
- return 0;
- }
-
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(mClassName);
- dest.writeInt(mIndex);
- dest.writeInt(mFromLayout ? 1 : 0);
- dest.writeInt(mFragmentId);
- dest.writeInt(mContainerId);
- dest.writeString(mTag);
- dest.writeInt(mRetainInstance ? 1 : 0);
- dest.writeInt(mDetached ? 1 : 0);
- dest.writeBundle(mArguments);
- dest.writeInt(mHidden ? 1 : 0);
- dest.writeBundle(mSavedFragmentState);
- }
-
- public static final Parcelable.Creator<FragmentState> CREATOR
- = new Parcelable.Creator<FragmentState>() {
- public FragmentState createFromParcel(Parcel in) {
- return new FragmentState(in);
- }
-
- public FragmentState[] newArray(int size) {
- return new FragmentState[size];
- }
- };
-}
-
/**
* A Fragment is a piece of an application's user interface or behavior
* that can be placed in an {@link Activity}. Interaction with fragments
/**
* Return true if the fragment is currently visible to the user. This means
- * it: (1) has been added, (2) has its view attached to the window, and
+ * it: (1) has been added, (2) has its view attached to the window, and
* (3) is not hidden.
*/
final public boolean isVisible() {
* declaration for the styleable used here is:</p>
*
* {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
- *
+ *
* <p>The fragment can then be declared within its activity's content layout
* through a tag like this:</p>
*
--- /dev/null
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.app;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+final class FragmentState implements Parcelable {
+ final String mClassName;
+ final int mIndex;
+ final boolean mFromLayout;
+ final int mFragmentId;
+ final int mContainerId;
+ final String mTag;
+ final boolean mRetainInstance;
+ final boolean mDetached;
+ final Bundle mArguments;
+ final boolean mHidden;
+
+ Bundle mSavedFragmentState;
+
+ Fragment mInstance;
+
+ FragmentState(Fragment frag) {
+ mClassName = frag.getClass().getName();
+ mIndex = frag.mIndex;
+ mFromLayout = frag.mFromLayout;
+ mFragmentId = frag.mFragmentId;
+ mContainerId = frag.mContainerId;
+ mTag = frag.mTag;
+ mRetainInstance = frag.mRetainInstance;
+ mDetached = frag.mDetached;
+ mArguments = frag.mArguments;
+ mHidden = frag.mHidden;
+ }
+
+ FragmentState(Parcel in) {
+ mClassName = in.readString();
+ mIndex = in.readInt();
+ mFromLayout = in.readInt() != 0;
+ mFragmentId = in.readInt();
+ mContainerId = in.readInt();
+ mTag = in.readString();
+ mRetainInstance = in.readInt() != 0;
+ mDetached = in.readInt() != 0;
+ mArguments = in.readBundle();
+ mHidden = in.readInt() != 0;
+ mSavedFragmentState = in.readBundle();
+ }
+
+ public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
+ Fragment parent, FragmentManagerNonConfig childNonConfig) {
+ if (mInstance == null) {
+ final Context context = host.getContext();
+ if (mArguments != null) {
+ mArguments.setClassLoader(context.getClassLoader());
+ }
+
+ if (container != null) {
+ mInstance = container.instantiate(context, mClassName, mArguments);
+ } else {
+ mInstance = Fragment.instantiate(context, mClassName, mArguments);
+ }
+
+ if (mSavedFragmentState != null) {
+ mSavedFragmentState.setClassLoader(context.getClassLoader());
+ mInstance.mSavedFragmentState = mSavedFragmentState;
+ }
+ mInstance.setIndex(mIndex, parent);
+ mInstance.mFromLayout = mFromLayout;
+ mInstance.mRestored = true;
+ mInstance.mFragmentId = mFragmentId;
+ mInstance.mContainerId = mContainerId;
+ mInstance.mTag = mTag;
+ mInstance.mRetainInstance = mRetainInstance;
+ mInstance.mDetached = mDetached;
+ mInstance.mHidden = mHidden;
+ mInstance.mFragmentManager = host.mFragmentManager;
+
+ if (FragmentManagerImpl.DEBUG) {
+ Log.v(FragmentManagerImpl.TAG, "Instantiated fragment " + mInstance);
+ }
+ }
+ mInstance.mChildNonConfig = childNonConfig;
+ return mInstance;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(mClassName);
+ dest.writeInt(mIndex);
+ dest.writeInt(mFromLayout ? 1 : 0);
+ dest.writeInt(mFragmentId);
+ dest.writeInt(mContainerId);
+ dest.writeString(mTag);
+ dest.writeInt(mRetainInstance ? 1 : 0);
+ dest.writeInt(mDetached ? 1 : 0);
+ dest.writeBundle(mArguments);
+ dest.writeInt(mHidden ? 1 : 0);
+ dest.writeBundle(mSavedFragmentState);
+ }
+
+ public static final Parcelable.Creator<FragmentState> CREATOR =
+ new Parcelable.Creator<FragmentState>() {
+ @Override
+ public FragmentState createFromParcel(Parcel in) {
+ return new FragmentState(in);
+ }
+
+ @Override
+ public FragmentState[] newArray(int size) {
+ return new FragmentState[size];
+ }
+ };
+}
\ No newline at end of file