EML viewer: Set title, and show arrow next to the app icon
- Set "Viewing FILENAME" as title. - Home icon now has "back" arrow. Closes the activity when clicked. Bug 3221312 Change-Id: I689499e10704d3c5d206df4aa12e21db9687c4c5
This commit is contained in:
parent
ad79ec4754
commit
d1ee5b8fa5
|
@ -398,6 +398,11 @@ save attachment.</string>
|
|||
<!-- Toast shown following a meeting invite reply, declined -->
|
||||
<string name="message_view_invite_toast_no">You have declined this invitation</string>
|
||||
<!--Confirmation dialog title shown when user tries to delete messages. [CHAR LIMIT=16] -->
|
||||
|
||||
<!-- Title of the EML viewer activity. [CHAR LIMIT=32] -->
|
||||
<string name="eml_view_title">Viewing
|
||||
<xliff:g id="filename" example="test.eml">%s</xliff:g></string>
|
||||
|
||||
<string name="message_delete_dialog_title">Discard message</string>
|
||||
<!--Confirmation dialog text shown when user tries to delete messages. [CHAR LIMIT=32] -->
|
||||
<plurals name="message_delete_confirm">
|
||||
|
|
|
@ -44,6 +44,7 @@ import android.os.Environment;
|
|||
import android.os.Handler;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
|
@ -1165,4 +1166,22 @@ public class Utility {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String[] ATTACHMENT_META_NAME_PROJECTION = {
|
||||
OpenableColumns.DISPLAY_NAME
|
||||
};
|
||||
private static final int ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME = 0;
|
||||
|
||||
/**
|
||||
* @return Filename of a content of {@code contentUri}. If the provider doesn't provide the
|
||||
* filename, returns the last path segment of the URI.
|
||||
*/
|
||||
public static String getContentFileName(Context context, Uri contentUri) {
|
||||
String name = getFirstRowString(context, contentUri, ATTACHMENT_META_NAME_PROJECTION, null,
|
||||
null, null, ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME);
|
||||
if (name == null) {
|
||||
name = contentUri.getLastPathSegment();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,11 @@ import com.android.email.provider.EmailContent.MessageColumns;
|
|||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.database.Cursor;
|
||||
|
@ -109,11 +107,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||
|
||||
private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1;
|
||||
|
||||
private static final String[] ATTACHMENT_META_NAME_PROJECTION = {
|
||||
OpenableColumns.DISPLAY_NAME
|
||||
};
|
||||
private static final int ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME = 0;
|
||||
|
||||
private static final String[] ATTACHMENT_META_SIZE_PROJECTION = {
|
||||
OpenableColumns.SIZE
|
||||
};
|
||||
|
@ -1073,22 +1066,12 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||
|
||||
private Attachment loadAttachmentInfo(Uri uri) {
|
||||
long size = -1;
|
||||
String name = null;
|
||||
ContentResolver contentResolver = getContentResolver();
|
||||
|
||||
// Load name & size independently, because not all providers support both
|
||||
Cursor metadataCursor = contentResolver.query(uri, ATTACHMENT_META_NAME_PROJECTION,
|
||||
null, null, null);
|
||||
if (metadataCursor != null) {
|
||||
try {
|
||||
if (metadataCursor.moveToFirst()) {
|
||||
name = metadataCursor.getString(ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME);
|
||||
}
|
||||
} finally {
|
||||
metadataCursor.close();
|
||||
}
|
||||
}
|
||||
metadataCursor = contentResolver.query(uri, ATTACHMENT_META_SIZE_PROJECTION,
|
||||
final String name = Utility.getContentFileName(this, uri);
|
||||
|
||||
Cursor metadataCursor = contentResolver.query(uri, ATTACHMENT_META_SIZE_PROJECTION,
|
||||
null, null, null);
|
||||
if (metadataCursor != null) {
|
||||
try {
|
||||
|
@ -1100,10 +1083,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||
}
|
||||
}
|
||||
|
||||
// When the name or size are not provided, we need to generate them locally.
|
||||
if (name == null) {
|
||||
name = uri.getLastPathSegment();
|
||||
}
|
||||
// When the size is not provided, we need to determine it locally.
|
||||
if (size < 0) {
|
||||
// if the URI is a file: URI, ask file system for its size
|
||||
if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
|
|
@ -18,11 +18,15 @@ package com.android.email.activity;
|
|||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.Utility;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* Activity to show file-based messages. (i.e. *.eml files, and possibly *.msg files).
|
||||
|
@ -37,6 +41,9 @@ import android.util.Log;
|
|||
* See {@link MessageViewBase} for the class relation diagram.
|
||||
*/
|
||||
public class MessageFileView extends MessageViewBase {
|
||||
|
||||
private ActionBar mActionBar;
|
||||
|
||||
/**
|
||||
* URI to the email (i.e. *.eml files, and possibly *.msg files) file that's being
|
||||
*/
|
||||
|
@ -44,6 +51,8 @@ public class MessageFileView extends MessageViewBase {
|
|||
|
||||
private MessageFileViewFragment mFragment;
|
||||
|
||||
private LoadFilenameTask mLoadFilenameTask;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.message_file_view;
|
||||
|
@ -53,6 +62,10 @@ public class MessageFileView extends MessageViewBase {
|
|||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mActionBar = getActionBar();
|
||||
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP
|
||||
| ActionBar.DISPLAY_SHOW_TITLE);
|
||||
|
||||
mFragment = (MessageFileViewFragment) getFragmentManager().findFragmentById(
|
||||
R.id.message_file_view_fragment);
|
||||
mFragment.setCallback(this);
|
||||
|
@ -65,10 +78,12 @@ public class MessageFileView extends MessageViewBase {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO set title here: "Viewing XXX.eml".
|
||||
|
||||
// Load message.
|
||||
getFragment().openMessage(mFileEmailUri);
|
||||
|
||||
// Set title.
|
||||
mLoadFilenameTask = new LoadFilenameTask(mFileEmailUri);
|
||||
mLoadFilenameTask.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,6 +91,23 @@ public class MessageFileView extends MessageViewBase {
|
|||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Utility.cancelTaskInterrupt(mLoadFilenameTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed(); // Treat as "back".
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/** @return always -1, as no accounts are associated with EML files. */
|
||||
@Override
|
||||
protected long getAccountId() {
|
||||
|
@ -87,4 +119,35 @@ public class MessageFileView extends MessageViewBase {
|
|||
protected MessageFileViewFragment getFragment() {
|
||||
return mFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the activity title. ("Viewing FILENAME")
|
||||
*/
|
||||
private void setTitle(String filename) {
|
||||
mActionBar.setTitle(getString(R.string.eml_view_title, filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the filename of the EML, and update the activity title.
|
||||
*/
|
||||
private class LoadFilenameTask extends AsyncTask<Void, Void, String> {
|
||||
private final Uri mContentUri;
|
||||
|
||||
public LoadFilenameTask(Uri contentUri) {
|
||||
mContentUri = contentUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
return Utility.getContentFileName(MessageFileView.this, mContentUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String filename) {
|
||||
if (filename == null || isCancelled()) {
|
||||
return;
|
||||
}
|
||||
setTitle(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.provider.AttachmentProvider;
|
||||
import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
|
||||
|
@ -185,8 +186,7 @@ public final class DBTestHelper {
|
|||
}
|
||||
|
||||
// Based on ProviderTestCase2.setUp().
|
||||
public static <T extends ContentProvider> Context getProviderContext(
|
||||
Context context, Class<T> providerClass) throws Exception {
|
||||
public static Context getProviderContext(Context context) throws Exception {
|
||||
MockContentResolver resolver = new MockContentResolver();
|
||||
final String filenamePrefix = "test.";
|
||||
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(
|
||||
|
@ -196,10 +196,14 @@ public final class DBTestHelper {
|
|||
final Context providerContext = new MyIsolatedContext(resolver, targetContextWrapper);
|
||||
providerContext.getContentResolver();
|
||||
|
||||
final T provider = providerClass.newInstance();
|
||||
provider.attachInfo(providerContext, null);
|
||||
Assert.assertNotNull(provider);
|
||||
resolver.addProvider(EmailContent.AUTHORITY, provider);
|
||||
// register EmailProvider and AttachmentProvider.
|
||||
final EmailProvider ep = new EmailProvider();
|
||||
ep.attachInfo(providerContext, null);
|
||||
resolver.addProvider(EmailContent.AUTHORITY, ep);
|
||||
|
||||
final AttachmentProvider ap = new AttachmentProvider();
|
||||
ap.attachInfo(providerContext, null);
|
||||
resolver.addProvider(AttachmentProvider.AUTHORITY, ap);
|
||||
return providerContext;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package com.android.email;
|
|||
|
||||
import com.android.email.mail.MessagingException;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -57,8 +56,7 @@ public class RefreshManagerTest extends InstrumentationTestCase {
|
|||
mContext = getInstrumentation().getTargetContext();
|
||||
mController = new MockController(mContext);
|
||||
mListener = new RefreshListener();
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
mContext, EmailProvider.class);
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(mContext);
|
||||
mTarget = new RefreshManager(mProviderContext, mController, mClock, null);
|
||||
mTarget.registerListener(mListener);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package com.android.email;
|
||||
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -42,7 +41,7 @@ public class UtilityLargeTest extends InstrumentationTestCase {
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
getInstrumentation().getTargetContext(), EmailProvider.class);
|
||||
getInstrumentation().getTargetContext());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,10 +17,15 @@
|
|||
package com.android.email;
|
||||
|
||||
import com.android.email.Utility.NewFileCreator;
|
||||
import com.android.email.provider.AttachmentProvider;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.Attachment;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Parcel;
|
||||
|
@ -397,6 +402,31 @@ public class UtilityUnitTests extends AndroidTestCase {
|
|||
assertEquals(4, two[1]);
|
||||
}
|
||||
|
||||
public void testGetContentFileName() throws Exception {
|
||||
Context providerContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
mContext);
|
||||
|
||||
final long ACCOUNT_ID = 1;
|
||||
final long MESSAGE_ID = 10;
|
||||
|
||||
Account account = ProviderTestUtils.setupAccount("account", true, providerContext);
|
||||
Mailbox mailbox = ProviderTestUtils.setupMailbox("box", account.mId, true, providerContext);
|
||||
|
||||
// Set up an attachment.
|
||||
Attachment att = ProviderTestUtils.setupAttachment(mailbox.mId, "name", 123, true,
|
||||
providerContext);
|
||||
long attachmentId = att.mId;
|
||||
Uri uri = AttachmentProvider.getAttachmentUri(account.mId, attachmentId);
|
||||
|
||||
// Case 1: exists in the provider.
|
||||
assertEquals("name", Utility.getContentFileName(providerContext, uri));
|
||||
|
||||
// Case 2: doesn't exist in the provider
|
||||
Uri notExistUri = AttachmentProvider.getAttachmentUri(account.mId, 123456789);
|
||||
String lastPathSegment = notExistUri.getLastPathSegment();
|
||||
assertEquals(lastPathSegment, Utility.getContentFileName(providerContext, notExistUri));
|
||||
}
|
||||
|
||||
private static Collection<Long> createLongCollection(long... values) {
|
||||
ArrayList<Long> ret = new ArrayList<Long>();
|
||||
for (long value : values) {
|
||||
|
|
|
@ -18,7 +18,6 @@ package com.android.email.activity;
|
|||
|
||||
import com.android.email.DBTestHelper;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -37,8 +36,7 @@ public class AccountSelectorAdapterAccountsLoaderTest extends LoaderTestCase {
|
|||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
mContext, EmailProvider.class);
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.android.email.mail.MessagingException;
|
|||
import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -63,7 +62,7 @@ public class MailboxFinderTest extends InstrumentationTestCase {
|
|||
super.setUp();
|
||||
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
getInstrumentation().getTargetContext(), EmailProvider.class);
|
||||
getInstrumentation().getTargetContext());
|
||||
mCallback = new MockCallback();
|
||||
mMockController = new MockController(getContext());
|
||||
Controller.injectMockControllerForTest(mMockController);
|
||||
|
|
|
@ -19,7 +19,6 @@ package com.android.email.activity;
|
|||
import com.android.email.DBTestHelper;
|
||||
import com.android.email.TestUtils;
|
||||
import com.android.email.provider.EmailContent.Message;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -46,7 +45,7 @@ public class MessageFileViewTest extends ActivityInstrumentationTestCase2<Messag
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
getInstrumentation().getTargetContext(), EmailProvider.class);
|
||||
getInstrumentation().getTargetContext());
|
||||
}
|
||||
|
||||
private void setUpIntent(Uri uri) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.android.email.TestUtils;
|
|||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.EmailContent.Message;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -51,7 +50,7 @@ public class MessageViewTest extends ActivityInstrumentationTestCase2<MessageVie
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
getInstrumentation().getTargetContext(), EmailProvider.class);
|
||||
getInstrumentation().getTargetContext());
|
||||
}
|
||||
|
||||
private void setUpIntent(long messageId, long mailboxId, boolean disableReply) {
|
||||
|
|
|
@ -19,7 +19,6 @@ package com.android.email.data;
|
|||
import com.android.email.DBTestHelper;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -31,8 +30,7 @@ public class MailboxAccountLoaderTestCase extends LoaderTestCase {
|
|||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||
getContext(), EmailProvider.class);
|
||||
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(getContext());
|
||||
}
|
||||
|
||||
private long createAccount(boolean isEas) {
|
||||
|
|
Loading…
Reference in New Issue