1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Clean up our back button support to be actually consistent and to not leak nearly as many activities.

This commit is contained in:
Jesse Vincent 2010-01-28 00:29:27 +00:00
parent 3ffad03e9b
commit 1945dc4ad4
6 changed files with 122 additions and 58 deletions

View File

@ -38,6 +38,7 @@
<activity
android:name="com.fsck.k9.activity.Accounts"
android:launchMode="singleTop"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -37,7 +37,7 @@ import android.os.PowerManager.WakeLock;
import android.text.TextUtils;
import android.util.Log;
import com.fsck.k9.activity.FolderList;
import com.fsck.k9.activity.MessageList;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.FetchProfile;
import com.fsck.k9.mail.Flag;
@ -3260,8 +3260,7 @@ public class MessagingController implements Runnable
Notification notif = new Notification(R.drawable.stat_notify_email_generic,
mApplication.getString(R.string.send_failure_subject), System.currentTimeMillis());
// JRV XXX TODO - do we want to notify MessageList too?
Intent i = FolderList.actionHandleAccountIntent(mApplication, account, account.getErrorFolderName());
Intent i = MessageList.actionHandleFolderIntent(mApplication, account, account.getErrorFolderName());
PendingIntent pi = PendingIntent.getActivity(mApplication, 0, i, 0);
@ -3874,8 +3873,7 @@ public class MessagingController implements Runnable
{
Notification notif = new Notification(R.drawable.ic_menu_refresh,
context.getString(R.string.notification_bg_send_ticker, account.getDescription()), System.currentTimeMillis());
// JRV XXX TODO - do we want to notify MessageList too?
Intent intent = FolderList.actionHandleAccountIntent(context, account, K9.INBOX);
Intent intent = MessageList.actionHandleFolderIntent(context, account, K9.INBOX);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_send_title),
account.getDescription() , pi);
@ -3985,8 +3983,7 @@ public class MessagingController implements Runnable
Notification notif = new Notification(R.drawable.ic_menu_refresh,
context.getString(R.string.notification_bg_sync_ticker, account.getDescription(), folder.getName()),
System.currentTimeMillis());
// JRV XXX TODO - do we want to notify MessageList too?
Intent intent = FolderList.actionHandleAccountIntent(context, account, K9.INBOX);
Intent intent = MessageList.actionHandleFolderIntent(context, account, K9.INBOX);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_sync_title), account.getDescription()
+ context.getString(R.string.notification_bg_title_separator) + folder.getName(), pi);
@ -4201,7 +4198,7 @@ public class MessagingController implements Runnable
Notification notif = new Notification(R.drawable.stat_notify_email_generic, messageNotice, System.currentTimeMillis());
notif.number = unreadMessageCount;
Intent i = FolderList.actionHandleAccountIntent(context, account);
Intent i = MessageList.actionHandleFolderIntent(context, account, account.getAutoExpandFolderName());
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
// 279 Unread (someone@gmail.com)

View File

