1 /* 2 * Copyright (C) 2006 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 org.robolectric.shadows; 18 19 import static org.robolectric.shadow.api.Shadow.directlyOn; 20 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.widget.CursorAdapter; 24 import java.util.List; 25 import org.robolectric.annotation.Implementation; 26 import org.robolectric.annotation.Implements; 27 import org.robolectric.annotation.RealObject; 28 29 /** 30 * @deprecated This class will be removed in Robolectric 3.5. The real 31 * Android CursorAdapter will be used instead. 32 */ 33 @Implements(CursorAdapter.class) 34 @Deprecated 35 public class ShadowCursorAdapter extends ShadowBaseAdapter { 36 private @RealObject CursorAdapter realCursorAdapter; 37 38 private List<View> views = null; 39 40 /** 41 * If {@link #setViews(List)} has been called, a corresponding view from that list will be returned. 42 * 43 * Otherwise, behaves like {@link CursorAdapter#getView(int, View, ViewGroup)}. 44 */ 45 @Implementation 46 @Deprecated 47 public View getView(int position, View convertView, ViewGroup parent) { 48 if (views != null) { 49 // if the cursor is null OR there are no views to dispense return null 50 if (realCursorAdapter.getCursor() == null || views.size() == 0 ) { 51 return null; 52 } 53 54 if (convertView != null) { 55 return convertView; 56 } 57 58 return views.get(position); 59 } else { 60 return directlyOn(realCursorAdapter, CursorAdapter.class).getView(position, convertView, parent); 61 } 62 } 63 64 /** 65 * Sets a list of views to be returned for successive calls to {@link #getView(int, View, ViewGroup)}. 66 * 67 * @param views The list of views 68 * @deprecated This method will be removed in Robolectric 3.5. The normal Android {@link #getView(int, View, ViewGroup)} behavior will be used instead. 69 */ 70 @Deprecated 71 public void setViews(List<View> views) { 72 this.views = views; 73 } 74 75 } 76