1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00
k-9/src/com/android/email/activity/ManageIdentities.java
Daniel Applebaum 10b9b0a05b Issue 117
Issue 30

Provide support for multiple identities.  Identities can be managed in
the Account Settings.  While composing a message, an identity can be
chosen for sending.  Identity information and signature edits are
saved in a header field, so that they survive being synced to the
server and back.

Provide support for editing the quoted text, either for replies or
forwards.  The quoted text is immediately editable, in a separate
editor from the main body.  When saved in a draft, the two are
contatenated, but the length of the main body is saved with the
identity information, and is used to split the two parts again, when
opening the draft.
2009-06-09 03:11:35 +00:00

162 lines
5.0 KiB
Java

package com.android.email.activity;
import android.content.Intent;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import com.android.email.Account;
import com.android.email.Preferences;
import com.android.email.R;
public class ManageIdentities extends ChooseIdentity
{
private boolean mIdentitiesChanged = false;
public static final String EXTRA_IDENTITIES = "com.android.email.EditIdentity_identities";
private static final int ACTIVITY_EDIT_IDENTITY = 1;
protected void setupClickListeners()
{
this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView adapterview, View view, int i, long l)
{
editItem(i);
}
});
ListView listView = getListView();
registerForContextMenu(listView);
}
private void editItem(int i)
{
Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount);
intent.putExtra(EditIdentity.EXTRA_IDENTITY, mAccount.getIdentity(i));
intent.putExtra(EditIdentity.EXTRA_IDENTITY_INDEX, i);
startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.manage_identities_option, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.new_identity:
Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount);
startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.manage_identities_context_menu_title);
getMenuInflater().inflate(R.menu.manage_identities_context, menu);
}
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
switch (item.getItemId())
{
case R.id.edit:
editItem(menuInfo.position);
break;
case R.id.up:
if (menuInfo.position > 0)
{
Account.Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position - 1, identity);
mIdentitiesChanged = true;
refreshView();
}
break;
case R.id.down:
if (menuInfo.position < identities.size() - 1)
{
Account.Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position + 1, identity);
mIdentitiesChanged = true;
refreshView();
}
break;
case R.id.top:
Account.Identity identity = identities.remove(menuInfo.position);
identities.add(0, identity);
mIdentitiesChanged = true;
refreshView();
break;
case R.id.remove:
if (identities.size() > 1)
{
identities.remove(menuInfo.position);
mIdentitiesChanged = true;
refreshView();
}
else
{
Toast.makeText(this, getString(R.string.no_removable_identity),
Toast.LENGTH_LONG).show();
}
break;
}
return true;
}
@Override
public void onResume()
{
super.onResume();
mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext()));
refreshView();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
saveIdentities();
}
return super.onKeyDown(keyCode, event);
}
private void saveIdentities()
{
if (mIdentitiesChanged)
{
mAccount.setIdentities(identities);
mAccount.save(Preferences.getPreferences(getApplication().getApplicationContext()));
}
finish();
}
}