summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/PagedView.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2010-08-09 16:03:15 -0700
committerWinson Chung <winsonc@google.com>2010-08-16 15:51:43 -0700
commit80baf5a6b3c62a62265f626d43d1167783c94131 (patch)
treeda3dba4d3920ffbae802ab256c19d5f0b590089b /src/com/android/launcher2/PagedView.java
parent321e9ee68848d9e782fd557f69cc070308ffbc9c (diff)
downloadandroid_packages_apps_Trebuchet-80baf5a6b3c62a62265f626d43d1167783c94131.tar.gz
android_packages_apps_Trebuchet-80baf5a6b3c62a62265f626d43d1167783c94131.tar.bz2
android_packages_apps_Trebuchet-80baf5a6b3c62a62265f626d43d1167783c94131.zip
Adding paging for the widget/shortcut/folder customization area and fixing bugs.
Adding pages for customization drawer with initial implementation of proposed flow layout for widgets. Fixes for keeping all apps, and widgets in sync with Launcher Model, optimizations for reloading all apps pages when invalidating. Adding some animations for tab transitions and feedback when long pressing to add certain items. Change-Id: I8d51749f3a91c964bed35681f3a9192200b0d93e
Diffstat (limited to 'src/com/android/launcher2/PagedView.java')
-rw-r--r--src/com/android/launcher2/PagedView.java114
1 files changed, 106 insertions, 8 deletions
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 26805e0b5..0e8ffa0fd 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -32,8 +33,14 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Animation.AnimationListener;
import android.widget.Scroller;
+import com.android.launcher.R;
+
/**
* An abstraction of the original Workspace which supports browsing through a
* sequential list of "pages" (or PagedViewCellLayouts).
@@ -81,16 +88,12 @@ public abstract class PagedView extends ViewGroup {
private ScreenSwitchListener mScreenSwitchListener;
private boolean mDimmedPagesDirty;
+ private final Handler mHandler = new Handler();
public interface ScreenSwitchListener {
void onScreenSwitch(View newScreen, int newScreenIndex);
}
- /**
- * Constructor
- *
- * @param context The application's context.
- */
public PagedView(Context context) {
this(context, null);
}
@@ -158,6 +161,7 @@ public abstract class PagedView extends ViewGroup {
mCurrentScreen = Math.max(0, Math.min(currentScreen, getScreenCount() - 1));
scrollTo(getChildOffset(mCurrentScreen) - getRelativeChildOffset(mCurrentScreen), 0);
+
invalidate();
notifyScreenSwitchListener();
}
@@ -457,6 +461,23 @@ public abstract class PagedView extends ViewGroup {
return mTouchState != TOUCH_STATE_REST;
}
+ protected void animateClickFeedback(View v, final Runnable r) {
+ // animate the view slightly to show click feedback running some logic after it is "pressed"
+ Animation anim = AnimationUtils.loadAnimation(getContext(),
+ R.anim.paged_view_click_feedback);
+ anim.setAnimationListener(new AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {}
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ r.run();
+ }
+ @Override
+ public void onAnimationEnd(Animation animation) {}
+ });
+ v.startAnimation(anim);
+ }
+
/*
* Determines if we should change the touch state to start scrolling after the
* user moves their touch point too far.
@@ -689,6 +710,10 @@ public abstract class PagedView extends ViewGroup {
if (!mScroller.isFinished()) mScroller.abortAnimation();
mScroller.startScroll(sX, 0, delta, 0, duration);
+
+ // only load some associated pages
+ loadAssociatedPages(mNextScreen);
+
invalidate();
}
@@ -775,13 +800,86 @@ public abstract class PagedView extends ViewGroup {
};
}
+ private void clearDimmedBitmaps(boolean skipCurrentScreens) {
+ final int count = getChildCount();
+ if (mCurrentScreen < count) {
+ if (skipCurrentScreens) {
+ int lowerScreenBound = Math.max(0, mCurrentScreen - 1);
+ int upperScreenBound = Math.min(mCurrentScreen + 1, count - 1);
+ for (int i = 0; i < count; ++i) {
+ if (i < lowerScreenBound || i > upperScreenBound) {
+ PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
+ layout.clearDimmedBitmap();
+ }
+ }
+ } else {
+ for (int i = 0; i < count; ++i) {
+ PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
+ layout.clearDimmedBitmap();
+ }
+ }
+ }
+ }
+ Runnable clearLayoutOtherDimmedBitmapsRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (mScroller.isFinished()) {
+ clearDimmedBitmaps(true);
+ mHandler.removeMessages(0);
+ } else {
+ mHandler.postDelayed(clearLayoutOtherDimmedBitmapsRunnable, 50);
+ }
+ }
+ };
+ Runnable clearLayoutDimmedBitmapsRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (mScroller.isFinished()) {
+ clearDimmedBitmaps(false);
+ mHandler.removeMessages(0);
+ } else {
+ mHandler.postDelayed(clearLayoutOtherDimmedBitmapsRunnable, 50);
+ }
+ }
+ };
+
+ // called when this paged view is no longer visible
+ public void cleanup() {
+ // clear all the layout dimmed bitmaps
+ mHandler.removeMessages(0);
+ mHandler.postDelayed(clearLayoutDimmedBitmapsRunnable, 500);
+ }
+
+ public void loadAssociatedPages(int screen) {
+ final int count = getChildCount();
+ if (screen < count) {
+ int lowerScreenBound = Math.max(0, screen - 1);
+ int upperScreenBound = Math.min(screen + 1, count - 1);
+ boolean hasDimmedBitmap = false;
+ for (int i = 0; i < count; ++i) {
+ if (lowerScreenBound <= i && i <= upperScreenBound) {
+ syncPageItems(i);
+ } else {
+ PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
+ if (layout.getChildCount() > 0) {
+ layout.removeAllViews();
+ }
+ hasDimmedBitmap |= layout.getDimmedBitmapAlpha() > 0.0f;
+ }
+ }
+
+ if (hasDimmedBitmap) {
+ mHandler.removeMessages(0);
+ mHandler.postDelayed(clearLayoutOtherDimmedBitmapsRunnable, 500);
+ }
+ }
+ }
+
public abstract void syncPages();
public abstract void syncPageItems(int page);
public void invalidatePageData() {
syncPages();
- for (int i = 0; i < getChildCount(); ++i) {
- syncPageItems(i);
- }
+ loadAssociatedPages(mCurrentScreen);
invalidateDimmedPages();
requestLayout();
}