diff options
author | Winson Chung <winsonc@google.com> | 2011-07-20 09:26:48 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-20 09:26:48 -0700 |
commit | ec8a2eee50290e7d9c95936041b937b6e94bb152 (patch) | |
tree | ec5505e3e37135705a82ee780a5a4e5303fa7f10 /src/com/android | |
parent | b424d29334cb076590e4f87b8802dca8e12d9911 (diff) | |
parent | 32174c878c77b4e0f13449f4c26ff6b487bc7ca6 (diff) | |
download | packages_apps_trebuchet-ec8a2eee50290e7d9c95936041b937b6e94bb152.zip packages_apps_trebuchet-ec8a2eee50290e7d9c95936041b937b6e94bb152.tar.gz packages_apps_trebuchet-ec8a2eee50290e7d9c95936041b937b6e94bb152.tar.bz2 |
Merge "Fxing issues with the scroll bar"
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizeTabHost.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 26 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedView.java | 83 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 7 |
4 files changed, 92 insertions, 28 deletions
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java index 2623586..ed408df 100644 --- a/src/com/android/launcher2/AppsCustomizeTabHost.java +++ b/src/com/android/launcher2/AppsCustomizeTabHost.java @@ -147,6 +147,10 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona anim.setDuration(duration); anim.addListener(new AnimatorListenerAdapter() { @Override + public void onAnimationStart(android.animation.Animator animation) { + mAppsCustomizePane.hideScrollingIndicator(false); + } + @Override public void onAnimationEnd(android.animation.Animator animation) { mAppsCustomizePane.setContentType(type); diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 6d0f88f..26f41fa 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -2410,12 +2410,6 @@ public final class Launcher extends Activity toView.setTranslationY(0.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); - - if (!springLoaded && !LauncherApplication.isScreenLarge()) { - // Hide the workspace scrollbar - mWorkspace.hideScrollingIndicator(true); - mWorkspace.hideScrollIndicatorTrack(); - } } @Override public void onAnimationEnd(Animator animation) { @@ -2427,6 +2421,12 @@ public final class Launcher extends Activity if (toView instanceof LauncherTransitionable) { ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim); } + + if (!springLoaded && !LauncherApplication.isScreenLarge()) { + // Hide the workspace scrollbar + mWorkspace.hideScrollingIndicator(true); + mWorkspace.hideScrollIndicatorTrack(); + } } }); @@ -2506,16 +2506,18 @@ public final class Launcher extends Activity } alphaAnim.addListener(new AnimatorListenerAdapter() { @Override + public void onAnimationStart(android.animation.Animator animation) { + if (!springLoaded && !LauncherApplication.isScreenLarge()) { + // Show the workspace scrollbar + mWorkspace.showScrollIndicatorTrack(); + mWorkspace.flashScrollingIndicator(); + } + } + @Override public void onAnimationEnd(Animator animation) { fromView.setVisibility(View.GONE); if (fromView instanceof LauncherTransitionable) { ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim); - - if (!springLoaded && !LauncherApplication.isScreenLarge()) { - // Show the workspace scrollbar - mWorkspace.showScrollIndicatorTrack(); - mWorkspace.flashScrollingIndicator(); - } } } }); diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 9ef1fa8..bed107a 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -161,11 +161,11 @@ public abstract class PagedView extends ViewGroup { protected boolean mIsDataReady = false; // Scrolling indicator + private android.animation.ValueAnimator mScrollIndicatorAnimator; private ImageView mScrollIndicator; private ImageView mScrollTrack; private boolean mHasScrollIndicator = true; private static final int sScrollIndicatorFadeInDuration = 150; - private static final int sScrollIndicatorFastFadeOutDuration = 50; private static final int sScrollIndicatorFadeOutDuration = 650; private static final int sScrollIndicatorFlashDuration = 650; @@ -260,10 +260,6 @@ public abstract class PagedView extends ViewGroup { return getChildAt(index); } - int getScrollWidth() { - return getWidth(); - } - /** * Updates the scroll of the current page immediately to its final scroll position. We use this * in CustomizePagedView to allow tabs to share the same PagedView while resetting the scroll of @@ -1676,7 +1672,13 @@ public abstract class PagedView extends ViewGroup { if (mScrollIndicator != null) { // Fade the indicator in updateScrollingIndicatorPosition(); - mScrollIndicator.animate().alpha(1f).setDuration(sScrollIndicatorFadeInDuration).start(); + mScrollIndicator.setVisibility(View.VISIBLE); + if (mScrollIndicatorAnimator != null) { + mScrollIndicatorAnimator.cancel(); + } + mScrollIndicatorAnimator = ObjectAnimator.ofFloat(mScrollIndicator, "alpha", 1f); + mScrollIndicatorAnimator.setDuration(sScrollIndicatorFadeInDuration); + mScrollIndicatorAnimator.start(); } } @@ -1688,11 +1690,41 @@ public abstract class PagedView extends ViewGroup { if (mScrollIndicator != null) { // Fade the indicator out updateScrollingIndicatorPosition(); - mScrollIndicator.animate().alpha(0f).setDuration(immediately ? - sScrollIndicatorFastFadeOutDuration : sScrollIndicatorFadeOutDuration).start(); + if (mScrollIndicatorAnimator != null) { + mScrollIndicatorAnimator.cancel(); + } + if (immediately) { + mScrollIndicator.setVisibility(View.GONE); + mScrollIndicator.setAlpha(0f); + } else { + mScrollIndicatorAnimator = ObjectAnimator.ofFloat(mScrollIndicator, "alpha", 0f); + mScrollIndicatorAnimator.setDuration(sScrollIndicatorFadeOutDuration); + mScrollIndicatorAnimator.addListener(new AnimatorListenerAdapter() { + private boolean cancelled = false; + @Override + public void onAnimationCancel(android.animation.Animator animation) { + cancelled = true; + } + @Override + public void onAnimationEnd(Animator animation) { + if (!cancelled) { + mScrollIndicator.setVisibility(View.GONE); + } + } + }); + mScrollIndicatorAnimator.start(); + } } } + /** + * To be overridden by subclasses to determine whether the scroll indicator should stretch to + * fill its space on the track or not. + */ + protected boolean hasElasticScrollIndicator() { + return false; + } + private void updateScrollingIndicator() { if (getChildCount() <= 1) return; if (!isScrollingIndicatorEnabled()) return; @@ -1706,16 +1738,35 @@ public abstract class PagedView extends ViewGroup { private void updateScrollingIndicatorPosition() { if (!isScrollingIndicatorEnabled()) return; - // We can make the page width smaller to make it look more centered + int numPages = getChildCount(); + int pageWidth = getMeasuredWidth(); + int maxPageWidth = (numPages * getMeasuredWidth()) + ((numPages - 1) * mPageSpacing); + int trackWidth = pageWidth; + int indicatorWidth = mScrollIndicator.getMeasuredWidth() - + mScrollIndicator.getPaddingLeft() - mScrollIndicator.getPaddingRight(); + int paddingLeft = 0; + int paddingRight = 0; + + // Get the track properties getScrollingIndicatorTrack(); - int pageWidth = mScrollTrack.getMeasuredWidth() - mScrollTrack.getPaddingLeft() - - mScrollTrack.getPaddingRight(); - int maxPageWidth = getChildCount() * getMeasuredWidth(); + if (mScrollTrack != null) { + paddingLeft = mScrollTrack.getPaddingLeft(); + paddingRight = mScrollTrack.getPaddingRight(); + trackWidth = mScrollTrack.getMeasuredWidth() - paddingLeft - paddingRight; + } + float offset = (float) getScrollX() / maxPageWidth; - int indicatorWidth = pageWidth / getChildCount(); - int indicatorCenterOffset = indicatorWidth / 2 - mScrollIndicator.getMeasuredWidth() / 2; - int indicatorPos = (int) (offset * pageWidth) + mScrollTrack.getPaddingLeft() + - indicatorCenterOffset; + int indicatorSpace = trackWidth / numPages; + int indicatorPos = (int) (offset * trackWidth) + paddingLeft; + if (hasElasticScrollIndicator()) { + if (mScrollIndicator.getMeasuredWidth() != indicatorSpace) { + mScrollIndicator.getLayoutParams().width = indicatorSpace; + mScrollIndicator.requestLayout(); + } + } else { + int indicatorCenterOffset = indicatorSpace / 2 - indicatorWidth / 2; + indicatorPos += indicatorCenterOffset; + } mScrollIndicator.setTranslationX(indicatorPos); mScrollIndicator.invalidate(); } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index e47f701..4fbf70f 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -3334,4 +3334,11 @@ public class Workspace extends SmoothPagedView public void getLocationInDragLayer(int[] loc) { mLauncher.getDragLayer().getLocationInDragLayer(this, loc); } + + /** + * Return true because we want the scrolling indicator to stretch to fit the space. + */ + protected boolean hasElasticScrollIndicator() { + return true; + } } |