Use a single account color resource table; add convenience methods

* The color chip resource table was duplicated in three files
* Move these into a common location in Email.java and add
  convenience method for retrieving color chip resource id based
  on accountId
* Simplifies future changes to account color selection
* Add RGB color information on these resources (provided by
  rfulcher) and add a convenience method for retrieving these

Change-Id: If1c2d22fba91cfce46a2618cd2b73cf7a534ce51
This commit is contained in:
Marc Blank 2010-02-04 08:54:47 -08:00
parent f19a02ac69
commit 37658316f9
5 changed files with 42 additions and 79 deletions

View File

@ -145,6 +145,44 @@ public class Email extends Application {
public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE = "com.android.exchange";
// The color chip resources and the RGB color values in the array below must be kept in sync
private static final int[] ACCOUNT_COLOR_CHIP_RES_IDS = new int[] {
R.drawable.appointment_indicator_leftside_1,
R.drawable.appointment_indicator_leftside_2,
R.drawable.appointment_indicator_leftside_3,
R.drawable.appointment_indicator_leftside_4,
R.drawable.appointment_indicator_leftside_5,
R.drawable.appointment_indicator_leftside_6,
R.drawable.appointment_indicator_leftside_7,
R.drawable.appointment_indicator_leftside_8,
R.drawable.appointment_indicator_leftside_9,
R.drawable.appointment_indicator_leftside_10,
R.drawable.appointment_indicator_leftside_11,
R.drawable.appointment_indicator_leftside_12,
R.drawable.appointment_indicator_leftside_13,
R.drawable.appointment_indicator_leftside_14,
R.drawable.appointment_indicator_leftside_15,
R.drawable.appointment_indicator_leftside_16,
R.drawable.appointment_indicator_leftside_17,
R.drawable.appointment_indicator_leftside_18,
R.drawable.appointment_indicator_leftside_19,
R.drawable.appointment_indicator_leftside_20,
R.drawable.appointment_indicator_leftside_21,
};
private static final int[] ACCOUNT_COLOR_CHIP_RGBS = new int[] {0x6aad08, 0xe24c7f, 0xed8500,
0x3b6dd3, 0x29ad9c, 0x6e38d1, 0x31649b, 0x309363, 0x109918, 0xcc3431, 0xacad18, 0xd4ad00,
0x9b449b, 0xe56021, 0xa46c6a, 0x8a6a8a, 0x60738b, 0x7082ab, 0x518987, 0x813149, 0xb48d59
};
public static int getAccountColorResourceId(long accountId) {
return ACCOUNT_COLOR_CHIP_RES_IDS[(int)accountId % ACCOUNT_COLOR_CHIP_RES_IDS.length];
}
public static int getAccountColor(long accountId) {
return ACCOUNT_COLOR_CHIP_RGBS[(int)accountId % ACCOUNT_COLOR_CHIP_RGBS.length];
}
/**
* Called throughout the application when the number of accounts has changed. This method
* enables or disables the Compose activity, the boot receiver and the service based on

View File

@ -130,30 +130,6 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
MailboxColumns.UNREAD_COUNT
};
private static final int[] mColorChipResIds = new int[] {
R.drawable.appointment_indicator_leftside_1,
R.drawable.appointment_indicator_leftside_2,
R.drawable.appointment_indicator_leftside_3,
R.drawable.appointment_indicator_leftside_4,
R.drawable.appointment_indicator_leftside_5,
R.drawable.appointment_indicator_leftside_6,
R.drawable.appointment_indicator_leftside_7,
R.drawable.appointment_indicator_leftside_8,
R.drawable.appointment_indicator_leftside_9,
R.drawable.appointment_indicator_leftside_10,
R.drawable.appointment_indicator_leftside_11,
R.drawable.appointment_indicator_leftside_12,
R.drawable.appointment_indicator_leftside_13,
R.drawable.appointment_indicator_leftside_14,
R.drawable.appointment_indicator_leftside_15,
R.drawable.appointment_indicator_leftside_16,
R.drawable.appointment_indicator_leftside_17,
R.drawable.appointment_indicator_leftside_18,
R.drawable.appointment_indicator_leftside_19,
R.drawable.appointment_indicator_leftside_20,
R.drawable.appointment_indicator_leftside_21,
};
/**
* Start the Accounts list activity. Uses the CLEAR_TOP flag which means that other stacked
* activities may be killed in order to get back to Accounts.
@ -791,8 +767,7 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
long accountId = cursor.getLong(Account.CONTENT_ID_COLUMN);
View chipView = view.findViewById(R.id.chip);
int chipResId = mColorChipResIds[(int)accountId % mColorChipResIds.length];
chipView.setBackgroundResource(chipResId);
chipView.setBackgroundResource(Email.getAccountColorResourceId(accountId));
chipView.setVisibility(View.VISIBLE);
String text = cursor.getString(Account.CONTENT_DISPLAY_NAME_COLUMN);

View File

@ -79,30 +79,6 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
private MailboxListHandler mHandler = new MailboxListHandler();
private ControllerResults mControllerCallback = new ControllerResults();
private static final int[] mColorChipResIds = new int[] {
R.drawable.appointment_indicator_leftside_1,
R.drawable.appointment_indicator_leftside_2,
R.drawable.appointment_indicator_leftside_3,
R.drawable.appointment_indicator_leftside_4,
R.drawable.appointment_indicator_leftside_5,
R.drawable.appointment_indicator_leftside_6,
R.drawable.appointment_indicator_leftside_7,
R.drawable.appointment_indicator_leftside_8,
R.drawable.appointment_indicator_leftside_9,
R.drawable.appointment_indicator_leftside_10,
R.drawable.appointment_indicator_leftside_11,
R.drawable.appointment_indicator_leftside_12,
R.drawable.appointment_indicator_leftside_13,
R.drawable.appointment_indicator_leftside_14,
R.drawable.appointment_indicator_leftside_15,
R.drawable.appointment_indicator_leftside_16,
R.drawable.appointment_indicator_leftside_17,
R.drawable.appointment_indicator_leftside_18,
R.drawable.appointment_indicator_leftside_19,
R.drawable.appointment_indicator_leftside_20,
R.drawable.appointment_indicator_leftside_21,
};
// DB access
private long mAccountId;
private LoadMailboxesTask mLoadMailboxesTask;
@ -636,8 +612,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
statusView.setVisibility(View.GONE);
}
View chipView = view.findViewById(R.id.chip);
int chipResId = mColorChipResIds[(int)mAccountId % mColorChipResIds.length];
chipView.setBackgroundResource(chipResId);
chipView.setBackgroundResource(Email.getAccountColorResourceId(mAccountId));
// TODO do we use a different count for special mailboxes (total count vs. unread)
int count = -1;
switch (type) {

View File

@ -114,30 +114,6 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
private TextView mRightTitle;
private ProgressBar mProgressIcon;
private static final int[] mColorChipResIds = new int[] {
R.drawable.appointment_indicator_leftside_1,
R.drawable.appointment_indicator_leftside_2,
R.drawable.appointment_indicator_leftside_3,
R.drawable.appointment_indicator_leftside_4,
R.drawable.appointment_indicator_leftside_5,
R.drawable.appointment_indicator_leftside_6,
R.drawable.appointment_indicator_leftside_7,
R.drawable.appointment_indicator_leftside_8,
R.drawable.appointment_indicator_leftside_9,
R.drawable.appointment_indicator_leftside_10,
R.drawable.appointment_indicator_leftside_11,
R.drawable.appointment_indicator_leftside_12,
R.drawable.appointment_indicator_leftside_13,
R.drawable.appointment_indicator_leftside_14,
R.drawable.appointment_indicator_leftside_15,
R.drawable.appointment_indicator_leftside_16,
R.drawable.appointment_indicator_leftside_17,
R.drawable.appointment_indicator_leftside_18,
R.drawable.appointment_indicator_leftside_19,
R.drawable.appointment_indicator_leftside_20,
R.drawable.appointment_indicator_leftside_21,
};
// DB access
private ContentResolver mResolver;
private long mMailboxId;
@ -1586,8 +1562,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
// Load the UI
View chipView = view.findViewById(R.id.chip);
int chipResId = mColorChipResIds[(int)itemView.mAccountId % mColorChipResIds.length];
chipView.setBackgroundResource(chipResId);
chipView.setBackgroundResource(Email.getAccountColorResourceId(itemView.mAccountId));
TextView fromView = (TextView) view.findViewById(R.id.from);
String text = cursor.getString(COLUMN_DISPLAY_NAME);

View File

@ -255,7 +255,7 @@ public class FolderSyncParser extends AbstractSyncParser {
cv.put(Calendars.SELECTED, 1);
cv.put(Calendars.HIDDEN, 0);
// TODO Find out how to set color!!
cv.put(Calendars.COLOR, 0xFF228B22 /*green*/);
cv.put(Calendars.COLOR, Email.getAccountColor(mAccountId));
cv.put(Calendars.TIMEZONE, Time.getCurrentTimezone());
cv.put(Calendars.ACCESS_LEVEL, Calendars.OWNER_ACCESS);
cv.put(Calendars.OWNER_ACCOUNT, mAccount.mEmailAddress);