OSDN Git Service

Fix selection highlight for tablets
authorMichael Kolb <kolby@google.com>
Tue, 21 May 2013 22:10:51 +0000 (15:10 -0700)
committerMichael Kolb <kolby@google.com>
Tue, 21 May 2013 22:31:51 +0000 (15:31 -0700)
  Bug: 9044356

Fixes selection highlight for the new asset sizes.

Change-Id: Ibf21a1f90d6cd1faf62a221d71d55928dc7a3b4a

src/com/android/gallery3d/filtershow/category/CategoryView.java
src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java

index 84a973b..059eb10 100644 (file)
@@ -44,6 +44,8 @@ public class CategoryView extends View implements View.OnClickListener {
     private Paint mSelectPaint;
     CategoryAdapter mAdapter;
     private int mSelectionStroke;
+    private Paint mBorderPaint;
+    private int mBorderStroke;
 
     public static void setTextSize(int size) {
         sTextSize = size;
@@ -63,6 +65,9 @@ public class CategoryView extends View implements View.OnClickListener {
         mSelectPaint = new Paint();
         mSelectPaint.setStyle(Paint.Style.FILL);
         mSelectPaint.setColor(res.getColor(R.color.filtershow_category_selection));
+        mBorderPaint = new Paint(mSelectPaint);
+        mBorderPaint.setColor(Color.BLACK);
+        mBorderStroke = mSelectionStroke / 3;
     }
 
     public void drawText(Canvas canvas, String text) {
@@ -91,8 +96,10 @@ public class CategoryView extends View implements View.OnClickListener {
                 Bitmap bitmap = mAction.getImage();
                 canvas.drawBitmap(bitmap, 0, 0, mPaint);
                 if (mAdapter.isSelected(this)) {
-                    SelectionRenderer.drawSelection(canvas, 0, 0, bitmap.getWidth(),
-                            bitmap.getHeight(), mSelectionStroke, mSelectPaint);
+                    SelectionRenderer.drawSelection(canvas, 0, 0,
+                            Math.min(bitmap.getWidth(), getWidth()),
+                            Math.min(bitmap.getHeight(), getHeight()),
+                            mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint);
                 }
             }
             mPaint.setColor(mBackgroundColor);
index 1b108bd..ef40c5e 100644 (file)
@@ -29,4 +29,20 @@ public class SelectionRenderer {
         canvas.drawRect(right - stroke, top, right, bottom, paint);
     }
 
+    public static void drawSelection(Canvas canvas, int left, int top, int right, int bottom,
+            int stroke, Paint selectPaint, int border, Paint borderPaint) {
+        canvas.drawRect(left, top, right, top + stroke, selectPaint);
+        canvas.drawRect(left, bottom - stroke, right, bottom, selectPaint);
+        canvas.drawRect(left, top, left + stroke, bottom, selectPaint);
+        canvas.drawRect(right - stroke, top, right, bottom, selectPaint);
+        canvas.drawRect(left + stroke, top + stroke, right - stroke,
+                top + stroke + border, borderPaint);
+        canvas.drawRect(left + stroke, bottom - stroke - border, right - stroke,
+                bottom - stroke, borderPaint);
+        canvas.drawRect(left + stroke, top + stroke, left + stroke + border,
+                bottom - stroke, borderPaint);
+        canvas.drawRect(right - stroke - border, top + stroke, right - stroke,
+                bottom - stroke, borderPaint);
+    }
+
 }