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

Commit fb79f554 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Android (Google) Code Review
Browse files

Merge "Add the ability to specify a list of tutorial steps in the gesture...

Merge "Add the ability to specify a list of tutorial steps in the gesture sandbox tutorial intent." into ub-launcher3-master
parents f6b05068 cf0b275a
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -104,7 +104,13 @@ final class AssistantGestureTutorialController extends TutorialController {
                        hideFeedback();
                        hideHandCoachingAnimation();
                        showRippleEffect(
                                () -> mTutorialFragment.changeController(ASSISTANT_COMPLETE));
                                () -> {
                                    if (mTutorialFragment.isTutorialComplete()) {
                                        mTutorialFragment.changeController(ASSISTANT_COMPLETE);
                                    } else {
                                        mTutorialFragment.continueTutorial();
                                    }
                                });
                        break;
                    case ASSISTANT_NOT_STARTED_BAD_ANGLE:
                        showFeedback(R.string.assistant_gesture_feedback_swipe_not_diagonal);
+7 −1
Original line number Diff line number Diff line
@@ -130,7 +130,13 @@ final class BackGestureTutorialController extends TutorialController {
                hideFeedback();
                hideHandCoachingAnimation();
                showRippleEffect(
                        () -> mTutorialFragment.changeController(BACK_NAVIGATION_COMPLETE));
                        () -> {
                            if (mTutorialFragment.isTutorialComplete()) {
                                mTutorialFragment.changeController(BACK_NAVIGATION_COMPLETE);
                            } else {
                                mTutorialFragment.continueTutorial();
                            }
                        });
                break;
            case BACK_CANCELLED_FROM_LEFT:
                showFeedback(R.string.back_gesture_feedback_cancelled_left_edge);
+65 −11
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.quickstep.interaction;

import static com.android.quickstep.interaction.TutorialFragment.KEY_TUTORIAL_TYPE;

import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
@@ -25,11 +23,14 @@ import android.view.Display;
import android.view.View;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.android.launcher3.R;
import com.android.quickstep.interaction.TutorialController.TutorialType;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;

/** Shows the gesture interactive sandbox in full screen mode. */
@@ -37,6 +38,9 @@ public class GestureSandboxActivity extends FragmentActivity {

    private static final String LOG_TAG = "GestureSandboxActivity";

    private static final String KEY_TUTORIAL_STEPS = "tutorial_steps";

    private Deque<TutorialType> mTutorialSteps;
    private TutorialFragment mFragment;

    @Override
@@ -45,7 +49,9 @@ public class GestureSandboxActivity extends FragmentActivity {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.gesture_tutorial_activity);

        mFragment = TutorialFragment.newInstance(getTutorialType(getIntent().getExtras()));
        Bundle args = savedInstanceState == null ? getIntent().getExtras() : savedInstanceState;
        mTutorialSteps = getTutorialSteps(args);
        mFragment = TutorialFragment.newInstance(mTutorialSteps.pop());
        getSupportFragmentManager().beginTransaction()
                .add(R.id.gesture_tutorial_fragment_container, mFragment)
                .commit();
@@ -72,17 +78,65 @@ public class GestureSandboxActivity extends FragmentActivity {
        }
    }

    private TutorialType getTutorialType(Bundle extras) {
        TutorialType defaultType = TutorialType.RIGHT_EDGE_BACK_NAVIGATION;
    @Override
    protected void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
        savedInstanceState.putStringArray(KEY_TUTORIAL_STEPS, getTutorialStepNames());
        super.onSaveInstanceState(savedInstanceState);
    }

    /** Returns true iff there aren't anymore tutorial types to display to the user. */
    public boolean isTutorialComplete() {
        return mTutorialSteps.isEmpty();
    }

    /**
     * Replaces the current TutorialFragment, continuing to the next tutorial step if there is one.
     *
     * If there is no following step, the tutorial is closed.
     */
    public void continueTutorial() {
        if (isTutorialComplete()) {
            mFragment.closeTutorial();
            return;
        }
        mFragment = TutorialFragment.newInstance(mTutorialSteps.pop());
        getSupportFragmentManager().beginTransaction()
            .replace(R.id.gesture_tutorial_fragment_container, mFragment)
            .runOnCommit(() -> mFragment.onAttachedToWindow())
            .commit();
    }

    private String[] getTutorialStepNames() {
        String[] tutorialStepNames = new String[mTutorialSteps.size()];

        int i = 0;
        for (TutorialType tutorialStep : mTutorialSteps) {
            tutorialStepNames[i++] = tutorialStep.name();
        }

        return tutorialStepNames;
    }

    private Deque<TutorialType> getTutorialSteps(Bundle extras) {
        Deque<TutorialType> defaultSteps = new ArrayDeque<>();
        defaultSteps.push(TutorialType.RIGHT_EDGE_BACK_NAVIGATION);

        if (extras == null || !extras.containsKey(KEY_TUTORIAL_STEPS)) {
            return defaultSteps;
        }

        String[] tutorialStepNames = extras.getStringArray(KEY_TUTORIAL_STEPS);

        if (extras == null || !extras.containsKey(KEY_TUTORIAL_TYPE)) {
            return defaultType;
        if (tutorialStepNames == null) {
            return defaultSteps;
        }
        try {
            return TutorialType.valueOf(extras.getString(KEY_TUTORIAL_TYPE, ""));
        } catch (IllegalArgumentException e) {
            return defaultType;

        Deque<TutorialType> tutorialSteps = new ArrayDeque<>();
        for (String tutorialStepName : tutorialStepNames) {
            tutorialSteps.addLast(TutorialType.valueOf(tutorialStepName));
        }

        return tutorialSteps;
    }

    private void hideSystemUI() {
+7 −2
Original line number Diff line number Diff line
@@ -94,8 +94,13 @@ final class HomeGestureTutorialController extends SwipeUpGestureTutorialControll
            case HOME_NAVIGATION:
                switch (result) {
                    case HOME_GESTURE_COMPLETED: {
                        animateFakeTaskViewHome(finalVelocity, () ->
                                mTutorialFragment.changeController(HOME_NAVIGATION_COMPLETE));
                        animateFakeTaskViewHome(finalVelocity, () -> {
                            if (mTutorialFragment.isTutorialComplete()) {
                                mTutorialFragment.changeController(HOME_NAVIGATION_COMPLETE);
                            } else {
                                mTutorialFragment.continueTutorial();
                            }
                        });
                        break;
                    }
                    case HOME_NOT_STARTED_TOO_FAR_FROM_EDGE:
+7 −2
Original line number Diff line number Diff line
@@ -104,8 +104,13 @@ final class OverviewGestureTutorialController extends SwipeUpGestureTutorialCont
                        showFeedback(R.string.overview_gesture_feedback_swipe_too_far_from_edge);
                        break;
                    case OVERVIEW_GESTURE_COMPLETED:
                        fadeOutFakeTaskView(true, () ->
                                mTutorialFragment.changeController(OVERVIEW_NAVIGATION_COMPLETE));
                        fadeOutFakeTaskView(true, () -> {
                            if (mTutorialFragment.isTutorialComplete()) {
                                mTutorialFragment.changeController(OVERVIEW_NAVIGATION_COMPLETE);
                            } else {
                                mTutorialFragment.continueTutorial();
                            }
                        });
                        break;
                    case HOME_OR_OVERVIEW_NOT_STARTED_WRONG_SWIPE_DIRECTION:
                    case HOME_OR_OVERVIEW_CANCELLED:
Loading