1 /* 2 * Copyright (C) 2007 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.xtremelabs.robolectric.shadows; 18 19 import com.xtremelabs.robolectric.internal.Implementation; 20 import com.xtremelabs.robolectric.internal.Implements; 21 22 import android.content.Context; 23 import android.database.Cursor; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.ResourceCursorAdapter; 28 29 30 /** 31 * An easy adapter that creates views defined in an XML file. You can specify 32 * the XML file that defines the appearance of the views. 33 */ 34 @Implements(ResourceCursorAdapter.class) 35 public class ShadowResourceCursorAdapter extends ShadowCursorAdapter { 36 private int mLayout; 37 38 private int mDropDownLayout; 39 40 private LayoutInflater mInflater; 41 42 /** 43 * Constructor. 44 * 45 * @param context The context where the ListView associated with this 46 * SimpleListItemFactory is running 47 * @param layout resource identifier of a layout file that defines the views 48 * for this list item. Unless you override them later, this will 49 * define both the item views and the drop down views. 50 */ 51 public void __constructor__(Context context, int layout, Cursor c) { 52 super.__constructor__(context, c); 53 mLayout = mDropDownLayout = layout; 54 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 55 } 56 57 /** 58 * Constructor. 59 * 60 * @param context The context where the ListView associated with this 61 * SimpleListItemFactory is running 62 * @param layout resource identifier of a layout file that defines the views 63 * for this list item. Unless you override them later, this will 64 * define both the item views and the drop down views. 65 * @param c The cursor from which to get the data. 66 * @param autoRequery If true the adapter will call requery() on the 67 * cursor whenever it changes so the most recent 68 * data is always displayed. 69 */ 70 public void __constructor__(Context context, int layout, Cursor c, boolean autoRequery) { 71 super.__constructor__(context, c, autoRequery); 72 mLayout = mDropDownLayout = layout; 73 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 74 } 75 76 /** 77 * Inflates view(s) from the specified XML file. 78 * 79 * @see android.widget.CursorAdapter#newView(android.content.Context, 80 * android.database.Cursor, ViewGroup) 81 */ 82 @Implementation 83 public View newView(Context context, Cursor cursor, ViewGroup parent) { 84 return mInflater.inflate(mLayout, parent, false); 85 } 86 87 @Implementation 88 public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) { 89 return mInflater.inflate(mDropDownLayout, parent, false); 90 } 91 92 /** 93 * <p>Sets the layout resource of the item views.</p> 94 * 95 * @param layout the layout resources used to create item views 96 */ 97 @Implementation 98 public void setViewResource(int layout) { 99 mLayout = layout; 100 } 101 102 /** 103 * <p>Sets the layout resource of the drop down views.</p> 104 * 105 * @param dropDownLayout the layout resources used to create drop down views 106 */ 107 @Implementation 108 public void setDropDownViewResource(int dropDownLayout) { 109 mDropDownLayout = dropDownLayout; 110 } 111 }