1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Add an actionbar to the MessageView activity.

This commit is contained in:
Sander Bogaert 2012-08-22 09:43:18 -04:00 committed by Andrew Chen
parent 7a035a73b0
commit c31c8923c2
15 changed files with 137 additions and 286 deletions

View File

@ -217,8 +217,8 @@
</activity>
<activity
android:name="com.fsck.k9.activity.MessageView"
android:theme="@android:style/Theme.Light"
android:configChanges="locale"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

View File

@ -7,8 +7,4 @@
<include layout="@layout/message"/>
<include layout="@layout/message_view_move_buttons"/>
<include layout="@layout/message_view_bottom_buttons"/>
</LinearLayout>

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/bottom_buttons"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="6dip"
android:background="@android:color/transparent"
android:gravity="center_vertical">
<Button
android:id="@+id/previous"
android:text="@string/message_view_prev_action"
android:contentDescription="@string/previous_action"
android:textSize="35dip"
android:padding="0dip"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1" />
<ImageButton
android:id="@+id/delete"
android:layout_height="wrap_content"
android:src="@drawable/ic_button_delete"
android:textSize="0dip"
android:layout_width="0dip"
android:layout_weight="1" />
<Button
android:id="@+id/next"
android:text="@string/message_view_next_action"
android:contentDescription="@string/next_action"
android:textSize="35dip"
android:padding="0dip"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1" />
</LinearLayout>
</merge>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/move_buttons"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="6dip"
android:background="@android:color/transparent"
android:gravity="center_vertical">
<Button
android:id="@+id/archive"
android:text="@string/message_view_archive_action"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1" />
<Button
android:id="@+id/move"
android:text="@string/message_view_move_action"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1" />
<Button
android:id="@+id/spam"
android:text="@string/message_view_spam_action"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1" />
</LinearLayout>
</merge>

View File

@ -1,68 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/reply"
android:alphabeticShortcut="r"
android:title="@string/reply_action"
android:icon="@drawable/ic_menu_reply"
android:id="@+id/next_message"
android:title="@string/next_action"
android:icon="@drawable/ic_action_next_message"
android:showAsAction="always"
/>
<item
android:id="@+id/reply_all"
android:alphabeticShortcut="a"
android:title="@string/reply_all_action"
android:icon="@drawable/ic_menu_reply_all"
/>
<item
android:id="@+id/forward"
android:alphabeticShortcut="f"
android:title="@string/forward_action"
android:icon="@drawable/ic_menu_forward_mail"
/>
<item
android:id="@+id/mark_as_unread"
android:alphabeticShortcut="u"
android:title="@string/mark_as_unread_action"
android:icon="@drawable/ic_menu_mark"
android:id="@+id/previous_message"
android:title="@string/previous_action"
android:icon="@drawable/ic_action_previous_message"
android:showAsAction="always"
/>
<item
android:id="@+id/delete"
android:alphabeticShortcut="q"
android:title="@string/delete_action"
android:icon="@drawable/ic_menu_delete"
android:icon="@drawable/ic_action_delete"
android:showAsAction="always"
/>
<item
android:id="@+id/show_full_header"
android:title="@string/show_full_header_action"
android:id="@+id/single_message_options"
android:icon="@drawable/ic_action_single_message_options"
android:showAsAction="ifRoom"
android:title="@string/single_message_options_action">
<menu>
<item
android:id="@+id/reply"
android:title="@string/reply_action"/>
<item
android:id="@+id/reply_all"
android:title="@string/reply_all_action"/>
<item
android:id="@+id/forward"
android:title="@string/forward_action"/>
</menu>
</item>
<item
android:id="@+id/archive"
android:title="@string/archive_action"
android:icon="@drawable/ic_action_archive"
android:showAsAction="ifRoom"
/>
<item
android:id="@+id/spam"
android:title="@string/spam_action"
android:icon="@drawable/ic_action_spam"
android:showAsAction="ifRoom"
/>
<item
android:id="@+id/move_or_copy"
android:title="@string/move_or_copy_action"
android:showAsAction="ifRoom"
android:icon="@drawable/ic_action_move_or_copy">
<menu>
<item
android:id="@+id/move"
android:title="@string/move_action"
/>
<item
android:id="@+id/copy"
android:title="@string/copy_action"
/>
</menu>
</item>
<item
android:id="@+id/toggle_unread"
android:alphabeticShortcut="u"
android:title="@string/read_toggle_action"
android:icon="@drawable/ic_action_toggle_read"
android:showAsAction="never"
/>
<item
android:id="@+id/flag"
android:alphabeticShortcut="s"
android:title="@string/flag_action"
android:icon="@drawable/ic_menu_forward_mail"
/>
<item
android:id="@+id/send_alternate"
android:title="@string/send_alternate_action"
android:icon="@drawable/ic_menu_forward_mail"
/>
<item
android:id="@+id/archive"
android:title="@string/archive_action"
/>
<item
android:id="@+id/spam"
android:title="@string/spam_action"
/>
<item
android:id="@+id/move"
android:title="@string/move_action"
/>
<item
android:id="@+id/copy"
android:title="@string/copy_action"
android:showAsAction="never"
/>
<item
android:id="@+id/select_text"
android:title="@string/select_text_action"
android:showAsAction="never"
/>
<item
android:id="@+id/share"
android:showAsAction="never"
android:title="@string/send_alternate_action"
/>
</menu>

