|
20 | 20 | import android.animation.AnimatorInflater; |
21 | 21 | import android.animation.AnimatorListenerAdapter; |
22 | 22 | import android.content.res.Configuration; |
| 23 | +import android.content.res.Resources; |
23 | 24 | import android.content.res.TypedArray; |
24 | 25 | import android.os.Bundle; |
25 | 26 | import android.os.Handler; |
@@ -427,6 +428,94 @@ public void run() { |
427 | 428 | } |
428 | 429 | }; |
429 | 430 |
|
| 431 | + private void logViewHierarchy(String prefix, View view) { |
| 432 | + StringBuilder builder = new StringBuilder(128); |
| 433 | + builder.append(prefix); |
| 434 | + DebugUtils.buildShortClassTag(view, builder); |
| 435 | + int id = view.getId(); |
| 436 | + if (id != -1) { |
| 437 | + builder.append(" #"); |
| 438 | + builder.append(Integer.toHexString(id)); |
| 439 | + if (id != 0 && id != -1) { |
| 440 | + try { |
| 441 | + String pkgname; |
| 442 | + switch (id&0xff000000) { |
| 443 | + case 0x7f000000: |
| 444 | + pkgname="app"; |
| 445 | + break; |
| 446 | + case 0x01000000: |
| 447 | + pkgname="android"; |
| 448 | + break; |
| 449 | + default: |
| 450 | + pkgname = view.getResources().getResourcePackageName(id); |
| 451 | + break; |
| 452 | + } |
| 453 | + String typename = view.getResources().getResourceTypeName(id); |
| 454 | + String entryname = view.getResources().getResourceEntryName(id); |
| 455 | + builder.append(" ("); |
| 456 | + builder.append(pkgname); |
| 457 | + builder.append(":"); |
| 458 | + builder.append(typename); |
| 459 | + builder.append("/"); |
| 460 | + builder.append(entryname); |
| 461 | + builder.append(")"); |
| 462 | + } catch (Resources.NotFoundException e) { |
| 463 | + } |
| 464 | + } |
| 465 | + } |
| 466 | + Object tag = view.getTag(); |
| 467 | + if (tag != null) { |
| 468 | + builder.append(" "); |
| 469 | + builder.append(tag); |
| 470 | + } |
| 471 | + builder.append("}"); |
| 472 | + Log.e(TAG, builder.toString()); |
| 473 | + |
| 474 | + if (!(view instanceof ViewGroup)) { |
| 475 | + return; |
| 476 | + } |
| 477 | + ViewGroup grp = (ViewGroup)view; |
| 478 | + final int N = grp.getChildCount(); |
| 479 | + if (N <= 0) { |
| 480 | + return; |
| 481 | + } |
| 482 | + prefix = prefix + " "; |
| 483 | + for (int i=0; i<N; i++) { |
| 484 | + logViewHierarchy(prefix, grp.getChildAt(i)); |
| 485 | + } |
| 486 | + } |
| 487 | + |
| 488 | + private void throwNoViewFound(Fragment f) { |
| 489 | + String msg = "No view found for id 0x" |
| 490 | + + Integer.toHexString(f.mContainerId) + " (" |
| 491 | + + f.getResources().getResourceName(f.mContainerId) |
| 492 | + + ") for fragment " + f; |
| 493 | + Log.e(TAG, msg); |
| 494 | + Log.e(TAG, "Activity state:"); |
| 495 | + if (f.getActivity() != null) { |
| 496 | + try { |
| 497 | + LogWriter logw = new LogWriter(Log.ERROR, TAG); |
| 498 | + PrintWriter pw = new PrintWriter(logw); |
| 499 | + f.getActivity().dump(" ", null, pw, new String[] { }); |
| 500 | + } catch (Exception e) { |
| 501 | + Log.e(TAG, "Failed dumping state", e); |
| 502 | + } |
| 503 | + } else { |
| 504 | + Log.e(TAG, " NULL ACTIVITY!"); |
| 505 | + } |
| 506 | + Log.e(TAG, "View hierarchy:"); |
| 507 | + if (f.getActivity() != null) { |
| 508 | + try { |
| 509 | + logViewHierarchy(" ", f.getActivity().getWindow().getDecorView()); |
| 510 | + } catch (Exception e) { |
| 511 | + Log.e(TAG, "Failed dumping view hierarchy", e); |
| 512 | + } |
| 513 | + } else { |
| 514 | + Log.e(TAG, " NULL ACTIVITY!"); |
| 515 | + } |
| 516 | + throw new IllegalArgumentException(msg); |
| 517 | + } |
| 518 | + |
430 | 519 | @Override |
431 | 520 | public FragmentTransaction beginTransaction() { |
432 | 521 | return new BackStackRecord(this); |
@@ -824,9 +913,7 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle, |
824 | 913 | if (f.mContainerId != 0) { |
825 | 914 | container = (ViewGroup)mActivity.findViewById(f.mContainerId); |
826 | 915 | if (container == null && !f.mRestored) { |
827 | | - throw new IllegalArgumentException("No view found for id 0x" |
828 | | - + Integer.toHexString(f.mContainerId) |
829 | | - + " for fragment " + f); |
| 916 | + throwNoViewFound(f); |
830 | 917 | } |
831 | 918 | } |
832 | 919 | f.mContainer = container; |
|
0 commit comments