BaseExpandableListAdapter.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
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.KeyEvent; 22 23/** 24 * Base class for a {@link ExpandableListAdapter} used to provide data and Views 25 * from some data to an expandable list view. 26 * <p> 27 * Adapters inheriting this class should verify that the base implementations of 28 * {@link #getCombinedChildId(long, long)} and {@link #getCombinedGroupId(long)} 29 * are correct in generating unique IDs from the group/children IDs. 30 * <p> 31 * @see SimpleExpandableListAdapter 32 * @see SimpleCursorTreeAdapter 33 */ 34public abstract class BaseExpandableListAdapter implements ExpandableListAdapter { 35 private final DataSetObservable mDataSetObservable = new DataSetObservable(); 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 * {@see DataSetObservable#notifyInvalidated()} 47 */ 48 public void notifyDataSetInvalidated() { 49 mDataSetObservable.notifyInvalidated(); 50 } 51 52 /** 53 * {@see DataSetObservable#notifyChanged()} 54 */ 55 public void notifyDataSetChanged() { 56 mDataSetObservable.notifyChanged(); 57 } 58 59 public boolean areAllItemsEnabled() { 60 return true; 61 } 62 63 public void onGroupCollapsed(int groupPosition) { 64 } 65 66 public void onGroupExpanded(int groupPosition) { 67 } 68 69 /** 70 * Override this method if you foresee a clash in IDs based on this scheme: 71 * <p> 72 * Base implementation returns a long: 73 * <li> bit 0: Whether this ID points to a child (unset) or group (set), so for this method 74 * this bit will be 1. 75 * <li> bit 1-31: Lower 31 bits of the groupId 76 * <li> bit 32-63: Lower 32 bits of the childId. 77 * <p> 78 * {@inheritDoc} 79 */ 80 public long getCombinedChildId(long groupId, long childId) { 81 return 0x8000000000000000L | ((groupId & 0x7FFFFFFF) << 32) | (childId & 0xFFFFFFFF); 82 } 83 84 /** 85 * Override this method if you foresee a clash in IDs based on this scheme: 86 * <p> 87 * Base implementation returns a long: 88 * <li> bit 0: Whether this ID points to a child (unset) or group (set), so for this method 89 * this bit will be 0. 90 * <li> bit 1-31: Lower 31 bits of the groupId 91 * <li> bit 32-63: Lower 32 bits of the childId. 92 * <p> 93 * {@inheritDoc} 94 */ 95 public long getCombinedGroupId(long groupId) { 96 return (groupId & 0x7FFFFFFF) << 32; 97 } 98 99 /** 100 * {@inheritDoc} 101 */ 102 public boolean isEmpty() { 103 return getGroupCount() == 0; 104 } 105 106} 107