blob: cae91fce64a315bf5818b5933441f857c62e2ae8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.widget;
18
Aurimas Liutikas99441c52016-10-11 16:48:32 -070019import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020
Mathew Inwood978c6e22018-08-21 15:58:55 +010021import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.res.TypedArray;
24import android.graphics.Canvas;
25import android.graphics.Rect;
Adam Powell45803472010-01-25 15:10:44 -080026import android.graphics.drawable.Drawable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Parcel;
28import android.os.Parcelable;
29import android.util.AttributeSet;
30import android.view.ContextMenu;
Aurimas Liutikas99441c52016-10-11 16:48:32 -070031import android.view.ContextMenu.ContextMenuInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.view.SoundEffectConstants;
33import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.widget.ExpandableListConnector.PositionMetadata;
35
Aurimas Liutikas99441c52016-10-11 16:48:32 -070036import com.android.internal.R;
Adam Powell45803472010-01-25 15:10:44 -080037
Aurimas Liutikas99441c52016-10-11 16:48:32 -070038import java.util.ArrayList;
Fabrice Di Megliof4efad02013-03-21 18:22:38 -070039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040/**
41 * A view that shows items in a vertically scrolling two-level list. This
42 * differs from the {@link ListView} by allowing two levels: groups which can
43 * individually be expanded to show its children. The items come from the
44 * {@link ExpandableListAdapter} associated with this view.
45 * <p>
46 * Expandable lists are able to show an indicator beside each item to display
47 * the item's current state (the states are usually one of expanded group,
48 * collapsed group, child, or last child). Use
49 * {@link #setChildIndicator(Drawable)} or {@link #setGroupIndicator(Drawable)}
50 * (or the corresponding XML attributes) to set these indicators (see the docs
51 * for each method to see additional state that each Drawable can have). The
52 * default style for an {@link ExpandableListView} provides indicators which
53 * will be shown next to Views given to the {@link ExpandableListView}. The
54 * layouts android.R.layout.simple_expandable_list_item_1 and
55 * android.R.layout.simple_expandable_list_item_2 (which should be used with
56 * {@link SimpleCursorTreeAdapter}) contain the preferred position information
57 * for indicators.
58 * <p>
59 * The context menu information set by an {@link ExpandableListView} will be a
60 * {@link ExpandableListContextMenuInfo} object with
61 * {@link ExpandableListContextMenuInfo#packedPosition} being a packed position
62 * that can be used with {@link #getPackedPositionType(long)} and the other
63 * similar methods.
64 * <p>
65 * <em><b>Note:</b></em> You cannot use the value <code>wrap_content</code>
66 * for the <code>android:layout_height</code> attribute of a
67 * ExpandableListView in XML if the parent's size is also not strictly specified
68 * (for example, if the parent were ScrollView you could not specify
69 * wrap_content since it also can be any length. However, you can use
70 * wrap_content if the ExpandableListView parent has a specific size, such as
71 * 100 pixels.
Aurimas Liutikas99441c52016-10-11 16:48:32 -070072 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 * @attr ref android.R.styleable#ExpandableListView_groupIndicator
74 * @attr ref android.R.styleable#ExpandableListView_indicatorLeft
75 * @attr ref android.R.styleable#ExpandableListView_indicatorRight
76 * @attr ref android.R.styleable#ExpandableListView_childIndicator
77 * @attr ref android.R.styleable#ExpandableListView_childIndicatorLeft
78 * @attr ref android.R.styleable#ExpandableListView_childIndicatorRight
79 * @attr ref android.R.styleable#ExpandableListView_childDivider
Fabrice Di Megliof4efad02013-03-21 18:22:38 -070080 * @attr ref android.R.styleable#ExpandableListView_indicatorStart
81 * @attr ref android.R.styleable#ExpandableListView_indicatorEnd
82 * @attr ref android.R.styleable#ExpandableListView_childIndicatorStart
83 * @attr ref android.R.styleable#ExpandableListView_childIndicatorEnd
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 */
85public class ExpandableListView extends ListView {
86
87 /**
88 * The packed position represents a group.
89 */
90 public static final int PACKED_POSITION_TYPE_GROUP = 0;
Aurimas Liutikas99441c52016-10-11 16:48:32 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 /**
93 * The packed position represents a child.
94 */
95 public static final int PACKED_POSITION_TYPE_CHILD = 1;
96
97 /**
98 * The packed position represents a neither/null/no preference.
99 */
100 public static final int PACKED_POSITION_TYPE_NULL = 2;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 /**
103 * The value for a packed position that represents neither/null/no
104 * preference. This value is not otherwise possible since a group type
105 * (first bit 0) should not have a child position filled.
106 */
107 public static final long PACKED_POSITION_VALUE_NULL = 0x00000000FFFFFFFFL;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 /** The mask (in packed position representation) for the child */
110 private static final long PACKED_POSITION_MASK_CHILD = 0x00000000FFFFFFFFL;
111
112 /** The mask (in packed position representation) for the group */
113 private static final long PACKED_POSITION_MASK_GROUP = 0x7FFFFFFF00000000L;
114
115 /** The mask (in packed position representation) for the type */
116 private static final long PACKED_POSITION_MASK_TYPE = 0x8000000000000000L;
117
118 /** The shift amount (in packed position representation) for the group */
119 private static final long PACKED_POSITION_SHIFT_GROUP = 32;
120
121 /** The shift amount (in packed position representation) for the type */
122 private static final long PACKED_POSITION_SHIFT_TYPE = 63;
123
124 /** The mask (in integer child position representation) for the child */
125 private static final long PACKED_POSITION_INT_MASK_CHILD = 0xFFFFFFFF;
126
127 /** The mask (in integer group position representation) for the group */
128 private static final long PACKED_POSITION_INT_MASK_GROUP = 0x7FFFFFFF;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 /** Serves as the glue/translator between a ListView and an ExpandableListView */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100131 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 private ExpandableListConnector mConnector;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700133
134 /** Gives us Views through group+child positions */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 private ExpandableListAdapter mAdapter;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /** Left bound for drawing the indicator. */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100138 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 private int mIndicatorLeft;
140
141 /** Right bound for drawing the indicator. */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100142 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 private int mIndicatorRight;
144
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700145 /** Start bound for drawing the indicator. */
146 private int mIndicatorStart;
147
148 /** End bound for drawing the indicator. */
149 private int mIndicatorEnd;
150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 /**
152 * Left bound for drawing the indicator of a child. Value of
153 * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorLeft.
154 */
155 private int mChildIndicatorLeft;
156
157 /**
158 * Right bound for drawing the indicator of a child. Value of
159 * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorRight.
160 */
161 private int mChildIndicatorRight;
162
163 /**
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700164 * Start bound for drawing the indicator of a child. Value of
165 * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorStart.
166 */
167 private int mChildIndicatorStart;
168
169 /**
170 * End bound for drawing the indicator of a child. Value of
171 * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorEnd.
172 */
173 private int mChildIndicatorEnd;
174
175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 * Denotes when a child indicator should inherit this bound from the generic
177 * indicator bounds
178 */
179 public static final int CHILD_INDICATOR_INHERIT = -1;
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700180
181 /**
182 * Denotes an undefined value for an indicator
183 */
184 private static final int INDICATOR_UNDEFINED = -2;
185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** The indicator drawn next to a group. */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100187 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 private Drawable mGroupIndicator;
189
190 /** The indicator drawn next to a child. */
191 private Drawable mChildIndicator;
192
193 private static final int[] EMPTY_STATE_SET = {};
194
195 /** State indicating the group is expanded. */
196 private static final int[] GROUP_EXPANDED_STATE_SET =
197 {R.attr.state_expanded};
198
199 /** State indicating the group is empty (has no children). */
200 private static final int[] GROUP_EMPTY_STATE_SET =
201 {R.attr.state_empty};
202
203 /** State indicating the group is expanded and empty (has no children). */
204 private static final int[] GROUP_EXPANDED_EMPTY_STATE_SET =
205 {R.attr.state_expanded, R.attr.state_empty};
206
207 /** States for the group where the 0th bit is expanded and 1st bit is empty. */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100208 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 private static final int[][] GROUP_STATE_SETS = {
210 EMPTY_STATE_SET, // 00
211 GROUP_EXPANDED_STATE_SET, // 01
212 GROUP_EMPTY_STATE_SET, // 10
213 GROUP_EXPANDED_EMPTY_STATE_SET // 11
214 };
215
216 /** State indicating the child is the last within its group. */
217 private static final int[] CHILD_LAST_STATE_SET =
218 {R.attr.state_last};
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 /** Drawable to be used as a divider when it is adjacent to any children */
Mathew Inwood978c6e22018-08-21 15:58:55 +0100221 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 private Drawable mChildDivider;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 // Bounds of the indicator to be drawn
225 private final Rect mIndicatorRect = new Rect();
226
227 public ExpandableListView(Context context) {
228 this(context, null);
229 }
230
231 public ExpandableListView(Context context, AttributeSet attrs) {
232 this(context, attrs, com.android.internal.R.attr.expandableListViewStyle);
233 }
234
Alan Viverette617feb92013-09-09 18:09:13 -0700235 public ExpandableListView(Context context, AttributeSet attrs, int defStyleAttr) {
236 this(context, attrs, defStyleAttr, 0);
237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Alan Viverette617feb92013-09-09 18:09:13 -0700239 public ExpandableListView(
240 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
241 super(context, attrs, defStyleAttr, defStyleRes);
242
243 final TypedArray a = context.obtainStyledAttributes(attrs,
244 com.android.internal.R.styleable.ExpandableListView, defStyleAttr, defStyleRes);
Aurimas Liutikasab324cf2019-02-07 16:46:38 -0800245 saveAttributeDataForStyleable(context, com.android.internal.R.styleable.ExpandableListView,
246 attrs, a, defStyleAttr, defStyleRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700248 mGroupIndicator = a.getDrawable(
249 com.android.internal.R.styleable.ExpandableListView_groupIndicator);
250 mChildIndicator = a.getDrawable(
251 com.android.internal.R.styleable.ExpandableListView_childIndicator);
252 mIndicatorLeft = a.getDimensionPixelSize(
253 com.android.internal.R.styleable.ExpandableListView_indicatorLeft, 0);
254 mIndicatorRight = a.getDimensionPixelSize(
255 com.android.internal.R.styleable.ExpandableListView_indicatorRight, 0);
Romain Guy875862e2011-01-17 11:37:24 -0800256 if (mIndicatorRight == 0 && mGroupIndicator != null) {
Romain Guyfb13abd2011-01-16 15:16:38 -0800257 mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 mChildIndicatorLeft = a.getDimensionPixelSize(
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700260 com.android.internal.R.styleable.ExpandableListView_childIndicatorLeft,
261 CHILD_INDICATOR_INHERIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 mChildIndicatorRight = a.getDimensionPixelSize(
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700263 com.android.internal.R.styleable.ExpandableListView_childIndicatorRight,
264 CHILD_INDICATOR_INHERIT);
265 mChildDivider = a.getDrawable(
266 com.android.internal.R.styleable.ExpandableListView_childDivider);
267
268 if (!isRtlCompatibilityMode()) {
269 mIndicatorStart = a.getDimensionPixelSize(
270 com.android.internal.R.styleable.ExpandableListView_indicatorStart,
271 INDICATOR_UNDEFINED);
272 mIndicatorEnd = a.getDimensionPixelSize(
273 com.android.internal.R.styleable.ExpandableListView_indicatorEnd,
274 INDICATOR_UNDEFINED);
275
276 mChildIndicatorStart = a.getDimensionPixelSize(
277 com.android.internal.R.styleable.ExpandableListView_childIndicatorStart,
278 CHILD_INDICATOR_INHERIT);
279 mChildIndicatorEnd = a.getDimensionPixelSize(
280 com.android.internal.R.styleable.ExpandableListView_childIndicatorEnd,
281 CHILD_INDICATOR_INHERIT);
282 }
283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 a.recycle();
285 }
Fabrice Di Megliof4efad02013-03-21 18:22:38 -0700286
287 /**
288 * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or
289 * RTL not supported)
290 */
291 private boolean isRtlCompatibilityMode() {
292 final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
293 return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport();
294 }
295
296 /**
297 * Return true if the application tag in the AndroidManifest has set "supportRtl" to true
298 */
299 private boolean hasRtlSupport() {
300 return mContext.getApplicationInfo().hasRtlSupport();
301 }
302
303 public void onRtlPropertiesChanged(int layoutDirection) {
304 resolveIndicator();
305 resolveChildIndicator();
306 }
307
308 /**
309 * Resolve start/end indicator. start/end indicator always takes precedence over left/right
310 * indicator when defined.
311 */
312 private void resolveIndicator() {
313 final boolean isLayoutRtl = isLayoutRtl();
314 if (isLayoutRtl) {
315 if (mIndicatorStart >= 0) {
316 mIndicatorRight = mIndicatorStart;
317 }
318 if (mIndicatorEnd >= 0) {
319 mIndicatorLeft = mIndicatorEnd;
320 }
321 } else {
322 if (mIndicatorStart >= 0) {
323 mIndicatorLeft = mIndicatorStart;
324 }
325 if (mIndicatorEnd >= 0) {
326 mIndicatorRight = mIndicatorEnd;
327 }
328 }
329 if (mIndicatorRight == 0 && mGroupIndicator != null) {
330 mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
331 }
332 }
333
334 /**
335 * Resolve start/end child indicator. start/end child indicator always takes precedence over
336 * left/right child indicator when defined.
337 */
338 private void resolveChildIndicator() {
339 final boolean isLayoutRtl = isLayoutRtl();
340 if (isLayoutRtl) {
341 if (mChildIndicatorStart >= CHILD_INDICATOR_INHERIT) {
342 mChildIndicatorRight = mChildIndicatorStart;
343 }
344 if (mChildIndicatorEnd >= CHILD_INDICATOR_INHERIT) {
345 mChildIndicatorLeft = mChildIndicatorEnd;
346 }
347 } else {
348 if (mChildIndicatorStart >= CHILD_INDICATOR_INHERIT) {
349 mChildIndicatorLeft = mChildIndicatorStart;
350 }
351 if (mChildIndicatorEnd >= CHILD_INDICATOR_INHERIT) {
352 mChildIndicatorRight = mChildIndicatorEnd;
353 }
354 }
355 }
356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 @Override
358 protected void dispatchDraw(Canvas canvas) {
359 // Draw children, etc.
360 super.dispatchDraw(canvas);
361
362 // If we have any indicators to draw, we do it here
363 if ((mChildIndicator == null) && (mGroupIndicator == null)) {
364 return;
365 }
366
367 int saveCount = 0;
368 final boolean clipToPadding = (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK;
369 if (clipToPadding) {
370 saveCount = canvas.save();
371 final int scrollX = mScrollX;
372 final int scrollY = mScrollY;
373 canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop,
374 scrollX + mRight - mLeft - mPaddingRight,
375 scrollY + mBottom - mTop - mPaddingBottom);
376 }
377
378 final int headerViewsCount = getHeaderViewsCount();
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 final int lastChildFlPos = mItemCount - getFooterViewsCount() - headerViewsCount - 1;
381
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700382 final int myB = mBottom;
383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 PositionMetadata pos;
385 View item;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700386 Drawable indicator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 int t, b;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 // Start at a value that is neither child nor group
390 int lastItemType = ~(ExpandableListPosition.CHILD | ExpandableListPosition.GROUP);
391
392 final Rect indicatorRect = mIndicatorRect;
393
394 // The "child" mentioned in the following two lines is this
395 // View's child, not referring to an expandable list's
396 // notion of a child (as opposed to a group)
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700397 final int childCount = getChildCount();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 for (int i = 0, childFlPos = mFirstPosition - headerViewsCount; i < childCount;
399 i++, childFlPos++) {
400
401 if (childFlPos < 0) {
402 // This child is header
403 continue;
404 } else if (childFlPos > lastChildFlPos) {
405 // This child is footer, so are all subsequent children
406 break;
407 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 item = getChildAt(i);
410 t = item.getTop();
411 b = item.getBottom();
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This item isn't on the screen
414 if ((b < 0) || (t > myB)) continue;
415
416 // Get more expandable list-related info for this item
417 pos = mConnector.getUnflattenedPos(childFlPos);
418
Fabrice Di Meglio605c5af2013-03-21 16:10:13 -0700419 final boolean isLayoutRtl = isLayoutRtl();
420 final int width = getWidth();
421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // If this item type and the previous item type are different, then we need to change
423 // the left & right bounds
424 if (pos.position.type != lastItemType) {
425 if (pos.position.type == ExpandableListPosition.CHILD) {
426 indicatorRect.left = (mChildIndicatorLeft == CHILD_INDICATOR_INHERIT) ?
427 mIndicatorLeft : mChildIndicatorLeft;
428 indicatorRect.right = (mChildIndicatorRight == CHILD_INDICATOR_INHERIT) ?
429 mIndicatorRight : mChildIndicatorRight;
430 } else {
431 indicatorRect.left = mIndicatorLeft;
432 indicatorRect.right = mIndicatorRight;
433 }
Fabrice Di Meglio605c5af2013-03-21 16:10:13 -0700434
435 if (isLayoutRtl) {
436 final int temp = indicatorRect.left;
437 indicatorRect.left = width - indicatorRect.right;
438 indicatorRect.right = width - temp;
439
440 indicatorRect.left -= mPaddingRight;
441 indicatorRect.right -= mPaddingRight;
442 } else {
443 indicatorRect.left += mPaddingLeft;
444 indicatorRect.right += mPaddingLeft;
445 }
Adam Powell3e5e6ac2011-02-28 21:55:52 -0800446
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700447 lastItemType = pos.position.type;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 }
449
450 if (indicatorRect.left != indicatorRect.right) {
451 // Use item's full height + the divider height
452 if (mStackFromBottom) {
453 // See ListView#dispatchDraw
454 indicatorRect.top = t;// - mDividerHeight;
455 indicatorRect.bottom = b;
456 } else {
457 indicatorRect.top = t;
458 indicatorRect.bottom = b;// + mDividerHeight;
459 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 // Get the indicator (with its state set to the item's state)
462 indicator = getIndicator(pos);
463 if (indicator != null) {
464 // Draw the indicator
465 indicator.setBounds(indicatorRect);
466 indicator.draw(canvas);
467 }
468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 pos.recycle();
470 }
471
472 if (clipToPadding) {
473 canvas.restoreToCount(saveCount);
474 }
475 }
476
477 /**
478 * Gets the indicator for the item at the given position. If the indicator
479 * is stateful, the state will be given to the indicator.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700480 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 * @param pos The flat list position of the item whose indicator
482 * should be returned.
483 * @return The indicator in the proper state.
484 */
485 private Drawable getIndicator(PositionMetadata pos) {
486 Drawable indicator;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 if (pos.position.type == ExpandableListPosition.GROUP) {
489 indicator = mGroupIndicator;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 if (indicator != null && indicator.isStateful()) {
492 // Empty check based on availability of data. If the groupMetadata isn't null,
493 // we do a check on it. Otherwise, the group is collapsed so we consider it
494 // empty for performance reasons.
495 boolean isEmpty = (pos.groupMetadata == null) ||
496 (pos.groupMetadata.lastChildFlPos == pos.groupMetadata.flPos);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 final int stateSetIndex =
499 (pos.isExpanded() ? 1 : 0) | // Expanded?
500 (isEmpty ? 2 : 0); // Empty?
501 indicator.setState(GROUP_STATE_SETS[stateSetIndex]);
502 }
503 } else {
504 indicator = mChildIndicator;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 if (indicator != null && indicator.isStateful()) {
507 // No need for a state sets array for the child since it only has two states
508 final int stateSet[] = pos.position.flatListPos == pos.groupMetadata.lastChildFlPos
509 ? CHILD_LAST_STATE_SET
510 : EMPTY_STATE_SET;
511 indicator.setState(stateSet);
512 }
513 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 return indicator;
516 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 /**
519 * Sets the drawable that will be drawn adjacent to every child in the list. This will
520 * be drawn using the same height as the normal divider ({@link #setDivider(Drawable)}) or
521 * if it does not have an intrinsic height, the height set by {@link #setDividerHeight(int)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700522 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 * @param childDivider The drawable to use.
524 */
525 public void setChildDivider(Drawable childDivider) {
526 mChildDivider = childDivider;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 }
528
529 @Override
530 void drawDivider(Canvas canvas, Rect bounds, int childIndex) {
531 int flatListPosition = childIndex + mFirstPosition;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 // Only proceed as possible child if the divider isn't above all items (if it is above
534 // all items, then the item below it has to be a group)
535 if (flatListPosition >= 0) {
Gilles Debunne272f3a92010-03-03 15:55:13 -0800536 final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
537 PositionMetadata pos = mConnector.getUnflattenedPos(adjustedPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 // If this item is a child, or it is a non-empty group that is expanded
539 if ((pos.position.type == ExpandableListPosition.CHILD) || (pos.isExpanded() &&
540 pos.groupMetadata.lastChildFlPos != pos.groupMetadata.flPos)) {
541 // These are the cases where we draw the child divider
542 final Drawable divider = mChildDivider;
Romain Guy95930e12010-10-04 13:46:02 -0700543 divider.setBounds(bounds);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 divider.draw(canvas);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 pos.recycle();
546 return;
547 }
548 pos.recycle();
549 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 // Otherwise draw the default divider
552 super.drawDivider(canvas, bounds, flatListPosition);
553 }
554
555 /**
556 * This overloaded method should not be used, instead use
557 * {@link #setAdapter(ExpandableListAdapter)}.
558 * <p>
559 * {@inheritDoc}
560 */
561 @Override
562 public void setAdapter(ListAdapter adapter) {
563 throw new RuntimeException(
564 "For ExpandableListView, use setAdapter(ExpandableListAdapter) instead of " +
565 "setAdapter(ListAdapter)");
566 }
567
568 /**
569 * This method should not be used, use {@link #getExpandableListAdapter()}.
570 */
571 @Override
572 public ListAdapter getAdapter() {
573 /*
574 * The developer should never really call this method on an
575 * ExpandableListView, so it would be nice to throw a RuntimeException,
576 * but AdapterView calls this
577 */
578 return super.getAdapter();
579 }
580
581 /**
582 * Register a callback to be invoked when an item has been clicked and the
583 * caller prefers to receive a ListView-style position instead of a group
584 * and/or child position. In most cases, the caller should use
585 * {@link #setOnGroupClickListener} and/or {@link #setOnChildClickListener}.
586 * <p />
587 * {@inheritDoc}
588 */
589 @Override
590 public void setOnItemClickListener(OnItemClickListener l) {
591 super.setOnItemClickListener(l);
592 }
593
594 /**
595 * Sets the adapter that provides data to this view.
596 * @param adapter The adapter that provides data to this view.
597 */
598 public void setAdapter(ExpandableListAdapter adapter) {
599 // Set member variable
600 mAdapter = adapter;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 if (adapter != null) {
603 // Create the connector
604 mConnector = new ExpandableListConnector(adapter);
605 } else {
606 mConnector = null;
607 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 // Link the ListView (superclass) to the expandable list data through the connector
610 super.setAdapter(mConnector);
611 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 /**
614 * Gets the adapter that provides data to this view.
615 * @return The adapter that provides data to this view.
616 */
617 public ExpandableListAdapter getExpandableListAdapter() {
618 return mAdapter;
619 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700620
Gilles Debunne272f3a92010-03-03 15:55:13 -0800621 /**
622 * @param position An absolute (including header and footer) flat list position.
623 * @return true if the position corresponds to a header or a footer item.
624 */
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800625 private boolean isHeaderOrFooterPosition(int position) {
626 final int footerViewsStart = mItemCount - getFooterViewsCount();
627 return (position < getHeaderViewsCount() || position >= footerViewsStart);
628 }
629
Gilles Debunne272f3a92010-03-03 15:55:13 -0800630 /**
631 * Converts an absolute item flat position into a group/child flat position, shifting according
632 * to the number of header items.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700633 *
Gilles Debunne272f3a92010-03-03 15:55:13 -0800634 * @param flatListPosition The absolute flat position
635 * @return A group/child flat position as expected by the connector.
636 */
637 private int getFlatPositionForConnector(int flatListPosition) {
638 return flatListPosition - getHeaderViewsCount();
639 }
640
641 /**
642 * Converts a group/child flat position into an absolute flat position, that takes into account
643 * the possible headers.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700644 *
Gilles Debunne272f3a92010-03-03 15:55:13 -0800645 * @param flatListPosition The child/group flat position
646 * @return An absolute flat position.
647 */
648 private int getAbsoluteFlatPosition(int flatListPosition) {
649 return flatListPosition + getHeaderViewsCount();
650 }
651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 @Override
653 public boolean performItemClick(View v, int position, long id) {
654 // Ignore clicks in header/footers
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800655 if (isHeaderOrFooterPosition(position)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 // Clicked on a header/footer, so ignore pass it on to super
657 return super.performItemClick(v, position, id);
658 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 // Internally handle the item click
Gilles Debunne272f3a92010-03-03 15:55:13 -0800661 final int adjustedPosition = getFlatPositionForConnector(position);
662 return handleItemClick(v, adjustedPosition, id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 /**
666 * This will either expand/collapse groups (if a group was clicked) or pass
667 * on the click to the proper child (if a child was clicked)
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700668 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 * @param position The flat list position. This has already been factored to
670 * remove the header/footer.
671 * @param id The ListAdapter ID, not the group or child ID.
672 */
673 boolean handleItemClick(View v, int position, long id) {
674 final PositionMetadata posMetadata = mConnector.getUnflattenedPos(position);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 id = getChildOrGroupId(posMetadata.position);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 boolean returnValue;
679 if (posMetadata.position.type == ExpandableListPosition.GROUP) {
680 /* It's a group, so handle collapsing/expanding */
Romain Guy40395452009-12-04 16:51:52 -0800681
682 /* It's a group click, so pass on event */
683 if (mOnGroupClickListener != null) {
684 if (mOnGroupClickListener.onGroupClick(this, v,
685 posMetadata.position.groupPos, id)) {
686 posMetadata.recycle();
687 return true;
688 }
689 }
690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 if (posMetadata.isExpanded()) {
692 /* Collapse it */
693 mConnector.collapseGroup(posMetadata);
694
695 playSoundEffect(SoundEffectConstants.CLICK);
Romain Guy40395452009-12-04 16:51:52 -0800696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 if (mOnGroupCollapseListener != null) {
698 mOnGroupCollapseListener.onGroupCollapse(posMetadata.position.groupPos);
699 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 /* Expand it */
702 mConnector.expandGroup(posMetadata);
703
704 playSoundEffect(SoundEffectConstants.CLICK);
Romain Guy40395452009-12-04 16:51:52 -0800705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 if (mOnGroupExpandListener != null) {
707 mOnGroupExpandListener.onGroupExpand(posMetadata.position.groupPos);
708 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700709
Adam Powell45803472010-01-25 15:10:44 -0800710 final int groupPos = posMetadata.position.groupPos;
711 final int groupFlatPos = posMetadata.position.flatListPos;
Gilles Debunne52b65d32010-03-01 10:54:51 -0800712
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700713 final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount();
Gilles Debunne52b65d32010-03-01 10:54:51 -0800714 smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos),
715 shiftedGroupPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 }
Romain Guy40395452009-12-04 16:51:52 -0800717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 returnValue = true;
719 } else {
720 /* It's a child, so pass on event */
721 if (mOnChildClickListener != null) {
722 playSoundEffect(SoundEffectConstants.CLICK);
723 return mOnChildClickListener.onChildClick(this, v, posMetadata.position.groupPos,
724 posMetadata.position.childPos, id);
725 }
Romain Guy40395452009-12-04 16:51:52 -0800726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 returnValue = false;
728 }
Romain Guy40395452009-12-04 16:51:52 -0800729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 posMetadata.recycle();
Romain Guy40395452009-12-04 16:51:52 -0800731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 return returnValue;
733 }
734
735 /**
736 * Expand a group in the grouped list view
737 *
738 * @param groupPos the group to be expanded
739 * @return True if the group was expanded, false otherwise (if the group
740 * was already expanded, this will return false)
741 */
742 public boolean expandGroup(int groupPos) {
John Reck63f46e72011-05-19 10:09:36 -0700743 return expandGroup(groupPos, false);
744 }
745
746 /**
747 * Expand a group in the grouped list view
748 *
749 * @param groupPos the group to be expanded
750 * @param animate true if the expanding group should be animated in
751 * @return True if the group was expanded, false otherwise (if the group
752 * was already expanded, this will return false)
753 */
754 public boolean expandGroup(int groupPos, boolean animate) {
John Reck820b2362012-04-18 10:41:19 -0700755 ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
756 ExpandableListPosition.GROUP, groupPos, -1, -1);
757 PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos);
758 elGroupPos.recycle();
John Reck63f46e72011-05-19 10:09:36 -0700759 boolean retValue = mConnector.expandGroup(pm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760
761 if (mOnGroupExpandListener != null) {
762 mOnGroupExpandListener.onGroupExpand(groupPos);
763 }
John Reck63f46e72011-05-19 10:09:36 -0700764
765 if (animate) {
766 final int groupFlatPos = pm.position.flatListPos;
767
768 final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount();
769 smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos),
770 shiftedGroupPosition);
771 }
772 pm.recycle();
773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 return retValue;
775 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 /**
778 * Collapse a group in the grouped list view
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700779 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 * @param groupPos position of the group to collapse
781 * @return True if the group was collapsed, false otherwise (if the group
782 * was already collapsed, this will return false)
783 */
784 public boolean collapseGroup(int groupPos) {
785 boolean retValue = mConnector.collapseGroup(groupPos);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 if (mOnGroupCollapseListener != null) {
788 mOnGroupCollapseListener.onGroupCollapse(groupPos);
789 }
790
791 return retValue;
792 }
793
794 /** Used for being notified when a group is collapsed */
795 public interface OnGroupCollapseListener {
796 /**
797 * Callback method to be invoked when a group in this expandable list has
798 * been collapsed.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700799 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 * @param groupPosition The group position that was collapsed
801 */
802 void onGroupCollapse(int groupPosition);
803 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700804
Mathew Inwood978c6e22018-08-21 15:58:55 +0100805 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 private OnGroupCollapseListener mOnGroupCollapseListener;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 public void setOnGroupCollapseListener(
809 OnGroupCollapseListener onGroupCollapseListener) {
810 mOnGroupCollapseListener = onGroupCollapseListener;
811 }
812
813 /** Used for being notified when a group is expanded */
814 public interface OnGroupExpandListener {
815 /**
816 * Callback method to be invoked when a group in this expandable list has
817 * been expanded.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700818 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 * @param groupPosition The group position that was expanded
820 */
821 void onGroupExpand(int groupPosition);
822 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700823
Mathew Inwood978c6e22018-08-21 15:58:55 +0100824 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 private OnGroupExpandListener mOnGroupExpandListener;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 public void setOnGroupExpandListener(
828 OnGroupExpandListener onGroupExpandListener) {
829 mOnGroupExpandListener = onGroupExpandListener;
830 }
831
832 /**
833 * Interface definition for a callback to be invoked when a group in this
834 * expandable list has been clicked.
835 */
836 public interface OnGroupClickListener {
837 /**
838 * Callback method to be invoked when a group in this expandable list has
839 * been clicked.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700840 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 * @param parent The ExpandableListConnector where the click happened
842 * @param v The view within the expandable list/ListView that was clicked
843 * @param groupPosition The group position that was clicked
844 * @param id The row id of the group that was clicked
845 * @return True if the click was handled
846 */
847 boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
848 long id);
849 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700850
Mathew Inwood978c6e22018-08-21 15:58:55 +0100851 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 private OnGroupClickListener mOnGroupClickListener;
853
854 public void setOnGroupClickListener(OnGroupClickListener onGroupClickListener) {
855 mOnGroupClickListener = onGroupClickListener;
856 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 /**
859 * Interface definition for a callback to be invoked when a child in this
860 * expandable list has been clicked.
861 */
862 public interface OnChildClickListener {
863 /**
864 * Callback method to be invoked when a child in this expandable list has
865 * been clicked.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700866 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 * @param parent The ExpandableListView where the click happened
868 * @param v The view within the expandable list/ListView that was clicked
869 * @param groupPosition The group position that contains the child that
870 * was clicked
871 * @param childPosition The child position within the group
872 * @param id The row id of the child that was clicked
873 * @return True if the click was handled
874 */
875 boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
876 int childPosition, long id);
877 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700878
Mathew Inwood978c6e22018-08-21 15:58:55 +0100879 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 private OnChildClickListener mOnChildClickListener;
881
882 public void setOnChildClickListener(OnChildClickListener onChildClickListener) {
883 mOnChildClickListener = onChildClickListener;
884 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 /**
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800887 * Converts a flat list position (the raw position of an item (child or group)
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900888 * in the list) to a group and/or child position (represented in a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 * packed position). This is useful in situations where the caller needs to
890 * use the underlying {@link ListView}'s methods. Use
891 * {@link ExpandableListView#getPackedPositionType} ,
892 * {@link ExpandableListView#getPackedPositionChild},
893 * {@link ExpandableListView#getPackedPositionGroup} to unpack.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700894 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 * @param flatListPosition The flat list position to be converted.
896 * @return The group and/or child position for the given flat list position
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800897 * in packed position representation. #PACKED_POSITION_VALUE_NULL if
898 * the position corresponds to a header or a footer item.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 */
900 public long getExpandableListPosition(int flatListPosition) {
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800901 if (isHeaderOrFooterPosition(flatListPosition)) {
902 return PACKED_POSITION_VALUE_NULL;
903 }
904
Gilles Debunne272f3a92010-03-03 15:55:13 -0800905 final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
906 PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 long packedPos = pm.position.getPackedPosition();
908 pm.recycle();
909 return packedPos;
910 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 /**
913 * Converts a group and/or child position to a flat list position. This is
914 * useful in situations where the caller needs to use the underlying
915 * {@link ListView}'s methods.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700916 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 * @param packedPosition The group and/or child positions to be converted in
918 * packed position representation. Use
919 * {@link #getPackedPositionForChild(int, int)} or
920 * {@link #getPackedPositionForGroup(int)}.
921 * @return The flat list position for the given child or group.
922 */
923 public int getFlatListPosition(long packedPosition) {
John Reck820b2362012-04-18 10:41:19 -0700924 ExpandableListPosition elPackedPos = ExpandableListPosition
925 .obtainPosition(packedPosition);
926 PositionMetadata pm = mConnector.getFlattenedPos(elPackedPos);
927 elPackedPos.recycle();
Gilles Debunne272f3a92010-03-03 15:55:13 -0800928 final int flatListPosition = pm.position.flatListPos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 pm.recycle();
Gilles Debunne272f3a92010-03-03 15:55:13 -0800930 return getAbsoluteFlatPosition(flatListPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
932
933 /**
934 * Gets the position of the currently selected group or child (along with
935 * its type). Can return {@link #PACKED_POSITION_VALUE_NULL} if no selection.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700936 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 * @return A packed position containing the currently selected group or
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800938 * child's position and type. #PACKED_POSITION_VALUE_NULL if no selection
939 * or if selection is on a header or a footer item.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 */
941 public long getSelectedPosition() {
942 final int selectedPos = getSelectedItemPosition();
Gilles Debunne47ccdf32010-02-26 11:30:24 -0800943
944 // The case where there is no selection (selectedPos == -1) is also handled here.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 return getExpandableListPosition(selectedPos);
946 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 /**
949 * Gets the ID of the currently selected group or child. Can return -1 if no
950 * selection.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700951 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 * @return The ID of the currently selected group or child. -1 if no
953 * selection.
954 */
955 public long getSelectedId() {
956 long packedPos = getSelectedPosition();
957 if (packedPos == PACKED_POSITION_VALUE_NULL) return -1;
958
959 int groupPos = getPackedPositionGroup(packedPos);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 if (getPackedPositionType(packedPos) == PACKED_POSITION_TYPE_GROUP) {
962 // It's a group
963 return mAdapter.getGroupId(groupPos);
964 } else {
965 // It's a child
966 return mAdapter.getChildId(groupPos, getPackedPositionChild(packedPos));
967 }
968 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 /**
971 * Sets the selection to the specified group.
972 * @param groupPosition The position of the group that should be selected.
973 */
974 public void setSelectedGroup(int groupPosition) {
975 ExpandableListPosition elGroupPos = ExpandableListPosition
976 .obtainGroupPosition(groupPosition);
977 PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos);
978 elGroupPos.recycle();
Gilles Debunne272f3a92010-03-03 15:55:13 -0800979 final int absoluteFlatPosition = getAbsoluteFlatPosition(pm.position.flatListPos);
980 super.setSelection(absoluteFlatPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 pm.recycle();
982 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 /**
985 * Sets the selection to the specified child. If the child is in a collapsed
986 * group, the group will only be expanded and child subsequently selected if
987 * shouldExpandGroup is set to true, otherwise the method will return false.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700988 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 * @param groupPosition The position of the group that contains the child.
990 * @param childPosition The position of the child within the group.
991 * @param shouldExpandGroup Whether the child's group should be expanded if
992 * it is collapsed.
993 * @return Whether the selection was successfully set on the child.
994 */
995 public boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) {
996 ExpandableListPosition elChildPos = ExpandableListPosition.obtainChildPosition(
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700997 groupPosition, childPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 PositionMetadata flatChildPos = mConnector.getFlattenedPos(elChildPos);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 if (flatChildPos == null) {
1001 // The child's group isn't expanded
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 // Shouldn't expand the group, so return false for we didn't set the selection
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001004 if (!shouldExpandGroup) return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005
1006 expandGroup(groupPosition);
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 flatChildPos = mConnector.getFlattenedPos(elChildPos);
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 // Sanity check
1011 if (flatChildPos == null) {
1012 throw new IllegalStateException("Could not find child");
1013 }
1014 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001015
Gilles Debunne272f3a92010-03-03 15:55:13 -08001016 int absoluteFlatPosition = getAbsoluteFlatPosition(flatChildPos.position.flatListPos);
1017 super.setSelection(absoluteFlatPosition);
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 elChildPos.recycle();
1020 flatChildPos.recycle();
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 return true;
1023 }
1024
1025 /**
1026 * Whether the given group is currently expanded.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001027 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 * @param groupPosition The group to check.
1029 * @return Whether the group is currently expanded.
1030 */
1031 public boolean isGroupExpanded(int groupPosition) {
1032 return mConnector.isGroupExpanded(groupPosition);
1033 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 /**
1036 * Gets the type of a packed position. See
1037 * {@link #getPackedPositionForChild(int, int)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001038 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 * @param packedPosition The packed position for which to return the type.
1040 * @return The type of the position contained within the packed position,
1041 * either {@link #PACKED_POSITION_TYPE_CHILD}, {@link #PACKED_POSITION_TYPE_GROUP}, or
1042 * {@link #PACKED_POSITION_TYPE_NULL}.
1043 */
1044 public static int getPackedPositionType(long packedPosition) {
1045 if (packedPosition == PACKED_POSITION_VALUE_NULL) {
1046 return PACKED_POSITION_TYPE_NULL;
1047 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 return (packedPosition & PACKED_POSITION_MASK_TYPE) == PACKED_POSITION_MASK_TYPE
1050 ? PACKED_POSITION_TYPE_CHILD
1051 : PACKED_POSITION_TYPE_GROUP;
1052 }
1053
1054 /**
1055 * Gets the group position from a packed position. See
1056 * {@link #getPackedPositionForChild(int, int)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001057 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 * @param packedPosition The packed position from which the group position
1059 * will be returned.
1060 * @return The group position portion of the packed position. If this does
1061 * not contain a group, returns -1.
1062 */
1063 public static int getPackedPositionGroup(long packedPosition) {
1064 // Null
1065 if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1;
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 return (int) ((packedPosition & PACKED_POSITION_MASK_GROUP) >> PACKED_POSITION_SHIFT_GROUP);
1068 }
1069
1070 /**
1071 * Gets the child position from a packed position that is of
1072 * {@link #PACKED_POSITION_TYPE_CHILD} type (use {@link #getPackedPositionType(long)}).
1073 * To get the group that this child belongs to, use
1074 * {@link #getPackedPositionGroup(long)}. See
1075 * {@link #getPackedPositionForChild(int, int)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001076 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 * @param packedPosition The packed position from which the child position
1078 * will be returned.
1079 * @return The child position portion of the packed position. If this does
1080 * not contain a child, returns -1.
1081 */
1082 public static int getPackedPositionChild(long packedPosition) {
1083 // Null
1084 if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1;
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 // Group since a group type clears this bit
1087 if ((packedPosition & PACKED_POSITION_MASK_TYPE) != PACKED_POSITION_MASK_TYPE) return -1;
1088
1089 return (int) (packedPosition & PACKED_POSITION_MASK_CHILD);
1090 }
1091
1092 /**
1093 * Returns the packed position representation of a child's position.
1094 * <p>
1095 * In general, a packed position should be used in
1096 * situations where the position given to/returned from an
1097 * {@link ExpandableListAdapter} or {@link ExpandableListView} method can
1098 * either be a child or group. The two positions are packed into a single
1099 * long which can be unpacked using
1100 * {@link #getPackedPositionChild(long)},
1101 * {@link #getPackedPositionGroup(long)}, and
1102 * {@link #getPackedPositionType(long)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001103 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 * @param groupPosition The child's parent group's position.
1105 * @param childPosition The child position within the group.
1106 * @return The packed position representation of the child (and parent group).
1107 */
1108 public static long getPackedPositionForChild(int groupPosition, int childPosition) {
1109 return (((long)PACKED_POSITION_TYPE_CHILD) << PACKED_POSITION_SHIFT_TYPE)
1110 | ((((long)groupPosition) & PACKED_POSITION_INT_MASK_GROUP)
1111 << PACKED_POSITION_SHIFT_GROUP)
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001112 | (childPosition & PACKED_POSITION_INT_MASK_CHILD);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114
1115 /**
1116 * Returns the packed position representation of a group's position. See
1117 * {@link #getPackedPositionForChild(int, int)}.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001118 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 * @param groupPosition The child's parent group's position.
1120 * @return The packed position representation of the group.
1121 */
1122 public static long getPackedPositionForGroup(int groupPosition) {
1123 // No need to OR a type in because PACKED_POSITION_GROUP == 0
1124 return ((((long)groupPosition) & PACKED_POSITION_INT_MASK_GROUP)
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001125 << PACKED_POSITION_SHIFT_GROUP);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
1127
1128 @Override
1129 ContextMenuInfo createContextMenuInfo(View view, int flatListPosition, long id) {
Gilles Debunne47ccdf32010-02-26 11:30:24 -08001130 if (isHeaderOrFooterPosition(flatListPosition)) {
1131 // Return normal info for header/footer view context menus
Jeff Sharkeyfd0d6272009-08-17 00:52:46 -07001132 return new AdapterContextMenuInfo(view, flatListPosition, id);
1133 }
1134
Gilles Debunne272f3a92010-03-03 15:55:13 -08001135 final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
Jeff Sharkeyfd0d6272009-08-17 00:52:46 -07001136 PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 ExpandableListPosition pos = pm.position;
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 id = getChildOrGroupId(pos);
1140 long packedPosition = pos.getPackedPosition();
John Reck820b2362012-04-18 10:41:19 -07001141
1142 pm.recycle();
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 return new ExpandableListContextMenuInfo(view, packedPosition, id);
1145 }
1146
1147 /**
1148 * Gets the ID of the group or child at the given <code>position</code>.
1149 * This is useful since there is no ListAdapter ID -> ExpandableListAdapter
1150 * ID conversion mechanism (in some cases, it isn't possible).
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001151 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 * @param position The position of the child or group whose ID should be
1153 * returned.
1154 */
1155 private long getChildOrGroupId(ExpandableListPosition position) {
1156 if (position.type == ExpandableListPosition.CHILD) {
1157 return mAdapter.getChildId(position.groupPos, position.childPos);
1158 } else {
1159 return mAdapter.getGroupId(position.groupPos);
1160 }
1161 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 /**
1164 * Sets the indicator to be drawn next to a child.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001165 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 * @param childIndicator The drawable to be used as an indicator. If the
1167 * child is the last child for a group, the state
1168 * {@link android.R.attr#state_last} will be set.
1169 */
1170 public void setChildIndicator(Drawable childIndicator) {
1171 mChildIndicator = childIndicator;
1172 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 /**
1175 * Sets the drawing bounds for the child indicator. For either, you can
1176 * specify {@link #CHILD_INDICATOR_INHERIT} to use inherit from the general
1177 * indicator's bounds.
1178 *
1179 * @see #setIndicatorBounds(int, int)
1180 * @param left The left position (relative to the left bounds of this View)
1181 * to start drawing the indicator.
1182 * @param right The right position (relative to the left bounds of this
1183 * View) to end the drawing of the indicator.
1184 */
1185 public void setChildIndicatorBounds(int left, int right) {
1186 mChildIndicatorLeft = left;
1187 mChildIndicatorRight = right;
Fabrice Di Megliof4efad02013-03-21 18:22:38 -07001188 resolveChildIndicator();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 }
Fabrice Di Megliof4efad02013-03-21 18:22:38 -07001190
1191 /**
1192 * Sets the relative drawing bounds for the child indicator. For either, you can
1193 * specify {@link #CHILD_INDICATOR_INHERIT} to use inherit from the general
1194 * indicator's bounds.
1195 *
1196 * @see #setIndicatorBounds(int, int)
1197 * @param start The start position (relative to the start bounds of this View)
1198 * to start drawing the indicator.
1199 * @param end The end position (relative to the end bounds of this
1200 * View) to end the drawing of the indicator.
1201 */
1202 public void setChildIndicatorBoundsRelative(int start, int end) {
1203 mChildIndicatorStart = start;
1204 mChildIndicatorEnd = end;
1205 resolveChildIndicator();
1206 }
1207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 /**
1209 * Sets the indicator to be drawn next to a group.
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001210 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 * @param groupIndicator The drawable to be used as an indicator. If the
1212 * group is empty, the state {@link android.R.attr#state_empty} will be
1213 * set. If the group is expanded, the state
1214 * {@link android.R.attr#state_expanded} will be set.
1215 */
1216 public void setGroupIndicator(Drawable groupIndicator) {
1217 mGroupIndicator = groupIndicator;
Romain Guy875862e2011-01-17 11:37:24 -08001218 if (mIndicatorRight == 0 && mGroupIndicator != null) {
1219 mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
1220 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
Romain Guy875862e2011-01-17 11:37:24 -08001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 /**
1224 * Sets the drawing bounds for the indicators (at minimum, the group indicator
1225 * is affected by this; the child indicator is affected by this if the
1226 * child indicator bounds are set to inherit).
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001227 *
1228 * @see #setChildIndicatorBounds(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 * @param left The left position (relative to the left bounds of this View)
1230 * to start drawing the indicator.
1231 * @param right The right position (relative to the left bounds of this
1232 * View) to end the drawing of the indicator.
1233 */
1234 public void setIndicatorBounds(int left, int right) {
1235 mIndicatorLeft = left;
1236 mIndicatorRight = right;
Fabrice Di Megliof4efad02013-03-21 18:22:38 -07001237 resolveIndicator();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 }
Fabrice Di Megliof4efad02013-03-21 18:22:38 -07001239
1240 /**
1241 * Sets the relative drawing bounds for the indicators (at minimum, the group indicator
1242 * is affected by this; the child indicator is affected by this if the
1243 * child indicator bounds are set to inherit).
1244 *
1245 * @see #setChildIndicatorBounds(int, int)
1246 * @param start The start position (relative to the start bounds of this View)
1247 * to start drawing the indicator.
1248 * @param end The end position (relative to the end bounds of this
1249 * View) to end the drawing of the indicator.
1250 */
1251 public void setIndicatorBoundsRelative(int start, int end) {
1252 mIndicatorStart = start;
1253 mIndicatorEnd = end;
1254 resolveIndicator();
1255 }
1256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 /**
1258 * Extra menu information specific to an {@link ExpandableListView} provided
1259 * to the
1260 * {@link android.view.View.OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo) }
1261 * callback when a context menu is brought up for this AdapterView.
1262 */
1263 public static class ExpandableListContextMenuInfo implements ContextMenu.ContextMenuInfo {
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 public ExpandableListContextMenuInfo(View targetView, long packedPosition, long id) {
1266 this.targetView = targetView;
1267 this.packedPosition = packedPosition;
1268 this.id = id;
1269 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 /**
1272 * The view for which the context menu is being displayed. This
1273 * will be one of the children Views of this {@link ExpandableListView}.
1274 */
1275 public View targetView;
1276
1277 /**
1278 * The packed position in the list represented by the adapter for which
1279 * the context menu is being displayed. Use the methods
1280 * {@link ExpandableListView#getPackedPositionType},
1281 * {@link ExpandableListView#getPackedPositionChild}, and
1282 * {@link ExpandableListView#getPackedPositionGroup} to unpack this.
1283 */
1284 public long packedPosition;
1285
1286 /**
1287 * The ID of the item (group or child) for which the context menu is
1288 * being displayed.
1289 */
1290 public long id;
1291 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 static class SavedState extends BaseSavedState {
1294 ArrayList<ExpandableListConnector.GroupMetadata> expandedGroupMetadataList;
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 /**
1297 * Constructor called from {@link ExpandableListView#onSaveInstanceState()}
1298 */
1299 SavedState(
1300 Parcelable superState,
1301 ArrayList<ExpandableListConnector.GroupMetadata> expandedGroupMetadataList) {
1302 super(superState);
1303 this.expandedGroupMetadataList = expandedGroupMetadataList;
1304 }
1305
1306 /**
1307 * Constructor called from {@link #CREATOR}
1308 */
1309 private SavedState(Parcel in) {
1310 super(in);
1311 expandedGroupMetadataList = new ArrayList<ExpandableListConnector.GroupMetadata>();
1312 in.readList(expandedGroupMetadataList, ExpandableListConnector.class.getClassLoader());
1313 }
1314
1315 @Override
1316 public void writeToParcel(Parcel out, int flags) {
1317 super.writeToParcel(out, flags);
1318 out.writeList(expandedGroupMetadataList);
1319 }
1320
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001321 public static final @android.annotation.NonNull Parcelable.Creator<SavedState> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 = new Parcelable.Creator<SavedState>() {
1323 public SavedState createFromParcel(Parcel in) {
1324 return new SavedState(in);
1325 }
1326
1327 public SavedState[] newArray(int size) {
1328 return new SavedState[size];
1329 }
1330 };
1331 }
1332
1333 @Override
1334 public Parcelable onSaveInstanceState() {
1335 Parcelable superState = super.onSaveInstanceState();
1336 return new SavedState(superState,
1337 mConnector != null ? mConnector.getExpandedGroupMetadataList() : null);
1338 }
1339
1340 @Override
1341 public void onRestoreInstanceState(Parcelable state) {
Romain Guy7444e142009-05-21 12:54:16 -07001342 if (!(state instanceof SavedState)) {
1343 super.onRestoreInstanceState(state);
1344 return;
1345 }
1346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 SavedState ss = (SavedState) state;
1348 super.onRestoreInstanceState(ss.getSuperState());
Aurimas Liutikas99441c52016-10-11 16:48:32 -07001349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 if (mConnector != null && ss.expandedGroupMetadataList != null) {
1351 mConnector.setExpandedGroupMetadataList(ss.expandedGroupMetadataList);
1352 }
1353 }
1354
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -08001355 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -08001356 public CharSequence getAccessibilityClassName() {
1357 return ExpandableListView.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -08001358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359}