Home | History | Annotate | Download | only in ui
      1 // Copyright (C) 2014 Google Inc.
      2 
      3 package com.android.mail.ui;
      4 
      5 import android.app.LoaderManager;
      6 import android.content.Context;
      7 import android.content.Loader;
      8 import android.net.Uri;
      9 import android.os.Bundle;
     10 
     11 import com.android.mail.content.CursorCreator;
     12 import com.android.mail.content.ObjectCursor;
     13 import com.android.mail.content.ObjectCursorLoader;
     14 import com.android.mail.providers.Account;
     15 import com.android.mail.providers.UIProvider;
     16 
     17 /**
     18  * Callbacks for loading an account cursor.
     19  */
     20 public class AccountLoadCallbacks implements LoaderManager.LoaderCallbacks<ObjectCursor<Account>> {
     21 
     22     public interface AccountLoadCallbackListener {
     23         void onAccountLoadCallbackFinished(ObjectCursor<Account> data);
     24     }
     25 
     26     private final Context mContext;
     27     private final Uri mAccountUri;
     28     private final AccountLoadCallbackListener mAccountLoadCallbackListener;
     29 
     30     public AccountLoadCallbacks(Context context, Uri accountUri,
     31                                 AccountLoadCallbackListener accountLoadCallbackListener) {
     32         mContext = context;
     33         mAccountUri = accountUri;
     34         mAccountLoadCallbackListener = accountLoadCallbackListener;
     35     }
     36 
     37     @Override
     38     public Loader<ObjectCursor<Account>> onCreateLoader(int id, Bundle args) {
     39         final String[] projection = UIProvider.ACCOUNTS_PROJECTION;
     40         final CursorCreator<Account> factory = Account.FACTORY;
     41         return new ObjectCursorLoader<Account>(mContext, mAccountUri, projection, factory);
     42     }
     43 
     44     @Override
     45     public void onLoadFinished(Loader<ObjectCursor<Account>> loader,
     46             ObjectCursor<Account> data) {
     47         mAccountLoadCallbackListener.onAccountLoadCallbackFinished(data);
     48     }
     49 
     50     @Override
     51     public void onLoaderReset(Loader<ObjectCursor<Account>> loader) {
     52     }
     53 }
     54