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 CellBroadcastListAdapter extends CursorAdapter {
30    private static final String TAG = "CellBroadcastListAdapter";
31
32    public CellBroadcastListAdapter(Context context, Cursor cursor) {
33        super(context, cursor, true);
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    public View newView(Context context, Cursor cursor, ViewGroup parent) {
45        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
46
47        LayoutInflater factory = LayoutInflater.from(context);
48        CellBroadcastListItem listItem = (CellBroadcastListItem) factory.inflate(
49                    R.layout.cell_broadcast_list_item, parent, false);
50
51        listItem.bind(message);
52        return listItem;
53    }
54
55    /**
56     * Bind an existing view to the data pointed to by cursor
57     * @param view Existing view, returned earlier by newView
58     * @param context Interface to application's global information
59     * @param cursor The cursor from which to get the data. The cursor is already
60     * moved to the correct position.
61     */
62    public void bindView(View view, Context context, Cursor cursor) {
63        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
64        CellBroadcastListItem listItem = (CellBroadcastListItem) view;
65        listItem.bind(message);
66    }
67}
68