Loading api/current.xml +29 −3 Original line number Diff line number Diff line Loading @@ -20484,6 +20484,17 @@ <parameter name="exitAnim" type="int"> </parameter> </method> <method name="popBackStack" return="boolean" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public" > </method> <method name="registerForContextMenu" return="void" abstract="false" Loading Loading @@ -24938,7 +24949,7 @@ visibility="public" > </method> <method name="onLowMemory" <method name="onInflate" return="void" abstract="false" native="false" Loading @@ -24948,8 +24959,12 @@ deprecated="not deprecated" visibility="public" > <parameter name="activity" type="android.app.Activity"> </parameter> <parameter name="attrs" type="android.util.AttributeSet"> </parameter> </method> <method name="onPause" <method name="onLowMemory" return="void" abstract="false" native="false" Loading @@ -24960,7 +24975,7 @@ visibility="public" > </method> <method name="onRestart" <method name="onPause" return="void" abstract="false" native="false" Loading Loading @@ -25081,6 +25096,17 @@ <parameter name="containerViewId" type="int"> </parameter> </method> <method name="addToBackStack" return="android.app.FragmentTransaction" abstract="true" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public" > </method> <method name="commit" return="void" abstract="true" core/java/android/app/Activity.java +107 −11 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; Loading @@ -39,7 +40,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.text.Selection; import android.text.SpannableStringBuilder; Loading @@ -52,6 +52,7 @@ import android.util.Log; import android.util.SparseArray; import android.view.ContextMenu; import android.view.ContextThemeWrapper; import android.view.InflateException; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; Loading @@ -69,6 +70,7 @@ import android.view.ViewGroup.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.widget.AdapterView; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; Loading Loading @@ -652,9 +654,19 @@ public class Activity extends ContextThemeWrapper final FragmentManager mFragments = new FragmentManager(); private final class FragmentTransactionImpl implements FragmentTransaction { private final Object[] sConstructorArgs = new Object[0]; private static final Class[] sConstructorSignature = new Class[] { }; private static final HashMap<String, Constructor> sConstructorMap = new HashMap<String, Constructor>(); private final class FragmentTransactionImpl implements FragmentTransaction, Runnable, BackStackState { ArrayList<Fragment> mAdded; ArrayList<Fragment> mRemoved; boolean mAddToBackStack; boolean mCommitted; public FragmentTransaction add(Fragment fragment, int containerViewId) { return add(fragment, null, containerViewId); Loading Loading @@ -692,7 +704,18 @@ public class Activity extends ContextThemeWrapper return this; } public FragmentTransaction addToBackStack() { mAddToBackStack = true; return this; } public void commit() { if (mCommitted) throw new IllegalStateException("commit already called"); mCommitted = true; mHandler.post(this); } public void run() { if (mRemoved != null) { for (int i=mRemoved.size()-1; i>=0; i--) { mFragments.removeFragment(mRemoved.get(i)); Loading @@ -700,13 +723,28 @@ public class Activity extends ContextThemeWrapper } if (mAdded != null) { for (int i=mAdded.size()-1; i>=0; i--) { mFragments.addFragment(mAdded.get(i)); mFragments.addFragment(mAdded.get(i), false); } } mFragments.moveToState(mFragments.mCurState, true); if (mAddToBackStack) { mFragments.addBackStackState(this); } } public void popFromBackStack() { if (mAdded != null) { for (int i=mAdded.size()-1; i>=0; i--) { mFragments.removeFragment(mAdded.get(i)); } } if (mFragments != null) { mFragments.moveToState(mFragments.mCurState); if (mRemoved != null) { for (int i=mRemoved.size()-1; i>=0; i--) { mFragments.addFragment(mRemoved.get(i), false); } } mFragments.moveToState(mFragments.mCurState, true); } } private static final class ManagedCursor { Loading Loading @@ -859,6 +897,7 @@ public class Activity extends ContextThemeWrapper protected void onCreate(Bundle savedInstanceState) { mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( com.android.internal.R.styleable.Window_windowNoDisplay, false); mFragments.dispatchCreate(savedInstanceState); mCalled = true; } Loading Loading @@ -1968,14 +2007,24 @@ public class Activity extends ContextThemeWrapper return false; } /** * Pop the last fragment transition from the local activity's fragment * back stack. If there is nothing to pop, false is returned. */ public boolean popBackStack() { return mFragments.popBackStackState(mHandler); } /** * Called when the activity has detected the user's press of the back * key. The default implementation simply finishes the current activity, * but you can override this to do whatever you want. */ public void onBackPressed() { if (!popBackStack()) { finish(); } } /** * Called when a touch screen event was not handled by any of the views Loading Loading @@ -3776,17 +3825,64 @@ public class Activity extends ContextThemeWrapper } /** * Stub implementation of {@link android.view.LayoutInflater.Factory#onCreateView} used when * inflating with the LayoutInflater returned by {@link #getSystemService}. This * implementation simply returns null for all view names. * Standard implementation of * {@link android.view.LayoutInflater.Factory#onCreateView} used when * inflating with the LayoutInflater returned by {@link #getSystemService}. * This implementation handles <fragment> tags to embed fragments inside * of the activity. * * @see android.view.LayoutInflater#createView * @see android.view.Window#getLayoutInflater */ public View onCreateView(String name, Context context, AttributeSet attrs) { if (!"fragment".equals(name)) { return null; } TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment); String fname = a.getString(com.android.internal.R.styleable.Fragment_name); int id = a.getInt(com.android.internal.R.styleable.Fragment_id, 0); String tag = a.getString(com.android.internal.R.styleable.Fragment_tag); a.recycle(); Constructor constructor = sConstructorMap.get(fname); Class clazz = null; try { if (constructor == null) { // Class not found in the cache, see if it's real, and try to add it clazz = getClassLoader().loadClass(fname); constructor = clazz.getConstructor(sConstructorSignature); sConstructorMap.put(fname, constructor); } Fragment fragment = (Fragment)constructor.newInstance(sConstructorArgs); fragment.onInflate(this, attrs); mFragments.addFragment(fragment, true); if (fragment.mView == null) { throw new IllegalStateException("Fragment " + fname + " did not create a view."); } return fragment.mView; } catch (NoSuchMethodException e) { InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + fname); ie.initCause(e); throw ie; } catch (ClassNotFoundException e) { // If loadClass fails, we should propagate the exception. throw new RuntimeException(e); } catch (Exception e) { InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (clazz == null ? "<unknown>" : clazz.getName())); ie.initCause(e); throw new RuntimeException(ie); } } // ------------------ Internal API ------------------ final void setParent(Activity parent) { Loading Loading @@ -3814,6 +3910,7 @@ public class Activity extends ContextThemeWrapper mWindow = PolicyManager.makeNewWindow(this); mWindow.setCallback(this); mWindow.getLayoutInflater().setFactory(this); if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { mWindow.setSoftInputMode(info.softInputMode); } Loading Loading @@ -3847,7 +3944,6 @@ public class Activity extends ContextThemeWrapper final void performCreate(Bundle icicle) { onCreate(icicle); mFragments.dispatchCreate(icicle); } final void performStart() { Loading core/java/android/app/Fragment.java +6 −4 Original line number Diff line number Diff line Loading @@ -17,8 +17,10 @@ package android.app; import android.content.ComponentCallbacks; import android.content.Context; import android.content.res.Configuration; import android.os.Bundle; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading Loading @@ -59,6 +61,10 @@ public class Fragment implements ComponentCallbacks { return mActivity; } public void onInflate(Activity activity, AttributeSet attrs) { mCalled = true; } public void onAttach(Activity activity) { mCalled = true; } Loading @@ -78,10 +84,6 @@ public class Fragment implements ComponentCallbacks { mCalled = true; } public void onRestart() { mCalled = true; } public void onResume() { mCalled = true; } Loading core/java/android/app/FragmentManager.java +54 −12 Original line number Diff line number Diff line Loading @@ -17,15 +17,21 @@ package android.app; import android.os.Bundle; import android.os.Handler; import android.view.ViewGroup; import java.util.ArrayList; interface BackStackState { public void popFromBackStack(); } /** * Container for fragments associated with an activity. */ class FragmentManager { final ArrayList<Fragment> mFragments = new ArrayList<Fragment>(); ArrayList<Fragment> mFragments; ArrayList<BackStackState> mBackStack; int mCurState = Fragment.INITIALIZING; Activity mActivity; Loading Loading @@ -130,20 +136,32 @@ class FragmentManager { f.mState = newState; } void moveToState(int newState) { void moveToState(int newState, boolean always) { if (mActivity == null && newState != Fragment.INITIALIZING) { throw new IllegalStateException("No activity"); } if (!always && mCurState == newState) { return; } mCurState = newState; if (mFragments != null) { for (int i=0; i<mFragments.size(); i++) { Fragment f = mFragments.get(i); moveToState(f, newState); } } } public void addFragment(Fragment fragment) { public void addFragment(Fragment fragment, boolean moveToStateNow) { if (mFragments == null) { mFragments = new ArrayList<Fragment>(); } mFragments.add(fragment); if (moveToStateNow) { moveToState(fragment, mCurState); } } public void removeFragment(Fragment fragment) { Loading @@ -151,33 +169,57 @@ class FragmentManager { moveToState(fragment, Fragment.INITIALIZING); } public void addBackStackState(BackStackState state) { if (mBackStack == null) { mBackStack = new ArrayList<BackStackState>(); } mBackStack.add(state); } public boolean popBackStackState(Handler handler) { if (mBackStack == null) { return false; } int last = mBackStack.size()-1; if (last < 0) { return false; } final BackStackState bss = mBackStack.remove(last); handler.post(new Runnable() { public void run() { bss.popFromBackStack(); } }); return true; } public void attachActivity(Activity activity) { if (mActivity != null) throw new IllegalStateException(); mActivity = activity; } public void dispatchCreate(Bundle state) { moveToState(Fragment.CREATED); moveToState(Fragment.CREATED, false); } public void dispatchStart() { moveToState(Fragment.STARTED); moveToState(Fragment.STARTED, false); } public void dispatchResume() { moveToState(Fragment.RESUMED); moveToState(Fragment.RESUMED, false); } public void dispatchPause() { moveToState(Fragment.STARTED); moveToState(Fragment.STARTED, false); } public void dispatchStop() { moveToState(Fragment.CREATED); moveToState(Fragment.CREATED, false); } public void dispatchDestroy() { moveToState(Fragment.INITIALIZING); moveToState(Fragment.INITIALIZING, false); mActivity = null; } } core/java/android/app/FragmentTransaction.java +1 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ public interface FragmentTransaction { public FragmentTransaction add(Fragment fragment, int containerViewId); public FragmentTransaction add(Fragment fragment, String name, int containerViewId); public FragmentTransaction remove(Fragment fragment); public FragmentTransaction addToBackStack(); public void commit(); } Loading
api/current.xml +29 −3 Original line number Diff line number Diff line Loading @@ -20484,6 +20484,17 @@ <parameter name="exitAnim" type="int"> </parameter> </method> <method name="popBackStack" return="boolean" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public" > </method> <method name="registerForContextMenu" return="void" abstract="false" Loading Loading @@ -24938,7 +24949,7 @@ visibility="public" > </method> <method name="onLowMemory" <method name="onInflate" return="void" abstract="false" native="false" Loading @@ -24948,8 +24959,12 @@ deprecated="not deprecated" visibility="public" > <parameter name="activity" type="android.app.Activity"> </parameter> <parameter name="attrs" type="android.util.AttributeSet"> </parameter> </method> <method name="onPause" <method name="onLowMemory" return="void" abstract="false" native="false" Loading @@ -24960,7 +24975,7 @@ visibility="public" > </method> <method name="onRestart" <method name="onPause" return="void" abstract="false" native="false" Loading Loading @@ -25081,6 +25096,17 @@ <parameter name="containerViewId" type="int"> </parameter> </method> <method name="addToBackStack" return="android.app.FragmentTransaction" abstract="true" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public" > </method> <method name="commit" return="void" abstract="true"
core/java/android/app/Activity.java +107 −11 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; Loading @@ -39,7 +40,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.text.Selection; import android.text.SpannableStringBuilder; Loading @@ -52,6 +52,7 @@ import android.util.Log; import android.util.SparseArray; import android.view.ContextMenu; import android.view.ContextThemeWrapper; import android.view.InflateException; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; Loading @@ -69,6 +70,7 @@ import android.view.ViewGroup.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.widget.AdapterView; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; Loading Loading @@ -652,9 +654,19 @@ public class Activity extends ContextThemeWrapper final FragmentManager mFragments = new FragmentManager(); private final class FragmentTransactionImpl implements FragmentTransaction { private final Object[] sConstructorArgs = new Object[0]; private static final Class[] sConstructorSignature = new Class[] { }; private static final HashMap<String, Constructor> sConstructorMap = new HashMap<String, Constructor>(); private final class FragmentTransactionImpl implements FragmentTransaction, Runnable, BackStackState { ArrayList<Fragment> mAdded; ArrayList<Fragment> mRemoved; boolean mAddToBackStack; boolean mCommitted; public FragmentTransaction add(Fragment fragment, int containerViewId) { return add(fragment, null, containerViewId); Loading Loading @@ -692,7 +704,18 @@ public class Activity extends ContextThemeWrapper return this; } public FragmentTransaction addToBackStack() { mAddToBackStack = true; return this; } public void commit() { if (mCommitted) throw new IllegalStateException("commit already called"); mCommitted = true; mHandler.post(this); } public void run() { if (mRemoved != null) { for (int i=mRemoved.size()-1; i>=0; i--) { mFragments.removeFragment(mRemoved.get(i)); Loading @@ -700,13 +723,28 @@ public class Activity extends ContextThemeWrapper } if (mAdded != null) { for (int i=mAdded.size()-1; i>=0; i--) { mFragments.addFragment(mAdded.get(i)); mFragments.addFragment(mAdded.get(i), false); } } mFragments.moveToState(mFragments.mCurState, true); if (mAddToBackStack) { mFragments.addBackStackState(this); } } public void popFromBackStack() { if (mAdded != null) { for (int i=mAdded.size()-1; i>=0; i--) { mFragments.removeFragment(mAdded.get(i)); } } if (mFragments != null) { mFragments.moveToState(mFragments.mCurState); if (mRemoved != null) { for (int i=mRemoved.size()-1; i>=0; i--) { mFragments.addFragment(mRemoved.get(i), false); } } mFragments.moveToState(mFragments.mCurState, true); } } private static final class ManagedCursor { Loading Loading @@ -859,6 +897,7 @@ public class Activity extends ContextThemeWrapper protected void onCreate(Bundle savedInstanceState) { mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( com.android.internal.R.styleable.Window_windowNoDisplay, false); mFragments.dispatchCreate(savedInstanceState); mCalled = true; } Loading Loading @@ -1968,14 +2007,24 @@ public class Activity extends ContextThemeWrapper return false; } /** * Pop the last fragment transition from the local activity's fragment * back stack. If there is nothing to pop, false is returned. */ public boolean popBackStack() { return mFragments.popBackStackState(mHandler); } /** * Called when the activity has detected the user's press of the back * key. The default implementation simply finishes the current activity, * but you can override this to do whatever you want. */ public void onBackPressed() { if (!popBackStack()) { finish(); } } /** * Called when a touch screen event was not handled by any of the views Loading Loading @@ -3776,17 +3825,64 @@ public class Activity extends ContextThemeWrapper } /** * Stub implementation of {@link android.view.LayoutInflater.Factory#onCreateView} used when * inflating with the LayoutInflater returned by {@link #getSystemService}. This * implementation simply returns null for all view names. * Standard implementation of * {@link android.view.LayoutInflater.Factory#onCreateView} used when * inflating with the LayoutInflater returned by {@link #getSystemService}. * This implementation handles <fragment> tags to embed fragments inside * of the activity. * * @see android.view.LayoutInflater#createView * @see android.view.Window#getLayoutInflater */ public View onCreateView(String name, Context context, AttributeSet attrs) { if (!"fragment".equals(name)) { return null; } TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment); String fname = a.getString(com.android.internal.R.styleable.Fragment_name); int id = a.getInt(com.android.internal.R.styleable.Fragment_id, 0); String tag = a.getString(com.android.internal.R.styleable.Fragment_tag); a.recycle(); Constructor constructor = sConstructorMap.get(fname); Class clazz = null; try { if (constructor == null) { // Class not found in the cache, see if it's real, and try to add it clazz = getClassLoader().loadClass(fname); constructor = clazz.getConstructor(sConstructorSignature); sConstructorMap.put(fname, constructor); } Fragment fragment = (Fragment)constructor.newInstance(sConstructorArgs); fragment.onInflate(this, attrs); mFragments.addFragment(fragment, true); if (fragment.mView == null) { throw new IllegalStateException("Fragment " + fname + " did not create a view."); } return fragment.mView; } catch (NoSuchMethodException e) { InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + fname); ie.initCause(e); throw ie; } catch (ClassNotFoundException e) { // If loadClass fails, we should propagate the exception. throw new RuntimeException(e); } catch (Exception e) { InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (clazz == null ? "<unknown>" : clazz.getName())); ie.initCause(e); throw new RuntimeException(ie); } } // ------------------ Internal API ------------------ final void setParent(Activity parent) { Loading Loading @@ -3814,6 +3910,7 @@ public class Activity extends ContextThemeWrapper mWindow = PolicyManager.makeNewWindow(this); mWindow.setCallback(this); mWindow.getLayoutInflater().setFactory(this); if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { mWindow.setSoftInputMode(info.softInputMode); } Loading Loading @@ -3847,7 +3944,6 @@ public class Activity extends ContextThemeWrapper final void performCreate(Bundle icicle) { onCreate(icicle); mFragments.dispatchCreate(icicle); } final void performStart() { Loading
core/java/android/app/Fragment.java +6 −4 Original line number Diff line number Diff line Loading @@ -17,8 +17,10 @@ package android.app; import android.content.ComponentCallbacks; import android.content.Context; import android.content.res.Configuration; import android.os.Bundle; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading Loading @@ -59,6 +61,10 @@ public class Fragment implements ComponentCallbacks { return mActivity; } public void onInflate(Activity activity, AttributeSet attrs) { mCalled = true; } public void onAttach(Activity activity) { mCalled = true; } Loading @@ -78,10 +84,6 @@ public class Fragment implements ComponentCallbacks { mCalled = true; } public void onRestart() { mCalled = true; } public void onResume() { mCalled = true; } Loading
core/java/android/app/FragmentManager.java +54 −12 Original line number Diff line number Diff line Loading @@ -17,15 +17,21 @@ package android.app; import android.os.Bundle; import android.os.Handler; import android.view.ViewGroup; import java.util.ArrayList; interface BackStackState { public void popFromBackStack(); } /** * Container for fragments associated with an activity. */ class FragmentManager { final ArrayList<Fragment> mFragments = new ArrayList<Fragment>(); ArrayList<Fragment> mFragments; ArrayList<BackStackState> mBackStack; int mCurState = Fragment.INITIALIZING; Activity mActivity; Loading Loading @@ -130,20 +136,32 @@ class FragmentManager { f.mState = newState; } void moveToState(int newState) { void moveToState(int newState, boolean always) { if (mActivity == null && newState != Fragment.INITIALIZING) { throw new IllegalStateException("No activity"); } if (!always && mCurState == newState) { return; } mCurState = newState; if (mFragments != null) { for (int i=0; i<mFragments.size(); i++) { Fragment f = mFragments.get(i); moveToState(f, newState); } } } public void addFragment(Fragment fragment) { public void addFragment(Fragment fragment, boolean moveToStateNow) { if (mFragments == null) { mFragments = new ArrayList<Fragment>(); } mFragments.add(fragment); if (moveToStateNow) { moveToState(fragment, mCurState); } } public void removeFragment(Fragment fragment) { Loading @@ -151,33 +169,57 @@ class FragmentManager { moveToState(fragment, Fragment.INITIALIZING); } public void addBackStackState(BackStackState state) { if (mBackStack == null) { mBackStack = new ArrayList<BackStackState>(); } mBackStack.add(state); } public boolean popBackStackState(Handler handler) { if (mBackStack == null) { return false; } int last = mBackStack.size()-1; if (last < 0) { return false; } final BackStackState bss = mBackStack.remove(last); handler.post(new Runnable() { public void run() { bss.popFromBackStack(); } }); return true; } public void attachActivity(Activity activity) { if (mActivity != null) throw new IllegalStateException(); mActivity = activity; } public void dispatchCreate(Bundle state) { moveToState(Fragment.CREATED); moveToState(Fragment.CREATED, false); } public void dispatchStart() { moveToState(Fragment.STARTED); moveToState(Fragment.STARTED, false); } public void dispatchResume() { moveToState(Fragment.RESUMED); moveToState(Fragment.RESUMED, false); } public void dispatchPause() { moveToState(Fragment.STARTED); moveToState(Fragment.STARTED, false); } public void dispatchStop() { moveToState(Fragment.CREATED); moveToState(Fragment.CREATED, false); } public void dispatchDestroy() { moveToState(Fragment.INITIALIZING); moveToState(Fragment.INITIALIZING, false); mActivity = null; } }
core/java/android/app/FragmentTransaction.java +1 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ public interface FragmentTransaction { public FragmentTransaction add(Fragment fragment, int containerViewId); public FragmentTransaction add(Fragment fragment, String name, int containerViewId); public FragmentTransaction remove(Fragment fragment); public FragmentTransaction addToBackStack(); public void commit(); }