1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/* 2ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * Copyright 2018 The Android Open Source Project 3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License. 6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at 7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and 14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License. 15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.cursoradapter.widget; 18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 19cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context; 20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.database.Cursor; 21fa72a48f5c7def6645a67084b86d461d1e1eb83dAurimas Liutikasimport android.view.LayoutInflater; 22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View; 23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup; 24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.widget.ResourceCursorAdapter}. 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to switch to the framework's implementation. See the framework SDK 30cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic abstract class ResourceCursorAdapter extends CursorAdapter { 33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn private int mLayout; 34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn private int mDropDownLayout; 364d2c7b7c4f194034c5f17c4bee7320d808aabe4cAurimas Liutikas 37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn private LayoutInflater mInflater; 384d2c7b7c4f194034c5f17c4bee7320d808aabe4cAurimas Liutikas 39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Constructor the enables auto-requery. 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @deprecated This option is discouraged, as it results in Cursor queries 43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being performed on the application's UI thread and thus can cause poor 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * responsiveness or even Application Not Responding errors. As an alternative, 45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}. 46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The context where the ListView associated with this adapter is running 48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param layout resource identifier of a layout file that defines the views 49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for this list item. Unless you override them later, this will 50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * define both the item views and the drop down views. 51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Deprecated 53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public ResourceCursorAdapter(Context context, int layout, Cursor c) { 54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(context, c); 55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLayout = mDropDownLayout = layout; 56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 584d2c7b7c4f194034c5f17c4bee7320d808aabe4cAurimas Liutikas 59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 60cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Constructor with default behavior as per 61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link CursorAdapter#CursorAdapter(Context, Cursor, boolean)}; it is recommended 62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you not use this, but instead {@link #ResourceCursorAdapter(Context, int, Cursor, int)}. 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER} 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will always be set. 65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 66d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated This option is discouraged, as it results in Cursor queries 67d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * being performed on the application's UI thread and thus can cause poor 68d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * responsiveness or even Application Not Responding errors. As an alternative, 69d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}. 70d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The context where the ListView associated with this adapter is running 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param layout resource identifier of a layout file that defines the views 73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for this list item. Unless you override them later, this will 74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * define both the item views and the drop down views. 75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param c The cursor from which to get the data. 76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param autoRequery If true the adapter will call requery() on the 77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * cursor whenever it changes so the most recent 78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * data is always displayed. Using true here is discouraged. 79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 80d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette @Deprecated 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public ResourceCursorAdapter(Context context, int layout, Cursor c, boolean autoRequery) { 82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(context, c, autoRequery); 83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLayout = mDropDownLayout = layout; 84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Standard constructor. 89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The context where the ListView associated with this adapter is running 91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param layout Resource identifier of a layout file that defines the views 92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for this list item. Unless you override them later, this will 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * define both the item views and the drop down views. 94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param c The cursor from which to get the data. 95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param flags Flags used to determine the behavior of the adapter, 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}. 97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public ResourceCursorAdapter(Context context, int layout, Cursor c, int flags) { 99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(context, c, flags); 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLayout = mDropDownLayout = layout; 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Inflates view(s) from the specified XML file. 1064d2c7b7c4f194034c5f17c4bee7320d808aabe4cAurimas Liutikas * 107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see android.widget.CursorAdapter#newView(android.content.Context, 108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * android.database.Cursor, ViewGroup) 109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View newView(Context context, Cursor cursor, ViewGroup parent) { 112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInflater.inflate(mLayout, parent, false); 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) { 117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInflater.inflate(mDropDownLayout, parent, false); 118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Sets the layout resource of the item views.</p> 122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param layout the layout resources used to create item views 124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setViewResource(int layout) { 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLayout = layout; 127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1284d2c7b7c4f194034c5f17c4bee7320d808aabe4cAurimas Liutikas 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Sets the layout resource of the drop down views.</p> 131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param dropDownLayout the layout resources used to create drop down views 133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setDropDownViewResource(int dropDownLayout) { 135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mDropDownLayout = dropDownLayout; 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 138