Convert Accounts to AccountFolderList

* Move relevant sources & resources to new name
* Convert from ListView to ExpandableListView
* No children yet - selecting account simply jumps to FML (temp)
* No other change to functionality (e.g. no menu changes yet)
This commit is contained in:
Andrew Stadler 2009-07-09 12:33:09 -07:00
parent b55bfc96f4
commit 72dce73390
9 changed files with 231 additions and 53 deletions

View File

@ -101,7 +101,7 @@
android:label="@string/debug_title">
</activity>
<activity
android:name=".activity.Accounts"
android:name=".activity.AccountFolderList"
android:label="@string/accounts_title"
android:launchMode="singleTop" >
</activity>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ExpandableListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<LinearLayout
android:id="@+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/accounts_welcome"
android:textColor="?android:attr/textColorPrimary" />
<View
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="54dip"
android:background="@android:drawable/bottom_bar">
<Button
android:id="@+id/add_new_account"
android:layout_width="wrap_content"
android:minWidth="@dimen/button_minWidth"
android:layout_height="wrap_content"
android:text="@string/next_action"
android:drawableRight="@drawable/button_indicator_next"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingLeft="36px"
android:paddingRight="4px">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="6px">
<TextView
android:id="@+id/description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/email"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:layout_height="fill_parent"
android:layout_width="0px"
android:layout_weight="1" />
<TextView
android:id="@+id/new_message_count"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/text_box_light"
android:paddingLeft="10px"
android:paddingRight="10px"
android:minWidth="64px"
android:gravity="right" />
</LinearLayout>

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,7 +27,7 @@ import com.android.email.provider.EmailContent.Account;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ExpandableListActivity;
import android.app.NotificationManager;
import android.content.ContentUris;
import android.content.Context;
@ -39,19 +39,23 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
public class Accounts extends ListActivity implements OnItemClickListener, OnClickListener {
public class AccountFolderList extends ExpandableListActivity
implements OnItemClickListener, OnClickListener {
private static final int DIALOG_REMOVE_ACCOUNT = 1;
/**
* Key codes used to open a debug settings screen.
@ -66,7 +70,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
private static final String ICICLE_SELECTED_ACCOUNT = "com.android.email.selectedAccount";
private EmailContent.Account mSelectedContextAccount;
ListView mListView;
ExpandableListView mListView;
LoadAccountsTask mAsyncTask;
/**
@ -88,7 +92,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
* activities may be killed in order to get back to Accounts.
*/
public static void actionShowAccounts(Context context) {
Intent i = new Intent(context, Accounts.class);
Intent i = new Intent(context, AccountFolderList.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
@ -96,17 +100,20 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.accounts);
mListView = getListView();
setContentView(R.layout.account_folder_list);
mListView = getExpandableListView();
mListView.setOnItemClickListener(this);
mListView.setItemsCanFocus(false);
findViewById(R.id.add_new_account).setOnClickListener(this);
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
mListView.setLongClickable(true);
registerForContextMenu(mListView);
findViewById(R.id.add_new_account).setOnClickListener(this);
if (icicle != null && icicle.containsKey(ICICLE_SELECTED_ACCOUNT)) {
mSelectedContextAccount = (Account) icicle.getParcelable(ICICLE_SELECTED_ACCOUNT);
}
mAsyncTask = (LoadAccountsTask) new LoadAccountsTask().execute();
}
@ -137,6 +144,19 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
}
}
@Override
public void onGroupExpand(int groupPosition) {
super.onGroupExpand(groupPosition);
// This is a temporary hack, until I implement the child cursors
AccountsAdapter adapter = (AccountsAdapter) mListView.getExpandableListAdapter();
if (adapter != null) {
Cursor groupCursor = adapter.getGroup(groupPosition);
long mailboxKey = groupCursor.getLong(EmailContent.Mailbox.CONTENT_ID_COLUMN);
FolderMessageList.actionHandleAccount(this, mailboxKey);
}
}
/**
* Async task to handle the cursor query out of the UI thread
*/
@ -144,7 +164,8 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
@Override
protected Cursor doInBackground(Void... params) {
return Accounts.this.managedQuery(
// TODO use a custom projection and don't have to sample all of these columns
return AccountFolderList.this.managedQuery(
EmailContent.Account.CONTENT_URI,
EmailContent.Account.CONTENT_PROJECTION,
null, null, null);
@ -152,8 +173,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
@Override
protected void onPostExecute(Cursor theCursor) {
AccountsAdapter adapter = new AccountsAdapter(Accounts.this,
R.layout.accounts_item, theCursor, sFromColumns, sToIds);
AccountsAdapter adapter = new AccountsAdapter(theCursor, AccountFolderList.this);
mListView.setAdapter(adapter);
// This is deferred until after the first fetch, so it won't flicker
@ -219,17 +239,18 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
try {
// Delete Remote store at first.
Store.getInstance(
mSelectedContextAccount.getStoreUri(Accounts.this),
mSelectedContextAccount.getStoreUri(AccountFolderList.this),
getApplication(), null).delete();
// Remove the Store instance from cache.
Store.removeInstance(mSelectedContextAccount.getStoreUri(Accounts.this));
Store.removeInstance(mSelectedContextAccount.getStoreUri(
AccountFolderList.this));
Uri uri = ContentUris.withAppendedId(
EmailContent.Account.CONTENT_URI, mSelectedContextAccount.mId);
Accounts.this.getContentResolver().delete(uri, null, null);
AccountFolderList.this.getContentResolver().delete(uri, null, null);
} catch (Exception e) {
// Ignore
}
Email.setServicesEnabled(Accounts.this);
Email.setServicesEnabled(AccountFolderList.this);
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
@ -243,7 +264,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
Cursor c = (Cursor) getListView().getItemAtPosition(menuInfo.position);
Cursor c = (Cursor) mListView.getItemAtPosition(menuInfo.position);
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
switch (item.getItemId()) {
case R.id.delete_account:
@ -260,7 +281,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
}
public void onItemClick(AdapterView parent, View view, int position, long id) {
Cursor c = (Cursor) getListView().getItemAtPosition(position);
Cursor c = (Cursor) mListView.getItemAtPosition(position);
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
onOpenAccount(accountId);
}
@ -315,33 +336,76 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
return super.onKeyDown(keyCode, event);
}
private static class AccountsAdapter extends SimpleCursorAdapter {
private static class AccountsAdapter extends CursorTreeAdapter {
public AccountsAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
setViewBinder(new MyViewBinder());
Context mContext;
private LayoutInflater mInflater;
public AccountsAdapter(Cursor c, Context context) {
super(c, context, true);
mContext = context;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/**
* This is only used for the unread messages count. Most of the views are handled
* normally by SimpleCursorAdapter.
*/
private static class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.new_message_count) {
int unreadMessageCount = 0; // TODO get unread count from Account
if (unreadMessageCount <= 0) {
view.setVisibility(View.GONE);
} else {
((TextView)view).setText(String.valueOf(unreadMessageCount));
}
return true;
}
return false;
@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild)
{
// TODO Auto-generated method stub
}
@Override
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded)
{
String text = cursor.getString(EmailContent.Account.CONTENT_DISPLAY_NAME_COLUMN);
if (text != null) {
TextView descriptionView = (TextView) view.findViewById(R.id.description);
descriptionView.setText(text);
}
text = cursor.getString(EmailContent.Account.CONTENT_EMAIL_ADDRESS_COLUMN);
if (text != null) {
TextView emailView = (TextView) view.findViewById(R.id.email);
emailView.setText(text);
}
TextView countView = (TextView) view.findViewById(R.id.new_message_count);
int unreadMessageCount = 0; // TODO get unread count from Account
if (unreadMessageCount <= 0) {
countView.setVisibility(View.GONE);
} else {
countView.setText(String.valueOf(unreadMessageCount));
}
}
/**
* We return null here (no immediate cursor availability) and use an AsyncTask to get
* the cursor in certain onclick situations
*/
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
return null;
}
/**
* Overriding this allows the child cursors to be requeried on dataset changes
*/
@Override
public void notifyDataSetChanged() {
notifyDataSetChanged(false);
}
@Override
protected View newChildView(Context context, Cursor cursor, boolean isLastChild,
ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
@Override
protected View newGroupView(Context context, Cursor cursor, boolean isExpanded,
ViewGroup parent) {
return mInflater.inflate(R.layout.account_folder_list_group, parent, false);
}
}
}

