MailboxMoveToAdapter.java revision 74bf57cfafde4095ee67985255cfaa8b1453115e
1/* 2 * Copyright (C) 2011 The Android Open Source Project 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 17package com.android.email.activity; 18 19import com.android.email.Email; 20import com.android.email.data.ThrottlingCursorLoader; 21import com.android.emailcommon.Logging; 22import com.android.emailcommon.provider.EmailContent; 23import com.android.emailcommon.provider.EmailContent.Mailbox; 24import com.android.emailcommon.utility.Utility; 25 26import android.content.Context; 27import android.content.Loader; 28import android.database.Cursor; 29import android.util.Log; 30import android.view.View; 31import android.view.ViewGroup; 32import android.widget.TextView; 33 34/** 35 * Cursor adapter for the "move to mailbox" dialog. 36 */ 37/*package*/ class MailboxMoveToAdapter extends MailboxesAdapter { 38 private static final String MAILBOX_SELECTION_MOVE_TO_FOLDER = 39 MAILBOX_SELECTION + " AND " + Mailbox.MOVE_TO_TARGET_MAILBOX_SELECTION; 40 41 public MailboxMoveToAdapter(Context context, Callback callback) { 42 super(context, callback); 43 } 44 45 @Override 46 public void bindView(View view, Context context, Cursor cursor) { 47 TextView t = (TextView) view; 48 t.setText(getDisplayName(context, cursor)); 49 } 50 51 @Override 52 public View newView(Context context, Cursor cursor, ViewGroup parent) { 53 return mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); 54 } 55 56 public static Loader<Cursor> createLoader(Context context, long accountId) { 57 if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { 58 Log.d(Logging.LOG_TAG, "MailboxDialogAdapter#createLoader accountId=" + accountId); 59 } 60 return new MailboxMoveToLoader(context, accountId); 61 } 62 63 /** 64 * Loader for the "move to mailbox" dialog. 65 */ 66 private static class MailboxMoveToLoader extends ThrottlingCursorLoader { 67 public MailboxMoveToLoader(Context context, long accountId) { 68 super(context, EmailContent.Mailbox.CONTENT_URI, 69 MailboxesAdapter.PROJECTION, MAILBOX_SELECTION_MOVE_TO_FOLDER, 70 new String[] { String.valueOf(accountId) }, MAILBOX_ORDER_BY); 71 } 72 73 @Override 74 public void onContentChanged() { 75 if (sEnableUpdate) { 76 super.onContentChanged(); 77 } 78 } 79 80 @Override 81 public Cursor loadInBackground() { 82 final Cursor mailboxesCursor = super.loadInBackground(); 83 return Utility.CloseTraceCursorWrapper.get(mailboxesCursor); 84 } 85 } 86} 87