Merge change I4db52312 into eclair
* changes: Don't do swipes to open all apps anymore.
This commit is contained in:
@@ -342,24 +342,13 @@ public class AllAppsView extends RSSurfaceView
|
||||
public void onDropCompleted(View target, boolean success) {
|
||||
}
|
||||
|
||||
public void setZoomSwipeInProgress(boolean swiping, boolean touchStillDown) {
|
||||
mZoomSwipeInProgress = swiping;
|
||||
if (!touchStillDown) {
|
||||
mRollo.mState.newTouchDown = 0;
|
||||
mRollo.mState.save();
|
||||
mRollo.mInvokeTouchUp.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void setZoomTarget(float amount) {
|
||||
zoom(amount, true);
|
||||
}
|
||||
|
||||
public void setZoom(float amount) {
|
||||
zoom(amount, false);
|
||||
}
|
||||
|
||||
private void zoom(float amount, boolean animate) {
|
||||
/**
|
||||
* Zoom to the specifed amount.
|
||||
*
|
||||
* @param amount [0..1] 0 is hidden, 1 is open
|
||||
* @param animate Whether to animate.
|
||||
*/
|
||||
public void zoom(float amount, boolean animate) {
|
||||
if (mRollo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -42,15 +42,7 @@ import android.widget.FrameLayout;
|
||||
public class DragLayer extends FrameLayout {
|
||||
private static final String TAG = "Launcher.DragLayer";
|
||||
|
||||
private static final int DRAG = 1;
|
||||
private static final int SWIPE = 2;
|
||||
private static final int BOTH = DRAG | SWIPE;
|
||||
|
||||
DragController mDragController;
|
||||
SwipeController mSwipeController;
|
||||
|
||||
private int mAllowed = BOTH;
|
||||
|
||||
|
||||
/**
|
||||
* Used to create a new DragLayer from XML.
|
||||
@@ -66,10 +58,6 @@ public class DragLayer extends FrameLayout {
|
||||
mDragController = controller;
|
||||
}
|
||||
|
||||
public void setSwipeController(SwipeController controller) {
|
||||
mSwipeController = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
@@ -77,47 +65,11 @@ public class DragLayer extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
boolean result = false;
|
||||
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
mAllowed = BOTH;
|
||||
}
|
||||
|
||||
if ((mAllowed & DRAG) != 0) {
|
||||
result = mDragController.onInterceptTouchEvent(ev);
|
||||
if (result) {
|
||||
mAllowed = DRAG;
|
||||
}
|
||||
}
|
||||
|
||||
if ((mAllowed & SWIPE) != 0) {
|
||||
result = mSwipeController.onInterceptTouchEvent(ev);
|
||||
if (result) {
|
||||
mAllowed = SWIPE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return mDragController.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
boolean result = false;
|
||||
|
||||
if ((mAllowed & DRAG) != 0) {
|
||||
result = mDragController.onTouchEvent(ev);
|
||||
if (result) {
|
||||
mAllowed = DRAG;
|
||||
}
|
||||
}
|
||||
|
||||
if ((mAllowed & SWIPE) != 0) {
|
||||
result = mSwipeController.onTouchEvent(ev);
|
||||
if (result) {
|
||||
mAllowed = SWIPE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return mDragController.onTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ public final class Launcher extends Activity
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
private DragController mDragController;
|
||||
private SwipeController mSwipeController;
|
||||
private Workspace mWorkspace;
|
||||
|
||||
private AppWidgetManager mAppWidgetManager;
|
||||
@@ -513,18 +512,14 @@ public final class Launcher extends Activity
|
||||
private void setupViews() {
|
||||
mDragController = new DragController(this);
|
||||
DragController dragController = mDragController;
|
||||
mSwipeController = new SwipeController(this);
|
||||
SwipeController swipeController = mSwipeController;
|
||||
|
||||
DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
|
||||
dragLayer.setDragController(dragController);
|
||||
dragLayer.setSwipeController(swipeController);
|
||||
|
||||
mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
|
||||
mAllAppsGrid.setLauncher(this);
|
||||
mAllAppsGrid.setDragController(dragController);
|
||||
mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
|
||||
swipeController.setAllAppsView(mAllAppsGrid);
|
||||
|
||||
mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
|
||||
final Workspace workspace = mWorkspace;
|
||||
@@ -1427,7 +1422,6 @@ public final class Launcher extends Activity
|
||||
}
|
||||
|
||||
if (mWorkspace.allowLongPress()) {
|
||||
mSwipeController.cancelSwipe();
|
||||
if (cellInfo.cell == null) {
|
||||
if (cellInfo.valid) {
|
||||
// User long pressed on empty space
|
||||
@@ -1601,7 +1595,7 @@ public final class Launcher extends Activity
|
||||
}
|
||||
|
||||
void showAllApps() {
|
||||
mSwipeController.setMode(SwipeController.MODE_ALL_APPS, true);
|
||||
mAllAppsGrid.zoom(1.0f, true);
|
||||
//mWorkspace.hide();
|
||||
|
||||
// TODO: fade these two too
|
||||
@@ -1611,7 +1605,7 @@ public final class Launcher extends Activity
|
||||
|
||||
void closeAllApps(boolean animated) {
|
||||
if (mAllAppsGrid.isVisible()) {
|
||||
mSwipeController.setMode(SwipeController.MODE_WORKSPACE, animated);
|
||||
mAllAppsGrid.zoom(0.0f, animated);
|
||||
mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
|
||||
|
||||
// TODO: fade these two too
|
||||
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SwipeController {
|
||||
private static final String TAG = "Launcher.SwipeController";
|
||||
|
||||
public static final int MODE_WORKSPACE = 0;
|
||||
public static final int MODE_ALL_APPS = 1;
|
||||
public static final int MODE_ALL_APPS_ZOOMED = 2;
|
||||
|
||||
private static final int FRAME_DELAY = 1000 / 30;
|
||||
private static final float DECAY_CONSTANT = 0.65f;
|
||||
private static final float SPRING_CONSTANT = 0.0009f;
|
||||
|
||||
// configuration
|
||||
private int mSlopX;
|
||||
private int mSlopY;
|
||||
private float mSwipeDistance;
|
||||
|
||||
private AllAppsView mAllAppsView;
|
||||
|
||||
// state
|
||||
private VelocityTracker mVelocityTracker;
|
||||
private boolean mCanceled;
|
||||
private boolean mTracking;
|
||||
private int mDownX;
|
||||
private int mDownY;
|
||||
|
||||
private int mMode;
|
||||
private int mMinDest;
|
||||
private int mMaxDest;
|
||||
private float mAmount;
|
||||
|
||||
public SwipeController(Context context) {
|
||||
ViewConfiguration config = ViewConfiguration.get(context);
|
||||
mSlopX = config.getScaledTouchSlop();
|
||||
mSlopY = 4 * mSlopX / 3; // make it 33% more biased towards horizontal swiping.
|
||||
|
||||
DisplayMetrics display = context.getResources().getDisplayMetrics();
|
||||
mSwipeDistance = display.heightPixels / 2; // one half of the screen
|
||||
|
||||
setMode(MODE_WORKSPACE, false);
|
||||
}
|
||||
|
||||
public void setAllAppsView(AllAppsView allAppsView) {
|
||||
mAllAppsView = allAppsView;
|
||||
}
|
||||
|
||||
public void setMode(int mode, boolean animate) {
|
||||
mMinDest = mode - 1;
|
||||
if (mMinDest < MODE_WORKSPACE) {
|
||||
mMinDest = MODE_WORKSPACE;
|
||||
}
|
||||
mMaxDest = mode + 1;
|
||||
if (mMaxDest > MODE_ALL_APPS) { // TODO: support _ZOOMED
|
||||
mMaxDest = MODE_ALL_APPS;
|
||||
}
|
||||
mCanceled = true;
|
||||
if (mAllAppsView != null) {
|
||||
// TODO: do something with the wallpaper
|
||||
if (animate) {
|
||||
mAllAppsView.setZoomTarget(mode);
|
||||
} else {
|
||||
mAllAppsView.setZoom(mode);
|
||||
}
|
||||
}
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the current swipe, if there is one, and animates back to wherever we were before.
|
||||
*/
|
||||
public void cancelSwipe() {
|
||||
mCanceled = true;
|
||||
mAllAppsView.setZoomTarget(mMode);
|
||||
}
|
||||
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
onTouchEvent(ev);
|
||||
return mTracking;
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (mVelocityTracker == null) {
|
||||
mVelocityTracker = VelocityTracker.obtain();
|
||||
}
|
||||
mVelocityTracker.addMovement(ev);
|
||||
|
||||
final int screenX = (int)ev.getRawX();
|
||||
final int screenY = (int)ev.getRawY();
|
||||
|
||||
final int deltaX = screenX - mDownX;
|
||||
final int deltaY = screenY - mDownY;
|
||||
|
||||
final int action = ev.getAction();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// Remember location of down touch
|
||||
mCanceled = false;
|
||||
mTracking = false;
|
||||
mDownX = screenX;
|
||||
mDownY = screenY;
|
||||
mAllAppsView.setZoomSwipeInProgress(true, true);
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (!mCanceled && !mTracking) {
|
||||
if (Math.abs(deltaX) > mSlopX) {
|
||||
mCanceled = true;
|
||||
mTracking = false;
|
||||
mAllAppsView.setZoomSwipeInProgress(false, true);
|
||||
} else if (Math.abs(deltaY) > mSlopY) {
|
||||
mTracking = true;
|
||||
}
|
||||
}
|
||||
if (mTracking && !mCanceled) {
|
||||
track(screenY);
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (mTracking && !mCanceled) {
|
||||
fling(screenY);
|
||||
mAllAppsView.setZoomSwipeInProgress(false, false);
|
||||
}
|
||||
mVelocityTracker.recycle();
|
||||
mVelocityTracker = null;
|
||||
break;
|
||||
}
|
||||
|
||||
return mTracking || mCanceled;
|
||||
}
|
||||
|
||||
private float clamp(float v) {
|
||||
if (v < mMinDest) {
|
||||
return mMinDest;
|
||||
} else if (v > mMaxDest) {
|
||||
return mMaxDest;
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
private float dist(int screenY) {
|
||||
return clamp(mMode - ((screenY - mDownY) / mSwipeDistance));
|
||||
}
|
||||
|
||||
private void track(int screenY) {
|
||||
mAmount = dist(screenY);
|
||||
|
||||
//Log.d(TAG, "mAmount=" + mAmount);
|
||||
mAllAppsView.setZoom(mAmount);
|
||||
}
|
||||
|
||||
private void fling(int screenY) {
|
||||
mAmount = dist(screenY);
|
||||
|
||||
mVelocityTracker.computeCurrentVelocity(1);
|
||||
|
||||
float velocity = mVelocityTracker.getYVelocity() / mSwipeDistance;
|
||||
int direction = velocity >= 0.0f ? 1 : -1;
|
||||
mAmount = dist(screenY);
|
||||
|
||||
int dest = mMode;
|
||||
if (mMode < mAmount) {
|
||||
if (velocity < 0) { // up
|
||||
dest = mMode + 1;
|
||||
}
|
||||
} else {
|
||||
if (velocity > 0) { // down
|
||||
dest = mMode - 1;
|
||||
}
|
||||
}
|
||||
// else dest == mMode, so go back to where we started
|
||||
|
||||
//Log.d(TAG, "velocity=" + velocity + " mAmount=" + mAmount + " dest=" + dest);
|
||||
mAllAppsView.setZoomTarget(dest);
|
||||
mMode = dest;
|
||||
mCanceled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user