CellBroadcastCursorAdapter.java revision 00b87064abfb9d254fbbf72110643d2e626365e6
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.cellbroadcastreceiver;
18
19import android.content.Context;
20import android.database.Cursor;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.CursorAdapter;
25
26/**
27 * The back-end data adapter for {@link CellBroadcastListActivity}.
28 */
29public class CellBroadcastCursorAdapter extends CursorAdapter {
30
31    public CellBroadcastCursorAdapter(Context context, Cursor cursor) {
32        // don't set FLAG_AUTO_REQUERY or FLAG_REGISTER_CONTENT_OBSERVER
33        super(context, cursor, 0);
34    }
35
36    /**
37     * Makes a new view to hold the data pointed to by cursor.
38     * @param context Interface to application's global information
39     * @param cursor The cursor from which to get the data. The cursor is already
40     * moved to the correct position.
41     * @param parent The parent to which the new view is attached to
42     * @return the newly created view.
43     */
44    @Override
45    public View newView(Context context, Cursor cursor, ViewGroup parent) {
46        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
47
48        LayoutInflater factory = LayoutInflater.from(context);
49        CellBroadcastListItem listItem = (CellBroadcastListItem) factory.inflate(
50                    R.layout.cell_broadcast_list_item, parent, false);
51
52        listItem.bind(message);
53        return listItem;
54    }
55
56    /**
57     * Bind an existing view to the data pointed to by cursor
58     * @param view Existing view, returned earlier by newView
59     * @param context Interface to application's global information
60     * @param cursor The cursor from which to get the data. The cursor is already
61     * moved to the correct position.
62     */
63    @Override
64    public void bindView(View view, Context context, Cursor cursor) {
65        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
66        CellBroadcastListItem listItem = (CellBroadcastListItem) view;
67        listItem.bind(message);
68    }
69}
70