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