mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Context actionbar for the account screen.
This commit is contained in:
parent
5392b8c331
commit
0f51eb54c1
BIN
res/drawable-hdpi/ic_action_settings.png
Normal file
BIN
res/drawable-hdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 592 B |
BIN
res/drawable-ldpi/ic_action_settings.png
Normal file
BIN
res/drawable-ldpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 356 B |
BIN
res/drawable-mdpi/ic_action_settings.png
Normal file
BIN
res/drawable-mdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 377 B |
BIN
res/drawable-xhdpi/ic_action_settings.png
Normal file
BIN
res/drawable-xhdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 739 B |
@ -1,32 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
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"
|
||||
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"
|
||||
android:title="@string/account_settings_action" />
|
||||
<item android:id="@+id/advanced"
|
||||
android:title="@string/advanced">
|
||||
<menu>
|
||||
<item android:id="@+id/compact"
|
||||
android:title="@string/compact_action" />
|
||||
<item android:id="@+id/clear"
|
||||
android:title="@string/clear_action" />
|
||||
<item android:id="@+id/recreate"
|
||||
android:title="@string/recreate_action" />
|
||||
<item android:id="@+id/delete_account"
|
||||
android:title="@string/remove_account_action" />
|
||||
<item android:id="@+id/clear_pending"
|
||||
android:title="@string/clear_pending_action" />
|
||||
<item android:id="@+id/export"
|
||||
android:title="@string/settings_export_account" />
|
||||
<item android:id="@+id/move_up"
|
||||
android:title="@string/manage_accounts_move_up_action" />
|
||||
<item android:id="@+id/move_down"
|
||||
android:title="@string/manage_accounts_move_down_action" />
|
||||
</menu>
|
||||
</item>
|
||||
android:title="@string/account_settings_action"
|
||||
android:showAsAction="always"
|
||||
android:icon="@drawable/ic_action_settings"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/compact"
|
||||
android:title="@string/compact_action"
|
||||
android:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/clear"
|
||||
android:title="@string/clear_action"
|
||||
android:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/recreate"
|
||||
android:title="@string/recreate_action"
|
||||
android:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/delete_account"
|
||||
android:title="@string/remove_account_action"
|
||||
android:showAsAction="never"/>
|
||||
<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>
|
||||
|
@ -101,6 +101,7 @@ http://k9mail.googlecode.com/
|
||||
<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_string_selected"><xliff:g id="selection_count">\"%s\"</xliff:g> account selected</string>
|
||||
<!-- 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="previous_action">Previous</string> <!-- Used as part of a multi-step process -->
|
||||
|
@ -28,21 +28,18 @@ import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
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.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
@ -51,10 +48,12 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
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.AccountStats;
|
||||
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.store.StorageManager;
|
||||
import com.fsck.k9.mail.store.WebDavStore;
|
||||
import com.fsck.k9.view.ColorChip;
|
||||
import com.fsck.k9.preferences.SettingsExporter;
|
||||
import com.fsck.k9.preferences.SettingsImportExportException;
|
||||
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.ImportContents;
|
||||
import com.fsck.k9.preferences.SettingsImporter.ImportResults;
|
||||
import com.fsck.k9.view.ColorChip;
|
||||
|
||||
|
||||
public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
@ -132,6 +131,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
|
||||
private MenuItem mRefreshMenuItem;
|
||||
private ActionBar mActionBar;
|
||||
private ActionMode mActionMode;
|
||||
|
||||
private TextView mActionBarTitle;
|
||||
private TextView mActionBarSubTitle;
|
||||
@ -398,6 +398,34 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
listView.setScrollingCacheEnabled(false);
|
||||
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)) {
|
||||
String accountUuid = icicle.getString("selectedContextAccount");
|
||||
mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||
@ -414,14 +442,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
|
||||
private void initializeActionBar() {
|
||||
mActionBar.setDisplayShowCustomEnabled(true);
|
||||
mActionBar.setCustomView(R.layout.actionbar_custom);
|
||||
mActionBar.setCustomView(R.layout.actionbar_custom);
|
||||
|
||||
View customView = mActionBar.getCustomView();
|
||||
mActionBarTitle = (TextView) customView.findViewById(R.id.actionbar_title_first);
|
||||
mActionBarSubTitle = (TextView) customView.findViewById(R.id.actionbar_title_sub);
|
||||
mActionBarUnread = (TextView) customView.findViewById(R.id.actionbar_unread_count);
|
||||
|
||||
mActionBar.setDisplayHomeAsUpEnabled(true);
|
||||
mActionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -618,6 +646,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
* @return false if unsuccessfull
|
||||
*/
|
||||
private boolean onOpenAccount(BaseAccount account) {
|
||||
// if we are still in a selection finish it
|
||||
if (mSelectedContextAccount != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
|
||||
if (account instanceof SearchAccount) {
|
||||
SearchAccount searchAccount = (SearchAccount)account;
|
||||
MessageList.actionHandle(this, searchAccount.getDescription(), searchAccount);
|
||||
@ -1090,64 +1123,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
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) {
|
||||
mHandler.workingAccount(account, R.string.compacting_account);
|
||||
MessagingController.getInstance(getApplication()).compact(account, null);
|
||||
@ -1287,10 +1262,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
@ -1299,45 +1270,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
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() {
|
||||
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
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) {
|
||||
|
||||
// TODO, prompt to allow a user to choose which accounts to export
|
||||
|
Loading…
Reference in New Issue
Block a user