summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2014-03-13 17:03:22 -0700
committerAdam Cohen <adamcohen@google.com>2014-03-20 11:48:22 -0700
commit432609a246819f3cf887a80c2ae56b61fc5ca25a (patch)
tree793ccc3e52d163fa09740082936422bc7b26e19b
parente769d1681e1177b9e37c0be9e12d1ede55d4e3a9 (diff)
downloadandroid_packages_apps_Trebuchet-432609a246819f3cf887a80c2ae56b61fc5ca25a.tar.gz
android_packages_apps_Trebuchet-432609a246819f3cf887a80c2ae56b61fc5ca25a.tar.bz2
android_packages_apps_Trebuchet-432609a246819f3cf887a80c2ae56b61fc5ca25a.zip
Adding in-activity intro screen (issue 12905636)
Change-Id: Ifb016ca6e5052fd91535b98a39f78569200955a8
-rw-r--r--src/com/android/launcher3/DragLayer.java42
-rw-r--r--src/com/android/launcher3/Launcher.java99
2 files changed, 114 insertions, 27 deletions
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java
index 862ceca28..7ccbe6b55 100644
--- a/src/com/android/launcher3/DragLayer.java
+++ b/src/com/android/launcher3/DragLayer.java
@@ -73,7 +73,8 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
private final Rect mInsets = new Rect();
- private int mDragViewIndex;
+ private View mOverlayView;
+ private int mTopViewIndex;
/**
* Used to create a new DragLayer from XML.
@@ -120,6 +121,16 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
setInsets(child, mInsets, new Rect());
}
+ public void showOverlayView(View introScreen) {
+ LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ mOverlayView = introScreen;
+ addView(introScreen, lp);
+ }
+
+ public void dismissOverlayView() {
+ removeView(mOverlayView);
+ }
+
private void setInsets(View child, Rect newInsets, Rect oldInsets) {
final FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) child.getLayoutParams();
if (child instanceof Insettable) {
@@ -770,27 +781,38 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
updateChildIndices();
}
+ @Override
+ public void bringChildToFront(View child) {
+ super.bringChildToFront(child);
+ updateChildIndices();
+ }
+
private void updateChildIndices() {
- mDragViewIndex = -1;
+ mTopViewIndex = -1;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
- if (getChildAt(i) instanceof DragView) {
- mDragViewIndex = i;
+ if (getChildAt(i) instanceof DragView ||
+ getChildAt(i) == mOverlayView) {
+ mTopViewIndex = i;
}
}
}
@Override
protected int getChildDrawingOrder(int childCount, int i) {
- if (mDragViewIndex == -1) {
+ // i represents the current draw iteration
+ if (mTopViewIndex == -1) {
+ // in general we do nothing
return i;
- } else if (i == mDragViewIndex) {
- return getChildCount()-1;
- } else if (i < mDragViewIndex) {
+ } else if (i == childCount - 1) {
+ // if we have a top index, we return it when drawing last item (highest z-order)
+ return mTopViewIndex;
+ } else if (i < mTopViewIndex) {
return i;
} else {
- // i > mDragViewIndex
- return i-1;
+ // for indexes greater than the top index, we fetch one item above to shift for the
+ // displacement of the top index
+ return i + 1;
}
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 05be4ae67..9456e66d4 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -191,6 +191,7 @@ public class Launcher extends Activity
private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
+ static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
@@ -213,6 +214,7 @@ public class Launcher extends Activity
public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT_FOLDER_CLOSE = 400;
private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
+ private static final int ACTIVITY_START_DELAY = 500;
private static final Object sLock = new Object();
private static int sScreen = DEFAULT_SCREEN;
@@ -481,10 +483,15 @@ public class Launcher extends Activity
// On large interfaces, we want the screen to auto-rotate based on the current orientation
unlockScreenOrientation(true);
+ if (shouldShowIntroScreen()) {
+ showIntroScreen();
+ } else {
+ showFirstRunActivity();
+ }
+
// The two first run cling paths are mutually exclusive, if the launcher is preinstalled
// on the device, then we always show the first run cling experience (or if there is no
// launcher2). Otherwise, we prompt the user upon started for migration
- showFirstRunActivity();
if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
if (mModel.canMigrateFromOldLauncherDb(this)) {
mLauncherClings.showMigrationCling();
@@ -518,21 +525,6 @@ public class Launcher extends Activity
}
/**
- * To be overridden by subclasses to indicate that there is an activity to launch
- * before showing the standard launcher experience.
- */
- protected boolean hasFirstRunActivity() {
- return false;
- }
-
- /**
- * To be overridden by subclasses to launch any first run activity
- */
- protected Intent getFirstRunActivity() {
- return null;
- }
-
- /**
* Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
* ensure the custom content page is added or removed if necessary.
*/
@@ -4441,20 +4433,38 @@ public class Launcher extends Activity
mLauncherClings.dismissFolderCling(v);
}
+
+ /**
+ * To be overridden by subclasses to indicate that there is an activity to launch
+ * before showing the standard launcher experience.
+ */
+ protected boolean hasFirstRunActivity() {
+ return false;
+ }
+
+ /**
+ * To be overridden by subclasses to launch any first run activity
+ */
+ protected Intent getFirstRunActivity() {
+ return null;
+ }
+
private boolean shouldRunFirstRunActivity() {
return !ActivityManager.isRunningInTestHarness() &&
!mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
}
- public void showFirstRunActivity() {
+ public boolean showFirstRunActivity() {
if (shouldRunFirstRunActivity() &&
hasFirstRunActivity()) {
Intent firstRunIntent = getFirstRunActivity();
if (firstRunIntent != null) {
startActivity(firstRunIntent);
markFirstRunActivityShown();
+ return true;
}
}
+ return false;
}
private void markFirstRunActivityShown() {
@@ -4463,6 +4473,61 @@ public class Launcher extends Activity
editor.apply();
}
+ /**
+ * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
+ * screen that must be displayed and dismissed.
+ */
+ protected boolean hasDismissableIntroScreen() {
+ return false;
+ }
+
+ /**
+ * Full screen intro screen to be shown and dismissed before the launcher can be used.
+ */
+ protected View getIntroScreen() {
+ return null;
+ }
+
+ /**
+ * To be overriden by subclasses to indicate whether the in-activity intro screen has been
+ * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
+ */
+ private boolean shouldShowIntroScreen() {
+ return hasDismissableIntroScreen() &&
+ !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
+ }
+
+ protected void showIntroScreen() {
+ View introScreen = getIntroScreen();
+ changeWallpaperVisiblity(false);
+ if (introScreen != null) {
+ mDragLayer.showOverlayView(introScreen);
+ }
+ }
+
+ public void dismissIntroScreen() {
+ markIntroScreenDismissed();
+ if (showFirstRunActivity()) {
+ // We delay hiding the intro view until the first run activity is showing. This
+ // avoids a blip.
+ mWorkspace.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mDragLayer.dismissOverlayView();
+ }
+ }, ACTIVITY_START_DELAY);
+ } else {
+ mDragLayer.dismissOverlayView();
+ }
+ changeWallpaperVisiblity(true);
+ }
+
+ private void markIntroScreenDismissed() {
+ SharedPreferences.Editor editor = mSharedPrefs.edit();
+ editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
+ editor.apply();
+ }
+
void showWorkspaceSearchAndHotseat() {
if (mWorkspace != null) mWorkspace.setAlpha(1f);
if (mHotseat != null) mHotseat.setAlpha(1f);