From b0f28bd9a52fa4e343c8299d1c3e225d8e01c1e9 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Fri, 30 Jul 2010 11:58:59 -0700 Subject: fixed bugs with layout in Launcher - fix bug where calling unshrink on initialization was setting all the screens' x coordinate to 0 - fix bug where mScrollX was not synched to the proper value for the mCurrentScreen it was on --- src/com/android/launcher2/Workspace.java | 94 ++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 1a2f8129d..3e52d7f42 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -342,6 +342,14 @@ public class Workspace extends ViewGroup * @param currentScreen */ void setCurrentScreen(int currentScreen) { + setCurrentScreen(currentScreen, true); + } + + void setCurrentScreen(int currentScreen, boolean animateScrolling) { + setCurrentScreen(currentScreen, animateScrolling, getWidth()); + } + + void setCurrentScreen(int currentScreen, boolean animateScrolling, int screenWidth) { if (!mScroller.isFinished()) mScroller.abortAnimation(); clearVacantCache(); @@ -350,9 +358,12 @@ public class Workspace extends ViewGroup mPreviousIndicator.setLevel(mCurrentScreen); mNextIndicator.setLevel(mCurrentScreen); } - - scrollTo(mCurrentScreen * getWidth(), 0); - updateWallpaperOffset(); + if (animateScrolling) { + scrollTo(mCurrentScreen * screenWidth, 0); + } else { + mScrollX = mCurrentScreen * screenWidth; + } + updateWallpaperOffset(screenWidth * (getChildCount() - 1)); invalidate(); } @@ -689,9 +700,8 @@ public class Workspace extends ViewGroup if (mFirstLayout) { setHorizontalScrollBarEnabled(false); - scrollTo(mCurrentScreen * width, 0); + setCurrentScreen(mCurrentScreen, false, width); setHorizontalScrollBarEnabled(true); - updateWallpaperOffset(width * (getChildCount() - 1)); } } @@ -1176,46 +1186,50 @@ public class Workspace extends ViewGroup // We call this when we trigger an unshrink by clicking on the CellLayout cl private void unshrink(CellLayout clThatWasClicked) { - int newCurrentScreen = mCurrentScreen; - final int screenCount = getChildCount(); - for (int i = 0; i < screenCount; i++) { - if (getChildAt(i) == clThatWasClicked) { - newCurrentScreen = i; + if (mIsSmall) { + int newCurrentScreen = mCurrentScreen; + final int screenCount = getChildCount(); + for (int i = 0; i < screenCount; i++) { + if (getChildAt(i) == clThatWasClicked) { + newCurrentScreen = i; + } } - } - final int delta = (newCurrentScreen - mCurrentScreen)*getWidth(); - for (int i = 0; i < screenCount; i++) { - CellLayout cl = (CellLayout) getChildAt(i); - cl.setX(cl.getX() + delta); - } - mScrollX = newCurrentScreen * getWidth(); + final int delta = (newCurrentScreen - mCurrentScreen)*getWidth(); + for (int i = 0; i < screenCount; i++) { + CellLayout cl = (CellLayout) getChildAt(i); + cl.setX(cl.getX() + delta); + } + mScrollX = newCurrentScreen * getWidth(); - unshrink(); - setCurrentScreen(newCurrentScreen); + unshrink(); + setCurrentScreen(newCurrentScreen); + } } public void unshrink() { - final int screenWidth = getWidth(); - Sequencer s = new Sequencer(); - final int screenCount = getChildCount(); - for (int i = 0; i < screenCount; i++) { - CellLayout cl = (CellLayout)getChildAt(i); - int x = screenWidth * i; - - PropertyAnimator translateX = new PropertyAnimator(500, cl, "x", cl.getX(), x); - PropertyAnimator translateY = new PropertyAnimator(500, cl, "y", cl.getY(), 0); - PropertyAnimator scaleX = new PropertyAnimator(500, cl, "scaleX", cl.getScaleX(), 1.0f); - PropertyAnimator scaleY = new PropertyAnimator(500, cl, "scaleY", cl.getScaleY(), 1.0f); - PropertyAnimator alpha = new PropertyAnimator( - 500, cl, "dimmedBitmapAlpha", cl.getDimmedBitmapAlpha(), 0.0f); - Sequencer.Builder b = s.play(translateX); - b.with(translateY); - b.with(scaleX); - b.with(scaleY); - b.with(alpha); + if (mIsSmall) { + final int screenWidth = getWidth(); + Sequencer s = new Sequencer(); + final int screenCount = getChildCount(); + for (int i = 0; i < screenCount; i++) { + CellLayout cl = (CellLayout)getChildAt(i); + int x = screenWidth * i; + + PropertyAnimator translateX = new PropertyAnimator(500, cl, "x", cl.getX(), x); + PropertyAnimator translateY = new PropertyAnimator(500, cl, "y", cl.getY(), 0); + PropertyAnimator scaleX = new PropertyAnimator(500, cl, "scaleX", cl.getScaleX(), 1.0f); + PropertyAnimator scaleY = new PropertyAnimator(500, cl, "scaleY", cl.getScaleY(), 1.0f); + PropertyAnimator alpha = new PropertyAnimator( + 500, cl, "dimmedBitmapAlpha", cl.getDimmedBitmapAlpha(), 0.0f); + Sequencer.Builder b = s.play(translateX); + b.with(translateY); + b.with(scaleX); + b.with(scaleY); + b.with(alpha); + } + s.addListener(mUnshrinkAnimationListener); + s.start(); } - s.addListener(mUnshrinkAnimationListener); - s.start(); } void snapToScreen(int whichScreen) { @@ -1301,7 +1315,7 @@ public class Workspace extends ViewGroup SavedState savedState = (SavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); if (savedState.currentScreen != -1) { - mCurrentScreen = savedState.currentScreen; + setCurrentScreen(savedState.currentScreen, false); Launcher.setScreen(mCurrentScreen); } } -- cgit v1.2.3