summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Hawkey <dhawkey@google.com>2013-09-19 17:16:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-19 17:16:32 +0000
commit8c082818a8ee813318e32a667883f73d7b94126a (patch)
tree866ad2c2122203217514d38d26a659492290b58a /src
parentdbdff6bc7b225255207a46fad8f536b55a18efac (diff)
parenta888158880fea53479447d883391f552604e46b6 (diff)
downloadandroid_packages_apps_Trebuchet-8c082818a8ee813318e32a667883f73d7b94126a.tar.gz
android_packages_apps_Trebuchet-8c082818a8ee813318e32a667883f73d7b94126a.tar.bz2
android_packages_apps_Trebuchet-8c082818a8ee813318e32a667883f73d7b94126a.zip
Merge "Support for dynamically adding/removing -1 screen" into jb-ub-now-indigo-rose
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Launcher.java33
-rw-r--r--src/com/android/launcher3/Workspace.java51
2 files changed, 67 insertions, 17 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index aad9b9f35..daf9f096b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -482,6 +482,33 @@ public class Launcher extends Activity
return false;
}
+ /**
+ * To be overridden by subclasses to create the custom content and call
+ * {@link #addToCustomContentPage}. This will only be invoked if
+ * {@link #hasCustomContentToLeft()} is {@code true}.
+ */
+ protected void addCustomContentToLeft() {
+ }
+
+ /**
+ * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
+ * ensure the custom content page is added or removed if necessary.
+ */
+ protected void invalidateHasCustomContentToLeft() {
+ if (mWorkspace.getScreenOrder().isEmpty()) {
+ // Not bound yet, wait for bindScreens to be called.
+ return;
+ }
+
+ if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
+ // Create the custom content page and call the subclass to populate it.
+ mWorkspace.createCustomContentPage();
+ addCustomContentToLeft();
+ } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
+ mWorkspace.removeCustomContentPage();
+ }
+ }
+
private void updateGlobalIcons() {
boolean searchVisible = false;
boolean voiceVisible = false;
@@ -896,6 +923,9 @@ public class Launcher extends Activity
}
protected void onFinishBindingItems() {
+ if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
+ addCustomContentToLeft();
+ }
}
QSBScroller mQsbScroller = new QSBScroller() {
@@ -3607,7 +3637,8 @@ public class Launcher extends Activity
}
// Create the custom content page (this call updates mDefaultScreen which calls
- // setCurrentPage() so ensure that all pages are added before calling this)
+ // setCurrentPage() so ensure that all pages are added before calling this).
+ // The actual content of the custom page will be added during onFinishBindingItems().
if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
mWorkspace.createCustomContentPage();
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 76d60a80b..596ac1113 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -52,7 +52,6 @@ import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewParent;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;
@@ -540,6 +539,24 @@ public class Workspace extends SmoothPagedView
setCurrentPage(getCurrentPage() + 1);
}
+ public void removeCustomContentPage() {
+ Launcher.addDumpLog(TAG, "10249126 - removeCustomContentPage()", true);
+
+ CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
+ if (customScreen == null) {
+ throw new RuntimeException("Expected custom content screen to exist");
+ }
+
+ mWorkspaceScreens.remove(CUSTOM_CONTENT_SCREEN_ID);
+ mScreenOrder.remove(CUSTOM_CONTENT_SCREEN_ID);
+ removeView(customScreen);
+ mCustomContentCallbacks = null;
+
+ // Ensure that the current page and default page are maintained.
+ mDefaultPage = mOriginalDefaultPage - 1;
+ setCurrentPage(getCurrentPage() - 1);
+ }
+
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks) {
if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
throw new RuntimeException("Expected custom content screen to exist");
@@ -1326,30 +1343,32 @@ public class Workspace extends SmoothPagedView
}
private void updateStateForCustomContent(int screenCenter) {
+ float translationX = 0;
+ float progress = 0;
if (hasCustomContent()) {
int index = mScreenOrder.indexOf(CUSTOM_CONTENT_SCREEN_ID);
int scrollDelta = getScrollForPage(index + 1) - getScrollX();
- float translationX = Math.max(scrollDelta, 0);
- float progress = (1.0f * scrollDelta) /
+ translationX = Math.max(scrollDelta, 0);
+ progress = (1.0f * scrollDelta) /
(getScrollForPage(index + 1) - getScrollForPage(index));
progress = Math.max(0, progress);
+ }
- if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return;
- mLastCustomContentScrollProgress = progress;
+ if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return;
+ mLastCustomContentScrollProgress = progress;
- setBackgroundAlpha(progress * 0.8f);
+ setBackgroundAlpha(progress * 0.8f);
- if (mLauncher.getHotseat() != null) {
- mLauncher.getHotseat().setTranslationX(translationX);
- }
+ if (mLauncher.getHotseat() != null) {
+ mLauncher.getHotseat().setTranslationX(translationX);
+ }
- if (getPageIndicator() != null) {
- getPageIndicator().setTranslationX(translationX);
- }
+ if (getPageIndicator() != null) {
+ getPageIndicator().setTranslationX(translationX);
+ }
- if (mCustomContentCallbacks != null) {
- mCustomContentCallbacks.onScrollProgressChanged(progress);
- }
+ if (mCustomContentCallbacks != null) {
+ mCustomContentCallbacks.onScrollProgressChanged(progress);
}
}
@@ -3809,7 +3828,7 @@ public class Workspace extends SmoothPagedView
@Override
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
// We don't dispatch restoreInstanceState to our children using this code path.
- // Some pages will be restored immediately as their items are bound immediately, and
+ // Some pages will be restored immediately as their items are bound immediately, and
// others we will need to wait until after their items are bound.
mSavedStates = container;
}