Merge "Add the gesture nav tutorial menu page" into tm-qpr-dev am: 1db2fcbd19

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22119029

Change-Id: Ie1f24b78ea9f49a1089e15331cadc35af0073490
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Schneider Victor-tulias authored and Automerger Merge Worker committed 2023-03-30 16:47:18 +00:00
commit cafab1d7cc
32 files changed
+963 -143

No files matched your search

@@ -294,17 +294,27 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
}
PreferenceCategory sandboxCategory = newCategory("Gesture Navigation Sandbox");
sandboxCategory.setSummary("Learn and practice navigation gestures");
Preference launchTutorialStepMenuPreference = new Preference(context);
launchTutorialStepMenuPreference.setKey("launchTutorialStepMenu");
launchTutorialStepMenuPreference.setTitle("Launch Gesture Tutorial Steps menu");
launchTutorialStepMenuPreference.setSummary("Select a gesture tutorial step.");
launchTutorialStepMenuPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra("use_tutorial_menu", true));
return true;
});
sandboxCategory.addPreference(launchTutorialStepMenuPreference);
Preference launchOnboardingTutorialPreference = new Preference(context);
launchOnboardingTutorialPreference.setKey("launchOnboardingTutorial");
launchOnboardingTutorialPreference.setTitle("Launch Onboarding Tutorial");
launchOnboardingTutorialPreference.setSummary("Learn the basic navigation gestures.");
launchOnboardingTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {
"HOME_NAVIGATION",
"BACK_NAVIGATION",
"OVERVIEW_NAVIGATION"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps",
new String[] {
"HOME_NAVIGATION",
"BACK_NAVIGATION",
"OVERVIEW_NAVIGATION"}));
return true;
});
sandboxCategory.addPreference(launchOnboardingTutorialPreference);
@@ -313,9 +323,9 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
launchBackTutorialPreference.setTitle("Launch Back Tutorial");
launchBackTutorialPreference.setSummary("Learn how to use the Back gesture");
launchBackTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {"BACK_NAVIGATION"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps", new String[] {"BACK_NAVIGATION"}));
return true;
});
sandboxCategory.addPreference(launchBackTutorialPreference);
@@ -324,9 +334,9 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
launchHomeTutorialPreference.setTitle("Launch Home Tutorial");
launchHomeTutorialPreference.setSummary("Learn how to use the Home gesture");
launchHomeTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {"HOME_NAVIGATION"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps", new String[] {"HOME_NAVIGATION"}));
return true;
});
sandboxCategory.addPreference(launchHomeTutorialPreference);
@@ -335,9 +345,9 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
launchOverviewTutorialPreference.setTitle("Launch Overview Tutorial");
launchOverviewTutorialPreference.setSummary("Learn how to use the Overview gesture");
launchOverviewTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {"OVERVIEW_NAVIGATION"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps", new String[] {"OVERVIEW_NAVIGATION"}));
return true;
});
sandboxCategory.addPreference(launchOverviewTutorialPreference);
@@ -346,9 +356,9 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
launchAssistantTutorialPreference.setTitle("Launch Assistant Tutorial");
launchAssistantTutorialPreference.setSummary("Learn how to use the Assistant gesture");
launchAssistantTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {"ASSISTANT"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps", new String[] {"ASSISTANT"}));
return true;
});
sandboxCategory.addPreference(launchAssistantTutorialPreference);
@@ -357,9 +367,9 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
launchSandboxModeTutorialPreference.setTitle("Launch Sandbox Mode");
launchSandboxModeTutorialPreference.setSummary("Practice navigation gestures");
launchSandboxModeTutorialPreference.setOnPreferenceClickListener(preference -> {
startActivity(launchSandboxIntent.putExtra(
"tutorial_steps",
new String[] {"SANDBOX_MODE"}));
startActivity(launchSandboxIntent
.putExtra("use_tutorial_menu", false)
.putExtra("tutorial_steps", new String[] {"SANDBOX_MODE"}));
return true;
});
sandboxCategory.addPreference(launchSandboxModeTutorialPreference);
@@ -15,8 +15,6 @@
*/
package com.android.quickstep.interaction;
import static com.android.quickstep.interaction.TutorialController.TutorialType.ASSISTANT_COMPLETE;
import android.graphics.PointF;
import com.android.launcher3.R;
@@ -47,7 +45,7 @@ final class AssistantGestureTutorialController extends TutorialController {
case ASSISTANT_COMPLETE:
if (result == BackGestureResult.BACK_COMPLETED_FROM_LEFT
|| result == BackGestureResult.BACK_COMPLETED_FROM_RIGHT) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -81,7 +79,7 @@ final class AssistantGestureTutorialController extends TutorialController {
break;
case ASSISTANT_COMPLETE:
if (result == NavBarGestureResult.HOME_GESTURE_COMPLETED) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -26,7 +26,9 @@ import com.android.quickstep.interaction.TutorialController.TutorialType;
/** Shows the Home gesture interactive tutorial. */
public class AssistantGestureTutorialFragment extends TutorialFragment {
public AssistantGestureTutorialFragment() {}
public AssistantGestureTutorialFragment(boolean fromTutorialMenu) {
super(fromTutorialMenu);
}
@Override
TutorialController createController(TutorialType type) {
@@ -109,7 +109,7 @@ final class BackGestureTutorialController extends TutorialController {
case BACK_NAVIGATION_COMPLETE:
if (result == BackGestureResult.BACK_COMPLETED_FROM_LEFT
|| result == BackGestureResult.BACK_COMPLETED_FROM_RIGHT) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -191,7 +191,7 @@ final class BackGestureTutorialController extends TutorialController {
}
if (mTutorialType == BACK_NAVIGATION_COMPLETE) {
if (result == NavBarGestureResult.HOME_GESTURE_COMPLETED) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
} else if (mTutorialType == BACK_NAVIGATION) {
switch (result) {
@@ -34,7 +34,13 @@ import java.util.ArrayList;
/** Shows the Back gesture interactive tutorial. */
public class BackGestureTutorialFragment extends TutorialFragment {
public BackGestureTutorialFragment() {}
public BackGestureTutorialFragment() {
this(false);
}
public BackGestureTutorialFragment(boolean fromTutorialMenu) {
super(fromTutorialMenu);
}
@Nullable
@Override
@@ -26,10 +26,12 @@ import android.view.View;
import android.view.Window;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.StatsLogManager;
import com.android.quickstep.TouchInteractionService.TISBinder;
import com.android.quickstep.interaction.TutorialController.TutorialType;
@@ -42,11 +44,12 @@ public class GestureSandboxActivity extends FragmentActivity {
private static final String KEY_TUTORIAL_STEPS = "tutorial_steps";
private static final String KEY_CURRENT_STEP = "current_step";
private static final String KEY_GESTURE_COMPLETE = "gesture_complete";
static final String KEY_TUTORIAL_TYPE = "tutorial_type";
static final String KEY_GESTURE_COMPLETE = "gesture_complete";
static final String KEY_USE_TUTORIAL_MENU = "use_tutorial_menu";
private TutorialType[] mTutorialSteps;
private TutorialType mCurrentTutorialStep;
private TutorialFragment mFragment;
@Nullable private TutorialType[] mTutorialSteps;
private GestureSandboxFragment mFragment;
private int mCurrentStep;
private int mNumSteps;
@@ -67,10 +70,26 @@ public class GestureSandboxActivity extends FragmentActivity {
mStatsLogManager = StatsLogManager.newInstance(getApplicationContext());
Bundle args = savedInstanceState == null ? getIntent().getExtras() : savedInstanceState;
mTutorialSteps = getTutorialSteps(args);
mCurrentTutorialStep = mTutorialSteps[mCurrentStep - 1];
mFragment = TutorialFragment.newInstance(
mCurrentTutorialStep, args.getBoolean(KEY_GESTURE_COMPLETE, false));
boolean gestureComplete = args != null && args.getBoolean(KEY_GESTURE_COMPLETE, false);
if (FeatureFlags.ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
&& args != null
&& args.getBoolean(KEY_USE_TUTORIAL_MENU, false)) {
mTutorialSteps = null;
TutorialType tutorialTypeOverride = (TutorialType) args.get(KEY_TUTORIAL_TYPE);
mFragment = tutorialTypeOverride == null
? new MenuFragment()
: makeTutorialFragment(
tutorialTypeOverride,
gestureComplete,
/* fromMenu= */ true);
} else {
mTutorialSteps = getTutorialSteps(args);
mFragment = makeTutorialFragment(
mTutorialSteps[mCurrentStep - 1],
gestureComplete,
/* fromMenu= */ false);
}
getSupportFragmentManager().beginTransaction()
.add(R.id.gesture_tutorial_fragment_container, mFragment)
.commit();
@@ -81,7 +100,9 @@ public class GestureSandboxActivity extends FragmentActivity {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
disableSystemGestures();
if (mFragment.shouldDisableSystemGestures()) {
disableSystemGestures();
}
mFragment.onAttachedToWindow();
}
@@ -103,7 +124,7 @@ public class GestureSandboxActivity extends FragmentActivity {
protected void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
savedInstanceState.putStringArray(KEY_TUTORIAL_STEPS, getTutorialStepNames());
savedInstanceState.putInt(KEY_CURRENT_STEP, mCurrentStep);
savedInstanceState.putBoolean(KEY_GESTURE_COMPLETE, mFragment.isGestureComplete());
mFragment.onSaveInstanceState(savedInstanceState);
super.onSaveInstanceState(savedInstanceState);
}
@@ -134,21 +155,45 @@ public class GestureSandboxActivity extends FragmentActivity {
* If there is no following step, the tutorial is closed.
*/
public void continueTutorial() {
if (isTutorialComplete()) {
mFragment.closeTutorial();
if (isTutorialComplete() || mTutorialSteps == null) {
mFragment.close();
return;
}
mCurrentTutorialStep = mTutorialSteps[mCurrentStep];
mFragment = TutorialFragment.newInstance(
mCurrentTutorialStep, /* gestureComplete= */ false);
launchTutorialStep(mTutorialSteps[mCurrentStep], false);
mCurrentStep++;
}
private TutorialFragment makeTutorialFragment(
@NonNull TutorialType tutorialType, boolean gestureComplete, boolean fromMenu) {
return TutorialFragment.newInstance(tutorialType, gestureComplete, fromMenu);
}
/**
* Launches the given gesture nav tutorial step.
*
* If the step is being launched from the gesture nav tutorial menu, then that step will launch
* the menu when complete.
*/
public void launchTutorialStep(@NonNull TutorialType tutorialType, boolean fromMenu) {
mFragment = makeTutorialFragment(tutorialType, false, fromMenu);
getSupportFragmentManager().beginTransaction()
.replace(R.id.gesture_tutorial_fragment_container, mFragment)
.runOnCommit(() -> mFragment.onAttachedToWindow())
.commit();
mCurrentStep++;
}
/** Launches the gesture nav tutorial menu page */
public void launchTutorialMenu() {
mFragment = new MenuFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.gesture_tutorial_fragment_container, mFragment)
.commit();
}
private String[] getTutorialStepNames() {
if (mTutorialSteps == null) {
return new String[0];
}
String[] tutorialStepNames = new String[mTutorialSteps.length];
int i = 0;
@@ -160,18 +205,19 @@ public class GestureSandboxActivity extends FragmentActivity {
}
private TutorialType[] getTutorialSteps(Bundle extras) {
TutorialType[] defaultSteps = new TutorialType[] {TutorialType.BACK_NAVIGATION};
TutorialType[] defaultSteps = new TutorialType[] {
TutorialType.HOME_NAVIGATION,
TutorialType.BACK_NAVIGATION,
TutorialType.OVERVIEW_NAVIGATION};
mCurrentStep = 1;
mNumSteps = 1;
mNumSteps = defaultSteps.length;
if (extras == null || !extras.containsKey(KEY_TUTORIAL_STEPS)) {
return defaultSteps;
}
Object savedSteps = extras.get(KEY_TUTORIAL_STEPS);
int currentStep = extras.getInt(KEY_CURRENT_STEP, -1);
String[] savedStepsNames;
Object savedSteps = extras.get(KEY_TUTORIAL_STEPS);
if (savedSteps instanceof String) {
savedStepsNames = TextUtils.isEmpty((String) savedSteps)
? null : ((String) savedSteps).split(",");
@@ -181,7 +227,7 @@ public class GestureSandboxActivity extends FragmentActivity {
return defaultSteps;
}
if (savedStepsNames == null) {
if (savedStepsNames == null || savedStepsNames.length == 0) {
return defaultSteps;
}
@@ -190,7 +236,7 @@ public class GestureSandboxActivity extends FragmentActivity {
tutorialSteps[i] = TutorialType.valueOf(savedStepsNames[i]);
}
mCurrentStep = Math.max(currentStep, 1);
mCurrentStep = Math.max(extras.getInt(KEY_CURRENT_STEP, -1), 1);
mNumSteps = tutorialSteps.length;
return tutorialSteps;
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.interaction;
import android.app.Activity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
/** Displays one page of the gesture nav tutorial. */
public abstract class GestureSandboxFragment extends Fragment {
void onAttachedToWindow() {}
void onDetachedFromWindow() {}
boolean shouldDisableSystemGestures() {
return true;
}
void close() {
FragmentActivity activity = getActivity();
if (activity != null) {
activity.setResult(Activity.RESULT_OK);
activity.finish();
}
}
}
@@ -100,7 +100,7 @@ final class HomeGestureTutorialController extends SwipeUpGestureTutorialControll
case HOME_NAVIGATION_COMPLETE:
if (result == BackGestureResult.BACK_COMPLETED_FROM_LEFT
|| result == BackGestureResult.BACK_COMPLETED_FROM_RIGHT) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -139,7 +139,7 @@ final class HomeGestureTutorialController extends SwipeUpGestureTutorialControll
break;
case HOME_NAVIGATION_COMPLETE:
if (result == NavBarGestureResult.HOME_GESTURE_COMPLETED) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -33,7 +33,13 @@ import java.util.ArrayList;
/** Shows the Home gesture interactive tutorial. */
public class HomeGestureTutorialFragment extends TutorialFragment {
public HomeGestureTutorialFragment() {}
public HomeGestureTutorialFragment() {
this(false);
}
public HomeGestureTutorialFragment(boolean fromTutorialMenu) {
super(fromTutorialMenu);
}
@Nullable
@Override
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.interaction;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_GESTURE_COMPLETE;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_TUTORIAL_TYPE;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_USE_TUTORIAL_MENU;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.R;
/** Displays the gesture nav tutorial menu. */
public final class MenuFragment extends GestureSandboxFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View root = inflater.inflate(
R.layout.gesture_tutorial_step_menu, container, false);
root.findViewById(R.id.gesture_tutorial_menu_home_button).setOnClickListener(
v -> launchTutorialStep(TutorialController.TutorialType.HOME_NAVIGATION));
root.findViewById(R.id.gesture_tutorial_menu_back_button).setOnClickListener(
v -> launchTutorialStep(TutorialController.TutorialType.BACK_NAVIGATION));
root.findViewById(R.id.gesture_tutorial_menu_overview_button).setOnClickListener(
v -> launchTutorialStep(TutorialController.TutorialType.OVERVIEW_NAVIGATION));
root.findViewById(R.id.gesture_tutorial_menu_done_button).setOnClickListener(
v -> close());
return root;
}
@Override
boolean shouldDisableSystemGestures() {
return false;
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean(KEY_USE_TUTORIAL_MENU, true);
savedInstanceState.remove(KEY_TUTORIAL_TYPE);
savedInstanceState.remove(KEY_GESTURE_COMPLETE);
super.onSaveInstanceState(savedInstanceState);
}
private void launchTutorialStep(@NonNull TutorialController.TutorialType tutorialType) {
((GestureSandboxActivity) getActivity()).launchTutorialStep(tutorialType, true);
}
}
@@ -116,7 +116,7 @@ final class OverviewGestureTutorialController extends SwipeUpGestureTutorialCont
case OVERVIEW_NAVIGATION_COMPLETE:
if (result == BackGestureResult.BACK_COMPLETED_FROM_LEFT
|| result == BackGestureResult.BACK_COMPLETED_FROM_RIGHT) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -178,7 +178,7 @@ final class OverviewGestureTutorialController extends SwipeUpGestureTutorialCont
break;
case OVERVIEW_NAVIGATION_COMPLETE:
if (result == NavBarGestureResult.HOME_GESTURE_COMPLETED) {
mTutorialFragment.closeTutorial();
mTutorialFragment.close();
}
break;
}
@@ -33,7 +33,13 @@ import java.util.ArrayList;
/** Shows the Overview gesture interactive tutorial. */
public class OverviewGestureTutorialFragment extends TutorialFragment {
public OverviewGestureTutorialFragment() {}
public OverviewGestureTutorialFragment() {
this(false);
}
public OverviewGestureTutorialFragment(boolean fromTutorialMenu) {
super(fromTutorialMenu);
}
@Nullable
@Override
@@ -26,7 +26,9 @@ import com.android.quickstep.interaction.TutorialController.TutorialType;
/** Shows the general navigation gesture sandbox environment. */
public class SandboxModeTutorialFragment extends TutorialFragment {
public SandboxModeTutorialFragment() {}
public SandboxModeTutorialFragment(boolean fromTutorialMenu) {
super(fromTutorialMenu);
}
@Override
TutorialController createController(TutorialType type) {
@@ -703,66 +703,65 @@ abstract class TutorialController implements BackGestureAttemptCallback,
}
private AlertDialog createSkipTutorialDialog() {
if (mContext instanceof GestureSandboxActivity) {
GestureSandboxActivity sandboxActivity = (GestureSandboxActivity) mContext;
View contentView = View.inflate(
sandboxActivity, R.layout.gesture_tutorial_dialog, null);
AlertDialog tutorialDialog = new AlertDialog
.Builder(sandboxActivity, R.style.Theme_AppCompat_Dialog_Alert)
.setView(contentView)
.create();
if (!(mContext instanceof GestureSandboxActivity)) {
return null;
}
GestureSandboxActivity sandboxActivity = (GestureSandboxActivity) mContext;
View contentView = View.inflate(
sandboxActivity, R.layout.gesture_tutorial_dialog, null);
AlertDialog tutorialDialog = new AlertDialog
.Builder(sandboxActivity, R.style.Theme_AppCompat_Dialog_Alert)
.setView(contentView)
.create();
PackageManager packageManager = mContext.getPackageManager();
CharSequence tipsAppName = DEFAULT_PIXEL_TIPS_APP_NAME;
PackageManager packageManager = mContext.getPackageManager();
CharSequence tipsAppName = DEFAULT_PIXEL_TIPS_APP_NAME;
try {
tipsAppName = packageManager.getApplicationLabel(
packageManager.getApplicationInfo(
PIXEL_TIPS_APP_PACKAGE_NAME, PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG,
"Could not find app label for package name: "
+ PIXEL_TIPS_APP_PACKAGE_NAME
+ ". Defaulting to 'Pixel Tips.'",
e);
}
TextView subtitleTextView = (TextView) contentView.findViewById(
R.id.gesture_tutorial_dialog_subtitle);
if (subtitleTextView != null) {
subtitleTextView.setText(
mContext.getString(R.string.skip_tutorial_dialog_subtitle, tipsAppName));
} else {
Log.w(LOG_TAG, "No subtitle view in the skip tutorial dialog to update.");
}
Button cancelButton = (Button) contentView.findViewById(
R.id.gesture_tutorial_dialog_cancel_button);
if (cancelButton != null) {
cancelButton.setOnClickListener(
v -> tutorialDialog.dismiss());
} else {
Log.w(LOG_TAG, "No cancel button in the skip tutorial dialog to update.");
}
Button confirmButton = contentView.findViewById(
R.id.gesture_tutorial_dialog_confirm_button);
if (confirmButton != null) {
confirmButton.setOnClickListener(v -> {
mTutorialFragment.closeTutorial(true);
tutorialDialog.dismiss();
});
} else {
Log.w(LOG_TAG, "No confirm button in the skip tutorial dialog to update.");
}
tutorialDialog.getWindow().setBackgroundDrawable(
new ColorDrawable(sandboxActivity.getColor(android.R.color.transparent)));
return tutorialDialog;
try {
tipsAppName = packageManager.getApplicationLabel(
packageManager.getApplicationInfo(
PIXEL_TIPS_APP_PACKAGE_NAME, PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG,
"Could not find app label for package name: "
+ PIXEL_TIPS_APP_PACKAGE_NAME
+ ". Defaulting to 'Pixel Tips.'",
e);
}
return null;
TextView subtitleTextView = (TextView) contentView.findViewById(
R.id.gesture_tutorial_dialog_subtitle);
if (subtitleTextView != null) {
subtitleTextView.setText(
mContext.getString(R.string.skip_tutorial_dialog_subtitle, tipsAppName));
} else {
Log.w(LOG_TAG, "No subtitle view in the skip tutorial dialog to update.");
}
Button cancelButton = (Button) contentView.findViewById(
R.id.gesture_tutorial_dialog_cancel_button);
if (cancelButton != null) {
cancelButton.setOnClickListener(
v -> tutorialDialog.dismiss());
} else {
Log.w(LOG_TAG, "No cancel button in the skip tutorial dialog to update.");
}
Button confirmButton = contentView.findViewById(
R.id.gesture_tutorial_dialog_confirm_button);
if (confirmButton != null) {
confirmButton.setOnClickListener(v -> {
mTutorialFragment.closeTutorialStep(true);
tutorialDialog.dismiss();
});
} else {
Log.w(LOG_TAG, "No confirm button in the skip tutorial dialog to update.");
}
tutorialDialog.getWindow().setBackgroundDrawable(
new ColorDrawable(sandboxActivity.getColor(android.R.color.transparent)));
return tutorialDialog;
}
protected AnimatorSet createFingerDotAppearanceAnimatorSet() {
@@ -18,11 +18,13 @@ package com.android.quickstep.interaction;
import static android.view.View.NO_ID;
import static com.android.launcher3.config.FeatureFlags.ENABLE_NEW_GESTURE_NAV_TUTORIAL;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_GESTURE_COMPLETE;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_TUTORIAL_TYPE;
import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_USE_TUTORIAL_MENU;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Insets;
@@ -43,8 +45,6 @@ import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
@@ -54,16 +54,17 @@ import com.android.quickstep.interaction.TutorialController.TutorialType;
import java.util.Set;
abstract class TutorialFragment extends Fragment implements OnTouchListener {
/** Displays a gesture nav tutorial step. */
abstract class TutorialFragment extends GestureSandboxFragment implements OnTouchListener {
private static final String LOG_TAG = "TutorialFragment";
static final String KEY_TUTORIAL_TYPE = "tutorial_type";
static final String KEY_GESTURE_COMPLETE = "gesture_complete";
private static final String TUTORIAL_SKIPPED_PREFERENCE_KEY = "pref_gestureTutorialSkipped";
private static final String COMPLETED_TUTORIAL_STEPS_PREFERENCE_KEY =
"pref_completedTutorialSteps";
private final boolean mFromTutorialMenu;
TutorialType mTutorialType;
boolean mGestureComplete = false;
@Nullable TutorialController mTutorialController = null;
@@ -85,10 +86,10 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
private boolean mIsFoldable;
public static TutorialFragment newInstance(
TutorialType tutorialType, boolean gestureComplete) {
TutorialFragment fragment = getFragmentForTutorialType(tutorialType);
TutorialType tutorialType, boolean gestureComplete, boolean fromTutorialMenu) {
TutorialFragment fragment = getFragmentForTutorialType(tutorialType, fromTutorialMenu);
if (fragment == null) {
fragment = new BackGestureTutorialFragment();
fragment = new BackGestureTutorialFragment(fromTutorialMenu);
tutorialType = TutorialType.BACK_NAVIGATION;
}
@@ -99,23 +100,28 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
return fragment;
}
TutorialFragment(boolean fromTutorialMenu) {
mFromTutorialMenu = fromTutorialMenu;
}
@Nullable
private static TutorialFragment getFragmentForTutorialType(TutorialType tutorialType) {
private static TutorialFragment getFragmentForTutorialType(
TutorialType tutorialType, boolean fromTutorialMenu) {
switch (tutorialType) {
case BACK_NAVIGATION:
case BACK_NAVIGATION_COMPLETE:
return new BackGestureTutorialFragment();
return new BackGestureTutorialFragment(fromTutorialMenu);
case HOME_NAVIGATION:
case HOME_NAVIGATION_COMPLETE:
return new HomeGestureTutorialFragment();
return new HomeGestureTutorialFragment(fromTutorialMenu);
case OVERVIEW_NAVIGATION:
case OVERVIEW_NAVIGATION_COMPLETE:
return new OverviewGestureTutorialFragment();
return new OverviewGestureTutorialFragment(fromTutorialMenu);
case ASSISTANT:
case ASSISTANT_COMPLETE:
return new AssistantGestureTutorialFragment();
return new AssistantGestureTutorialFragment(fromTutorialMenu);
case SANDBOX_MODE:
return new SandboxModeTutorialFragment();
return new SandboxModeTutorialFragment(fromTutorialMenu);
default:
Log.e(LOG_TAG, "Failed to find an appropriate fragment for " + tutorialType.name());
}
@@ -202,6 +208,7 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
mFingerDotView = mRootView.findViewById(R.id.gesture_tutorial_finger_dot);
mFakePreviousTaskView = mRootView.findViewById(
R.id.gesture_tutorial_fake_previous_task_view);
return mRootView;
}
@@ -355,6 +362,7 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
| mNavBarGestureHandler.onInterceptTouch(motionEvent);
}
@Override
void onAttachedToWindow() {
StatsLogManager statsLogManager = getStatsLogManager();
if (statsLogManager != null) {
@@ -363,6 +371,7 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
mEdgeBackGestureHandler.setViewGroupParent(getRootView());
}
@Override
void onDetachedFromWindow() {
mEdgeBackGestureHandler.setViewGroupParent(null);
}
@@ -385,6 +394,8 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putSerializable(KEY_TUTORIAL_TYPE, mTutorialType);
savedInstanceState.putBoolean(KEY_GESTURE_COMPLETE, isGestureComplete());
savedInstanceState.putBoolean(KEY_USE_TUTORIAL_MENU, mFromTutorialMenu);
super.onSaveInstanceState(savedInstanceState);
}
@@ -410,17 +421,18 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
GestureSandboxActivity gestureSandboxActivity = getGestureSandboxActivity();
if (gestureSandboxActivity == null) {
closeTutorial();
close();
return;
}
gestureSandboxActivity.continueTutorial();
}
void closeTutorial() {
closeTutorial(false);
@Override
void close() {
closeTutorialStep(false);
}
void closeTutorial(boolean tutorialSkipped) {
void closeTutorialStep(boolean tutorialSkipped) {
if (tutorialSkipped) {
SharedPreferences sharedPrefs = getSharedPreferences();
if (sharedPrefs != null) {
@@ -432,11 +444,12 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
StatsLogManager.LauncherEvent.LAUNCHER_GESTURE_TUTORIAL_SKIPPED);
}
}
FragmentActivity activity = getActivity();
if (activity != null) {
activity.setResult(Activity.RESULT_OK);
activity.finish();
GestureSandboxActivity gestureSandboxActivity = getGestureSandboxActivity();
if (mFromTutorialMenu && gestureSandboxActivity != null) {
gestureSandboxActivity.launchTutorialMenu();
return;
}
super.close();
}
void startSystemNavigationSetting() {
@@ -470,9 +483,10 @@ abstract class TutorialFragment extends Fragment implements OnTouchListener {
@Nullable
private GestureSandboxActivity getGestureSandboxActivity() {
Context context = getContext();
Activity activity = getActivity();
return context instanceof GestureSandboxActivity ? (GestureSandboxActivity) context : null;
return activity instanceof GestureSandboxActivity
? (GestureSandboxActivity) activity : null;
}
@Nullable