2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
package com.android.email.activity;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import android.app.ListActivity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.Window;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.android.email.Account;
|
2009-08-29 18:17:49 -04:00
|
|
|
import com.android.email.K9ListActivity;
|
2009-06-08 23:11:35 -04:00
|
|
|
import com.android.email.Preferences;
|
|
|
|
import com.android.email.R;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class ChooseIdentity extends K9ListActivity
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
Account mAccount;
|
2009-11-21 17:45:39 -05:00
|
|
|
String mUID;
|
2009-06-08 23:11:35 -04:00
|
|
|
ArrayAdapter<String> adapter;
|
|
|
|
private ChooseIdentityHandler mHandler = new ChooseIdentityHandler();
|
|
|
|
|
|
|
|
public static final String EXTRA_ACCOUNT = "com.android.email.ChooseIdentity_account";
|
|
|
|
public static final String EXTRA_IDENTITY = "com.android.email.ChooseIdentity_identity";
|
|
|
|
|
|
|
|
protected List<Account.Identity> identities = null;
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
|
|
|
|
|
|
|
getListView().setTextFilterEnabled(true);
|
|
|
|
getListView().setItemsCanFocus(false);
|
|
|
|
getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
|
|
|
|
Intent intent = getIntent();
|
|
|
|
mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
|
|
|
|
|
|
|
|
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
|
|
|
|
|
|
|
|
setListAdapter(adapter);
|
|
|
|
setupClickListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onResume()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onResume();
|
|
|
|
refreshView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
protected void refreshView()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
adapter.clear();
|
|
|
|
|
|
|
|
identities = mAccount.getIdentities();
|
2009-11-24 19:40:29 -05:00
|
|
|
for (Account.Identity identity : identities)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
String email = identity.getEmail();
|
|
|
|
String description = identity.getDescription();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (description == null || description.trim().length() == 0)
|
|
|
|
{
|
2009-11-21 17:45:39 -05:00
|
|
|
description = getString(R.string.message_view_from_format, identity.getName(), identity.getEmail());
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
adapter.add(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
protected void setupClickListeners()
|
|
|
|
{
|
|
|
|
this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
|
|
|
|
{
|
|
|
|
public void onItemClick(AdapterView adapterview, View view, int i, long l)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
Account.Identity identity = mAccount.getIdentity(i);
|
|
|
|
String email = identity.getEmail();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (email != null && email.trim().equals("") == false)
|
|
|
|
{
|
2009-11-21 17:45:39 -05:00
|
|
|
Intent intent = new Intent();
|
|
|
|
|
|
|
|
intent.putExtra(EXTRA_IDENTITY, mAccount.getIdentity(i));
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
finish();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
Toast.makeText(ChooseIdentity.this, getString(R.string.identity_has_no_email),
|
2009-11-21 17:45:39 -05:00
|
|
|
Toast.LENGTH_LONG).show();
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
class ChooseIdentityHandler extends Handler
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
private static final int MSG_PROGRESS = 2;
|
|
|
|
private static final int MSG_DATA_CHANGED = 3;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void handleMessage(android.os.Message msg)
|
|
|
|
{
|
|
|
|
switch (msg.what)
|
|
|
|
{
|
|
|
|
case MSG_PROGRESS:
|
|
|
|
setProgressBarIndeterminateVisibility(msg.arg1 != 0);
|
|
|
|
break;
|
|
|
|
case MSG_DATA_CHANGED:
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
break;
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void progress(boolean progress)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
android.os.Message msg = new android.os.Message();
|
|
|
|
msg.what = MSG_PROGRESS;
|
|
|
|
msg.arg1 = progress ? 1 : 0;
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void dataChanged()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
sendEmptyMessage(MSG_DATA_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|