diff --git a/src/com/android/launcher/GesturesActivity.java b/src/com/android/launcher/GesturesActivity.java
deleted file mode 100644
index 5c67a1e..0000000
--- a/src/com/android/launcher/GesturesActivity.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * Copyright (C) 2009 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.launcher;
-
-import android.app.ListActivity;
-import android.app.Dialog;
-import android.app.AlertDialog;
-import android.os.Bundle;
-import android.os.AsyncTask;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-import android.widget.AdapterView;
-import android.widget.Toast;
-import android.widget.EditText;
-import android.widget.BaseAdapter;
-import android.widget.CheckBox;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.LayoutInflater;
-import android.view.ContextMenu;
-import android.view.MenuItem;
-import android.gesture.GestureLibrary;
-import android.gesture.Gesture;
-import android.graphics.Bitmap;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.BitmapDrawable;
-import android.text.TextUtils;
-import android.database.DataSetObserver;
-
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Collections;
-import java.util.Map;
-
-public class GesturesActivity extends ListActivity implements AdapterView.OnItemClickListener {
-    private static final int MENU_ID_RENAME = 1;
-    private static final int MENU_ID_REMOVE = 2;
-
-    private static final int DIALOG_RENAME_GESTURE = 1;
-
-    // Type: long (id)
-    private static final String GESTURES_INFO_ID = "gestures.info_id";
-
-    private final Comparator<ApplicationInfo> mSorter =
-            new LauncherModel.ApplicationInfoComparator();
-
-    private GesturesAdapter mAdapter;
-    private GestureLibrary mStore;
-    private GesturesLoadTask mTask;
-
-    private Dialog mRenameDialog;
-    private EditText mInput;
-    private ApplicationInfo mCurrentRenameInfo;
-    private SharedPreferences mPreferences;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.gestures_settings);
-
-        mAdapter = new GesturesAdapter(this);
-        setListAdapter(new GesturesSettingsAdapter(mAdapter));
-        getListView().setOnItemClickListener(this);
-
-        mStore = Launcher.getGestureLibrary(this);
-        mTask = (GesturesLoadTask) new GesturesLoadTask().execute();
-
-        registerForContextMenu(getListView());
-
-        mPreferences = getSharedPreferences(GesturesConstants.PREFERENCES_NAME, MODE_PRIVATE);
-    }
-
-    @SuppressWarnings({ "UnusedDeclaration" })
-    public void back(View v) {
-        finish();
-    }
-
-    @Override
-    protected void onDestroy() {
-        super.onDestroy();
-
-        if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
-            mTask.cancel(true);
-            mTask = null;
-        }
-
-        cleanupRenameDialog();
-    }
-
-    @Override
-    protected void onSaveInstanceState(Bundle outState) {
-        super.onSaveInstanceState(outState);
-
-        if (mCurrentRenameInfo != null) {
-            outState.putLong(GESTURES_INFO_ID, mCurrentRenameInfo.id);
-        }
-    }
-
-    @Override
-    protected void onRestoreInstanceState(Bundle state) {
-        super.onRestoreInstanceState(state);
-
-        long id = state.getLong(GESTURES_INFO_ID, -1);
-        if (id != -1) {
-            mCurrentRenameInfo = Launcher.getModel().queryGesture(this, String.valueOf(id));
-        }
-    }
-
-    @Override
-    public void onCreateContextMenu(ContextMenu menu, View v,
-            ContextMenu.ContextMenuInfo menuInfo) {
-
-        super.onCreateContextMenu(menu, v, menuInfo);
-
-        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
-        if (info.position > 2) {
-            menu.setHeaderTitle(((TextView) info.targetView).getText());
-
-            menu.add(0, MENU_ID_RENAME, 0, R.string.gestures_rename);
-            menu.add(0, MENU_ID_REMOVE, 0, R.string.gestures_delete);
-        }
-    }
-
-    @Override
-    public boolean onContextItemSelected(MenuItem item) {
-        final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)
-                item.getMenuInfo();
-        final ApplicationInfo info = (ApplicationInfo) menuInfo.targetView.getTag();
-
-        switch (item.getItemId()) {
-            case MENU_ID_RENAME:
-                renameGesture(info);
-                return true;
-            case MENU_ID_REMOVE:
-                deleteGesture(info);
-                return true;
-        }
-
-        return super.onContextItemSelected(item);
-    }
-
-    private void renameGesture(ApplicationInfo info) {
-        mCurrentRenameInfo = info;
-        showDialog(DIALOG_RENAME_GESTURE);
-    }
-
-    @Override
-    protected Dialog onCreateDialog(int id) {
-        if (id == DIALOG_RENAME_GESTURE) {
-            return createRenameDialog();
-        }
-        return super.onCreateDialog(id);
-    }
-
-    @Override
-    protected void onPrepareDialog(int id, Dialog dialog) {
-        super.onPrepareDialog(id, dialog);
-        if (id == DIALOG_RENAME_GESTURE && mCurrentRenameInfo != null) {
-            mInput.setText(mCurrentRenameInfo.title);
-        }
-    }
-
-    private Dialog createRenameDialog() {
-        final View layout = View.inflate(this, R.layout.rename_folder, null);
-        mInput = (EditText) layout.findViewById(R.id.folder_name);
-        ((TextView) layout.findViewById(R.id.label)).setText(R.string.gestures_rename_label);
-
-        AlertDialog.Builder builder = new AlertDialog.Builder(this);
-        builder.setIcon(0);
-        builder.setTitle(getString(R.string.gestures_rename_title));
-        builder.setCancelable(true);
-        builder.setOnCancelListener(new Dialog.OnCancelListener() {
-            public void onCancel(DialogInterface dialog) {
-                cleanupRenameDialog();
-            }
-        });
-        builder.setNegativeButton(getString(R.string.cancel_action),
-            new Dialog.OnClickListener() {
-                public void onClick(DialogInterface dialog, int which) {
-                    cleanupRenameDialog();
-                }
-            }
-        );
-        builder.setPositiveButton(getString(R.string.rename_action),
-            new Dialog.OnClickListener() {
-                public void onClick(DialogInterface dialog, int which) {
-                    changeGestureName();
-                }
-            }
-        );
-        builder.setView(layout);
-        return builder.create();
-    }
-
-    private void changeGestureName() {
-        final String name = mInput.getText().toString();
-        if (!TextUtils.isEmpty(name)) {
-            final ApplicationInfo renameInfo = mCurrentRenameInfo;
-            final GesturesActivity.GesturesAdapter adapter = mAdapter;
-            final int count = adapter.getCount();
-
-            // Simple linear search, there should not be enough items to warrant
-            // a more sophisticated search
-            for (int i = 0; i < count; i++) {
-                final ApplicationInfo info = adapter.getItem(i);
-                if (info.id == renameInfo.id) {
-                    info.title = mInput.getText();
-                    LauncherModel.updateGestureInDatabase(this, info);
-                    break;
-                }
-            }
-
-            adapter.notifyDataSetChanged();
-        }
-        mCurrentRenameInfo = null;
-    }
-
-    private void cleanupRenameDialog() {
-        if (mRenameDialog != null) {
-            mRenameDialog.dismiss();
-            mRenameDialog = null;
-        }
-        mCurrentRenameInfo = null;
-    }
-
-    private void deleteGesture(ApplicationInfo info) {
-        mStore.removeEntry(String.valueOf(info.id));
-        // TODO: On a thread?
-        mStore.save();
-
-        final GesturesActivity.GesturesAdapter adapter = mAdapter;
-        adapter.setNotifyOnChange(false);
-        adapter.remove(info);
-        adapter.sort(mSorter);
-        adapter.notifyDataSetChanged();
-
-        LauncherModel.deleteGestureFromDatabase(this, info);
-
-        Toast.makeText(this, R.string.gestures_delete_success, Toast.LENGTH_SHORT).show();
-    }
-
-    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-        if (position == 1) {
-            final CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
-            checkBox.toggle();
-            mPreferences.edit().putBoolean(GesturesConstants.PREFERENCES_HOME_KEY,
-                    checkBox.isChecked()).commit();
-        }
-    }
-
-    private class GesturesLoadTask extends AsyncTask<Void, ApplicationInfo, Boolean> {
-        private int mThumbnailSize;
-        private int mThumbnailInset;
-        private int mPathColor;
-
-        @Override
-        protected void onPreExecute() {
-            super.onPreExecute();
-
-            final Resources resources = getResources();
-            mPathColor = resources.getColor(R.color.gesture_color);
-            mThumbnailInset = (int) resources.getDimension(R.dimen.gesture_thumbnail_inset);
-            mThumbnailSize = (int) resources.getDimension(R.dimen.gesture_thumbnail_size);
-        }
-
-        protected Boolean doInBackground(Void... params) {
-            if (isCancelled()) return Boolean.FALSE;
-
-            final GestureLibrary store = mStore;
-
-            if (store.load()) {
-                final LauncherModel model = Launcher.getModel();
-
-                for (String name : store.getGestureEntries()) {
-                    if (isCancelled()) break;
-
-                    final Gesture gesture = store.getGestures(name).get(0);
-                    final Bitmap bitmap = gesture.toBitmap(mThumbnailSize, mThumbnailSize,
-                            mThumbnailInset, mPathColor);
-                    final ApplicationInfo info = model.queryGesture(GesturesActivity.this, name);
-
-                    mAdapter.addBitmap(info.id, bitmap);
-                    publishProgress(info);
-                }
-
-                return Boolean.TRUE;
-            }
-
-            return Boolean.FALSE;
-        }
-
-        @Override
-        protected void onProgressUpdate(ApplicationInfo... values) {
-            super.onProgressUpdate(values);
-
-            final GesturesActivity.GesturesAdapter adapter = mAdapter;
-            adapter.setNotifyOnChange(false);
-
-            for (ApplicationInfo info : values) {
-                adapter.add(info);
-            }
-
-            adapter.sort(mSorter);
-            adapter.notifyDataSetChanged();
-        }
-    }
-
-    private class GesturesAdapter extends ArrayAdapter<ApplicationInfo> {
-        private final LayoutInflater mInflater;
-        private final Map<Long, Drawable> mThumbnails = Collections.synchronizedMap(
-                new HashMap<Long, Drawable>());
-
-        public GesturesAdapter(Context context) {
-            super(context, 0);
-            mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        }
-
-        void addBitmap(Long id, Bitmap bitmap) {
-            mThumbnails.put(id, new BitmapDrawable(bitmap));
-        }
-
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            if (convertView == null) {
-                convertView = mInflater.inflate(R.layout.gestures_settings_item, parent, false);
-            }
-
-            final ApplicationInfo info = getItem(position);
-            final TextView label = (TextView) convertView;
-
-            label.setTag(info);
-            label.setText(info.title);
-            label.setCompoundDrawablesWithIntrinsicBounds(info.icon, null,
-                    mThumbnails.get(info.id), null);
-
-            return convertView;
-        }
-    }
-
-    private class GesturesSettingsAdapter extends BaseAdapter {
-        private static final int FIXED_CHILDREN_COUNT = 3;
-
-        private static final int VIEW_TYPE_SEPARATOR = 0;
-        private static final int VIEW_TYPE_CHECKBOX = 1;
-
-        private final GesturesAdapter mAdapter;
-        private final LayoutInflater mInflater;
-
-        public GesturesSettingsAdapter(GesturesAdapter adapter) {
-            mAdapter = adapter;
-            mInflater = adapter.mInflater;
-            adapter.registerDataSetObserver(new DataSetObserver() {
-                @Override
-                public void onChanged() {
-                    notifyDataSetChanged();
-                }
-
-                @Override
-                public void onInvalidated() {
-                    notifyDataSetInvalidated();
-                }
-            });
-        }
-
-        public int getCount() {
-            return FIXED_CHILDREN_COUNT + mAdapter.getCount();
-        }
-
-        public Object getItem(int position) {
-            if (position < FIXED_CHILDREN_COUNT) {
-                return String.valueOf(position);
-            }
-            return mAdapter.getItem(position - FIXED_CHILDREN_COUNT);
-        }
-
-        public long getItemId(int position) {
-            return position;
-        }
-
-        @Override
-        public int getItemViewType(int position) {
-            if (position < FIXED_CHILDREN_COUNT) {
-                switch (position) {
-                    case 0:
-                    case 2:
-                        return VIEW_TYPE_SEPARATOR;
-                    case 1:
-                        return VIEW_TYPE_CHECKBOX;
-                }
-            }
-            return 2 + super.getItemViewType(position);
-        }
-
-        @Override
-        public int getViewTypeCount() {
-            return 2 + mAdapter.getViewTypeCount();
-        }
-
-        @Override
-        public boolean areAllItemsEnabled() {
-            return false;
-        }
-
-        @Override
-        public boolean isEnabled(int position) {
-            return position != 0 && position != 2;
-        }
-
-        public View getView(int position, View convertView, ViewGroup parent) {
-            if (position < FIXED_CHILDREN_COUNT) {
-                // NOTE: Don't bother with ViewHolders here, we only have 3 items and
-                //       the list is likely to not be very long
-                switch (position) {
-                    case 0:
-                        convertView = createHeader(convertView, parent,
-                                R.string.gestures_group_settings);
-                        break;
-                    case 1:
-                        convertView = createSetting(convertView, parent,
-                                R.string.gestures_preference_hotkey_title,
-                                R.string.gestures_preference_hotkey_summary);
-                        break;
-                    case 2:
-                        convertView = createHeader(convertView, parent,
-                                R.string.gestures_group_gestures);
-                        break;
-                }
-                return convertView;
-            }
-            return mAdapter.getView(position - FIXED_CHILDREN_COUNT, convertView, parent);
-        }
-
-        private View createSetting(View convertView, ViewGroup parent,
-                int title, int summary) {
-
-            if (convertView == null) {
-                convertView = mInflater.inflate(R.layout.list_checkbox_2lines, parent, false);
-            }
-
-            ((TextView) convertView.findViewById(R.id.title)).setText(title);
-            ((TextView) convertView.findViewById(R.id.summary)).setText(summary);
-            ((CheckBox) convertView.findViewById(R.id.checkbox)).setChecked(
-                    mPreferences.getBoolean(GesturesConstants.PREFERENCES_HOME_KEY, false));
-
-            return convertView;
-        }
-
-        private View createHeader(View convertView, ViewGroup parent, int text) {
-            if (convertView == null) {
-                convertView = mInflater.inflate(R.layout.list_category, parent, false);
-            }
-            ((TextView) convertView).setText(text);
-            return convertView;
-        }
-    }
-}
diff --git a/src/com/android/launcher/GesturesConstants.java b/src/com/android/launcher/GesturesConstants.java
deleted file mode 100644
index 93a1f10b..0000000
--- a/src/com/android/launcher/GesturesConstants.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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.launcher;
-
-interface GesturesConstants {
-    final double PREDICTION_THRESHOLD = 1.0;
-    final String STORE_NAME = "gestures";
-    final long MATCH_DELAY = 370;
-    final float LENGTH_THRESHOLD = 120.0f;
-    int PATH_SAMPLE_COUNT = 10;
-    String PREFERENCES_NAME = "gestures";
-    String PREFERENCES_HOME_KEY = "gestures.home";
-}
diff --git a/src/com/android/launcher/GesturesPanel.java b/src/com/android/launcher/GesturesPanel.java
deleted file mode 100644
index c0fce47..0000000
--- a/src/com/android/launcher/GesturesPanel.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2009 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.launcher;
-
-import android.widget.LinearLayout;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.KeyEvent;
-
-public class GesturesPanel extends LinearLayout {
-    public GesturesPanel(Context context) {
-        super(context);
-    }
-
-    public GesturesPanel(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    @Override
-    public boolean isOpaque() {
-        return true;
-    }
-
-    @Override
-    public boolean dispatchKeyEvent(KeyEvent event) {
-        final int keyCode = event.getKeyCode();
-        
-        switch (keyCode) {
-            case KeyEvent.KEYCODE_VOLUME_UP:
-            case KeyEvent.KEYCODE_VOLUME_DOWN:
-            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
-            case KeyEvent.KEYCODE_MUTE:
-            case KeyEvent.KEYCODE_HEADSETHOOK:
-            case KeyEvent.KEYCODE_MEDIA_STOP:
-            case KeyEvent.KEYCODE_MEDIA_NEXT:
-            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
-            case KeyEvent.KEYCODE_MEDIA_REWIND:
-            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
-            case KeyEvent.KEYCODE_CAMERA:
-            case KeyEvent.KEYCODE_CALL:
-            case KeyEvent.KEYCODE_SEARCH:
-                return ((Launcher) mContext).getWorkspace().getRootView().dispatchKeyEvent(event);
-        }
-        
-        if (keyCode == KeyEvent.KEYCODE_BACK) {
-            if (event.getAction() == KeyEvent.ACTION_DOWN) {
-                ((Launcher) mContext).hideGesturesPanel();
-                return true;
-            }
-        } else {
-            return super.dispatchKeyEvent(event);
-        }
-        return false;
-    }
-}
diff --git a/src/com/android/launcher/Launcher.java b/src/com/android/launcher/Launcher.java
index 25ad4e5..3fd141d 100644
--- a/src/com/android/launcher/Launcher.java
+++ b/src/com/android/launcher/Launcher.java
@@ -32,7 +32,6 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.SharedPreferences;
 import android.content.Intent.ShortcutIconResource;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
@@ -67,8 +66,6 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.MotionEvent;
-import android.view.Gravity;
 import android.view.View.OnLongClickListener;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
@@ -76,16 +73,8 @@
 import android.widget.SlidingDrawer;
 import android.widget.TextView;
 import android.widget.Toast;
-import android.widget.ImageView;
-import android.widget.PopupWindow;
-import android.widget.Button;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
-import android.gesture.GestureOverlayView;
-import android.gesture.GestureLibraries;
-import android.gesture.GestureLibrary;
-import android.gesture.Gesture;
-import android.gesture.Prediction;
 
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
@@ -106,9 +95,6 @@
     private static final boolean PROFILE_DRAWER = false;
     private static final boolean PROFILE_ROTATE = false;
     private static final boolean DEBUG_USER_INTERFACE = false;
-    private static final boolean DEBUG_GESTURES = false;
-
-    private static final boolean CONFIG_GESTURES_IMMEDIATE_MODE = true;
 
     private static final int WALLPAPER_SCREENS_SPAN = 2;
 
@@ -117,8 +103,7 @@
     private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
     private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
     private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
-    private static final int MENU_GESTURES = MENU_NOTIFICATIONS + 1;
-    private static final int MENU_SETTINGS = MENU_GESTURES + 1;
+    private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
 
     private static final int REQUEST_CREATE_SHORTCUT = 1;
     private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
@@ -127,9 +112,6 @@
     private static final int REQUEST_PICK_SHORTCUT = 7;
     private static final int REQUEST_PICK_LIVE_FOLDER = 8;
     private static final int REQUEST_PICK_APPWIDGET = 9;
-    private static final int REQUEST_PICK_GESTURE_ACTION = 10;
-    private static final int REQUEST_CREATE_GESTURE_ACTION = 11;
-    private static final int REQUEST_CREATE_GESTURE_APPLICATION_ACTION = 12;
 
     static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
 
@@ -172,12 +154,6 @@
     private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
     // Type: long
     private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
-    // Type: Gesture (Parcelable)
-    private static final String RUNTIME_STATE_PENDING_GESTURE = "launcher.gesture";
-    // Type: boolean
-    private static final String RUNTIME_STATE_GESTURES_PANEL = "launcher.gesture_panel_showing";
-    // Type: Gesture (Parcelable)
-    private static final String RUNTIME_STATE_GESTURES_PANEL_GESTURE = "launcher.gesture_panel_gesture";
 
     private static final LauncherModel sModel = new LauncherModel();
 
@@ -188,8 +164,6 @@
 
     private static WallpaperIntentReceiver sWallpaperReceiver;
 
-    private static GestureLibrary sLibrary;
-
     private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();
     private final ContentObserver mObserver = new FavoritesChangeObserver();
 
@@ -230,24 +204,11 @@
 
     private DesktopBinder mBinder;
 
-    private View mGesturesPanel;
-    private GestureOverlayView mGesturesOverlay;
-    private ImageView mGesturesAdd;
-    private PopupWindow mGesturesWindow;
-    private Launcher.GesturesProcessor mGesturesProcessor;
-    private Gesture mCurrentGesture;
-    private GesturesAction mGesturesAction;
-    private boolean mHideGesturesPanel;
-    private TextView mGesturesPrompt;
-    private Button mGesturesSend;
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mInflater = getLayoutInflater();
 
-        getGestureLibrary(this);
-
         mAppWidgetManager = AppWidgetManager.getInstance(this);
 
         mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
@@ -405,11 +366,7 @@
         // For example, the user would PICK_SHORTCUT for "Music playlist", and we
         // launch over to the Music app to actually CREATE_SHORTCUT.
 
-        if (resultCode == RESULT_OK && (mAddItemCellInfo != null ||
-                ((requestCode == REQUEST_PICK_GESTURE_ACTION ||
-                requestCode == REQUEST_CREATE_GESTURE_ACTION ||
-                requestCode == REQUEST_CREATE_GESTURE_APPLICATION_ACTION) && mCurrentGesture != null))) {
-
+        if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
             switch (requestCode) {
                 case REQUEST_PICK_APPLICATION:
                     completeAddApplication(this, data, mAddItemCellInfo, !mDesktopLocked);
@@ -432,16 +389,6 @@
                 case REQUEST_CREATE_APPWIDGET:
                     completeAddAppWidget(data, mAddItemCellInfo, !mDesktopLocked);
                     break;
-                case REQUEST_PICK_GESTURE_ACTION:
-                    processShortcut(data, REQUEST_CREATE_GESTURE_APPLICATION_ACTION,
-                            REQUEST_CREATE_GESTURE_ACTION);
-                    break;
-                case REQUEST_CREATE_GESTURE_ACTION:
-                    completeCreateGesture(data, true);
-                    break;
-                case REQUEST_CREATE_GESTURE_APPLICATION_ACTION:
-                    completeCreateGesture(data, false);
-                    break;
             }
         } else if (requestCode == REQUEST_PICK_APPWIDGET &&
                 resultCode == RESULT_CANCELED && data != null) {
@@ -486,23 +433,10 @@
     @Override
     protected void onPause() {
         super.onPause();
-        if (mGesturesWindow != null) {
-            mGesturesWindow.setAnimationStyle(0);
-            mGesturesWindow.update();
-        }
         closeDrawer(false);
     }
 
     @Override
-    protected void onStop() {
-        super.onStop();
-        if (mHideGesturesPanel) {
-            mHideGesturesPanel = false;
-            hideGesturesPanel();
-        }
-    }
-
-    @Override
     public Object onRetainNonConfigurationInstance() {
         // Flag any binder to stop early before switching
         if (mBinder != null) {
@@ -589,31 +523,6 @@
             mFolderInfo = sModel.getFolderById(this, id);
             mRestoring = true;
         }
-
-        mCurrentGesture = (Gesture) savedState.get(RUNTIME_STATE_PENDING_GESTURE);
-
-        boolean gesturesShowing = savedState.getBoolean(RUNTIME_STATE_GESTURES_PANEL, false);
-        if (gesturesShowing) {
-            if (mCurrentGesture == null) {
-                mCurrentGesture = (Gesture) savedState.get(RUNTIME_STATE_GESTURES_PANEL_GESTURE);
-            }
-            final Gesture gesture = mCurrentGesture;
-            mWorkspace.post(new Runnable() {
-                public void run() {
-                    showGesturesPanel(false);
-                    if (gesture != null && mWorkspace.getParent() != null) {
-                        mGesturesProcessor.matchGesture(gesture);
-                        mWorkspace.post(new Runnable() {
-                            public void run() {
-                                if (gesture != null && mWorkspace.getParent() != null) {
-                                    mGesturesOverlay.setGesture(gesture);
-                                }
-                            }
-                        });
-                    }
-                }
-            });
-        }
     }
 
     /**
@@ -661,72 +570,6 @@
         dragLayer.setIgnoredDropTarget(grid);
         dragLayer.setDragScoller(workspace);
         dragLayer.setDragListener(deleteZone);
-
-        mGesturesPanel = mInflater.inflate(R.layout.gestures, mDragLayer, false);
-        final View gesturesPanel = mGesturesPanel;
-
-        mGesturesAction = new GesturesAction();
-
-        mGesturesPrompt = (TextView) gesturesPanel.findViewById(R.id.gestures_prompt);
-        mGesturesSend = (Button) gesturesPanel.findViewById(R.id.gestures_action);
-        mGesturesSend.setOnClickListener(mGesturesAction);
-       
-        mGesturesAdd = (ImageView) gesturesPanel.findViewById(R.id.gestures_add);
-        final ImageView gesturesAdd = mGesturesAdd;
-        gesturesAdd.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                createGesture();
-            }
-        });
-
-        gesturesPanel.findViewById(R.id.gestures_list).setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                startActivity(new Intent(Launcher.this, GesturesActivity.class));
-            }
-        });
-
-        mGesturesOverlay = (GestureOverlayView) gesturesPanel.findViewById(R.id.gestures_overlay);
-        mGesturesProcessor = new GesturesProcessor();
-
-        final GestureOverlayView overlay = mGesturesOverlay;
-        overlay.addOnGestureListener(mGesturesProcessor);
-    }
-
-    private void createGesture() {
-        if (!mWaitingForResult) {
-            mCurrentGesture = mGesturesOverlay.getGesture();
-            mWaitingForResult = true;
-            pickShortcut(REQUEST_PICK_GESTURE_ACTION, R.string.title_select_shortcut);
-        }
-    }
-
-    private void completeCreateGesture(Intent data, boolean isShortcut) {
-        ApplicationInfo info;
-
-        if (isShortcut) {
-            info = infoFromShortcutIntent(this, data);
-        } else {
-            info = infoFromApplicationIntent(this, data);
-        }
-
-        boolean success = false;
-        if (info != null) {
-            info.isGesture = true;
-
-            if (LauncherModel.addGestureToDatabase(this, info, false)) {
-                mGesturesProcessor.addGesture(String.valueOf(info.id), mCurrentGesture);
-                mGesturesProcessor.update(info, mCurrentGesture);
-                Toast.makeText(this, getString(R.string.gestures_created, info.title),
-                        Toast.LENGTH_SHORT).show();
-                success = true;
-            }
-        }
-
-        if (!success) {
-            Toast.makeText(this, getString(R.string.gestures_failed), Toast.LENGTH_SHORT).show();
-        }
-
-        mCurrentGesture = null;
     }
 
     /**
@@ -977,32 +820,8 @@
             if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
                     Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
 
-                // TODO: This really should not be done here every time
-                final SharedPreferences preferences =
-                        getSharedPreferences(GesturesConstants.PREFERENCES_NAME, MODE_PRIVATE);
-                final boolean homeKey = preferences.getBoolean(
-                        GesturesConstants.PREFERENCES_HOME_KEY, false);
-
-                if (!homeKey) {
-                    if (!mWorkspace.isDefaultScreenShowing()) {
-                        mWorkspace.moveToDefaultScreen();
-                    }
-
-                    if (mGesturesWindow == null || mGesturesWindow.isShowing()) {
-                        hideGesturesPanel();
-                    }                    
-                } else {
-                    if (mGesturesPanel != null && mDragLayer.getWindowVisibility() == View.VISIBLE
-                            && (mDragLayer.hasWindowFocus() || (mGesturesWindow != null
-                            && mGesturesWindow.isShowing()))) {
-
-                        SearchManager searchManager =
-                                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
-
-                        if (!searchManager.isVisible()) {
-                            onHomeKeyPressed();
-                        }
-                    }
+                if (!mWorkspace.isDefaultScreenShowing()) {
+                    mWorkspace.moveToDefaultScreen();
                 }
 
                 closeDrawer();
@@ -1019,83 +838,6 @@
         }
     }
 
-    private void onHomeKeyPressed() {
-        if (mGesturesWindow == null || !mGesturesWindow.isShowing()) {
-            showGesturesPanel();
-        } else {
-            hideGesturesPanel();
-        }
-    }
-
-    private void showGesturesPanel() {
-        showGesturesPanel(true);
-    }
-
-    private void showGesturesPanel(boolean animate) {
-        resetGesturesPrompt();
-
-        mGesturesAdd.setVisibility(View.GONE);
-
-        mGesturesOverlay.clear(false);
-
-        PopupWindow window;
-        if (mGesturesWindow == null) {
-            mGesturesWindow = new PopupWindow(this);
-            window = mGesturesWindow;
-            window.setFocusable(true);
-            window.setTouchable(true);
-            window.setBackgroundDrawable(getResources().getDrawable(
-                    android.R.drawable.screen_background_dark));
-            window.setContentView(mGesturesPanel);
-        } else {
-            window = mGesturesWindow;
-        }
-        window.setAnimationStyle(animate ? com.android.internal.R.style.Animation_Toast : 0);
-
-        final int[] xy = new int[2];
-        final DragLayer dragLayer = mDragLayer;
-        dragLayer.getLocationOnScreen(xy);
-
-        window.setWidth(dragLayer.getWidth());
-        window.setHeight(dragLayer.getHeight() - 1);
-        window.showAtLocation(dragLayer, Gravity.TOP | Gravity.LEFT, xy[0], xy[1] + 1);
-    }
-
-    private void resetGesturesPrompt() {
-        mGesturesAction.intent = null;
-        mGesturesPrompt.setText(R.string.gestures_instructions);
-        mGesturesPrompt.setVisibility(View.VISIBLE);
-        mGesturesSend.setVisibility(View.GONE);
-    }
-
-    private void setGestureUnknown() {
-        mGesturesAction.intent = null;
-        mGesturesPrompt.setText(R.string.gestures_unknown);
-        mGesturesPrompt.setVisibility(View.VISIBLE);
-        mGesturesSend.setVisibility(View.GONE);
-    }
-
-    private void setGestureAction(Drawable icon, CharSequence title) {
-        mGesturesPrompt.setVisibility(View.GONE);
-        mGesturesSend.setVisibility(View.VISIBLE);
-        mGesturesSend.setText(title);
-        mGesturesSend.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
-    }
-
-    void hideGesturesPanel() {
-        hideGesturesPanel(true);
-    }
-
-    void hideGesturesPanel(boolean animate) {
-        if (mGesturesWindow != null) {
-            final PopupWindow popupWindow = mGesturesWindow;
-            popupWindow.setAnimationStyle(animate ?
-                    com.android.internal.R.style.Animation_Toast : 0);
-            popupWindow.update();
-            popupWindow.dismiss();
-        }
-    }
-
     @Override
     protected void onRestoreInstanceState(Bundle savedInstanceState) {
         // Do not call super here
@@ -1146,21 +888,6 @@
             outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
             outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
         }
-
-        if (mCurrentGesture != null && mWaitingForResult) {
-            outState.putParcelable(RUNTIME_STATE_PENDING_GESTURE, mCurrentGesture);
-        }
-
-        if (mGesturesWindow != null && mGesturesWindow.isShowing()) {
-            outState.putBoolean(RUNTIME_STATE_GESTURES_PANEL, true);
-
-            if (mCurrentGesture == null || !mWaitingForResult) {
-                final Gesture gesture = mGesturesOverlay.getGesture();
-                if (gesture != null) {
-                    outState.putParcelable(RUNTIME_STATE_GESTURES_PANEL_GESTURE, gesture);
-                }
-            }
-        }
     }
 
     @Override
@@ -1177,7 +904,6 @@
 
         TextKeyListener.getInstance().release();
 
-        hideGesturesPanel(false);
         mAllAppsGrid.clearTextFilter();
         mAllAppsGrid.setAdapter(null);
         sModel.unbind();
@@ -1280,11 +1006,6 @@
                 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
                 .setAlphabeticShortcut('N');
 
-        // TODO: Remove
-        menu.add(0, MENU_GESTURES, 0, R.string.menu_gestures)
-                .setIcon(com.android.internal.R.drawable.ic_menu_compose)
-                .setAlphabeticShortcut('G');
-
         final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
         settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
@@ -1321,9 +1042,6 @@
             case MENU_NOTIFICATIONS:
                 showNotifications();
                 return true;
-            case MENU_GESTURES:
-                showGesturesPanel();
-                return true;
         }
 
         return super.onOptionsItemSelected(item);
@@ -1852,7 +1570,6 @@
     }
 
     void startActivitySafely(Intent intent) {
-        mHideGesturesPanel = true;
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         try {
             startActivity(intent);
@@ -1979,14 +1696,6 @@
         return sModel;
     }
 
-    static GestureLibrary getGestureLibrary(Context context) {
-        if (sLibrary == null) {
-            // The context is not kept by the library so it's safe to do this
-            sLibrary = GestureLibraries.fromPrivateFile(context, GesturesConstants.STORE_NAME);
-        }
-        return sLibrary;
-    }
-
     void closeAllApplications() {
         mDrawer.close();
     }
@@ -2511,139 +2220,4 @@
             }
         }
     }
-
-    private class GesturesProcessor implements GestureOverlayView.OnGestureListener {
-
-        private final GestureMatcher mMatcher = new GestureMatcher();
-
-        GesturesProcessor() {
-            // TODO: Maybe the load should happen on a background thread?
-            sLibrary.load();
-        }
-
-        public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {
-            //noinspection PointlessBooleanExpression,ConstantConditions
-            if (!CONFIG_GESTURES_IMMEDIATE_MODE) {
-                overlay.removeCallbacks(mMatcher);
-                resetGesturesPrompt();
-            }
-
-            mGesturesAdd.setVisibility(View.GONE);
-        }
-
-        public void onGesture(GestureOverlayView overlay, MotionEvent event) {
-        }
-
-        public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
-            if (CONFIG_GESTURES_IMMEDIATE_MODE) {
-                mMatcher.gesture = overlay.getGesture();
-                if (mMatcher.gesture.getLength() < GesturesConstants.LENGTH_THRESHOLD) {
-                    overlay.clear(false);
-                    if (mGesturesAction.intent != null) {
-                        mGesturesAction.intent = null;
-                        setGestureAction(null, getString(R.string.gestures_unknown));
-                    }
-                } else {
-                    mMatcher.run();
-                }
-            } else {
-                overlay.removeCallbacks(mMatcher);
-
-                mMatcher.gesture = overlay.getGesture();
-                if (mMatcher.gesture.getLength() < GesturesConstants.LENGTH_THRESHOLD) {
-                    overlay.clear(false);
-                    if (mGesturesAction.intent != null) {
-                        mGesturesAction.intent = null;
-                        setGestureAction(null, getString(R.string.gestures_unknown));
-                    }
-                } else {
-                    overlay.postDelayed(mMatcher, GesturesConstants.MATCH_DELAY);
-                }
-            }
-        }
-
-        void matchGesture(Gesture gesture) {
-            mGesturesAdd.setVisibility(View.VISIBLE);
-
-            if (gesture != null) {
-                final ArrayList<Prediction> predictions = sLibrary.recognize(gesture);
-
-                if (DEBUG_GESTURES) {
-                    for (Prediction p : predictions) {
-                        d(LOG_TAG, String.format("name=%s, score=%f", p.name, p.score));
-                    }
-                }
-
-                boolean match = false;
-                if (predictions.size() > 0) {
-                    final Prediction prediction = predictions.get(0);
-                    if (prediction.score > GesturesConstants.PREDICTION_THRESHOLD) {
-                        match = true;
-
-                        ApplicationInfo info = sModel.queryGesture(Launcher.this, prediction.name);
-                        if (info != null) {
-                            updatePrompt(info);
-                        }
-                    }
-                }
-
-                if (!match){
-                    mGesturesAction.intent = null;
-                    setGestureUnknown();
-                }
-            }
-        }
-
-        private void updatePrompt(ApplicationInfo info) {
-            // TODO: BRING BACK            
-            if (mGesturesAction.intent != null &&
-                    info.intent.toUri(0).equals(mGesturesAction.intent.toUri(0)) &&
-                    info.title.equals(mGesturesSend.getText())) {
-                return;
-            }
-
-            setGestureAction(info.icon, info.title);
-
-            mGesturesAction.intent = info.intent;
-        }
-
-        public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {
-            //noinspection PointlessBooleanExpression,ConstantConditions
-            if (!CONFIG_GESTURES_IMMEDIATE_MODE) {
-                overlay.removeCallbacks(mMatcher);
-            }
-        }
-
-        void addGesture(String name, Gesture gesture) {
-            sLibrary.addGesture(name, gesture);
-            // TODO: On a background thread?
-            sLibrary.save();
-        }
-
-        void update(ApplicationInfo info, Gesture gesture) {
-            mGesturesOverlay.setGesture(gesture);
-            updatePrompt(info);
-        }
-
-        class GestureMatcher implements Runnable {
-            Gesture gesture;
-
-            public void run() {
-                if (gesture != null) {
-                    matchGesture(gesture);
-                }
-            }
-        }
-    }
-
-    private class GesturesAction implements View.OnClickListener {
-        Intent intent;
-
-        public void onClick(View v) {
-            if (intent != null) {
-                startActivitySafely(intent);
-            }
-        }
-    }
 }
-
