1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.email.activity; 18 19 import com.android.email.R; 20 import com.android.emailcommon.Logging; 21 import com.android.emailcommon.provider.Account; 22 import com.android.emailcommon.utility.EmailAsyncTask; 23 import com.android.emailcommon.utility.Utility; 24 import com.google.common.annotations.VisibleForTesting; 25 26 import android.app.ActionBar; 27 import android.app.Activity; 28 import android.net.Uri; 29 import android.os.Bundle; 30 import android.util.Log; 31 import android.view.MenuItem; 32 33 /** 34 * Activity to show file-based messages. (i.e. *.eml files, and possibly *.msg files). 35 */ 36 public class MessageFileView extends Activity implements MessageViewFragmentBase.Callback { 37 private ActionBar mActionBar; 38 39 private MessageFileViewFragment mFragment; 40 41 private final EmailAsyncTask.Tracker mTaskTracker = new EmailAsyncTask.Tracker(); 42 43 @Override onCreate(Bundle icicle)44 public void onCreate(Bundle icicle) { 45 super.onCreate(icicle); 46 ActivityHelper.debugSetWindowFlags(this); 47 setContentView(R.layout.message_file_view); 48 49 mActionBar = getActionBar(); 50 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP 51 | ActionBar.DISPLAY_SHOW_TITLE); 52 53 mFragment = (MessageFileViewFragment) getFragmentManager().findFragmentById( 54 R.id.message_file_view_fragment); 55 mFragment.setCallback(this); 56 57 final Uri fileEmailUri = getIntent().getData(); 58 if (fileEmailUri == null) { 59 Log.w(Logging.LOG_TAG, "Insufficient intent parameter. Closing..."); 60 finish(); 61 return; 62 } 63 64 mFragment.setFileUri(fileEmailUri); 65 66 // Set title. 67 new LoadFilenameTask(fileEmailUri).executeParallel(); 68 } 69 70 @Override onResume()71 public void onResume() { 72 super.onResume(); 73 } 74 75 @Override onDestroy()76 public void onDestroy() { 77 super.onDestroy(); 78 mTaskTracker.cancellAllInterrupt(); 79 } 80 81 @Override onOptionsItemSelected(MenuItem item)82 public boolean onOptionsItemSelected(MenuItem item) { 83 switch (item.getItemId()) { 84 case android.R.id.home: 85 onBackPressed(); // Treat as "back". 86 return true; 87 } 88 89 return super.onOptionsItemSelected(item); 90 } 91 92 /** 93 * Set the activity title. ("Viewing FILENAME") 94 */ setTitle(String filename)95 private void setTitle(String filename) { 96 mActionBar.setTitle(getString(R.string.eml_view_title, filename)); 97 } 98 99 /** 100 * Load the filename of the EML, and update the activity title. 101 */ 102 private class LoadFilenameTask extends EmailAsyncTask<Void, Void, String> { 103 private final Uri mContentUri; 104 LoadFilenameTask(Uri contentUri)105 public LoadFilenameTask(Uri contentUri) { 106 super(mTaskTracker); 107 mContentUri = contentUri; 108 } 109 110 @Override doInBackground(Void... params)111 protected String doInBackground(Void... params) { 112 return Utility.getContentFileName(MessageFileView.this, mContentUri); 113 } 114 115 @Override onSuccess(String filename)116 protected void onSuccess(String filename) { 117 if (filename == null) { 118 return; 119 } 120 setTitle(filename); 121 } 122 } 123 124 @Override onUrlInMessageClicked(String url)125 public boolean onUrlInMessageClicked(String url) { 126 // EML files don't have the "owner" account, so use the default account as the sender. 127 return ActivityHelper.openUrlInMessage(this, url, Account.NO_ACCOUNT); 128 } 129 130 @Override onMessageNotExists()131 public void onMessageNotExists() { // Probably meessage deleted. 132 finish(); 133 } 134 135 @Override onLoadMessageStarted()136 public void onLoadMessageStarted() { 137 // Not important for EMLs 138 } 139 140 @Override onLoadMessageFinished()141 public void onLoadMessageFinished() { 142 // Not important for EMLs 143 } 144 145 @Override onLoadMessageError(String errorMessage)146 public void onLoadMessageError(String errorMessage) { 147 // Not important for EMLs 148 } 149 150 @VisibleForTesting getFragment()151 MessageFileViewFragment getFragment() { 152 return mFragment; 153 } 154 } 155