cross-project refactoring
Attachment.mimeType -> contentType
Attachment.contentUri(String) -> contentUri(Uri)
Change-Id: I333453943914c241c63f9ec0a3824150e52706fd
diff --git a/src/com/android/mail/browse/MessageHeaderAttachment.java b/src/com/android/mail/browse/MessageHeaderAttachment.java
index 14fa022..634f64d 100644
--- a/src/com/android/mail/browse/MessageHeaderAttachment.java
+++ b/src/com/android/mail/browse/MessageHeaderAttachment.java
@@ -25,7 +25,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -123,7 +122,7 @@
LogUtils.d(LOG_TAG, "got attachment list row: name=%s state/dest=%d/%d dled=%d" +
" contentUri=%s MIME=%s", attachment.name, attachment.state,
attachment.destination, attachment.downloadedSize, attachment.contentUri,
- attachment.mimeType);
+ attachment.contentType);
if (prevAttachment == null || TextUtils.equals(attachment.name, prevAttachment.name)) {
mTitle.setText(attachment.name);
@@ -271,7 +270,7 @@
break;
case R.id.info_attachment:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
- int dialogMessage = MimeType.isBlocked(mAttachment.mimeType)
+ int dialogMessage = MimeType.isBlocked(mAttachment.contentType)
? R.string.attachment_type_blocked : R.string.no_application_found;
builder.setTitle(R.string.more_info_attachment).setMessage(dialogMessage).show();
break;
@@ -328,14 +327,14 @@
setButtonVisible(mCancelButton, isDownloading);
- final boolean canInstall = MimeType.isInstallable(mAttachment.mimeType);
+ final boolean canInstall = MimeType.isInstallable(mAttachment.contentType);
setButtonVisible(mInstallButton, canInstall && !isDownloading);
if (!canInstall) {
final boolean canPreview = (mAttachment.previewIntent != null);
- final boolean canView = MimeType.isViewable(getContext(), mAttachment.mimeType);
- final boolean canPlay = MimeType.isPlayable(mAttachment.mimeType);
+ final boolean canView = MimeType.isViewable(getContext(), mAttachment.contentType);
+ final boolean canPlay = MimeType.isPlayable(mAttachment.contentType);
setButtonVisible(mPreviewButton, canPreview);
setButtonVisible(mPlayButton, canView && canPlay && !isDownloading);
@@ -361,8 +360,8 @@
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- Utils.setIntentDataAndTypeAndNormalize(intent, Uri.parse(mAttachment.contentUri),
- mAttachment.mimeType);
+ Utils.setIntentDataAndTypeAndNormalize(intent, mAttachment.contentUri,
+ mAttachment.contentType);
try {
getContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
diff --git a/src/com/android/mail/compose/AttachmentComposeView.java b/src/com/android/mail/compose/AttachmentComposeView.java
index fcdea19..a232279 100644
--- a/src/com/android/mail/compose/AttachmentComposeView.java
+++ b/src/com/android/mail/compose/AttachmentComposeView.java
@@ -42,7 +42,7 @@
mSize = attachment.size;
LogUtils.d(LOG_TAG, ">>>>> Attachment uri: %s", attachment.originExtras);
- LogUtils.d(LOG_TAG, ">>>>> type: %s", attachment.mimeType);
+ LogUtils.d(LOG_TAG, ">>>>> type: %s", attachment.contentType);
LogUtils.d(LOG_TAG, ">>>>> name: %s", mFilename);
LogUtils.d(LOG_TAG, ">>>>> size: %d", mSize);
diff --git a/src/com/android/mail/compose/AttachmentsView.java b/src/com/android/mail/compose/AttachmentsView.java
index 292577f..82c3470 100644
--- a/src/com/android/mail/compose/AttachmentsView.java
+++ b/src/com/android/mail/compose/AttachmentsView.java
@@ -180,9 +180,9 @@
Attachment attachment = new Attachment();
// partId will be assigned by the engine.
attachment.name = null;
- attachment.mimeType = contentType;
+ attachment.contentType = contentType;
attachment.size = 0;
- attachment.contentUri = uri.toString();
+ attachment.contentUri = uri;
attachment.origin = isLocal ? Attachment.LOCAL_FILE : Attachment.SERVER_ATTACHMENT;
attachment.originExtras = uri.toString();
diff --git a/src/com/android/mail/providers/Attachment.java b/src/com/android/mail/providers/Attachment.java
index 4190c3d..3da8ba6 100644
--- a/src/com/android/mail/providers/Attachment.java
+++ b/src/com/android/mail/providers/Attachment.java
@@ -53,9 +53,7 @@
/**
* MIME type of the file. See {@link AttachmentColumns#CONTENT_TYPE}.
*/
- // TODO: rename to be consistent with UIProvider name: "contentType"
- @Deprecated
- public String mimeType;
+ public String contentType;
/**
* See {@link AttachmentColumns#STATE}.
@@ -75,9 +73,7 @@
/**
* See {@link AttachmentColumns#CONTENT_URI}.
*/
- // TODO: change this to be a Uri for consistency with other URIs in data model objects.
- @Deprecated
- public String contentUri;
+ public Uri contentUri;
/**
* See {@link AttachmentColumns#THUMBNAIL_URI}. Might be null.
@@ -106,11 +102,11 @@
name = in.readString();
size = in.readInt();
uri = in.readParcelable(null);
- mimeType = in.readString();
+ contentType = in.readString();
state = in.readInt();
destination = in.readInt();
downloadedSize = in.readInt();
- contentUri = in.readString();
+ contentUri = in.readParcelable(null);
thumbnailUri = in.readParcelable(null);
previewIntent = in.readParcelable(null);
partId = in.readString();
@@ -129,12 +125,11 @@
name = cursor.getString(UIProvider.ATTACHMENT_NAME_COLUMN);
size = cursor.getInt(UIProvider.ATTACHMENT_SIZE_COLUMN);
uri = Uri.parse(cursor.getString(UIProvider.ATTACHMENT_URI_COLUMN));
- mimeType = cursor.getString(UIProvider.ATTACHMENT_CONTENT_TYPE_COLUMN);
+ contentType = cursor.getString(UIProvider.ATTACHMENT_CONTENT_TYPE_COLUMN);
state = cursor.getInt(UIProvider.ATTACHMENT_STATE_COLUMN);
destination = cursor.getInt(UIProvider.ATTACHMENT_DESTINATION_COLUMN);
downloadedSize = cursor.getInt(UIProvider.ATTACHMENT_DOWNLOADED_SIZE_COLUMN);
- // TODO: change to use parseUri()
- contentUri = cursor.getString(UIProvider.ATTACHMENT_CONTENT_URI_COLUMN);
+ contentUri = parseOptionalUri(cursor.getString(UIProvider.ATTACHMENT_CONTENT_URI_COLUMN));
thumbnailUri = parseOptionalUri(
cursor.getString(UIProvider.ATTACHMENT_THUMBNAIL_URI_COLUMN));
previewIntent = getOptionalIntentFromBlob(
@@ -149,23 +144,23 @@
if (attachmentValues != null) {
partId = attachmentValues[0];
name = attachmentValues[1];
- mimeType = attachmentValues[2];
+ contentType = attachmentValues[2];
try {
size = Integer.parseInt(attachmentValues[3]);
} catch (NumberFormatException e) {
size = 0;
}
- mimeType = attachmentValues[4];
+ contentType = attachmentValues[4];
origin = Integer.parseInt(attachmentValues[5]);
- contentUri = attachmentValues[6];
+ contentUri = parseOptionalUri(attachmentValues[6]);
originExtras = attachmentValues[7];
}
}
public String toJoinedString() {
- // FIXME: mimeType is read/written twice
+ // FIXME: contentType is read/written twice
return TextUtils.join("|", Lists.newArrayList(partId == null ? "" : partId,
- name == null ? "" : name.replaceAll("[|\n]", ""), mimeType, size, mimeType,
+ name == null ? "" : name.replaceAll("[|\n]", ""), contentType, size, contentType,
origin + "", contentUri, TextUtils.isEmpty(originExtras) ? contentUri
: originExtras, ""));
}
@@ -195,11 +190,11 @@
dest.writeString(name);
dest.writeInt(size);
dest.writeParcelable(uri, flags);
- dest.writeString(mimeType);
+ dest.writeString(contentType);
dest.writeInt(state);
dest.writeInt(destination);
dest.writeInt(downloadedSize);
- dest.writeString(contentUri);
+ dest.writeParcelable(contentUri, flags);
dest.writeParcelable(thumbnailUri, flags);
dest.writeParcelable(previewIntent, flags);
dest.writeString(partId);
@@ -220,7 +215,7 @@
};
public boolean isImage() {
- return mimeType.startsWith("image");
+ return contentType.startsWith("image/");
}
public boolean isDownloading() {
diff --git a/src/com/android/mail/utils/AttachmentUtils.java b/src/com/android/mail/utils/AttachmentUtils.java
index 4e4b22c..48714d2 100644
--- a/src/com/android/mail/utils/AttachmentUtils.java
+++ b/src/com/android/mail/utils/AttachmentUtils.java
@@ -61,11 +61,11 @@
// try to get a friendly name for the exact mime type
// then try to show a friendly name for the mime family
// finally, give up and just show the file extension
- String displayType = getMimeTypeDisplayName(context, attachment.mimeType);
- int index = attachment.mimeType.indexOf('/');
+ String displayType = getMimeTypeDisplayName(context, attachment.contentType);
+ int index = attachment.contentType.indexOf('/');
if (displayType == null && index > 0) {
displayType = getMimeTypeDisplayName(context,
- attachment.mimeType.substring(0, index));
+ attachment.contentType.substring(0, index));
}
if (displayType == null) {
String extension = Utils.getFileExtension(attachment.name);
diff --git a/tests/src/com/android/mail/providers/AttachmentTests.java b/tests/src/com/android/mail/providers/AttachmentTests.java
index 88ed5e7..a4622bf 100644
--- a/tests/src/com/android/mail/providers/AttachmentTests.java
+++ b/tests/src/com/android/mail/providers/AttachmentTests.java
@@ -15,6 +15,7 @@
*/
package com.android.mail.providers;
+import android.net.Uri;
import android.test.AndroidTestCase;
import com.android.mail.providers.Attachment;
@@ -30,8 +31,8 @@
for (int i = 0; i < 5; i++) {
attachment = new Attachment();
attachment.name = "name" + i;
- attachment.contentUri = "content://" + i;
- attachment.mimeType = "mimeType" + i;
+ attachment.contentUri = Uri.parse("content://" + i);
+ attachment.contentType = "mimeType" + i;
attachment.size = i;
attachment.partId = i + "";
attachment.originExtras = "extras" + i;
@@ -43,8 +44,8 @@
assertEquals(reformed.size(), 5);
for (int i = 0; i < 5; i++) {
assertEquals(reformed.get(i).name, "name" + i);
- assertEquals(reformed.get(i).contentUri, "content://" + i);
- assertEquals(reformed.get(i).mimeType, "mimeType" + i);
+ assertEquals(reformed.get(i).contentUri, Uri.parse("content://" + i));
+ assertEquals(reformed.get(i).contentType, "mimeType" + i);
assertEquals(reformed.get(i).size, i);
assertEquals(reformed.get(i).partId, i + "");
assertEquals(reformed.get(i).originExtras, "extras" + i);