Merge "Fix/suppress error-prone warnings in framework's fragment." into oc-dev

This commit is contained in:
Aurimas Liutikas
2017-04-21 15:14:04 +00:00
committed by Android (Google) Code Review
4 changed files with 20 additions and 2 deletions

View File

@@ -890,6 +890,7 @@ final class BackStackRecord extends FragmentTransaction implements
* this set of ops
* @return the new oldPrimaryNav fragment after this record's ops would be run
*/
@SuppressWarnings("ReferenceEquality")
Fragment expandOps(ArrayList<Fragment> added, Fragment oldPrimaryNav) {
for (int opNum = 0; opNum < mOps.size(); opNum++) {
final Op op = mOps.get(opNum);

View File

@@ -58,6 +58,7 @@ import android.widget.AdapterView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
final class FragmentState implements Parcelable {
final String mClassName;
@@ -620,7 +621,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
}
sClassMap.put(fname, clazz);
}
Fragment f = (Fragment)clazz.newInstance();
Fragment f = (Fragment) clazz.getConstructor().newInstance();
if (args != null) {
args.setClassLoader(f.getClass().getClassLoader());
f.setArguments(args);
@@ -638,6 +639,12 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
throw new InstantiationException("Unable to instantiate fragment " + fname
+ ": make sure class name exists, is public, and has an"
+ " empty constructor that is public", e);
} catch (NoSuchMethodException e) {
throw new InstantiationException("Unable to instantiate fragment " + fname
+ ": could not find Fragment constructor", e);
} catch (InvocationTargetException e) {
throw new InstantiationException("Unable to instantiate fragment " + fname
+ ": calling Fragment constructor caused an exception", e);
}
}

View File

@@ -1123,6 +1123,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
return mCurState >= state;
}
@SuppressWarnings("ReferenceEquality")
void moveToState(Fragment f, int newState, int transit, int transitionStyle,
boolean keepActive) {
if (DEBUG && false) Log.v(TAG, "moveToState: " + f
@@ -1226,6 +1227,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
}
f.mRetaining = false;
}
// fall through
case Fragment.CREATED:
// This is outside the if statement below on purpose; we want this to run
// even if we do a moveToState from CREATED => *, CREATED => CREATED, and
@@ -1286,16 +1288,19 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
}
f.mSavedFragmentState = null;
}
// fall through
case Fragment.ACTIVITY_CREATED:
if (newState > Fragment.ACTIVITY_CREATED) {
f.mState = Fragment.STOPPED;
}
// fall through
case Fragment.STOPPED:
if (newState > Fragment.STOPPED) {
if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
f.performStart();
dispatchOnFragmentStarted(f, false);
}
// fall through
case Fragment.STARTED:
if (newState > Fragment.STARTED) {
if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f);
@@ -1314,12 +1319,14 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
f.performPause();
dispatchOnFragmentPaused(f, false);
}
// fall through
case Fragment.STARTED:
if (newState < Fragment.STARTED) {
if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);
f.performStop();
dispatchOnFragmentStopped(f, false);
}
// fall through
case Fragment.STOPPED:
case Fragment.ACTIVITY_CREATED:
if (newState < Fragment.ACTIVITY_CREATED) {
@@ -1374,6 +1381,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
f.mView = null;
f.mInLayout = false;
}
// fall through
case Fragment.CREATED:
if (newState < Fragment.CREATED) {
if (mDestroyed) {
@@ -3192,6 +3200,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
}
}
@SuppressWarnings("ReferenceEquality")
public void setPrimaryNavigationFragment(Fragment f) {
if (f != null && (mActive.get(f.mIndex) != f
|| (f.mHost != null && f.getFragmentManager() != this))) {

View File

@@ -1236,6 +1236,7 @@ class FragmentTransition {
* added fragments have Views in the hierarchy or false if the
* operations haven't been executed yet.
*/
@SuppressWarnings("ReferenceEquality")
private static void addToFirstInLastOut(BackStackRecord transaction, BackStackRecord.Op op,
SparseArray<FragmentContainerTransition> transitioningFragments, boolean isPop,
boolean isOptimizedTransaction) {
@@ -1305,7 +1306,7 @@ class FragmentTransition {
containerTransition.firstOut = null;
}
/**
/*
* Ensure that fragments that are entering are at least at the CREATED state
* so that they may load Transitions using TransitionInflater.
*/