| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; |
| 20 |
|
| 21 |
import android.compat.annotation.UnsupportedAppUsage; |
| 22 |
import android.content.Context; |
| 23 |
import android.content.res.TypedArray; |
| 24 |
import android.graphics.Canvas; |
| 25 |
import android.graphics.Rect; |
| 26 |
import android.graphics.drawable.Drawable; |
| 27 |
import android.os.Parcel; |
| 28 |
import android.os.Parcelable; |
| 29 |
import android.util.AttributeSet; |
| 30 |
import android.view.ContextMenu; |
| 31 |
import android.view.ContextMenu.ContextMenuInfo; |
| 32 |
import android.view.SoundEffectConstants; |
| 33 |
import android.view.View; |
| 34 |
import android.widget.ExpandableListConnector.PositionMetadata; |
| 35 |
|
| 36 |
import com.android.internal.R; |
| 37 |
|
| 38 |
import java.util.ArrayList; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public class ExpandableListView extends ListView { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public static final int PACKED_POSITION_TYPE_GROUP = 0; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static final int PACKED_POSITION_TYPE_CHILD = 1; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static final int PACKED_POSITION_TYPE_NULL = 2; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public static final long PACKED_POSITION_VALUE_NULL = 0x00000000FFFFFFFFL; |
| 108 |
|
| 109 |
|
| 110 |
private static final long PACKED_POSITION_MASK_CHILD = 0x00000000FFFFFFFFL; |
| 111 |
|
| 112 |
|
| 113 |
private static final long PACKED_POSITION_MASK_GROUP = 0x7FFFFFFF00000000L; |
| 114 |
|
| 115 |
|
| 116 |
private static final long PACKED_POSITION_MASK_TYPE = 0x8000000000000000L; |
| 117 |
|
| 118 |
|
| 119 |
private static final long PACKED_POSITION_SHIFT_GROUP = 32; |
| 120 |
|
| 121 |
|
| 122 |
private static final long PACKED_POSITION_SHIFT_TYPE = 63; |
| 123 |
|
| 124 |
|
| 125 |
private static final long PACKED_POSITION_INT_MASK_CHILD = 0xFFFFFFFF; |
| 126 |
|
| 127 |
|
| 128 |
private static final long PACKED_POSITION_INT_MASK_GROUP = 0x7FFFFFFF; |
| 129 |
|
| 130 |
|
| 131 |
@UnsupportedAppUsage |
| 132 |
private ExpandableListConnector mConnector; |
| 133 |
|
| 134 |
|
| 135 |
private ExpandableListAdapter mAdapter; |
| 136 |
|
| 137 |
|
| 138 |
@UnsupportedAppUsage |
| 139 |
private int mIndicatorLeft; |
| 140 |
|
| 141 |
|
| 142 |
@UnsupportedAppUsage |
| 143 |
private int mIndicatorRight; |
| 144 |
|
| 145 |
|
| 146 |
private int mIndicatorStart; |
| 147 |
|
| 148 |
|
| 149 |
private int mIndicatorEnd; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
private int mChildIndicatorLeft; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
private int mChildIndicatorRight; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
private int mChildIndicatorStart; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
private int mChildIndicatorEnd; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public static final int CHILD_INDICATOR_INHERIT = -1; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
private static final int INDICATOR_UNDEFINED = -2; |
| 185 |
|
| 186 |
|
| 187 |
@UnsupportedAppUsage |
| 188 |
private Drawable mGroupIndicator; |
| 189 |
|
| 190 |
|
| 191 |
private Drawable mChildIndicator; |
| 192 |
|
| 193 |
private static final int[] EMPTY_STATE_SET = {}; |
| 194 |
|
| 195 |
|
| 196 |
private static final int[] GROUP_EXPANDED_STATE_SET = |
| 197 |
{R.attr.state_expanded}; |
| 198 |
|
| 199 |
|
| 200 |
private static final int[] GROUP_EMPTY_STATE_SET = |
| 201 |
{R.attr.state_empty}; |
| 202 |
|
| 203 |
|
| 204 |
private static final int[] GROUP_EXPANDED_EMPTY_STATE_SET = |
| 205 |
{R.attr.state_expanded, R.attr.state_empty}; |
| 206 |
|
| 207 |
|
| 208 |
@UnsupportedAppUsage |
| 209 |
private static final int[][] GROUP_STATE_SETS = { |
| 210 |
EMPTY_STATE_SET, |
| 211 |
GROUP_EXPANDED_STATE_SET, |
| 212 |
GROUP_EMPTY_STATE_SET, |
| 213 |
GROUP_EXPANDED_EMPTY_STATE_SET |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
private static final int[] CHILD_LAST_STATE_SET = |
| 218 |
{R.attr.state_last}; |
| 219 |
|
| 220 |
|
| 221 |
@UnsupportedAppUsage |
| 222 |
private Drawable mChildDivider; |
| 223 |
|
| 224 |
|
| 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 |
|
| 235 |
public ExpandableListView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 236 |
this(context, attrs, defStyleAttr, 0); |
| 237 |
} |
| 238 |
|
| 239 |
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); |
| 245 |
saveAttributeDataForStyleable(context, com.android.internal.R.styleable.ExpandableListView, |
| 246 |
attrs, a, defStyleAttr, defStyleRes); |
| 247 |
|
| 248 |
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); |
| 256 |
if (mIndicatorRight == 0 && mGroupIndicator != null) { |
| 257 |
mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth(); |
| 258 |
} |
| 259 |
mChildIndicatorLeft = a.getDimensionPixelSize( |
| 260 |
com.android.internal.R.styleable.ExpandableListView_childIndicatorLeft, |
| 261 |
CHILD_INDICATOR_INHERIT); |
| 262 |
mChildIndicatorRight = a.getDimensionPixelSize( |
| 263 |
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 |
|
| 284 |
a.recycle(); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
private boolean isRtlCompatibilityMode() { |
| 292 |
final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 293 |
return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport(); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 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 |
|
| 310 |
|
| 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 |
|
| 336 |
|
| 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 |
|
| 357 |
@Override |
| 358 |
protected void dispatchDraw(Canvas canvas) { |
| 359 |
|
| 360 |
super.dispatchDraw(canvas); |
| 361 |
|
| 362 |
|
| 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(); |
| 379 |
|
| 380 |
final int lastChildFlPos = mItemCount - getFooterViewsCount() - headerViewsCount - 1; |
| 381 |
|
| 382 |
final int myB = mBottom; |
| 383 |
|
| 384 |
PositionMetadata pos; |
| 385 |
View item; |
| 386 |
Drawable indicator; |
| 387 |
int t, b; |
| 388 |
|
| 389 |
|
| 390 |
int lastItemType = ~(ExpandableListPosition.CHILD | ExpandableListPosition.GROUP); |
| 391 |
|
| 392 |
final Rect indicatorRect = mIndicatorRect; |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
final int childCount = getChildCount(); |
| 398 |
for (int i = 0, childFlPos = mFirstPosition - headerViewsCount; i < childCount; |
| 399 |
i++, childFlPos++) { |
| 400 |
|
| 401 |
if (childFlPos < 0) { |
| 402 |
|
| 403 |
continue; |
| 404 |
} else if (childFlPos > lastChildFlPos) { |
| 405 |
|
| 406 |
break; |
| 407 |
} |
| 408 |
|
| 409 |
item = getChildAt(i); |
| 410 |
t = item.getTop(); |
| 411 |
b = item.getBottom(); |
| 412 |
|
| 413 |
|
| 414 |
if ((b < 0) || (t > myB)) continue; |
| 415 |
|
| 416 |
|
| 417 |
pos = mConnector.getUnflattenedPos(childFlPos); |
| 418 |
|
| 419 |
final boolean isLayoutRtl = isLayoutRtl(); |
| 420 |
final int width = getWidth(); |
| 421 |
|
| 422 |
|
| 423 |
|
| 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 |
} |
| 434 |
|
| 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 |
} |
| 446 |
|
| 447 |
lastItemType = pos.position.type; |
| 448 |
} |
| 449 |
|
| 450 |
if (indicatorRect.left != indicatorRect.right) { |
| 451 |
|
| 452 |
if (mStackFromBottom) { |
| 453 |
|
| 454 |
indicatorRect.top = t; |
| 455 |
indicatorRect.bottom = b; |
| 456 |
} else { |
| 457 |
indicatorRect.top = t; |
| 458 |
indicatorRect.bottom = b; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
indicator = getIndicator(pos); |
| 463 |
if (indicator != null) { |
| 464 |
|
| 465 |
indicator.setBounds(indicatorRect); |
| 466 |
indicator.draw(canvas); |
| 467 |
} |
| 468 |
} |
| 469 |
pos.recycle(); |
| 470 |
} |
| 471 |
|
| 472 |
if (clipToPadding) { |
| 473 |
canvas.restoreToCount(saveCount); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
private Drawable getIndicator(PositionMetadata pos) { |
| 486 |
Drawable indicator; |
| 487 |
|
| 488 |
if (pos.position.type == ExpandableListPosition.GROUP) { |
| 489 |
indicator = mGroupIndicator; |
| 490 |
|
| 491 |
if (indicator != null && indicator.isStateful()) { |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
boolean isEmpty = (pos.groupMetadata == null) || |
| 496 |
(pos.groupMetadata.lastChildFlPos == pos.groupMetadata.flPos); |
| 497 |
|
| 498 |
final int stateSetIndex = |
| 499 |
(pos.isExpanded() ? 1 : 0) | |
| 500 |
(isEmpty ? 2 : 0); |
| 501 |
indicator.setState(GROUP_STATE_SETS[stateSetIndex]); |
| 502 |
} |
| 503 |
} else { |
| 504 |
indicator = mChildIndicator; |
| 505 |
|
| 506 |
if (indicator != null && indicator.isStateful()) { |
| 507 |
|
| 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 |
} |
| 514 |
|
| 515 |
return indicator; |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public void setChildDivider(Drawable childDivider) { |
| 526 |
mChildDivider = childDivider; |
| 527 |
} |
| 528 |
|
| 529 |
@Override |
| 530 |
void drawDivider(Canvas canvas, Rect bounds, int childIndex) { |
| 531 |
int flatListPosition = childIndex + mFirstPosition; |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
if (flatListPosition >= 0) { |
| 536 |
final int adjustedPosition = getFlatPositionForConnector(flatListPosition); |
| 537 |
PositionMetadata pos = mConnector.getUnflattenedPos(adjustedPosition); |
| 538 |
|
| 539 |
if ((pos.position.type == ExpandableListPosition.CHILD) || (pos.isExpanded() && |
| 540 |
pos.groupMetadata.lastChildFlPos != pos.groupMetadata.flPos)) { |
| 541 |
|
| 542 |
final Drawable divider = mChildDivider; |
| 543 |
divider.setBounds(bounds); |
| 544 |
divider.draw(canvas); |
| 545 |
pos.recycle(); |
| 546 |
return; |
| 547 |
} |
| 548 |
pos.recycle(); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
super.drawDivider(canvas, bounds, flatListPosition); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 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 |
|
| 570 |
|
| 571 |
@Override |
| 572 |
public ListAdapter getAdapter() { |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
return super.getAdapter(); |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
@Override |
| 590 |
public void setOnItemClickListener(OnItemClickListener l) { |
| 591 |
super.setOnItemClickListener(l); |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
public void setAdapter(ExpandableListAdapter adapter) { |
| 599 |
|
| 600 |
mAdapter = adapter; |
| 601 |
|
| 602 |
if (adapter != null) { |
| 603 |
|
| 604 |
mConnector = new ExpandableListConnector(adapter); |
| 605 |
} else { |
| 606 |
mConnector = null; |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
super.setAdapter(mConnector); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
public ExpandableListAdapter getExpandableListAdapter() { |
| 618 |
return mAdapter; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
private boolean isHeaderOrFooterPosition(int position) { |
| 626 |
final int footerViewsStart = mItemCount - getFooterViewsCount(); |
| 627 |
return (position < getHeaderViewsCount() || position >= footerViewsStart); |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
private int getFlatPositionForConnector(int flatListPosition) { |
| 638 |
return flatListPosition - getHeaderViewsCount(); |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
private int getAbsoluteFlatPosition(int flatListPosition) { |
| 649 |
return flatListPosition + getHeaderViewsCount(); |
| 650 |
} |
| 651 |
|
| 652 |
@Override |
| 653 |
public boolean performItemClick(View v, int position, long id) { |
| 654 |
|
| 655 |
if (isHeaderOrFooterPosition(position)) { |
| 656 |
|
| 657 |
return super.performItemClick(v, position, id); |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
final int adjustedPosition = getFlatPositionForConnector(position); |
| 662 |
return handleItemClick(v, adjustedPosition, id); |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
boolean handleItemClick(View v, int position, long id) { |
| 674 |
final PositionMetadata posMetadata = mConnector.getUnflattenedPos(position); |
| 675 |
|
| 676 |
id = getChildOrGroupId(posMetadata.position); |
| 677 |
|
| 678 |
boolean returnValue; |
| 679 |
if (posMetadata.position.type == ExpandableListPosition.GROUP) { |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
if (mOnGroupClickListener != null) { |
| 684 |
if (mOnGroupClickListener.onGroupClick(this, v, |
| 685 |
posMetadata.position.groupPos, id)) { |
| 686 |
posMetadata.recycle(); |
| 687 |
return true; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
if (posMetadata.isExpanded()) { |
| 692 |
|
| 693 |
mConnector.collapseGroup(posMetadata); |
| 694 |
|
| 695 |
playSoundEffect(SoundEffectConstants.CLICK); |
| 696 |
|
| 697 |
if (mOnGroupCollapseListener != null) { |
| 698 |
mOnGroupCollapseListener.onGroupCollapse(posMetadata.position.groupPos); |
| 699 |
} |
| 700 |
} else { |
| 701 |
|
| 702 |
mConnector.expandGroup(posMetadata); |
| 703 |
|
| 704 |
playSoundEffect(SoundEffectConstants.CLICK); |
| 705 |
|
| 706 |
if (mOnGroupExpandListener != null) { |
| 707 |
mOnGroupExpandListener.onGroupExpand(posMetadata.position.groupPos); |
| 708 |
} |
| 709 |
|
| 710 |
final int groupPos = posMetadata.position.groupPos; |
| 711 |
final int groupFlatPos = posMetadata.position.flatListPos; |
| 712 |
|
| 713 |
final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount(); |
| 714 |
smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos), |
| 715 |
shiftedGroupPosition); |
| 716 |
} |
| 717 |
|
| 718 |
returnValue = true; |
| 719 |
} else { |
| 720 |
|
| 721 |
if (mOnChildClickListener != null) { |
| 722 |
playSoundEffect(SoundEffectConstants.CLICK); |
| 723 |
return mOnChildClickListener.onChildClick(this, v, posMetadata.position.groupPos, |
| 724 |
posMetadata.position.childPos, id); |
| 725 |
} |
| 726 |
|
| 727 |
returnValue = false; |
| 728 |
} |
| 729 |
|
| 730 |
posMetadata.recycle(); |
| 731 |
|
| 732 |
return returnValue; |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
public boolean expandGroup(int groupPos) { |
| 743 |
return expandGroup(groupPos, false); |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
public boolean expandGroup(int groupPos, boolean animate) { |
| 755 |
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain( |
| 756 |
ExpandableListPosition.GROUP, groupPos, -1, -1); |
| 757 |
PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos); |
| 758 |
elGroupPos.recycle(); |
| 759 |
boolean retValue = mConnector.expandGroup(pm); |
| 760 |
|
| 761 |
if (mOnGroupExpandListener != null) { |
| 762 |
mOnGroupExpandListener.onGroupExpand(groupPos); |
| 763 |
} |
| 764 |
|
| 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 |
|
| 774 |
return retValue; |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
public boolean collapseGroup(int groupPos) { |
| 785 |
boolean retValue = mConnector.collapseGroup(groupPos); |
| 786 |
|
| 787 |
if (mOnGroupCollapseListener != null) { |
| 788 |
mOnGroupCollapseListener.onGroupCollapse(groupPos); |
| 789 |
} |
| 790 |
|
| 791 |
return retValue; |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
public interface OnGroupCollapseListener { |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
void onGroupCollapse(int groupPosition); |
| 803 |
} |
| 804 |
|
| 805 |
@UnsupportedAppUsage |
| 806 |
private OnGroupCollapseListener mOnGroupCollapseListener; |
| 807 |
|
| 808 |
public void setOnGroupCollapseListener( |
| 809 |
OnGroupCollapseListener onGroupCollapseListener) { |
| 810 |
mOnGroupCollapseListener = onGroupCollapseListener; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
public interface OnGroupExpandListener { |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
void onGroupExpand(int groupPosition); |
| 822 |
} |
| 823 |
|
| 824 |
@UnsupportedAppUsage |
| 825 |
private OnGroupExpandListener mOnGroupExpandListener; |
| 826 |
|
| 827 |
public void setOnGroupExpandListener( |
| 828 |
OnGroupExpandListener onGroupExpandListener) { |
| 829 |
mOnGroupExpandListener = onGroupExpandListener; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
public interface OnGroupClickListener { |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, |
| 848 |
long id); |
| 849 |
} |
| 850 |
|
| 851 |
@UnsupportedAppUsage |
| 852 |
private OnGroupClickListener mOnGroupClickListener; |
| 853 |
|
| 854 |
public void setOnGroupClickListener(OnGroupClickListener onGroupClickListener) { |
| 855 |
mOnGroupClickListener = onGroupClickListener; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
public interface OnChildClickListener { |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
boolean onChildClick(ExpandableListView parent, View v, int groupPosition, |
| 876 |
int childPosition, long id); |
| 877 |
} |
| 878 |
|
| 879 |
@UnsupportedAppUsage |
| 880 |
private OnChildClickListener mOnChildClickListener; |
| 881 |
|
| 882 |
public void setOnChildClickListener(OnChildClickListener onChildClickListener) { |
| 883 |
mOnChildClickListener = onChildClickListener; |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
public long getExpandableListPosition(int flatListPosition) { |
| 901 |
if (isHeaderOrFooterPosition(flatListPosition)) { |
| 902 |
return PACKED_POSITION_VALUE_NULL; |
| 903 |
} |
| 904 |
|
| 905 |
final int adjustedPosition = getFlatPositionForConnector(flatListPosition); |
| 906 |
PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition); |
| 907 |
long packedPos = pm.position.getPackedPosition(); |
| 908 |
pm.recycle(); |
| 909 |
return packedPos; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
public int getFlatListPosition(long packedPosition) { |
| 924 |
ExpandableListPosition elPackedPos = ExpandableListPosition |
| 925 |
.obtainPosition(packedPosition); |
| 926 |
PositionMetadata pm = mConnector.getFlattenedPos(elPackedPos); |
| 927 |
elPackedPos.recycle(); |
| 928 |
final int flatListPosition = pm.position.flatListPos; |
| 929 |
pm.recycle(); |
| 930 |
return getAbsoluteFlatPosition(flatListPosition); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
public long getSelectedPosition() { |
| 942 |
final int selectedPos = getSelectedItemPosition(); |
| 943 |
|
| 944 |
|
| 945 |
return getExpandableListPosition(selectedPos); |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
public long getSelectedId() { |
| 956 |
long packedPos = getSelectedPosition(); |
| 957 |
if (packedPos == PACKED_POSITION_VALUE_NULL) return -1; |
| 958 |
|
| 959 |
int groupPos = getPackedPositionGroup(packedPos); |
| 960 |
|
| 961 |
if (getPackedPositionType(packedPos) == PACKED_POSITION_TYPE_GROUP) { |
| 962 |
|
| 963 |
return mAdapter.getGroupId(groupPos); |
| 964 |
} else { |
| 965 |
|
| 966 |
return mAdapter.getChildId(groupPos, getPackedPositionChild(packedPos)); |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
public void setSelectedGroup(int groupPosition) { |
| 975 |
ExpandableListPosition elGroupPos = ExpandableListPosition |
| 976 |
.obtainGroupPosition(groupPosition); |
| 977 |
PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos); |
| 978 |
elGroupPos.recycle(); |
| 979 |
final int absoluteFlatPosition = getAbsoluteFlatPosition(pm.position.flatListPos); |
| 980 |
super.setSelection(absoluteFlatPosition); |
| 981 |
pm.recycle(); |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
public boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) { |
| 996 |
ExpandableListPosition elChildPos = ExpandableListPosition.obtainChildPosition( |
| 997 |
groupPosition, childPosition); |
| 998 |
PositionMetadata flatChildPos = mConnector.getFlattenedPos(elChildPos); |
| 999 |
|
| 1000 |
if (flatChildPos == null) { |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
if (!shouldExpandGroup) return false; |
| 1005 |
|
| 1006 |
expandGroup(groupPosition); |
| 1007 |
|
| 1008 |
flatChildPos = mConnector.getFlattenedPos(elChildPos); |
| 1009 |
|
| 1010 |
|
| 1011 |
if (flatChildPos == null) { |
| 1012 |
throw new IllegalStateException("Could not find child"); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
int absoluteFlatPosition = getAbsoluteFlatPosition(flatChildPos.position.flatListPos); |
| 1017 |
super.setSelection(absoluteFlatPosition); |
| 1018 |
|
| 1019 |
elChildPos.recycle(); |
| 1020 |
flatChildPos.recycle(); |
| 1021 |
|
| 1022 |
return true; |
| 1023 |
} |
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
public boolean isGroupExpanded(int groupPosition) { |
| 1032 |
return mConnector.isGroupExpanded(groupPosition); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
public static int getPackedPositionType(long packedPosition) { |
| 1045 |
if (packedPosition == PACKED_POSITION_VALUE_NULL) { |
| 1046 |
return PACKED_POSITION_TYPE_NULL; |
| 1047 |
} |
| 1048 |
|
| 1049 |
return (packedPosition & PACKED_POSITION_MASK_TYPE) == PACKED_POSITION_MASK_TYPE |
| 1050 |
? PACKED_POSITION_TYPE_CHILD |
| 1051 |
: PACKED_POSITION_TYPE_GROUP; |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
public static int getPackedPositionGroup(long packedPosition) { |
| 1064 |
|
| 1065 |
if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1; |
| 1066 |
|
| 1067 |
return (int) ((packedPosition & PACKED_POSITION_MASK_GROUP) >> PACKED_POSITION_SHIFT_GROUP); |
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
public static int getPackedPositionChild(long packedPosition) { |
| 1083 |
|
| 1084 |
if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1; |
| 1085 |
|
| 1086 |
|
| 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 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 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) |
| 1112 |
| (childPosition & PACKED_POSITION_INT_MASK_CHILD); |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
public static long getPackedPositionForGroup(int groupPosition) { |
| 1123 |
|
| 1124 |
return ((((long)groupPosition) & PACKED_POSITION_INT_MASK_GROUP) |
| 1125 |
<< PACKED_POSITION_SHIFT_GROUP); |
| 1126 |
} |
| 1127 |
|
| 1128 |
@Override |
| 1129 |
ContextMenuInfo createContextMenuInfo(View view, int flatListPosition, long id) { |
| 1130 |
if (isHeaderOrFooterPosition(flatListPosition)) { |
| 1131 |
|
| 1132 |
return new AdapterContextMenuInfo(view, flatListPosition, id); |
| 1133 |
} |
| 1134 |
|
| 1135 |
final int adjustedPosition = getFlatPositionForConnector(flatListPosition); |
| 1136 |
PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition); |
| 1137 |
ExpandableListPosition pos = pm.position; |
| 1138 |
|
| 1139 |
id = getChildOrGroupId(pos); |
| 1140 |
long packedPosition = pos.getPackedPosition(); |
| 1141 |
|
| 1142 |
pm.recycle(); |
| 1143 |
|
| 1144 |
return new ExpandableListContextMenuInfo(view, packedPosition, id); |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 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 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
public void setChildIndicator(Drawable childIndicator) { |
| 1171 |
mChildIndicator = childIndicator; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
public void setChildIndicatorBounds(int left, int right) { |
| 1186 |
mChildIndicatorLeft = left; |
| 1187 |
mChildIndicatorRight = right; |
| 1188 |
resolveChildIndicator(); |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
public void setChildIndicatorBoundsRelative(int start, int end) { |
| 1203 |
mChildIndicatorStart = start; |
| 1204 |
mChildIndicatorEnd = end; |
| 1205 |
resolveChildIndicator(); |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
public void setGroupIndicator(Drawable groupIndicator) { |
| 1217 |
mGroupIndicator = groupIndicator; |
| 1218 |
if (mIndicatorRight == 0 && mGroupIndicator != null) { |
| 1219 |
mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth(); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
public void setIndicatorBounds(int left, int right) { |
| 1235 |
mIndicatorLeft = left; |
| 1236 |
mIndicatorRight = right; |
| 1237 |
resolveIndicator(); |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
public void setIndicatorBoundsRelative(int start, int end) { |
| 1252 |
mIndicatorStart = start; |
| 1253 |
mIndicatorEnd = end; |
| 1254 |
resolveIndicator(); |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
public static class ExpandableListContextMenuInfo implements ContextMenu.ContextMenuInfo { |
| 1264 |
|
| 1265 |
public ExpandableListContextMenuInfo(View targetView, long packedPosition, long id) { |
| 1266 |
this.targetView = targetView; |
| 1267 |
this.packedPosition = packedPosition; |
| 1268 |
this.id = id; |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
public View targetView; |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
public long packedPosition; |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
public long id; |
| 1291 |
} |
| 1292 |
|
| 1293 |
static class SavedState extends BaseSavedState { |
| 1294 |
ArrayList<ExpandableListConnector.GroupMetadata> expandedGroupMetadataList; |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
SavedState( |
| 1300 |
Parcelable superState, |
| 1301 |
ArrayList<ExpandableListConnector.GroupMetadata> expandedGroupMetadataList) { |
| 1302 |
super(superState); |
| 1303 |
this.expandedGroupMetadataList = expandedGroupMetadataList; |
| 1304 |
} |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
private SavedState(Parcel in) { |
| 1310 |
super(in); |
| 1311 |
expandedGroupMetadataList = new ArrayList<ExpandableListConnector.GroupMetadata>(); |
| 1312 |
in.readList(expandedGroupMetadataList, ExpandableListConnector.class.getClassLoader(), android.widget.ExpandableListConnector.GroupMetadata.class); |
| 1313 |
} |
| 1314 |
|
| 1315 |
@Override |
| 1316 |
public void writeToParcel(Parcel out, int flags) { |
| 1317 |
super.writeToParcel(out, flags); |
| 1318 |
out.writeList(expandedGroupMetadataList); |
| 1319 |
} |
| 1320 |
|
| 1321 |
public static final @android.annotation.NonNull Parcelable.Creator<SavedState> CREATOR |
| 1322 |
= 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) { |
| 1342 |
if (!(state instanceof SavedState)) { |
| 1343 |
super.onRestoreInstanceState(state); |
| 1344 |
return; |
| 1345 |
} |
| 1346 |
|
| 1347 |
SavedState ss = (SavedState) state; |
| 1348 |
super.onRestoreInstanceState(ss.getSuperState()); |
| 1349 |
|
| 1350 |
if (mConnector != null && ss.expandedGroupMetadataList != null) { |
| 1351 |
mConnector.setExpandedGroupMetadataList(ss.expandedGroupMetadataList); |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
@Override |
| 1356 |
public CharSequence getAccessibilityClassName() { |
| 1357 |
return ExpandableListView.class.getName(); |
| 1358 |
} |
| 1359 |
} |