If you think the Android project device-frame-generator listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 Prateek Srivastava (@f2prateek)
*//fromwww.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.f2prateek.dfg.ui.debug;
import android.view.View;
import android.view.ViewGroup;
/**
* A {@link android.view.ViewGroup.OnHierarchyChangeListener hierarchy change listener} which
* recursively
* monitors an entire tree of views.
*/publicfinalclass HierarchyTreeChangeListener implements ViewGroup.OnHierarchyChangeListener {
/**
* Wrap a regular
* {@link android.view.ViewGroup.OnHierarchyChangeListener hierarchy change listener} with one
* that monitors an entire tree of views.
*/publicstatic HierarchyTreeChangeListener wrap(ViewGroup.OnHierarchyChangeListener delegate) {
returnnew HierarchyTreeChangeListener(delegate);
}
privatefinal ViewGroup.OnHierarchyChangeListener delegate;
private HierarchyTreeChangeListener(ViewGroup.OnHierarchyChangeListener delegate) {
if (delegate == null) {
thrownew NullPointerException("Delegate must not be null.");
}
this.delegate = delegate;
}
@Override publicvoid onChildViewAdded(View parent, View child) {
delegate.onChildViewAdded(parent, child);
if (child instanceof ViewGroup) {
ViewGroup childGroup = (ViewGroup) child;
childGroup.setOnHierarchyChangeListener(this);
for (int i = 0; i < childGroup.getChildCount(); i++) {
onChildViewAdded(childGroup, childGroup.getChildAt(i));
}
}
}
@Override publicvoid onChildViewRemoved(View parent, View child) {
if (child instanceof ViewGroup) {
ViewGroup childGroup = (ViewGroup) child;
for (int i = 0; i < childGroup.getChildCount(); i++) {
onChildViewRemoved(childGroup, childGroup.getChildAt(i));
}
childGroup.setOnHierarchyChangeListener(null);
}
delegate.onChildViewRemoved(parent, child);
}
}