From 14ff4d006e50cb5d422ddc992006661a75368112 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 10 Nov 2011 05:34:34 +0100 Subject: [PATCH] Removed onBackPressed() magic --- src/com/fsck/k9/activity/EditIdentity.java | 10 ++--- src/com/fsck/k9/activity/FolderList.java | 26 ++----------- .../fsck/k9/activity/ManageIdentities.java | 8 ++-- src/com/fsck/k9/activity/MessageCompose.java | 24 +----------- src/com/fsck/k9/activity/MessageList.java | 17 +------- src/com/fsck/k9/activity/MessageView.java | 39 +------------------ .../k9/activity/setup/AccountSettings.java | 9 ++--- .../setup/AccountSetupComposition.java | 9 ++--- .../k9/activity/setup/FolderSettings.java | 18 ++++----- .../k9/activity/setup/FontSizeSettings.java | 9 ++--- src/com/fsck/k9/activity/setup/Prefs.java | 18 ++++----- 11 files changed, 36 insertions(+), 151 deletions(-) diff --git a/src/com/fsck/k9/activity/EditIdentity.java b/src/com/fsck/k9/activity/EditIdentity.java index 6fff570cb..931609739 100644 --- a/src/com/fsck/k9/activity/EditIdentity.java +++ b/src/com/fsck/k9/activity/EditIdentity.java @@ -1,7 +1,6 @@ package com.fsck.k9.activity; import android.os.Bundle; -import android.view.KeyEvent; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -125,12 +124,9 @@ public class EditIdentity extends K9Activity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveIdentity(); - return true; - } - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + saveIdentity(); + super.onBackPressed(); } @Override diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index 47b346fcc..5e0155332 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -356,38 +356,18 @@ public class FolderList extends K9ListActivity { @Override public void onBackPressed() { - // This will be called either automatically for you on 2.0 - // or later, or by the code above on earlier versions of the - // platform. if (K9.manageBack()) { onAccounts(); } else { - // TODO - when we move to android 2.0, uncomment this instead. - // super.onBackPressed() - finish(); + super.onBackPressed(); } } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { //Shortcuts that work no matter what is selected - - if ( - // TODO - when we move to android 2.0, uncomment this. - // android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR && - - keyCode == KeyEvent.KEYCODE_BACK - && event.getRepeatCount() == 0 - && K9.manageBack()) { - // Take care of calling this method on earlier versions of - // the platform where it doesn't exist. - onBackPressed(); - return true; - } - - switch (keyCode) { case KeyEvent.KEYCODE_Q: - //case KeyEvent.KEYCODE_BACK: { onAccounts(); return true; diff --git a/src/com/fsck/k9/activity/ManageIdentities.java b/src/com/fsck/k9/activity/ManageIdentities.java index 3e5d83813..a15aaaa6f 100644 --- a/src/com/fsck/k9/activity/ManageIdentities.java +++ b/src/com/fsck/k9/activity/ManageIdentities.java @@ -119,11 +119,9 @@ public class ManageIdentities extends ChooseIdentity { @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveIdentities(); - } - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + saveIdentities(); + super.onBackPressed(); } private void saveIdentities() { diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 3a282a947..d6e4e546f 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -29,7 +29,6 @@ import android.os.Parcelable; import android.provider.OpenableColumns; import android.text.util.Rfc822Tokenizer; import android.util.Log; -import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -1834,13 +1833,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override public void onBackPressed() { - // This will be called either automatically for you on 2.0 - // or later, or by the code above on earlier versions of the - // platform. if (mDraftNeedsSaving) { showDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); } else { - finish(); + super.onBackPressed(); } } @@ -1868,24 +1864,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc return super.onCreateDialog(id); } - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if ( - // TODO - when we move to android 2.0, uncomment this. - // android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR && - - keyCode == KeyEvent.KEYCODE_BACK - && event.getRepeatCount() == 0 - && K9.manageBack()) { - // Take care of calling this method on earlier versions of - // the platform where it doesn't exist. - onBackPressed(); - return true; - } - - return super.onKeyDown(keyCode, event); - } - /** * Returns true if all attachments were able to be attached, otherwise returns false. */ diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 5c6d8c023..91ce323cc 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -898,9 +898,6 @@ public class MessageList @Override public void onBackPressed() { - // This will be called either automatically for you on 2.0 - // or later, or by the code above on earlier versions of the - // platform. if (K9.manageBack()) { if (mQueryString == null) { onShowFolderList(); @@ -908,24 +905,12 @@ public class MessageList onAccounts(); } } else { - finish(); + super.onBackPressed(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if ( - // XXX TODO - when we go to android 2.0, uncomment this - // android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR && - keyCode == KeyEvent.KEYCODE_BACK - && event.getRepeatCount() == 0 - ) { - // Take care of calling this method on earlier versions of - // the platform where it doesn't exist. - onBackPressed(); - return true; - } - // Shortcuts that work no matter what is selected switch (keyCode) { diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index f969b9d55..5c62f8f35 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -27,8 +27,6 @@ import com.fsck.k9.view.SingleMessageView; import com.fsck.k9.view.AttachmentView.AttachmentFileDownloadCallback; import java.io.File; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.*; public class MessageView extends K9Activity implements OnClickListener { @@ -42,27 +40,6 @@ public class MessageView extends K9Activity implements OnClickListener { private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2; private static final int ACTIVITY_CHOOSE_DIRECTORY = 3; - /** - * Whether parent class have the onBackPressed() method (with no argument) - */ - private static final boolean HAS_SUPER_ON_BACK_METHOD; - static { - boolean hasOnBackMethod; - try { - final Class superClass = MessageView.class.getSuperclass(); - final Method method = superClass.getMethod("onBackPressed", new Class[] {}); - hasOnBackMethod = (method.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC; - } catch (final SecurityException e) { - if (K9.DEBUG) { - Log.v(K9.LOG_TAG, "Security exception while checking for 'onBackPressed' method", e); - } - hasOnBackMethod = false; - } catch (final NoSuchMethodException e) { - hasOnBackMethod = false; - } - HAS_SUPER_ON_BACK_METHOD = hasOnBackMethod; - } - private SingleMessageView mMessageView; private PgpData mPgpData; @@ -150,15 +127,6 @@ public class MessageView extends K9Activity implements OnClickListener { @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { - if ( - // XXX TODO - when we go to android 2.0, uncomment this - // android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR && - keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { - // Take care of calling this method on earlier versions of - // the platform where it doesn't exist. - onBackPressed(); - return true; - } switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: { if (K9.useVolumeKeysForNavigationEnabled()) { @@ -263,17 +231,12 @@ public class MessageView extends K9Activity implements OnClickListener { @Override public void onBackPressed() { - // This will be called either automatically for you on 2.0 - // or later, or by the code above on earlier versions of the - // platform. if (K9.manageBack()) { String folder = (mMessage != null) ? mMessage.getFolder().getName() : null; MessageList.actionHandleFolder(this, mAccount, folder); finish(); - } else if (HAS_SUPER_ON_BACK_METHOD) { - super.onBackPressed(); } else { - finish(); + super.onBackPressed(); } } diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index 9ca88f15d..762066907 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -9,7 +9,6 @@ import android.os.Bundle; import android.os.Vibrator; import android.preference.*; import android.util.Log; -import android.view.KeyEvent; import java.util.Iterator; import java.util.Map; @@ -809,11 +808,9 @@ public class AccountSettings extends K9PreferenceActivity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveSettings(); - } - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + saveSettings(); + super.onBackPressed(); } private void onCompositionSettings() { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java index f0bed3220..47815eac8 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java @@ -3,7 +3,6 @@ package com.fsck.k9.activity.setup; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.KeyEvent; import android.view.View; import android.widget.CompoundButton; import android.widget.CheckBox; @@ -121,11 +120,9 @@ public class AccountSetupComposition extends K9Activity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveSettings(); - } - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + saveSettings(); + super.onBackPressed(); } @Override diff --git a/src/com/fsck/k9/activity/setup/FolderSettings.java b/src/com/fsck/k9/activity/setup/FolderSettings.java index a461fd083..1dabbf0c4 100644 --- a/src/com/fsck/k9/activity/setup/FolderSettings.java +++ b/src/com/fsck/k9/activity/setup/FolderSettings.java @@ -8,7 +8,6 @@ import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.util.Log; -import android.view.KeyEvent; import com.fsck.k9.*; import com.fsck.k9.activity.K9PreferenceActivity; import com.fsck.k9.mail.Folder.FolderClass; @@ -151,16 +150,13 @@ public class FolderSettings extends K9PreferenceActivity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - try { - saveSettings(); - } catch (MessagingException e) { - Log.e(K9.LOG_TAG, "Saving folder settings failed", e); - } + public void onBackPressed() { + try { + saveSettings(); + } catch (MessagingException e) { + Log.e(K9.LOG_TAG, "Saving folder settings failed", e); } - return super.onKeyDown(keyCode, event); + + super.onBackPressed(); } - - } diff --git a/src/com/fsck/k9/activity/setup/FontSizeSettings.java b/src/com/fsck/k9/activity/setup/FontSizeSettings.java index b51f2da99..8760d107c 100644 --- a/src/com/fsck/k9/activity/setup/FontSizeSettings.java +++ b/src/com/fsck/k9/activity/setup/FontSizeSettings.java @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.preference.*; -import android.view.KeyEvent; import com.fsck.k9.*; import com.fsck.k9.activity.K9PreferenceActivity; @@ -160,10 +159,8 @@ public class FontSizeSettings extends K9PreferenceActivity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveSettings(); - } - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + saveSettings(); + super.onBackPressed(); } } diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index 86baa13fd..0164979b2 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -17,7 +17,6 @@ import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; -import android.view.KeyEvent; import android.widget.Toast; import com.fsck.k9.K9; @@ -401,16 +400,15 @@ public class Prefs extends K9PreferenceActivity { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - saveSettings(); - if (K9.manageBack()) { - Accounts.listAccounts(this); - finish(); - return true; - } + public void onBackPressed() { + saveSettings(); + + if (K9.manageBack()) { + Accounts.listAccounts(this); + finish(); + } else { + super.onBackPressed(); } - return super.onKeyDown(keyCode, event); } private void onFontSizeSettings() {