150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby/*
250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * Copyright (C) 2011 The Android Open Source Project
350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby *
450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * Licensed under the Apache License, Version 2.0 (the "License");
550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * you may not use this file except in compliance with the License.
650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * You may obtain a copy of the License at
750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby *
850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby *      http://www.apache.org/licenses/LICENSE-2.0
950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby *
1050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * Unless required by applicable law or agreed to in writing, software
1150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * distributed under the License is distributed on an "AS IS" BASIS,
1250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * See the License for the specific language governing permissions and
1450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * limitations under the License.
1550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby */
1650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
1750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambypackage com.android.cellbroadcastreceiver;
1850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
1950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.content.Context;
2050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.database.Cursor;
2150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.view.LayoutInflater;
2250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.view.View;
2350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.view.ViewGroup;
2450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambyimport android.widget.CursorAdapter;
2550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
2650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby/**
2750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby * The back-end data adapter for {@link CellBroadcastListActivity}.
2850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby */
2950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hambypublic class CellBroadcastListAdapter extends CursorAdapter {
3050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    private static final String TAG = "CellBroadcastListAdapter";
3150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
3250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    public CellBroadcastListAdapter(Context context, Cursor cursor) {
3350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        super(context, cursor, true);
3450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    }
3550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
3650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    /**
3750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * Makes a new view to hold the data pointed to by cursor.
3850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param context Interface to application's global information
3950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param cursor The cursor from which to get the data. The cursor is already
4050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * moved to the correct position.
4150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param parent The parent to which the new view is attached to
4250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @return the newly created view.
4350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     */
4450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    public View newView(Context context, Cursor cursor, ViewGroup parent) {
4550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
4650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
4750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        LayoutInflater factory = LayoutInflater.from(context);
4850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        CellBroadcastListItem listItem = (CellBroadcastListItem) factory.inflate(
4950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby                    R.layout.cell_broadcast_list_item, parent, false);
5050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
5150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        listItem.bind(message);
5250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        return listItem;
5350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    }
5450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby
5550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    /**
5650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * Bind an existing view to the data pointed to by cursor
5750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param view Existing view, returned earlier by newView
5850a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param context Interface to application's global information
5950a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * @param cursor The cursor from which to get the data. The cursor is already
6050a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     * moved to the correct position.
6150a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby     */
6250a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    public void bindView(View view, Context context, Cursor cursor) {
6350a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        CellBroadcastMessage message = CellBroadcastMessage.createFromCursor(cursor);
6450a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        CellBroadcastListItem listItem = (CellBroadcastListItem) view;
6550a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby        listItem.bind(message);
6650a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby    }
6750a624a47ce645a7992e346e40a4e7ec5e0df9b7Jake Hamby}
68