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
17package android.widget;
18
19import android.database.DataSetObservable;
20import android.database.DataSetObserver;
21import android.view.View;
22import android.view.ViewGroup;
23
24/**
25 * Common base class of common implementation for an {@link Adapter} that can be
26 * used in both {@link ListView} (by implementing the specialized
27 * {@link ListAdapter} interface} and {@link Spinner} (by implementing the
28 * specialized {@link SpinnerAdapter} interface.
29 */
30public abstract class BaseAdapter implements ListAdapter, SpinnerAdapter {
31    private final DataSetObservable mDataSetObservable = new DataSetObservable();
32
33    public boolean hasStableIds() {
34        return false;
35    }
36
37    public void registerDataSetObserver(DataSetObserver observer) {
38        mDataSetObservable.registerObserver(observer);
39    }
40
41    public void unregisterDataSetObserver(DataSetObserver observer) {
42        mDataSetObservable.unregisterObserver(observer);
43    }
44
45    /**
46     * Notifies the attached View that the underlying data has been changed
47     * and it should refresh itself.
48     */
49    public void notifyDataSetChanged() {
50        mDataSetObservable.notifyChanged();
51    }
52
53    public void notifyDataSetInvalidated() {
54        mDataSetObservable.notifyInvalidated();
55    }
56
57    public boolean areAllItemsEnabled() {
58        return true;
59    }
60
61    public boolean isEnabled(int position) {
62        return true;
63    }
64
65    public View getDropDownView(int position, View convertView, ViewGroup parent) {
66        return getView(position, convertView, parent);
67    }
68
69    public int getItemViewType(int position) {
70        return 0;
71    }
72
73    public int getViewTypeCount() {
74        return 1;
75    }
76
77    public boolean isEmpty() {
78        return getCount() == 0;
79    }
80}
81