View File

@ -502,7 +502,7 @@ public class FolderMessageList extends ExpandableListActivity {
}
// If no useable account was specified, just go to the accounts list screen instead
if (mAccount == null) {
Accounts.actionShowAccounts(this);
AccountFolderList.actionShowAccounts(this);
finish();
return;
}
@ -834,7 +834,7 @@ public class FolderMessageList extends ExpandableListActivity {
}
private void onAccounts() {
Accounts.actionShowAccounts(this);
AccountFolderList.actionShowAccounts(this);
finish();
}

View File

@ -431,7 +431,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
if (mAccount == null) {
// There are no accounts set up. This should not have happened. Prompt the
// user to set up an account as an acceptable bailout.
Accounts.actionShowAccounts(this);
AccountFolderList.actionShowAccounts(this);
mDraftNeedsSaving = false;
finish();
return;

View File

@ -261,7 +261,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
}
private void onAccounts() {
Accounts.actionShowAccounts(this);
AccountFolderList.actionShowAccounts(this);
finish();
}

View File

@ -74,7 +74,7 @@ public class Welcome extends Activity {
}
// Otherwise (n=0 or n>1) go to the account info screen
Accounts.actionShowAccounts(this);
AccountFolderList.actionShowAccounts(this);
finish();
}

View File

@ -20,15 +20,13 @@ import com.android.email.Account;
import com.android.email.Email;
import com.android.email.MessagingController;
import com.android.email.MessagingListener;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.activity.Accounts;
import com.android.email.activity.AccountFolderList;
import com.android.email.activity.FolderMessageList;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Store;
import com.android.email.mail.store.LocalStore;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent;
import android.app.AlarmManager;
import android.app.Notification;
@ -274,7 +272,7 @@ public class MailService extends Service {
}
ringtone = account1.getRingtone();
}
Intent i = new Intent(context, Accounts.class);
Intent i = new Intent(context, AccountFolderList.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
notif.setLatestEventInfo(context, getString(R.string.notification_new_title),
getResources().