JoinContactLoader.java revision ecd392b81d65a5dd5511b2f96bbedfb5b8157ae7
1/*
2 * Copyright (C) 2010 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 */
16package com.android.contacts.list;
17
18import android.content.Context;
19import android.content.CursorLoader;
20import android.database.Cursor;
21import android.database.MatrixCursor;
22import android.net.Uri;
23import android.util.Log;
24
25/**
26 * A specialized loader for the Join Contacts UI.  It executes two queries:
27 * join suggestions and (optionally) the full contact list.
28 */
29public class JoinContactLoader extends CursorLoader {
30
31    private String[] mProjection;
32    private Uri mSuggestionUri;
33    private Cursor mSuggestionsCursor;
34
35    public JoinContactLoader(Context context) {
36        super(context, null, null, null, null, null);
37    }
38
39    public void setSuggestionUri(Uri uri) {
40        this.mSuggestionUri = uri;
41    }
42
43    @Override
44    public void setProjection(String[] projection) {
45        super.setProjection(projection);
46        this.mProjection = projection;
47    }
48
49    public Cursor getSuggestionsCursor() {
50        return mSuggestionsCursor;
51    }
52
53    @Override
54    public Cursor loadInBackground() {
55        // First execute the suggestions query, then call super.loadInBackground
56        // to load the entire list
57        mSuggestionsCursor = getContext().getContentResolver()
58                .query(mSuggestionUri, mProjection, null, null, null);
59        return super.loadInBackground();
60    }
61}