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

Context actionbar for the account screen.

This commit is contained in:
Sander Bogaert 2012-08-28 10:06:31 -04:00 committed by Andrew Chen
parent 5392b8c331
commit 0f51eb54c1
7 changed files with 176 additions and 140 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

View File

@ -1,32 +1,51 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/open"
android:title="@string/open_action" />
<item android:id="@+id/check_mail" <item android:id="@+id/check_mail"
android:title="@string/check_mail_action" /> android:title="@string/check_mail_action"
android:showAsAction="always"
android:icon="@drawable/ic_action_refresh" />
<item android:id="@+id/empty_trash" <item android:id="@+id/empty_trash"
android:title="@string/empty_trash_action" /> android:title="@string/empty_trash_action"
android:showAsAction="always"
android:icon="@drawable/ic_action_delete" />
<item android:id="@+id/edit_account" <item android:id="@+id/edit_account"
android:title="@string/account_settings_action" /> android:title="@string/account_settings_action"
<item android:id="@+id/advanced" android:showAsAction="always"
android:title="@string/advanced"> android:icon="@drawable/ic_action_settings"/>
<menu>
<item android:id="@+id/compact" <item
android:title="@string/compact_action" /> android:id="@+id/compact"
<item android:id="@+id/clear" android:title="@string/compact_action"
android:title="@string/clear_action" /> android:showAsAction="never"/>
<item android:id="@+id/recreate" <item
android:title="@string/recreate_action" /> android:id="@+id/clear"
<item android:id="@+id/delete_account" android:title="@string/clear_action"
android:title="@string/remove_account_action" /> android:showAsAction="never"/>
<item android:id="@+id/clear_pending" <item
android:title="@string/clear_pending_action" /> android:id="@+id/recreate"
<item android:id="@+id/export" android:title="@string/recreate_action"
android:title="@string/settings_export_account" /> android:showAsAction="never"/>
<item android:id="@+id/move_up" <item
android:title="@string/manage_accounts_move_up_action" /> android:id="@+id/delete_account"
<item android:id="@+id/move_down" android:title="@string/remove_account_action"
android:title="@string/manage_accounts_move_down_action" /> android:showAsAction="never"/>
</menu> <item
</item> android:id="@+id/clear_pending"
android:title="@string/clear_pending_action"
android:showAsAction="never"/>
<item
android:id="@+id/export"
android:title="@string/settings_export_account"
android:showAsAction="never"/>
<item
android:id="@+id/move_up"
android:title="@string/manage_accounts_move_up_action"
android:showAsAction="never"/>
<item
android:id="@+id/move_down"
android:title="@string/manage_accounts_move_down_action"
android:showAsAction="never"/>
</menu> </menu>

View File

@ -101,6 +101,7 @@ http://k9mail.googlecode.com/
<string name="status_syncing_off">\u0020(Syncing disabled)</string> <string name="status_syncing_off">\u0020(Syncing disabled)</string>
<string name="actionbar_selected"><xliff:g id="selection_count">%d</xliff:g> selected</string> <string name="actionbar_selected"><xliff:g id="selection_count">%d</xliff:g> selected</string>
<string name="actionbar_string_selected"><xliff:g id="selection_count">\"%s\"</xliff:g> account selected</string>
<!-- Actions will be used as buttons and in menu items --> <!-- Actions will be used as buttons and in menu items -->
<string name="next_action">Next</string> <!-- Used as part of a multi-step process --> <string name="next_action">Next</string> <!-- Used as part of a multi-step process -->
<string name="previous_action">Previous</string> <!-- Used as part of a multi-step process --> <string name="previous_action">Previous</string> <!-- Used as part of a multi-step process -->

View File

