OSDN Git Service

Disable hardware layers for drag views
authorMichael Jurka <mikejurka@google.com>
Fri, 29 Jun 2012 22:17:04 +0000 (15:17 -0700)
committerMichael Jurka <mikejurka@google.com>
Fri, 29 Jun 2012 22:17:04 +0000 (15:17 -0700)
Also, avoiding allocating paint object every time we swipe

src/com/android/launcher2/CellLayout.java
src/com/android/launcher2/DragView.java

index 284db1b..34c290a 100644 (file)
@@ -159,6 +159,7 @@ public class CellLayout extends ViewGroup {
 
     private final static PorterDuffXfermode sAddBlendMode =
             new PorterDuffXfermode(PorterDuff.Mode.ADD);
+    private final static Paint sPaint = new Paint();
 
     public CellLayout(Context context) {
         this(context, null);
@@ -302,11 +303,11 @@ public class CellLayout extends ViewGroup {
     }
 
     public void enableHardwareLayers() {
-        mShortcutsAndWidgets.setLayerType(LAYER_TYPE_HARDWARE, null);
+        mShortcutsAndWidgets.setLayerType(LAYER_TYPE_HARDWARE, sPaint);
     }
 
     public void disableHardwareLayers() {
-        mShortcutsAndWidgets.setLayerType(LAYER_TYPE_NONE, null);
+        mShortcutsAndWidgets.setLayerType(LAYER_TYPE_NONE, sPaint);
     }
 
     public void buildHardwareLayer() {
index d7ac97d..389421d 100644 (file)
@@ -244,9 +244,6 @@ public class DragView extends View {
     public void show(int touchX, int touchY) {
         mDragLayer.addView(this);
 
-        // Enable hw-layers on this view
-        setLayerType(View.LAYER_TYPE_HARDWARE, null);
-
         // Start the pick-up animation
         DragLayer.LayoutParams lp = new DragLayer.LayoutParams(0, 0);
         lp.width = mBitmap.getWidth();
@@ -255,7 +252,12 @@ public class DragView extends View {
         setLayoutParams(lp);
         setTranslationX(touchX - mRegistrationX);
         setTranslationY(touchY - mRegistrationY);
-        mAnim.start();
+        // Post the animation to skip other expensive work happening on the first frame
+        post(new Runnable() {
+                public void run() {
+                    mAnim.start();
+                }
+            });
     }
 
     public void cancelAnimation() {
@@ -282,9 +284,6 @@ public class DragView extends View {
 
     void remove() {
         if (getParent() != null) {
-            // Disable hw-layers on this view
-            setLayerType(View.LAYER_TYPE_NONE, null);
-
             mDragLayer.removeView(DragView.this);
         }
     }