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;
|
@Nullable private TutorialType[] mTutorialSteps;
|
||||||
private GestureSandboxFragment mCurrentFragment;
|
private GestureSandboxFragment mCurrentFragment;
|
||||||
private GestureSandboxFragment mPendingFragment;
|
|
||||||
|
|
||||||
private int mCurrentStep;
|
private int mCurrentStep;
|
||||||
private int mNumSteps;
|
private int mNumSteps;
|
||||||
@@ -177,22 +176,16 @@ public class GestureSandboxActivity extends FragmentActivity {
|
|||||||
&& getResources().getConfiguration().orientation
|
&& getResources().getConfiguration().orientation
|
||||||
== ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
== ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||||
|
|
||||||
GestureSandboxFragment recreatedFragment =
|
|
||||||
showRotationPrompt || mPendingFragment == null
|
|
||||||
? null : mPendingFragment.recreateFragment();
|
|
||||||
showFragment(showRotationPrompt
|
showFragment(showRotationPrompt
|
||||||
? new RotationPromptFragment()
|
? new RotationPromptFragment()
|
||||||
: recreatedFragment == null
|
: mCurrentFragment.canRecreateFragment()
|
||||||
? mCurrentFragment : recreatedFragment);
|
? mCurrentFragment.recreateFragment() : mCurrentFragment);
|
||||||
} else {
|
} else {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showFragment(@NonNull GestureSandboxFragment fragment) {
|
private void showFragment(@NonNull GestureSandboxFragment fragment) {
|
||||||
if (mCurrentFragment.recreateFragment() != null) {
|
|
||||||
mPendingFragment = mCurrentFragment;
|
|
||||||
}
|
|
||||||
mCurrentFragment = fragment;
|
mCurrentFragment = fragment;
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.replace(R.id.gesture_tutorial_fragment_container, mCurrentFragment)
|
.replace(R.id.gesture_tutorial_fragment_container, mCurrentFragment)
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public abstract class GestureSandboxFragment extends Fragment {
|
|||||||
|
|
||||||
void onDetachedFromWindow() {}
|
void onDetachedFromWindow() {}
|
||||||
|
|
||||||
|
boolean canRecreateFragment() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
GestureSandboxFragment recreateFragment() {
|
GestureSandboxFragment recreateFragment() {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ public final class MenuFragment extends GestureSandboxFragment {
|
|||||||
return new MenuFragment();
|
return new MenuFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean canRecreateFragment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ abstract class TutorialFragment extends GestureSandboxFragment implements OnTouc
|
|||||||
return newInstance(tutorialType, isGestureComplete(), mFromTutorialMenu);
|
return newInstance(tutorialType, isGestureComplete(), mFromTutorialMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean canRecreateFragment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
abstract TutorialType getDefaultTutorialType();
|
abstract TutorialType getDefaultTutorialType();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user