@ -28,21 +28,18 @@ import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextMenu;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -51,10 +48,12 @@ import android.widget.RelativeLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.AccountStats; import com.fsck.k9.AccountStats;
import com.fsck.k9.BaseAccount; import com.fsck.k9.BaseAccount;
@ -80,7 +79,6 @@ import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.store.WebDavStore;
import com.fsck.k9.view.ColorChip;
import com.fsck.k9.preferences.SettingsExporter; import com.fsck.k9.preferences.SettingsExporter;
import com.fsck.k9.preferences.SettingsImportExportException; import com.fsck.k9.preferences.SettingsImportExportException;
import com.fsck.k9.preferences.SettingsImporter; import com.fsck.k9.preferences.SettingsImporter;
@ -88,6 +86,7 @@ import com.fsck.k9.preferences.SettingsImporter.AccountDescription;
import com.fsck.k9.preferences.SettingsImporter.AccountDescriptionPair; import com.fsck.k9.preferences.SettingsImporter.AccountDescriptionPair;
import com.fsck.k9.preferences.SettingsImporter.ImportContents; import com.fsck.k9.preferences.SettingsImporter.ImportContents;
import com.fsck.k9.preferences.SettingsImporter.ImportResults; import com.fsck.k9.preferences.SettingsImporter.ImportResults;
import com.fsck.k9.view.ColorChip;
public class Accounts extends K9ListActivity implements OnItemClickListener { public class Accounts extends K9ListActivity implements OnItemClickListener {
@ -132,6 +131,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
private MenuItem mRefreshMenuItem; private MenuItem mRefreshMenuItem;
private ActionBar mActionBar; private ActionBar mActionBar;
private ActionMode mActionMode;
private TextView mActionBarTitle; private TextView mActionBarTitle;
private TextView mActionBarSubTitle; private TextView mActionBarSubTitle;
@ -398,6 +398,34 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
listView.setScrollingCacheEnabled(false); listView.setScrollingCacheEnabled(false);
registerForContextMenu(listView); registerForContextMenu(listView);
// Enable context action bar behaviour
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// is already in selection mode we ignore the next ones
if (mSelectedContextAccount != null) {
return false;
}
mSelectedContextAccount = mAdapter.getItem(position);
// we only handle real accounts this way
if (mSelectedContextAccount instanceof SearchAccount) {
mSelectedContextAccount = null;
return false;
}
mSelectedContextAccount = mAdapter.getItem(position);
mActionMode = Accounts.this.startActionMode(mActionModeCallback);
mActionMode.invalidate();
mActionMode.setTitle(String.format(getString(R.string.actionbar_string_selected),
mSelectedContextAccount.getDescription()));
return true;
}
});
if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) { if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) {
String accountUuid = icicle.getString("selectedContextAccount"); String accountUuid = icicle.getString("selectedContextAccount");
mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid); mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid);
@ -618,6 +646,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
* @return false if unsuccessfull * @return false if unsuccessfull
*/ */
private boolean onOpenAccount(BaseAccount account) { private boolean onOpenAccount(BaseAccount account) {
// if we are still in a selection finish it
if (mSelectedContextAccount != null) {
mActionMode.finish();
}
if (account instanceof SearchAccount) { if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount)account; SearchAccount searchAccount = (SearchAccount)account;
MessageList.actionHandle(this, searchAccount.getDescription(), searchAccount); MessageList.actionHandle(this, searchAccount.getDescription(), searchAccount);
@ -1090,64 +1123,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
super.onPrepareDialog(id, d); super.onPrepareDialog(id, d);
} }
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
// submenus don't actually set the menuInfo, so the "advanced"
// submenu wouldn't work.
if (menuInfo != null) {
mSelectedContextAccount = (BaseAccount)getListView().getItemAtPosition(menuInfo.position);
}
Account realAccount = null;
if (mSelectedContextAccount instanceof Account) {
realAccount = (Account)mSelectedContextAccount;
}
switch (item.getItemId()) {
case R.id.delete_account:
onDeleteAccount(realAccount);
break;
case R.id.edit_account:
onEditAccount(realAccount);
break;
case R.id.open:
onOpenAccount(mSelectedContextAccount);
break;
case R.id.activate:
onActivateAccount(realAccount);
break;
case R.id.check_mail:
onCheckMail(realAccount);
break;
case R.id.clear_pending:
onClearCommands(realAccount);
break;
case R.id.empty_trash:
onEmptyTrash(realAccount);
break;
case R.id.compact:
onCompact(realAccount);
break;
case R.id.clear:
onClear(realAccount);
break;
case R.id.recreate:
onRecreate(realAccount);
break;
case R.id.export:
onExport(false, realAccount);
break;
case R.id.move_up:
onMove(realAccount, true);
break;
case R.id.move_down:
onMove(realAccount, false);
break;
}
return true;
}
private void onCompact(Account account) { private void onCompact(Account account) {
mHandler.workingAccount(account, R.string.compacting_account); mHandler.workingAccount(account, R.string.compacting_account);
MessagingController.getInstance(getApplication()).compact(account, null); MessagingController.getInstance(getApplication()).compact(account, null);
@ -1287,10 +1262,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
return version; return version;
} }
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return true;
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
@ -1299,45 +1270,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
return true; return true;
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.accounts_context_menu_title);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
BaseAccount account = mAdapter.getItem(info.position);
if ((account instanceof Account) && !((Account) account).isEnabled()) {
getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
} else {
getMenuInflater().inflate(R.menu.accounts_context, menu);
}
if (account instanceof SearchAccount) {
for (int i = 0; i < menu.size(); i++) {
android.view.MenuItem item = menu.getItem(i);
if (item.getItemId() != R.id.open) {
item.setVisible(false);
}
}
}
else {
EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
menu.findItem(R.id.move_up).setEnabled(false);
}
else {
menu.findItem(R.id.move_up).setEnabled(true);
}
if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
menu.findItem(R.id.move_down).setEnabled(false);
}
else {
menu.findItem(R.id.move_down).setEnabled(true);
}
}
}
private void onImport() { private void onImport() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT); Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE); i.addCategory(Intent.CATEGORY_OPENABLE);
@ -1853,6 +1785,90 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} }
/*
* Assume this will only be used for REAL ACCOUNTS. This means not the
* unified inbox, all messages ( and whatever may come in the future ).
*/
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(mSelectedContextAccount);
if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
menu.findItem(R.id.move_up).setVisible(false);
}
else {
menu.findItem(R.id.move_up).setVisible(true);
}
if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
menu.findItem(R.id.move_down).setVisible(false);
}
else {
menu.findItem(R.id.move_down).setVisible(true);
}
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mSelectedContextAccount = null;
mActionMode = null;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.accounts_context, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Account realAccount = (Account)mSelectedContextAccount;
switch (item.getItemId()) {
case R.id.delete_account:
onDeleteAccount(realAccount);
break;
case R.id.edit_account:
onEditAccount(realAccount);
break;
case R.id.activate:
onActivateAccount(realAccount);
break;
case R.id.check_mail:
onCheckMail(realAccount);
break;
case R.id.clear_pending:
onClearCommands(realAccount);
break;
case R.id.empty_trash:
onEmptyTrash(realAccount);
break;
case R.id.compact:
onCompact(realAccount);
break;
case R.id.clear:
onClear(realAccount);
break;
case R.id.recreate:
onRecreate(realAccount);
break;
case R.id.export:
onExport(false, realAccount);
break;
case R.id.move_up:
onMove(realAccount, true);
break;
case R.id.move_down:
onMove(realAccount, false);
break;
}
return true;
}
};
public void onExport(final boolean includeGlobals, final Account account) { public void onExport(final boolean includeGlobals, final Account account) {
// TODO, prompt to allow a user to choose which accounts to export // TODO, prompt to allow a user to choose which accounts to export