refactor chip code to be a little less ugly
This commit is contained in:
parent
950940ca3a
commit
baf99b114b
3 changed files with 52 additions and 47 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue