From 7dc1e86d91148fb79c380eacf734813ee8828299 Mon Sep 17 00:00:00 2001 From: Ben Komalo Date: Mon, 11 Apr 2011 20:33:26 -0700 Subject: [PATCH] Less aggressive selection change in msg content. All focus changes to the message body content was pushing the selection to the end, which is wrong if state restoration happens, and is just non-standard behavior if the user explicitly taps on a particular spot on the text view. Make this slightly less aggressive. Misc other changes in compose view. Bug: 3076256 Change-Id: I9edb9c3c4edb5ddec12207f4136f3ca73cabf89d --- src/com/android/email/Controller.java | 1 - .../email/activity/MessageCompose.java | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 7a3d3926c..7dff4f464 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -661,7 +661,6 @@ public class Controller { * IMAP and POP. * * @param mailboxId the mailbox - * @param callback */ public void loadMoreMessages(final long mailboxId) { Utility.runAsync(new Runnable() { diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index e1cb65e90..9d662a246 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -594,7 +594,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus setFocusShifter(R.id.subject_label, R.id.subject); setFocusShifter(R.id.tap_trap, R.id.message_content); - mSubjectView.setOnFocusChangeListener(this); mMessageContentView.setOnFocusChangeListener(this); updateAttachmentContainer(); @@ -732,11 +731,20 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus } } + @Override public void onFocusChange(View view, boolean focused) { if (focused) { switch (view.getId()) { case R.id.message_content: - setMessageContentSelection((mAccount != null) ? mAccount.mSignature : null); + // When focusing on the message content via tabbing to it, or other means of + // auto focusing, move the cursor to the end of the body (before the signature). + if (mMessageContentView.getSelectionStart() == 0 + && mMessageContentView.getSelectionEnd() == 0) { + // There is no way to determine if the focus change was programmatic or due + // to keyboard event, or if it was due to a tap/restore. Use a best-guess + // by using the fact that auto-focus/keyboard tabs set the selection to 0. + setMessageContentSelection((mAccount != null) ? mAccount.mSignature : null); + } } } } @@ -1339,6 +1347,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mMessageContentView.append("\n"); } mMessageContentView.append(signature); + + // Reset cursor to right before the signature. + mMessageContentView.setSelection(textLength); } } @@ -1617,11 +1628,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus } /** - * Set a cursor to the end of a body except a signature + * Set a cursor to the end of a body except a signature. */ /* package */ void setMessageContentSelection(String signature) { - // when selecting the message content, explicitly move IP to the end of the message, - // so you can quickly resume typing into a draft int selection = mMessageContentView.length(); if (!TextUtils.isEmpty(signature)) { int signatureLength = signature.length(); @@ -1659,7 +1668,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mSubjectView.requestFocus(); } else { mMessageContentView.requestFocus(); - setMessageContentSelection((mAccount != null) ? mAccount.mSignature : null); } } }