View File

@ -146,7 +146,7 @@ http://k9mail.googlecode.com/
<string name="accounts_action">Accounts</string>
<string name="mark_as_read_action">Mark as read</string>
<string name="read_toggle_action">(un)read</string>
<string name="read_toggle_action">Toggle (un)read</string>
<string name="send_alternate_action">Share</string>
<string name="send_alternate_chooser_title">Choose sender</string>

View File

@ -45,7 +45,6 @@ import com.fsck.k9.view.SingleMessageView;
public class MessageView extends K9Activity implements OnClickListener {
private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference";
private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences";
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
private static final String EXTRA_MESSAGE_LIST_EXTRAS = "com.fsck.k9.MessageView_messageListExtras";
private static final String STATE_PGP_DATA = "pgpData";
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
@ -55,13 +54,7 @@ public class MessageView extends K9Activity implements OnClickListener {
private SingleMessageView mMessageView;
private PgpData mPgpData;
private View mNext;
private View mPrevious;
private View mDelete;
private View mArchive;
private View mMove;
private View mSpam;
private Menu mMenu;
private Account mAccount;
private MessageReference mMessageReference;
private ArrayList<MessageReference> mMessageReferences;
@ -399,51 +392,14 @@ public class MessageView extends K9Activity implements OnClickListener {
}
mAccount = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "MessageView got message " + mMessageReference);
if (intent.getBooleanExtra(EXTRA_NEXT, false)) {
mNext.requestFocus();
}
mScreenWidthInPixels = getResources().getDisplayMetrics().widthPixels;
// Enable gesture detection for MessageViews
mGestureDetector = new GestureDetector(new MyGestureDetector(false));
setupButtonViews();
displayMessage(mMessageReference);
}
private void setupButtonViews() {
setOnClickListener(R.id.from);
setOnClickListener(R.id.reply);
setOnClickListener(R.id.reply_all);
setOnClickListener(R.id.delete);
setOnClickListener(R.id.forward);
setOnClickListener(R.id.next);
setOnClickListener(R.id.previous);
setOnClickListener(R.id.archive);
setOnClickListener(R.id.move);
setOnClickListener(R.id.spam);
setOnClickListener(R.id.download_remainder);
mNext = findViewById(R.id.next);
mPrevious = findViewById(R.id.previous);
mDelete = findViewById(R.id.delete);
mArchive = findViewById(R.id.archive);
mMove = findViewById(R.id.move);
mSpam = findViewById(R.id.spam);
if (!mAccount.getEnableMoveButtons()) {
View buttons = findViewById(R.id.move_buttons);
buttons.setVisibility(View.GONE);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -473,46 +429,7 @@ public class MessageView extends K9Activity implements OnClickListener {
mMessageView.resetHeaderView();
mController.loadMessageForView(mAccount, mMessageReference.folderName, mMessageReference.uid, mListener);
setupDisplayMessageButtons();
}
private void setupDisplayMessageButtons() {
mDelete.setEnabled(true);
mNext.setEnabled(mNextMessage != null);
mPrevious.setEnabled(mPreviousMessage != null);
// If moving isn't support at all, then all of them must be disabled anyway.
if (mController.isMoveCapable(mAccount)) {
// Only enable the button if they have an archive folder and it's not the current folder.
mArchive.setEnabled(!mMessageReference.folderName.equals(mAccount.getArchiveFolderName()) &&
mAccount.hasArchiveFolder());
// Only enable the button if the Spam folder is not the current folder and not NONE.
mSpam.setEnabled(!mMessageReference.folderName.equals(mAccount.getSpamFolderName()) &&
mAccount.hasSpamFolder());
mMove.setEnabled(true);
} else {
disableMoveButtons();
}
}
private void disableButtons() {
mMessageView.setLoadPictures(false);
disableMoveButtons();
mNext.setEnabled(false);
mPrevious.setEnabled(false);
mDelete.setEnabled(false);
}
private void disableMoveButtons() {
mArchive.setEnabled(false);
mMove.setEnabled(false);
mSpam.setEnabled(false);
}
private void setOnClickListener(int viewCode) {
View thisView = findViewById(viewCode);
if (thisView != null) {
thisView.setOnClickListener(this);
}
configureMenu(mMenu);
}
private void findSurroundingMessagesUid() {
@ -563,7 +480,7 @@ public class MessageView extends K9Activity implements OnClickListener {
if (mMessage != null) {
// Disable the delete button after it's tapped (to try to prevent
// accidental clicks)
disableButtons();
mMenu.findItem(R.id.delete).setEnabled(false);
Message messageToDelete = mMessage;
showNextMessageOrReturn();
mController.deleteMessages(new Message[] {messageToDelete}, null);
@ -771,12 +688,11 @@ public class MessageView extends K9Activity implements OnClickListener {
return;
}
mLastDirection = NEXT;
disableButtons();
//toggleActionsState(mMenu, false);
if (K9.showAnimations()) {
mMessageView.startAnimation(outToLeftAnimation());
}
displayMessage(mNextMessage);
mNext.requestFocus();
}
protected void onPrevious() {
@ -786,12 +702,11 @@ public class MessageView extends K9Activity implements OnClickListener {
return;
}
mLastDirection = PREVIOUS;
disableButtons();
//toggleActionsState(mMenu, false);
if (K9.showAnimations()) {
mMessageView.startAnimation(inFromRightAnimation());
}
displayMessage(mPreviousMessage);
mPrevious.requestFocus();
}
private void onToggleRead() {
@ -815,33 +730,6 @@ public class MessageView extends K9Activity implements OnClickListener {
public void onClick(View view) {
switch (view.getId()) {
case R.id.reply:
onReply();
break;
case R.id.reply_all:
onReplyAll();
break;
case R.id.delete:
onDelete();
break;
case R.id.forward:
onForward();
break;
case R.id.archive:
onRefile(mAccount.getArchiveFolderName());
break;
case R.id.spam:
onRefile(mAccount.getSpamFolderName());
break;
case R.id.move:
onMove();
break;
case R.id.next:
onNext();
break;
case R.id.previous:
onPrevious();
break;
case R.id.download:
((AttachmentView)view).saveFile();
break;
@ -857,6 +745,12 @@ public class MessageView extends K9Activity implements OnClickListener {
case android.R.id.home:
finish();
break;
case R.id.next_message:
onNext();
break;
case R.id.previous_message:
onPrevious();
break;
case R.id.delete:
onDelete();
break;
@ -869,15 +763,15 @@ public class MessageView extends K9Activity implements OnClickListener {
case R.id.forward:
onForward();
break;
case R.id.send_alternate:
onSendAlternate();
break;
case R.id.mark_as_unread:
onToggleRead();
break;
case R.id.flag:
onFlag();
break;
case R.id.share:
onSendAlternate();
break;
case R.id.toggle_unread:
onToggleRead();
break;
case R.id.archive:
onRefile(mAccount.getArchiveFolderName());
break;
@ -890,14 +784,6 @@ public class MessageView extends K9Activity implements OnClickListener {
case R.id.copy:
onCopy();
break;
case R.id.show_full_header:
runOnUiThread(new Runnable() {
@Override
public void run() {
mMessageView.showAllHeaders();
}
});
break;
case R.id.select_text:
mMessageView.beginSelectingText();
break;
@ -911,21 +797,61 @@ public class MessageView extends K9Activity implements OnClickListener {
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.message_view_option, menu);
if (!mController.isCopyCapable(mAccount)) {
menu.findItem(R.id.copy).setVisible(false);
}
if (!mController.isMoveCapable(mAccount)) {
mMenu = menu;
configureMenu(menu);
return true;
}
private void configureMenu(Menu menu){
// first run displayMessage() gets called before onCreateOptionMenu()
if (menu == null) {
return;
}
// enable them all
menu.findItem(R.id.copy).setVisible(true);
menu.findItem(R.id.move).setVisible(true);
menu.findItem(R.id.archive).setVisible(true);
menu.findItem(R.id.spam).setVisible(true);
toggleActionsState(menu, true);
menu.findItem(R.id.next_message).setVisible(mNextMessage != null);
menu.findItem(R.id.previous_message).setVisible(mPreviousMessage != null);
// comply with the setting
if (!mAccount.getEnableMoveButtons()) {
menu.findItem(R.id.move).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
} else {
// check message, folder capability
if (!mController.isCopyCapable(mAccount)) {
menu.findItem(R.id.copy).setVisible(false);
}
if (mController.isMoveCapable(mAccount)) {
menu.findItem(R.id.move).setVisible(true);
menu.findItem(R.id.archive).setVisible(
!mMessageReference.folderName.equals(mAccount.getArchiveFolderName())
&& mAccount.hasArchiveFolder());
menu.findItem(R.id.spam).setVisible(
!mMessageReference.folderName.equals(mAccount.getSpamFolderName())
&& mAccount.hasSpamFolder());
} else {
menu.findItem(R.id.copy).setVisible(false);
menu.findItem(R.id.move).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
}
}
if (!mAccount.hasArchiveFolder()) {
menu.findItem(R.id.archive).setVisible(false);
}
if (!mAccount.hasSpamFolder()) {
menu.findItem(R.id.spam).setVisible(false);
}
return true;
}
private void toggleActionsState(Menu menu, boolean state){
for(int i=0; i<menu.size(); ++i) {
menu.getItem(i).setEnabled(state);
}
}
// TODO: when switching to API version 8, override onCreateDialog(int, Bundle)
@ -972,28 +898,6 @@ public class MessageView extends K9Activity implements OnClickListener {
return super.onCreateDialog(id);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (menu != null) {
MenuItem flagItem = menu.findItem(R.id.flag);
if (flagItem != null && mMessage != null) {
flagItem.setTitle((mMessage.isSet(Flag.FLAGGED) ? R.string.unflag_action : R.string.flag_action));
}
MenuItem additionalHeadersItem = menu.findItem(R.id.show_full_header);
if (additionalHeadersItem != null) {
additionalHeadersItem.setTitle(mMessageView.additionalHeadersVisible() ?
R.string.hide_full_header_action : R.string.show_full_header_action);
}
if (mMessage != null) {
int actionTitle = mMessage.isSet(Flag.SEEN) ?
R.string.mark_as_unread_action : R.string.mark_as_read_action;
menu.findItem(R.id.mark_as_unread).setTitle(actionTitle);
}
}
return super.onPrepareOptionsMenu(menu);
}
class Listener extends MessagingListener {
@Override
public void loadMessageForViewHeadersAvailable(final Account account, String folder, String uid,