From baf99b114b5ee4982fd0c86b9ec0e619303504aa Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 21 Sep 2012 16:44:39 -0400 Subject: [PATCH] refactor chip code to be a little less ugly --- src/com/fsck/k9/Account.java | 25 +++++---- src/com/fsck/k9/activity/Accounts.java | 2 +- src/com/fsck/k9/view/ColorChip.java | 72 +++++++++++++------------- 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 7f9e32b23..62b21afe9 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -198,6 +198,7 @@ public class Account implements BaseAccount { private ColorChip mToMeReadColorChip; private ColorChip mFromMeUnreadColorChip; private ColorChip mFromMeReadColorChip; + private ColorChip mCheckmarkChip; /** @@ -763,15 +764,21 @@ public class Account implements BaseAccount { } public synchronized void cacheChips() { - mReadColorChip = new ColorChip(mChipColor, true, false, false, false); - mUnreadColorChip = new ColorChip(mChipColor, false, false, false, false); - mToMeReadColorChip = new ColorChip(mChipColor, true, true, false, false); - mToMeUnreadColorChip = new ColorChip(mChipColor, false,true, false, false); - mFromMeReadColorChip = new ColorChip(mChipColor, true, false, true, false); - mFromMeUnreadColorChip = new ColorChip(mChipColor, false, false, true, false); - mFlaggedReadColorChip = new ColorChip(mChipColor, true, false, false, true); - mFlaggedUnreadColorChip = new ColorChip(mChipColor, false, false, false, true); + mReadColorChip = new ColorChip(mChipColor, true, ColorChip.CIRCULAR); + mUnreadColorChip = new ColorChip(mChipColor, false, ColorChip.CIRCULAR); + mToMeReadColorChip = new ColorChip(mChipColor, true, ColorChip.RIGHT_POINTING); + mToMeUnreadColorChip = new ColorChip(mChipColor, false,ColorChip.RIGHT_POINTING); + mFromMeReadColorChip = new ColorChip(mChipColor, true, ColorChip.LEFT_POINTING); + mFromMeUnreadColorChip = new ColorChip(mChipColor, false,ColorChip.LEFT_POINTING); + mFlaggedReadColorChip = new ColorChip(mChipColor, true, ColorChip.STAR); + mFlaggedUnreadColorChip = new ColorChip(mChipColor, false, ColorChip.STAR); + mCheckmarkChip = new ColorChip(mChipColor, true, ColorChip.CHECKMARK); } + + public ColorChip getCheckmarkChip() { + return mCheckmarkChip; + } + public synchronized int getChipColor() { return mChipColor; } @@ -809,7 +816,7 @@ public class Account implements BaseAccount { } public ColorChip generateColorChip() { - return new ColorChip(mChipColor, false, false, false, false); + return new ColorChip(mChipColor, false, ColorChip.CIRCULAR); } diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index f4219505a..67497ff27 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -1713,7 +1713,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } } else { - holder.chip.setBackgroundDrawable(new ColorChip(0xff999999, false, false, false, false).drawable()); + holder.chip.setBackgroundDrawable(new ColorChip(0xff999999, false, ColorChip.CIRCULAR).drawable()); } diff --git a/src/com/fsck/k9/view/ColorChip.java b/src/com/fsck/k9/view/ColorChip.java index 99dcaa78b..040198c9e 100644 --- a/src/com/fsck/k9/view/ColorChip.java +++ b/src/com/fsck/k9/view/ColorChip.java @@ -7,55 +7,53 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.PathShape; public class ColorChip { - private static final Path CIRCULAR_CHIP_PATH = new Path(); - private static final Path LEFT_POINTING_CHIP_PATH = new Path(); - private static final Path RIGHT_POINTING_CHIP_PATH = new Path(); - private static final Path STAR_CHIP_PATH = new Path(); + public static final Path CIRCULAR = new Path(); + public static final Path LEFT_POINTING = new Path(); + public static final Path RIGHT_POINTING = new Path(); + public static final Path STAR = new Path(); + public static final Path CHECKMARK = new Path(); + static { - CIRCULAR_CHIP_PATH.addCircle(8,8,7f,Path.Direction.CW); - CIRCULAR_CHIP_PATH.close(); + CIRCULAR.addCircle(8,8,7f,Path.Direction.CW); + CIRCULAR.close(); - RIGHT_POINTING_CHIP_PATH.addArc(new RectF(0f,0f,15f,15f) , 90, 180); - RIGHT_POINTING_CHIP_PATH.lineTo(16f,7f); - RIGHT_POINTING_CHIP_PATH.lineTo(8f, 15f); - RIGHT_POINTING_CHIP_PATH.close(); + RIGHT_POINTING.addArc(new RectF(0f,0f,15f,15f) , 90, 180); + RIGHT_POINTING.lineTo(16f,7f); + RIGHT_POINTING.lineTo(8f, 15f); + RIGHT_POINTING.close(); - LEFT_POINTING_CHIP_PATH.addArc(new RectF(0f,0f,15f,15f) , 270, 180); - LEFT_POINTING_CHIP_PATH.moveTo(8f, 0f); - LEFT_POINTING_CHIP_PATH.lineTo(0f,7f); - LEFT_POINTING_CHIP_PATH.lineTo(8f, 15f); - LEFT_POINTING_CHIP_PATH.close(); + LEFT_POINTING.addArc(new RectF(0f,0f,15f,15f) , 270, 180); + LEFT_POINTING.moveTo(8f, 0f); + LEFT_POINTING.lineTo(0f,7f); + LEFT_POINTING.lineTo(8f, 15f); + LEFT_POINTING.close(); - STAR_CHIP_PATH.moveTo(8f,0f); - STAR_CHIP_PATH.lineTo(11f,5f); - STAR_CHIP_PATH.lineTo(16f,6f); - STAR_CHIP_PATH.lineTo(12f,10f); - STAR_CHIP_PATH.lineTo(14f,16f); - STAR_CHIP_PATH.lineTo(8f,13f); - STAR_CHIP_PATH.lineTo(2f,16f); - STAR_CHIP_PATH.lineTo(4f,10f); - STAR_CHIP_PATH.lineTo(0f,6f); - STAR_CHIP_PATH.lineTo(5f,5f); - STAR_CHIP_PATH.lineTo(8f,0f); - STAR_CHIP_PATH.close(); + STAR.moveTo(8f,0f); + STAR.lineTo(11f,5f); + STAR.lineTo(16f,6f); + STAR.lineTo(12f,10f); + STAR.lineTo(14f,16f); + STAR.lineTo(8f,13f); + STAR.lineTo(2f,16f); + STAR.lineTo(4f,10f); + STAR.lineTo(0f,6f); + STAR.lineTo(5f,5f); + STAR.lineTo(8f,0f); + STAR.close(); + CHECKMARK.moveTo(0f,10f); + CHECKMARK.lineTo(6f,16f); + CHECKMARK.lineTo(16f,2f); } private ShapeDrawable mDrawable; - public ColorChip(int color, boolean messageRead, boolean toMe, boolean fromMe, boolean messageFlagged ) { - if (messageFlagged) { - mDrawable = new ShapeDrawable(new PathShape(STAR_CHIP_PATH, 16f, 16f)); - } else if ( fromMe ) { - mDrawable = new ShapeDrawable(new PathShape(LEFT_POINTING_CHIP_PATH, 16f, 16f)); - } else if ( toMe) { - mDrawable = new ShapeDrawable(new PathShape(RIGHT_POINTING_CHIP_PATH, 16f, 16f)); - } else { - mDrawable = new ShapeDrawable(new PathShape(CIRCULAR_CHIP_PATH, 16f, 16f)); - } + public ColorChip(int color, boolean messageRead, Path shape) { + + mDrawable = new ShapeDrawable(new PathShape(shape, 16f, 16f)); mDrawable.getPaint().setStrokeWidth(1); if (messageRead) {