@ -40,6 +40,33 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
private AccountsHandler mHandler = new AccountsHandler();
private AccountsAdapter mAdapter;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (
// TODO - once we upgrade to 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;
}
return super.onKeyDown(keyCode, event);
}
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.
finish();
}
class AccountsHandler extends Handler
{
private void setViewTitle()
@ -278,8 +305,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
boolean startup = (boolean)intent.getBooleanExtra(EXTRA_STARTUP, true);
if (startup && accounts.length == 1)
{
onOpenAccount(accounts[0], true);
finish();
onOpenAccount(accounts[0]);
}
else
{
@ -403,16 +429,17 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
}
private void onOpenAccount(Account account, boolean startup)
private void onOpenAccount(Account account)
{
if (K9.FOLDER_NONE.equals(account.getAutoExpandFolderName()))
{
FolderList.actionHandleAccount(this, account, startup);
FolderList.actionHandleAccount(this, account);
}
else
{
MessageList.actionHandleFolder(this, account, account.getAutoExpandFolderName(), startup);
MessageList.actionHandleFolder(this, account, account.getAutoExpandFolderName());
}
finish();
}
public void onClick(View view)
@ -506,7 +533,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
onEditAccount(mSelectedContextAccount);
break;
case R.id.open:
onOpenAccount(mSelectedContextAccount, false);
onOpenAccount(mSelectedContextAccount);
break;
case R.id.check_mail:
onCheckMail(mSelectedContextAccount);
@ -545,7 +572,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public void onItemClick(AdapterView parent, View view, int position, long id)
{
Account account = (Account)parent.getItemAtPosition(position);
onOpenAccount(account, false);
onOpenAccount(account);
}
@Override

View File

@ -48,8 +48,6 @@ public class FolderList extends K9ListActivity
private static final String EXTRA_CLEAR_NOTIFICATION = "clearNotification";
private static final String EXTRA_STARTUP = "startup";
private static final boolean REFRESH_REMOTE = true;
private ListView mListView;
@ -62,8 +60,6 @@ public class FolderList extends K9ListActivity
private FolderListHandler mHandler = new FolderListHandler();
private boolean mStartup = false;
private int mUnreadMessageCount = 0;
class FolderListHandler extends Handler
@ -204,11 +200,10 @@ public class FolderList extends K9ListActivity
sendMail(mAccount);
}
private static void actionHandleAccount(Context context, Account account, String initialFolder, boolean startup)
private static void actionHandleAccount(Context context, Account account, String initialFolder)
{
Intent intent = new Intent(context, FolderList.class);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_STARTUP, startup);
if (initialFolder != null)
{
@ -218,14 +213,9 @@ public class FolderList extends K9ListActivity
context.startActivity(intent);
}
public static void actionHandleAccount(Context context, Account account, String initialFolder)
public static void actionHandleAccount(Context context, Account account)
{
actionHandleAccount(context, account, initialFolder, false);
}
public static void actionHandleAccount(Context context, Account account, boolean startup)
{
actionHandleAccount(context, account, null, startup);
actionHandleAccount(context, account, null);
}
public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder)
@ -243,10 +233,6 @@ public class FolderList extends K9ListActivity
{
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
}
else
{
intent.putExtra(EXTRA_STARTUP, true);
}
return intent;
}
@ -269,17 +255,10 @@ public class FolderList extends K9ListActivity
if (savedInstanceState == null)
{
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
mStartup = (boolean) intent.getBooleanExtra(EXTRA_STARTUP, false);
if (initialFolder == null
&& mStartup)
{
initialFolder = mAccount.getAutoExpandFolderName();
}
}
else
{
initialFolder = null;
mStartup = false;
savedFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
if (savedFolderName != null)
{
@ -287,11 +266,11 @@ public class FolderList extends K9ListActivity
}
}
if (mStartup
&& initialFolder != null
&& !K9.FOLDER_NONE.equals(initialFolder))
if (
initialFolder != null
&& !K9.FOLDER_NONE.equals(initialFolder))
{
onOpenFolder(initialFolder, true);
onOpenFolder(initialFolder);
finish();
}
else
@ -319,7 +298,7 @@ public class FolderList extends K9ListActivity
{
public void onItemClick(AdapterView parent, View v, int itemPosition, long id)
{
MessageList.actionHandleFolder(FolderList.this, mAccount, ((FolderInfoHolder)mAdapter.getItem(id)).name, false);
onOpenFolder(((FolderInfoHolder)mAdapter.getItem(id)).name);
}
});
registerForContextMenu(mListView);
@ -394,10 +373,33 @@ public class FolderList extends K9ListActivity
}
}
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.
onAccounts();
}
@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)
{
// 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:
@ -444,11 +446,7 @@ public class FolderList extends K9ListActivity
private void onAccounts()
{
if (mStartup || isTaskRoot())
{
Accounts.listAccounts(this);
}
Accounts.listAccounts(this);
finish();
}
@ -526,9 +524,10 @@ public class FolderList extends K9ListActivity
}
}
private void onOpenFolder(String folder, boolean startup)
private void onOpenFolder(String folder)
{
MessageList.actionHandleFolder(this, mAccount, folder, startup);
MessageList.actionHandleFolder(this, mAccount, folder);
finish();
}
private void onCompact(Account account)
@ -558,7 +557,7 @@ public class FolderList extends K9ListActivity
switch (item.getItemId())
{
case R.id.open_folder:
onOpenFolder(folder.name, false);
onOpenFolder(folder.name);
break;
case R.id.mark_all_as_read:

View File

@ -63,7 +63,6 @@ public class MessageList
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_STARTUP = "startup";
private static final String EXTRA_FOLDER = "folder";
private static final String EXTRA_QUERY = "query";
@ -283,18 +282,22 @@ public class MessageList
* given folder
*/
public static void actionHandleFolder(Context context, Account account, String folder, boolean startup)
public static void actionHandleFolder(Context context, Account account, String folder)
{
Intent intent = actionHandleFolderIntent(context,account,folder);
context.startActivity(intent);
}
public static Intent actionHandleFolderIntent(Context context, Account account, String folder)
{
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_STARTUP, startup);
if (folder != null)
{
intent.putExtra(EXTRA_FOLDER, folder);
}
context.startActivity(intent);
return intent;
}
public void onItemClick(AdapterView parent, View v, int position, long id)
@ -515,10 +518,29 @@ public class MessageList
}
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.
onShowFolderList();
}
@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)
@ -699,7 +721,7 @@ public class MessageList
private void onShowFolderList()
{
FolderList.actionHandleAccount(this, mAccount, false);
FolderList.actionHandleAccount(this, mAccount);
finish();
}

View File

@ -103,6 +103,14 @@ public class MessageView extends K9Activity
private Listener mListener = new Listener();
private MessageViewHandler mHandler = new MessageViewHandler();
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.
finish();
}
@Override
public boolean dispatchKeyEvent(KeyEvent event)
@ -122,6 +130,16 @@ public class MessageView extends K9Activity
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (
// TODO: when we get to 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();
}
switch (keyCode)
{
case KeyEvent.KEYCODE_DEL: