OSDN Git Service

Fixing issue with shadow drawing over search bar.
authorWinson <winsonc@google.com>
Wed, 20 Jul 2016 19:55:49 +0000 (12:55 -0700)
committerWinson <winsonc@google.com>
Wed, 20 Jul 2016 23:21:24 +0000 (16:21 -0700)
- Adding notion of clip-against view for click shadow alignment.

Bug: 30255227
Change-Id: Id5716a3484051a55690025d61f709e3d96cbe024

src/com/android/launcher3/CellLayout.java
src/com/android/launcher3/ClickShadowView.java
src/com/android/launcher3/Utilities.java
src/com/android/launcher3/allapps/AllAppsRecyclerViewContainerView.java

index 9030dae..77f6612 100644 (file)
@@ -406,7 +406,8 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
             mTouchFeedbackView.animate().cancel();
         } else {
             if (mTouchFeedbackView.setBitmap(background)) {
-                mTouchFeedbackView.alignWithIconView(icon, mShortcutsAndWidgets);
+                mTouchFeedbackView.alignWithIconView(icon, mShortcutsAndWidgets,
+                        null /* clipAgainstView */);
                 mTouchFeedbackView.animateShadow();
             }
         }
index e2bc6ba..aad1112 100644 (file)
@@ -21,6 +21,7 @@ import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
+import android.graphics.Rect;
 import android.view.View;
 import android.view.ViewDebug;
 import android.view.ViewGroup;
@@ -91,13 +92,27 @@ public class ClickShadowView extends View {
      * Aligns the shadow with {@param view}
      * @param viewParent immediate parent of {@param view}. It must be a sibling of this view.
      */
-    public void alignWithIconView(BubbleTextView view, ViewGroup viewParent) {
+    public void alignWithIconView(BubbleTextView view, ViewGroup viewParent, View clipAgainstView) {
         float leftShift = view.getLeft() + viewParent.getLeft() - getLeft();
         float topShift = view.getTop() + viewParent.getTop() - getTop();
         int iconWidth = view.getRight() - view.getLeft();
+        int iconHeight = view.getBottom() - view.getTop();
         int iconHSpace = iconWidth - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft();
         float drawableWidth = view.getIcon().getBounds().width();
 
+        if (clipAgainstView != null) {
+            // Set the bounds to clip against
+            int[] coords = new int[] {0, 0};
+            Utilities.getDescendantCoordRelativeToAncestor(clipAgainstView, (View) getParent(),
+                    coords, false);
+            int clipLeft = (int) Math.max(0, coords[0] - leftShift - mShadowPadding);
+            int clipTop = (int) Math.max(0, coords[1] - topShift - mShadowPadding) ;
+            setClipBounds(new Rect(clipLeft, clipTop, clipLeft + iconWidth, clipTop + iconHeight));
+        } else {
+            // Reset the clip bounds
+            setClipBounds(null);
+        }
+
         setTranslationX(leftShift
                 + viewParent.getTranslationX()
                 + view.getCompoundPaddingLeft() * view.getScaleX()
index 7b1a16c..ef78195 100644 (file)
@@ -113,8 +113,8 @@ public final class Utilities {
                 && "NMR1".compareTo(VERSION.CODENAME) <= 0;
     }
 
-    // TODO: use Build.VERSION_CODES when available
-    public static final boolean ATLEAST_MARSHMALLOW = Build.VERSION.SDK_INT >= 23;
+    public static final boolean ATLEAST_MARSHMALLOW =
+            Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
 
     public static final boolean ATLEAST_LOLLIPOP_MR1 =
             Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1;
index 09a7d59..1d5b209 100644 (file)
@@ -18,6 +18,7 @@ package com.android.launcher3.allapps;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.util.AttributeSet;
+import android.view.View;
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
 
@@ -26,6 +27,7 @@ import com.android.launcher3.BubbleTextView.BubbleTextShadowHandler;
 import com.android.launcher3.ClickShadowView;
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Launcher;
+import com.android.launcher3.R;
 
 /**
  * A container for RecyclerView to allow for the click shadow view to be shown behind an icon that
@@ -63,7 +65,8 @@ public class AllAppsRecyclerViewContainerView extends FrameLayout
             mTouchFeedbackView.setBitmap(null);
             mTouchFeedbackView.animate().cancel();
         } else if (mTouchFeedbackView.setBitmap(background)) {
-            mTouchFeedbackView.alignWithIconView(icon, (ViewGroup) icon.getParent());
+            View rv = findViewById(R.id.apps_list_view);
+            mTouchFeedbackView.alignWithIconView(icon, (ViewGroup) icon.getParent(), rv);
             mTouchFeedbackView.animateShadow();
         }
     }