Mindy Pereira | f645288 | 2012-02-14 18:13:13 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2012, Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.mail.browse; |
| 18 | |
| 19 | import com.android.mail.R; |
| 20 | |
| 21 | import android.app.Activity; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.database.Cursor; |
| 25 | import android.net.Uri; |
| 26 | import android.os.Bundle; |
| 27 | import android.view.LayoutInflater; |
| 28 | import android.view.View; |
| 29 | import android.view.ViewGroup; |
| 30 | import android.widget.ListView; |
| 31 | import android.widget.SimpleCursorAdapter; |
| 32 | |
| 33 | import com.android.mail.providers.Account; |
| 34 | import com.android.mail.providers.Folder; |
| 35 | import com.android.mail.providers.Message; |
| 36 | import com.android.mail.providers.UIProvider; |
| 37 | import com.android.mail.ui.FolderItemView; |
| 38 | import com.android.mail.ui.FolderItemView.DropHandler; |
| 39 | import com.android.mail.utils.Utils; |
| 40 | |
| 41 | public class FoldersListActivity extends Activity { |
| 42 | private ListView mListView; |
| 43 | private Account mAccount; |
| 44 | private Cursor mFoldersCursor; |
| 45 | |
| 46 | public static void launch(Context launcher, Account account) { |
| 47 | Intent intent = new Intent(launcher, FoldersListActivity.class); |
| 48 | intent.putExtra(Utils.EXTRA_ACCOUNT, account); |
| 49 | launcher.startActivity(intent); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void onCreate(Bundle savedInstanceState) { |
| 54 | super.onCreate(savedInstanceState); |
| 55 | setContentView(R.layout.folders_activity); |
| 56 | mListView = (ListView) findViewById(R.id.folders_list); |
| 57 | mAccount = (Account) getIntent().getParcelableExtra(Utils.EXTRA_ACCOUNT); |
| 58 | mFoldersCursor = getContentResolver().query(Uri.parse(mAccount.folderListUri), |
| 59 | UIProvider.FOLDERS_PROJECTION, null, null, null); |
| 60 | mListView.setAdapter(new FolderListAdapter(this, R.layout.folder_item, mFoldersCursor, |
| 61 | null, null)); |
| 62 | } |
| 63 | |
| 64 | private class FolderListAdapter extends SimpleCursorAdapter { |
| 65 | |
| 66 | public FolderListAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { |
| 67 | super(context, layout, c, new String[0], new int[0], 0); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public View getView(int position, View convertView, ViewGroup parent) { |
| 72 | FolderItemView folderItemView; |
| 73 | if (convertView != null) { |
| 74 | folderItemView = (FolderItemView) convertView; |
| 75 | } else { |
| 76 | folderItemView = (FolderItemView) LayoutInflater.from(FoldersListActivity.this) |
| 77 | .inflate(R.layout.folder_item, null); |
| 78 | } |
| 79 | mFoldersCursor.moveToPosition(position); |
| 80 | folderItemView.bind(new Folder(mFoldersCursor), null); |
| 81 | return folderItemView; |
| 82 | } |
| 83 | } |
| 84 | } |