Fix incorrect fragment in gesture tutorial when rotating the screen
This change makes the current fragment load on configuration changes for the gesture navigation tutorial. Previously, the old fragment would be recreated causing inconsistencies when rotating the screen. Not marking a flag as this change is for both the previous gesture tutorial and the current one. Fix: 317162126 Test: Run the tutorial and rotate the screen after each step. The tutorial should progress like normal. Flag: N/A Change-Id: I09c40006dd0ef6e9e78fa44e36962a678918420a
This commit is contained in:
@@ -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