Localize special folder names
* make utility for looking up icon id for mailbox * make utility for looking up localized name for mailbox BUG: 2065586
This commit is contained in:
parent
aa69a17477
commit
dadba99498
|
@ -80,5 +80,42 @@
|
|||
<item>4</item>
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
<string-array name="special_mailbox_display_names" translatable="false">
|
||||
<!-- TYPE_INBOX = 0 -->
|
||||
<item>@string/special_mailbox_display_name_inbox</item>
|
||||
<!-- TYPE_MAIL = 1 -->
|
||||
<item></item>
|
||||
<!-- TYPE_PARENT = 2 -->
|
||||
<item></item>
|
||||
<!-- TYPE_OUTBOX = 3 -->
|
||||
<item>@string/special_mailbox_display_name_junk</item>
|
||||
<!-- TYPE_DRAFTS = 4 -->
|
||||
<item>@string/special_mailbox_display_name_drafts</item>
|
||||
<!-- TYPE_SENT = 5 -->
|
||||
<item>@string/special_mailbox_display_name_sent</item>
|
||||
<!-- TYPE_TRASH = 6 -->
|
||||
<item>@string/special_mailbox_display_name_trash</item>
|
||||
<!-- TYPE_JUNK = 7 -->
|
||||
<item>@string/special_mailbox_display_name_junk</item>
|
||||
</string-array>
|
||||
|
||||
<array name="special_mailbox_icons" translatable="false">
|
||||
<!-- TYPE_INBOX = 0 -->
|
||||
<item>@drawable/ic_list_inbox</item>
|
||||
<!-- TYPE_MAIL = 1 -->
|
||||
<item>@drawable/ic_list_folder</item>
|
||||
<!-- TYPE_PARENT = 2 -->
|
||||
<item>@drawable/ic_list_folder</item>
|
||||
<!-- TYPE_OUTBOX = 3 -->
|
||||
<item>@drawable/ic_list_outbox</item>
|
||||
<!-- TYPE_DRAFTS = 4 -->
|
||||
<item>@drawable/ic_list_drafts</item>
|
||||
<!-- TYPE_SENT = 5 -->
|
||||
<item>@drawable/ic_list_sent</item>
|
||||
<!-- TYPE_TRASH = 6 -->
|
||||
<item>@drawable/ic_list_trash</item>
|
||||
<!-- TYPE_JUNK = 7 -->
|
||||
<item></item>
|
||||
</array>
|
||||
</resources>
|
||||
|
|
|
@ -33,6 +33,9 @@ import java.util.Date;
|
|||
|
||||
import com.android.email.codec.binary.Base64;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Editable;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -273,4 +276,64 @@ public class Utility {
|
|||
}
|
||||
return selection.toString();
|
||||
}
|
||||
|
||||
public static class FolderProperties {
|
||||
|
||||
private static FolderProperties sInstance;
|
||||
|
||||
// Caches for frequently accessed resources.
|
||||
private String[] mSpecialMailbox = new String[] {};
|
||||
private TypedArray mSpecialMailboxDrawable;
|
||||
private Drawable mDefaultMailboxDrawable;
|
||||
|
||||
private FolderProperties(Context context) {
|
||||
mSpecialMailbox = context.getResources().getStringArray(
|
||||
R.array.special_mailbox_display_names);
|
||||
for (int i = 0; i < mSpecialMailbox.length; ++i) {
|
||||
if ("".equals(mSpecialMailbox[i])) {
|
||||
// there is no localized name, so use the display name from the server
|
||||
mSpecialMailbox[i] = null;
|
||||
}
|
||||
}
|
||||
mSpecialMailboxDrawable =
|
||||
context.getResources().obtainTypedArray(R.array.special_mailbox_icons);
|
||||
mDefaultMailboxDrawable =
|
||||
context.getResources().getDrawable(R.drawable.ic_list_folder);
|
||||
}
|
||||
|
||||
public static FolderProperties getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (FolderProperties.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new FolderProperties(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup names of localized special mailboxes
|
||||
* @param type
|
||||
* @return Localized strings
|
||||
*/
|
||||
public String getDisplayName(int type) {
|
||||
if (type < mSpecialMailbox.length) {
|
||||
return mSpecialMailbox[type];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup icons of special mailboxes
|
||||
* @param type
|
||||
* @return icon's drawable
|
||||
*/
|
||||
public synchronized Drawable getIconIds(int type) {
|
||||
if (type < mSpecialMailboxDrawable.length()) {
|
||||
return mSpecialMailboxDrawable.getDrawable(type);
|
||||
}
|
||||
return mDefaultMailboxDrawable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.android.email.activity;
|
|||
import com.android.email.Controller;
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.Utility;
|
||||
import com.android.email.activity.setup.AccountSettings;
|
||||
import com.android.email.activity.setup.AccountSetupBasics;
|
||||
import com.android.email.mail.MessagingException;
|
||||
|
@ -74,8 +75,6 @@ public class AccountFolderList extends ListActivity
|
|||
KeyEvent.KEYCODE_D, KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_B, KeyEvent.KEYCODE_U,
|
||||
KeyEvent.KEYCODE_G
|
||||
};
|
||||
private static String[] sSpecialMailboxDisplayNameListCache;
|
||||
|
||||
private int mSecretKeyCodeIndex = 0;
|
||||
|
||||
private static final String ICICLE_SELECTED_ACCOUNT = "com.android.email.selectedAccount";
|
||||
|
@ -175,9 +174,6 @@ public class AccountFolderList extends ListActivity
|
|||
mSelectedContextAccount = (Account) icicle.getParcelable(ICICLE_SELECTED_ACCOUNT);
|
||||
}
|
||||
|
||||
// Called only for filling cache of specialMailboxDisplayName
|
||||
getSpecialMailboxDisplayName(this, 0);
|
||||
|
||||
((TextView) findViewById(R.id.title_left_text)).setText(R.string.app_name);
|
||||
|
||||
mLoadAccountsTask = (LoadAccountsTask) new LoadAccountsTask().execute();
|
||||
|
@ -331,46 +327,6 @@ public class AccountFolderList extends ListActivity
|
|||
return childCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localized name for special folders.
|
||||
* @param context
|
||||
* @param type The mailbox type of interest
|
||||
* @return A localized name, or null if the mailbox is not special
|
||||
*/
|
||||
private static String getSpecialMailboxDisplayName(Context context, int type) {
|
||||
final int MAILBOX_TYPE_SIZE = 8;
|
||||
if (sSpecialMailboxDisplayNameListCache == null) {
|
||||
sSpecialMailboxDisplayNameListCache = new String[MAILBOX_TYPE_SIZE];
|
||||
// TYPE_INBOX = 0
|
||||
sSpecialMailboxDisplayNameListCache[0] = context.getString(
|
||||
R.string.special_mailbox_display_name_inbox);
|
||||
// TYPE_MAIL = 1
|
||||
sSpecialMailboxDisplayNameListCache[1] = null;
|
||||
// TYPE_PARENT = 2
|
||||
sSpecialMailboxDisplayNameListCache[2] = null;
|
||||
// TYPE_DRAFTS = 3
|
||||
sSpecialMailboxDisplayNameListCache[3] = context.getString(
|
||||
R.string.special_mailbox_display_name_drafts);
|
||||
// TYPE_OUTBOX = 4
|
||||
sSpecialMailboxDisplayNameListCache[4] = context.getString(
|
||||
R.string.special_mailbox_display_name_outbox);
|
||||
// TYPE_SENT = 5
|
||||
sSpecialMailboxDisplayNameListCache[5] = context.getString(
|
||||
R.string.special_mailbox_display_name_sent);
|
||||
// TYPE_TRASH = 6
|
||||
sSpecialMailboxDisplayNameListCache[6] = context.getString(
|
||||
R.string.special_mailbox_display_name_trash);
|
||||
// TYPE_JUNK = 7
|
||||
sSpecialMailboxDisplayNameListCache[7] = context.getString(
|
||||
R.string.special_mailbox_display_name_junk);
|
||||
}
|
||||
if (type >= MAILBOX_TYPE_SIZE) {
|
||||
return null;
|
||||
} else {
|
||||
return sSpecialMailboxDisplayNameListCache[type];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async task to handle the accounts query outside of the UI thread
|
||||
*/
|
||||
|
@ -696,7 +652,8 @@ public class AccountFolderList extends ListActivity
|
|||
// Invisible (not "gone") to maintain spacing
|
||||
view.findViewById(R.id.chip).setVisibility(View.INVISIBLE);
|
||||
|
||||
String text = getSpecialMailboxDisplayName(context, cursor.getInt(MAILBOX_TYPE));
|
||||
String text = Utility.FolderProperties.getInstance(context)
|
||||
.getDisplayName(cursor.getInt(MAILBOX_TYPE));
|
||||
if (text == null) {
|
||||
text = cursor.getString(MAILBOX_DISPLAY_NAME);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.android.email.activity;
|
|||
|
||||
import com.android.email.Controller;
|
||||
import com.android.email.R;
|
||||
import com.android.email.Utility;
|
||||
import com.android.email.activity.setup.AccountSettings;
|
||||
import com.android.email.mail.MessagingException;
|
||||
import com.android.email.provider.EmailContent;
|
||||
|
@ -419,8 +420,12 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
|
|||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
// TODO translation by mailbox type
|
||||
String text = cursor.getString(COLUMN_DISPLAY_NAME);
|
||||
int type = cursor.getInt(COLUMN_TYPE);
|
||||
String text = Utility.FolderProperties.getInstance(context)
|
||||
.getDisplayName(type);
|
||||
if (text == null) {
|
||||
text = cursor.getString(COLUMN_DISPLAY_NAME);
|
||||
}
|
||||
TextView nameView = (TextView) view.findViewById(R.id.mailbox_name);
|
||||
if (text != null) {
|
||||
nameView.setText(text);
|
||||
|
@ -455,29 +460,8 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
|
|||
countView.setVisibility(View.GONE);
|
||||
}
|
||||
ImageView folderIcon = (ImageView) view.findViewById(R.id.folder_icon);
|
||||
int type = cursor.getInt(COLUMN_TYPE);
|
||||
int resId = -1;
|
||||
switch (type) {
|
||||
case Mailbox.TYPE_INBOX:
|
||||
resId = R.drawable.ic_list_inbox;
|
||||
break;
|
||||
case Mailbox.TYPE_OUTBOX:
|
||||
resId = R.drawable.ic_list_outbox;
|
||||
break;
|
||||
case Mailbox.TYPE_DRAFTS:
|
||||
resId = R.drawable.ic_list_drafts;
|
||||
break;
|
||||
case Mailbox.TYPE_SENT:
|
||||
resId = R.drawable.ic_list_sent;
|
||||
break;
|
||||
case Mailbox.TYPE_TRASH:
|
||||
resId = R.drawable.ic_list_trash;
|
||||
break;
|
||||
default:
|
||||
resId = R.drawable.ic_list_folder;
|
||||
break;
|
||||
}
|
||||
folderIcon.setImageResource(resId);
|
||||
folderIcon.setImageDrawable(Utility.FolderProperties.getInstance(context)
|
||||
.getIconIds(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -133,10 +133,12 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
|||
EmailContent.RECORD_ID, MailboxColumns.TYPE, MailboxColumns.FLAG_VISIBLE
|
||||
};
|
||||
|
||||
private static final int MAILBOX_DISPLAY_NAME_COLUMN_ID = 0;
|
||||
private static final int MAILBOX_ACCOUNT_KEY_COLUMN_ID = 1;
|
||||
private static final int MAILBOX_NAME_COLUMN_ID = 0;
|
||||
private static final int MAILBOX_NAME_COLUMN_ACCOUNT_KEY = 1;
|
||||
private static final int MAILBOX_NAME_COLUMN_TYPE = 2;
|
||||
private static final String[] MAILBOX_NAME_PROJECTION = new String[] {
|
||||
MailboxColumns.DISPLAY_NAME, MailboxColumns.ACCOUNT_KEY};
|
||||
MailboxColumns.DISPLAY_NAME, MailboxColumns.ACCOUNT_KEY,
|
||||
MailboxColumns.TYPE};
|
||||
|
||||
private static final int ACCOUNT_DISPLAY_NAME_COLUMN_ID = 0;
|
||||
private static final String[] ACCOUNT_NAME_PROJECTION = new String[] {
|
||||
|
@ -925,8 +927,12 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
|||
new String[] { Long.toString(mMailboxKey) }, null);
|
||||
try {
|
||||
if (c.moveToFirst()) {
|
||||
mailboxName = c.getString(MAILBOX_DISPLAY_NAME_COLUMN_ID);
|
||||
accountKey = c.getString(MAILBOX_ACCOUNT_KEY_COLUMN_ID);
|
||||
mailboxName = Utility.FolderProperties.getInstance(MessageList.this)
|
||||
.getDisplayName(c.getInt(MAILBOX_NAME_COLUMN_TYPE));
|
||||
if (mailboxName == null) {
|
||||
mailboxName = c.getString(MAILBOX_NAME_COLUMN_ID);
|
||||
}
|
||||
accountKey = c.getString(MAILBOX_NAME_COLUMN_ACCOUNT_KEY);
|
||||
}
|
||||
} finally {
|
||||
c.close();
|
||||
|
|
Loading…
Reference in New Issue