merge in jb-release history after reset to master
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index a5964df..4639c57 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -53,6 +53,7 @@
private LinearLayout mContent;
private boolean mInTransition;
+ private boolean mTransitioningToWorkspace;
private boolean mResetAfterTransition;
public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
@@ -154,8 +155,23 @@
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ // If we are mid transition then intercept touch events here so we can ignore them
+ if (mInTransition) {
+ return true;
+ }
+ return super.onInterceptTouchEvent(ev);
+ };
+
@Override
public boolean onTouchEvent(MotionEvent event) {
+ // Allow touch events to fall through if we are transitioning to the workspace
+ if (mInTransition) {
+ if (mTransitioningToWorkspace) {
+ return super.onTouchEvent(event);
+ }
+ }
+
// Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
// through to the workspace and trigger showWorkspace()
if (event.getY() < mAppsCustomizePane.getBottom()) {
@@ -349,6 +365,7 @@
@Override
public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
mInTransition = true;
+ mTransitioningToWorkspace = toWorkspace;
if (toWorkspace) {
// Going from All Apps -> Workspace
@@ -377,6 +394,11 @@
}
@Override
+ public void onLauncherTransitionStep(Launcher l, float t) {
+ // Do nothing
+ }
+
+ @Override
public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
mInTransition = false;
if (animated) {
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 92a3d08..c8e7e32 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -23,6 +23,7 @@
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
@@ -49,7 +50,6 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
-import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -249,6 +249,10 @@
static final ArrayList<String> sDumpLogs = new ArrayList<String>();
PendingAddWidgetInfo mWidgetBeingConfigured = null;
+ // We only want to get the SharedPreferences once since it does an FS stat each time we get
+ // it from the context.
+ private SharedPreferences mSharedPrefs;
+
private BubbleTextView mWaitingForResume;
@@ -276,6 +280,7 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LauncherApplication app = ((LauncherApplication)getApplication());
+ mSharedPrefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
mModel = app.setLauncher(this);
mIconCache = app.getIconCache();
mDragController = new DragController(this);
@@ -2224,12 +2229,24 @@
if (v instanceof LauncherTransitionable) {
((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
}
+
+ // Update the workspace transition step as well
+ dispatchOnLauncherTransitionStep(v, 0f);
+ }
+
+ private void dispatchOnLauncherTransitionStep(View v, float t) {
+ if (v instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
+ }
}
private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
if (v instanceof LauncherTransitionable) {
((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
}
+
+ // Update the workspace transition step as well
+ dispatchOnLauncherTransitionStep(v, 1f);
}
/**
@@ -2314,6 +2331,14 @@
.ofFloat(toView, "alpha", 0f, 1f)
.setDuration(fadeDuration);
alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
+ alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ float t = (Float) animation.getAnimatedValue();
+ dispatchOnLauncherTransitionStep(fromView, t);
+ dispatchOnLauncherTransitionStep(toView, t);
+ }
+ });
// toView should appear right at the end of the workspace shrink
// animation
@@ -2469,6 +2494,14 @@
.ofFloat(fromView, "alpha", 1f, 0f)
.setDuration(fadeOutDuration);
alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
+ alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ float t = 1f - (Float) animation.getAnimatedValue();
+ dispatchOnLauncherTransitionStep(fromView, t);
+ dispatchOnLauncherTransitionStep(toView, t);
+ }
+ });
mStateAnimation = new AnimatorSet();
@@ -3340,11 +3373,14 @@
public void onAnimationEnd(Animator animation) {
cling.setVisibility(View.GONE);
cling.cleanup();
- SharedPreferences prefs =
- getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(flag, true);
- editor.commit();
+ // We should update the shared preferences on a background thread
+ new Thread("dismissClingThread") {
+ public void run() {
+ SharedPreferences.Editor editor = mSharedPrefs.edit();
+ editor.putBoolean(flag, true);
+ editor.commit();
+ }
+ }.start();
};
});
anim.start();
@@ -3364,9 +3400,8 @@
}
public void showFirstRunWorkspaceCling() {
// Enable the clings only if they have not been dismissed before
- SharedPreferences prefs =
- getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
- if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
+ if (isClingsEnabled() &&
+ !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
initCling(R.id.workspace_cling, null, false, 0);
} else {
removeCling(R.id.workspace_cling);
@@ -3374,9 +3409,8 @@
}
public void showFirstRunAllAppsCling(int[] position) {
// Enable the clings only if they have not been dismissed before
- SharedPreferences prefs =
- getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
- if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
+ if (isClingsEnabled() &&
+ !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
initCling(R.id.all_apps_cling, position, true, 0);
} else {
removeCling(R.id.all_apps_cling);
@@ -3384,15 +3418,13 @@
}
public Cling showFirstRunFoldersCling() {
// Enable the clings only if they have not been dismissed before
- SharedPreferences prefs =
- getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
- Cling cling = null;
- if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
- cling = initCling(R.id.folder_cling, null, true, 0);
+ if (isClingsEnabled() &&
+ !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
+ return initCling(R.id.folder_cling, null, true, 0);
} else {
removeCling(R.id.folder_cling);
+ return null;
}
- return cling;
}
public boolean isFolderClingVisible() {
Cling cling = (Cling) findViewById(R.id.folder_cling);
@@ -3447,5 +3479,6 @@
interface LauncherTransitionable {
View getContent();
void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
+ void onLauncherTransitionStep(Launcher l, float t);
void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index f61917f..0d7498a 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -55,6 +55,7 @@
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
import android.view.animation.DecelerateInterpolator;
@@ -234,7 +235,7 @@
private float[] mNewBackgroundAlphaMultipliers;
private float[] mNewAlphas;
private float[] mNewRotationYs;
- private float mTransitionProgress = 1f;
+ private float mTransitionProgress;
/**
* Used to inflate the Workspace from XML.
@@ -577,20 +578,26 @@
*/
@Override
public boolean onTouch(View v, MotionEvent event) {
- return (isSmall() || mIsSwitchingState);
+ return (isSmall() || !isFinishedSwitchingState());
}
public boolean isSwitchingState() {
return mIsSwitchingState;
}
+ /** This differs from isSwitchingState in that we take into account how far the transition
+ * has completed. */
+ private boolean isFinishedSwitchingState() {
+ return !mIsSwitchingState || (mTransitionProgress > 0.5f);
+ }
+
protected void onWindowVisibilityChanged (int visibility) {
mLauncher.onWindowVisibilityChanged(visibility);
}
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
- if (isSmall() || mIsSwitchingState) {
+ if (isSmall() || !isFinishedSwitchingState()) {
// when the home screens are shrunken, shouldn't allow side-scrolling
return false;
}
@@ -618,35 +625,36 @@
@Override
protected void determineScrollingStart(MotionEvent ev) {
- if (!isSmall() && !mIsSwitchingState) {
- float deltaX = Math.abs(ev.getX() - mXDown);
- float deltaY = Math.abs(ev.getY() - mYDown);
+ if (isSmall()) return;
+ if (!isFinishedSwitchingState()) return;
- if (Float.compare(deltaX, 0f) == 0) return;
+ float deltaX = Math.abs(ev.getX() - mXDown);
+ float deltaY = Math.abs(ev.getY() - mYDown);
- float slope = deltaY / deltaX;
- float theta = (float) Math.atan(slope);
+ if (Float.compare(deltaX, 0f) == 0) return;
- if (deltaX > mTouchSlop || deltaY > mTouchSlop) {
- cancelCurrentPageLongPress();
- }
+ float slope = deltaY / deltaX;
+ float theta = (float) Math.atan(slope);
- if (theta > MAX_SWIPE_ANGLE) {
- // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace
- return;
- } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
- // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to
- // increase the touch slop to make it harder to begin scrolling the workspace. This
- // results in vertically scrolling widgets to more easily. The higher the angle, the
- // more we increase touch slop.
- theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
- float extraRatio = (float)
- Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
- super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
- } else {
- // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special
- super.determineScrollingStart(ev);
- }
+ if (deltaX > mTouchSlop || deltaY > mTouchSlop) {
+ cancelCurrentPageLongPress();
+ }
+
+ if (theta > MAX_SWIPE_ANGLE) {
+ // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace
+ return;
+ } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
+ // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to
+ // increase the touch slop to make it harder to begin scrolling the workspace. This
+ // results in vertically scrolling widgets to more easily. The higher the angle, the
+ // more we increase touch slop.
+ theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
+ float extraRatio = (float)
+ Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
+ super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
+ } else {
+ // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special
+ super.determineScrollingStart(ev);
}
}
@@ -676,6 +684,14 @@
showOutlines();
}
+ // If we are not fading in adjacent screens, we still need to restore the alpha in case the
+ // user scrolls while we are transitioning (should not affect dispatchDraw optimizations)
+ if (!mFadeInAdjacentScreens) {
+ for (int i = 0; i < getChildCount(); ++i) {
+ getPageAt(i).setAlpha(1f);
+ }
+ }
+
// Show the scroll indicator as you pan the page
showScrollingIndicator(false);
}
@@ -1704,6 +1720,11 @@
}
@Override
+ public void onLauncherTransitionStep(Launcher l, float t) {
+ mTransitionProgress = t;
+ }
+
+ @Override
public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
mIsSwitchingState = false;
mWallpaperOffset.setOverrideHorizontalCatchupConstant(false);