Switched to tabbed version of AllApps2D on xlarge screens.

- add a temporary new zoom animation for all apps
- modify AllApps2D to allow it to be transparent
- other changes to dismiss the customization drawer when appropriate

Change-Id: I5660ab77f256ded299c1721c589983a1b30d56a4
diff --git a/src/com/android/launcher2/AllApps2D.java b/src/com/android/launcher2/AllApps2D.java
index b18fc1a..b993364 100644
--- a/src/com/android/launcher2/AllApps2D.java
+++ b/src/com/android/launcher2/AllApps2D.java
@@ -16,15 +16,15 @@
 
 package com.android.launcher2;
 
-import java.util.ArrayList;
-import java.util.Collections;
+import com.android.launcher.R;
 
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.res.Resources;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.Bitmap;
-import android.graphics.Color;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.KeyEvent;
@@ -39,7 +39,8 @@
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
-import com.android.launcher.R;
+import java.util.ArrayList;
+import java.util.Collections;
 
 public class AllApps2D
         extends RelativeLayout
@@ -67,6 +68,8 @@
 
     private AppsAdapter mAppsAdapter;
 
+    private boolean mIsViewOpaque;
+
     // ------------------------------------------------------------
     
     public static class HomeButton extends ImageButton {
@@ -125,24 +128,24 @@
 
     @Override
     protected void onFinishInflate() {
-        setBackgroundColor(Color.BLACK);
+        mIsViewOpaque = super.isOpaque();
 
         try {
             mGrid = (GridView)findViewWithTag("all_apps_2d_grid");
             if (mGrid == null) throw new Resources.NotFoundException();
             mGrid.setOnItemClickListener(this);
             mGrid.setOnItemLongClickListener(this);
-            mGrid.setBackgroundColor(Color.BLACK);
-            mGrid.setCacheColorHint(Color.BLACK);
             
+            // The home button is optional; some layouts might not use it
             ImageButton homeButton = (ImageButton) findViewWithTag("all_apps_2d_home");
-            if (homeButton == null) throw new Resources.NotFoundException();
-            homeButton.setOnClickListener(
-                new View.OnClickListener() {
-                    public void onClick(View v) {
-                        mLauncher.closeAllApps(true);
-                    }
-                });
+            if (homeButton != null) {
+                homeButton.setOnClickListener(
+                    new View.OnClickListener() {
+                        public void onClick(View v) {
+                            mLauncher.closeAllApps(true);
+                        }
+                    });
+            }
         } catch (Resources.NotFoundException e) {
             Log.e(TAG, "Can't find necessary layout elements for AllApps2D");
         }
@@ -251,7 +254,7 @@
 
     @Override
     public boolean isOpaque() {
-        return mZoom > 0.999f;
+        return mIsViewOpaque && mZoom > 0.999f;
     }
 
     public void setApps(ArrayList<ApplicationInfo> list) {
diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java
new file mode 100644
index 0000000..67293d9
--- /dev/null
+++ b/src/com/android/launcher2/AllAppsTabbed.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2010 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 com.android.launcher.R;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.widget.TabHost;
+
+import java.util.ArrayList;
+
+/**
+ * Implements a tabbed version of AllApps2D.
+ */
+public class AllAppsTabbed extends TabHost implements AllAppsView {
+
+    private static final String TAG = "Launcher.AllAppsTabbed";
+
+    private AllAppsView mAllApps2D;
+
+    public AllAppsTabbed(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    protected void onFinishInflate() {
+        try {
+            mAllApps2D = (AllAppsView)findViewById(R.id.all_apps_2d);
+            if (mAllApps2D == null) throw new Resources.NotFoundException();
+        } catch (Resources.NotFoundException e) {
+            Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
+        }
+        setup();
+
+        // This lets us share the same view between all tabs
+        TabContentFactory contentFactory = new TabContentFactory() {
+            public View createTabContent(String tag) {
+                return (View)mAllApps2D;
+            }
+        };
+
+        // TODO: Make these tabs show the appropriate content (they're no-ops for now)
+        addTab(newTabSpec("apps").setIndicator("All").setContent(contentFactory));
+        addTab(newTabSpec("apps").setIndicator("Apps").setContent(contentFactory));
+        addTab(newTabSpec("apps").setIndicator("Games").setContent(contentFactory));
+        addTab(newTabSpec("apps").setIndicator("Downloaded").setContent(contentFactory));
+
+        setCurrentTab(0);
+        setVisibility(GONE);
+    }
+
+    @Override
+    public void setLauncher(Launcher launcher) {
+        mAllApps2D.setLauncher(launcher);
+    }
+
+    @Override
+    public void setDragController(DragController dragger) {
+        mAllApps2D.setDragController(dragger);
+    }
+
+    @Override
+    public void zoom(float zoom, boolean animate) {
+        // NOTE: animate parameter is ignored for the TabHost itself
+        setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
+        mAllApps2D.zoom(zoom, animate);
+        bringChildToFront((View)mAllApps2D);
+        getParent().bringChildToFront(this);
+    }
+
+    @Override
+    public boolean isVisible() {
+        return mAllApps2D.isVisible();
+    }
+
+    @Override
+    public void setApps(ArrayList<ApplicationInfo> list) {
+        mAllApps2D.setApps(list);
+    }
+
+    @Override
+    public void addApps(ArrayList<ApplicationInfo> list) {
+        mAllApps2D.addApps(list);
+    }
+
+    @Override
+    public void removeApps(ArrayList<ApplicationInfo> list) {
+        mAllApps2D.removeApps(list);
+    }
+
+    @Override
+    public void updateApps(ArrayList<ApplicationInfo> list) {
+        mAllApps2D.updateApps(list);
+    }
+
+    @Override
+    public void dumpState() {
+        mAllApps2D.dumpState();
+    }
+
+    @Override
+    public void surrender() {
+        mAllApps2D.surrender();
+    }
+
+}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index dd93cbb..43b12ed 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -34,8 +34,8 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.Intent.ShortcutIconResource;
+import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
@@ -68,10 +68,11 @@
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.View.OnLongClickListener;
 import android.view.ViewGroup;
 import android.view.WindowManager;
-import android.view.View.OnLongClickListener;
 import android.view.animation.Animation;
+import android.view.animation.Animation.AnimationListener;
 import android.view.animation.AnimationUtils;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
@@ -1027,10 +1028,13 @@
             boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
                         != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
             boolean allAppsVisible = isAllAppsVisible();
+
+            // TODO: Figure out the right thing to do in XLarge mode here
             if (!mWorkspace.isDefaultScreenShowing()) {
                 mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
             }
             closeAllApps(alreadyOnHome && allAppsVisible);
+            hideCustomizationDrawer();
 
             final View v = getWindow().peekDecorView();
             if (v != null && v.getWindowToken() != null) {
@@ -1256,7 +1260,14 @@
 
     private void addItems() {
         closeAllApps(true);
-        showAddDialog(mMenuAddInfo);
+        if (LauncherApplication.isScreenXLarge()) {
+            // Animate the widget chooser up from the bottom of the screen
+            if (!isCustomizationDrawerVisible()) {
+                showCustomizationDrawer();
+            }
+        } else {
+            showAddDialog(mMenuAddInfo);
+        }
     }
 
     void addAppWidgetFromDrop(ComponentName appWidgetProvider, CellLayout.CellInfo cellInfo) {
@@ -1487,6 +1498,8 @@
     public void onBackPressed() {
         if (isAllAppsVisible()) {
             closeAllApps(true);
+        } else if (isCustomizationDrawerVisible()) {
+            hideCustomizationDrawer();
         } else {
             closeFolder();
         }
@@ -1560,26 +1573,10 @@
         }
     }
 
-    private final class SlideDownFinishedListener implements Animation.AnimationListener {
-        TabHost mHomeCustomizationDrawer;
-        SlideDownFinishedListener(TabHost homeCustomizationDrawer) {
-            mHomeCustomizationDrawer = homeCustomizationDrawer;
-        }
-        public void onAnimationEnd(Animation animation) {
-            mHomeCustomizationDrawer.setVisibility(View.GONE);
-        }
-        public void onAnimationRepeat(Animation animation) {}
-        public void onAnimationStart(Animation animation) {}
-    }
-
     public boolean onTouch(View v, MotionEvent event) {
         // this is being forwarded from mWorkspace;
         // clicking anywhere on the workspace causes the drawer to slide down
-        if (mHomeCustomizationDrawer != null && mHomeCustomizationDrawer.getVisibility() == View.VISIBLE) {
-            Animation slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_down);
-            slideDownAnimation.setAnimationListener(new SlideDownFinishedListener(mHomeCustomizationDrawer));
-            mHomeCustomizationDrawer.startAnimation(slideDownAnimation);
-        }
+        hideCustomizationDrawer();
         return false;
     }
 
@@ -1590,16 +1587,7 @@
      * @param v The view that was clicked.
      */
     public void onClickAddButton(View v) {
-
-        // Animate the widget chooser up from the bottom of the screen
-        if (mHomeCustomizationDrawer != null && mHomeCustomizationDrawer.getVisibility() == View.GONE) {
-            mHomeCustomizationDrawer.setVisibility(View.VISIBLE);
-            mHomeCustomizationDrawer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_up));
-        }
-    }
-
-    public void onClickAllAppsButton(View w) {
-        showAllApps(true);
+        addItems();
     }
 
     void startActivitySafely(Intent intent, Object tag) {
@@ -2036,7 +2024,16 @@
     }
 
     void showAllApps(boolean animated) {
-        mAllAppsGrid.zoom(1.0f, animated);
+        hideCustomizationDrawer();
+
+        if (LauncherApplication.isScreenXLarge() && animated) {
+            // Not really a zoom -- this just makes the view visible
+            mAllAppsGrid.zoom(1.0f, false);
+            Animation anim = AnimationUtils.loadAnimation(this, R.anim.all_apps_zoom_in);
+            ((View) mAllAppsGrid).startAnimation(anim);
+        } else {
+            mAllAppsGrid.zoom(1.0f, animated);
+        }
 
         ((View) mAllAppsGrid).setFocusable(true);
         ((View) mAllAppsGrid).requestFocus();
@@ -2087,7 +2084,19 @@
     void closeAllApps(boolean animated) {
         if (mAllAppsGrid.isVisible()) {
             mWorkspace.setVisibility(View.VISIBLE);
-            mAllAppsGrid.zoom(0.0f, animated);
+            if (LauncherApplication.isScreenXLarge() && animated) {
+                Animation anim = AnimationUtils.loadAnimation(this, R.anim.all_apps_zoom_out);
+                anim.setAnimationListener(new AnimationListener() {
+                    public void onAnimationStart(Animation animation) {}
+                    public void onAnimationRepeat(Animation animation) {}
+                    public void onAnimationEnd(Animation animation) {
+                        mAllAppsGrid.zoom(0.0f, false);
+                    }
+                });
+                ((View)mAllAppsGrid).startAnimation(anim);
+            } else {
+                mAllAppsGrid.zoom(0.0f, animated);
+            }
             ((View)mAllAppsGrid).setFocusable(false);
             mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
         }
@@ -2101,6 +2110,33 @@
         // TODO
     }
 
+    private boolean isCustomizationDrawerVisible() {
+        return mHomeCustomizationDrawer != null && mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
+    }
+
+    private void showCustomizationDrawer() {
+        if (isAllAppsVisible()) {
+            // TODO: Make a smoother transition here
+            closeAllApps(false);
+        }
+        mHomeCustomizationDrawer.setVisibility(View.VISIBLE);
+        mHomeCustomizationDrawer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_up));
+    }
+
+    private void hideCustomizationDrawer() {
+        if (isCustomizationDrawerVisible()) {
+            Animation slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_down);
+            slideDownAnimation.setAnimationListener(new Animation.AnimationListener() {
+                public void onAnimationEnd(Animation animation) {
+                    mHomeCustomizationDrawer.setVisibility(View.GONE);
+                }
+                public void onAnimationRepeat(Animation animation) {}
+                public void onAnimationStart(Animation animation) {}
+            });
+            mHomeCustomizationDrawer.startAnimation(slideDownAnimation);
+        }
+    }
+
     /**
      * Displays the shortcut creation dialog and launches, if necessary, the
      * appropriate activity.