Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca987a3d authored by Saumya Prakash's avatar Saumya Prakash Committed by Android (Google) Code Review
Browse files

Merge "Fix incorrect fragment in gesture tutorial when rotating the screen" into 24D1-dev

parents 3e239309 92b20d89
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -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)
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ public abstract class GestureSandboxFragment extends Fragment {

    void onDetachedFromWindow() {}

    boolean canRecreateFragment() {
        return false;
    }

    @Nullable
    GestureSandboxFragment recreateFragment() {
        return null;
+5 −0
Original line number Diff line number Diff line
@@ -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) {
+5 −0
Original line number Diff line number Diff line
@@ -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();