Merge "Fix incorrect fragment in gesture tutorial when rotating the screen" into 24D1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ca987a3dff
@@ -59,7 +59,6 @@ public class GestureSandboxActivity extends FragmentActivity {
|
||||
|
||||
@Nullable private TutorialType[] mTutorialSteps;
|
||||
private GestureSandboxFragment mCurrentFragment;
|
||||
private GestureSandboxFragment mPendingFragment;
|
||||
|
||||
private int mCurrentStep;
|
||||
private int mNumSteps;
|
||||
@@ -177,22 +176,16 @@ public class GestureSandboxActivity extends FragmentActivity {
|
||||
&& getResources().getConfiguration().orientation
|
||||
== ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
|
||||
GestureSandboxFragment recreatedFragment =
|
||||
showRotationPrompt || mPendingFragment == null
|
||||
? null : mPendingFragment.recreateFragment();
|
||||
showFragment(showRotationPrompt
|
||||
? new RotationPromptFragment()
|
||||
: recreatedFragment == null
|
||||
? mCurrentFragment : recreatedFragment);
|
||||
: mCurrentFragment.canRecreateFragment()
|
||||
? mCurrentFragment.recreateFragment() : mCurrentFragment);
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
}
|
||||
|
||||
private void showFragment(@NonNull GestureSandboxFragment fragment) {
|
||||
if (mCurrentFragment.recreateFragment() != null) {
|
||||
mPendingFragment = mCurrentFragment;
|
||||
}
|
||||
mCurrentFragment = fragment;
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.gesture_tutorial_fragment_container, mCurrentFragment)
|
||||
|
||||
@@ -28,6 +28,10 @@ public abstract class GestureSandboxFragment extends Fragment {
|
||||
|
||||
void onDetachedFromWindow() {}
|
||||
|
||||
boolean canRecreateFragment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
GestureSandboxFragment recreateFragment() {
|
||||
return null;
|
||||
|
||||
@@ -38,6 +38,11 @@ public final class MenuFragment extends GestureSandboxFragment {
|
||||
return new MenuFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean canRecreateFragment() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
@@ -114,6 +114,11 @@ abstract class TutorialFragment extends GestureSandboxFragment implements OnTouc
|
||||
return newInstance(tutorialType, isGestureComplete(), mFromTutorialMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean canRecreateFragment() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
abstract TutorialType getDefaultTutorialType();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user