Merge change 5236 into donut

* changes:
  RelativeLayout was ignoring some dependencies.
This commit is contained in:
Android (Google) Code Review
2009-06-24 12:44:30 -07:00

View File

@@ -40,7 +40,6 @@ import java.util.Comparator;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/** /**
@@ -279,6 +278,17 @@ public class RelativeLayout extends ViewGroup {
graph.getSortedViews(mSortedVerticalChildren, ABOVE, BELOW, ALIGN_BASELINE, graph.getSortedViews(mSortedVerticalChildren, ABOVE, BELOW, ALIGN_BASELINE,
ALIGN_TOP, ALIGN_BOTTOM); ALIGN_TOP, ALIGN_BOTTOM);
graph.getSortedViews(mSortedHorizontalChildren, LEFT_OF, RIGHT_OF, ALIGN_LEFT, ALIGN_RIGHT); graph.getSortedViews(mSortedHorizontalChildren, LEFT_OF, RIGHT_OF, ALIGN_LEFT, ALIGN_RIGHT);
if (DEBUG_GRAPH) {
d(LOG_TAG, "=== Ordered list of vertical children");
for (View view : mSortedVerticalChildren) {
DependencyGraph.printViewId(getResources(), view);
}
d(LOG_TAG, "=== Ordered list of horizontal children");
for (View view : mSortedHorizontalChildren) {
DependencyGraph.printViewId(getResources(), view);
}
}
} }
@Override @Override
@@ -333,7 +343,6 @@ public class RelativeLayout extends ViewGroup {
ignore = findViewById(mIgnoreGravity); ignore = findViewById(mIgnoreGravity);
} }
View[] views = mSortedVerticalChildren; View[] views = mSortedVerticalChildren;
int count = views.length; int count = views.length;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -755,7 +764,7 @@ public class RelativeLayout extends ViewGroup {
private View getRelatedView(int[] rules, int relation) { private View getRelatedView(int[] rules, int relation) {
int id = rules[relation]; int id = rules[relation];
if (id != 0) { if (id != 0) {
View v = findViewById(id); View v = mGraph.mNodes.get(id).view;
if (v == null) { if (v == null) {
return null; return null;
} }
@@ -763,7 +772,7 @@ public class RelativeLayout extends ViewGroup {
// Find the first non-GONE view up the chain // Find the first non-GONE view up the chain
while (v.getVisibility() == View.GONE) { while (v.getVisibility() == View.GONE) {
rules = ((LayoutParams) v.getLayoutParams()).getRules(); rules = ((LayoutParams) v.getLayoutParams()).getRules();
v = v.findViewById(rules[relation]); v = mGraph.mNodes.get((rules[relation])).view;
if (v == null) { if (v == null) {
return null; return null;
} }
@@ -1099,12 +1108,6 @@ public class RelativeLayout extends ViewGroup {
} }
private static class DependencyGraph { private static class DependencyGraph {
/**
* List of views with no id. These views cannot be dependencies of
* other views, so treat the apart for faster processing.
*/
private ArrayList<View> mNakedRoots = new ArrayList<View>();
/** /**
* List of nodes in the graph. Each node is identified by its * List of nodes in the graph. Each node is identified by its
* view id (see View#getId()). * view id (see View#getId()).
@@ -1129,7 +1132,6 @@ public class RelativeLayout extends ViewGroup {
} }
nodes.clear(); nodes.clear();
mNakedRoots.clear();
mRoots.clear(); mRoots.clear();
} }
@@ -1139,13 +1141,7 @@ public class RelativeLayout extends ViewGroup {
* @param view The view to be added as a node to the graph. * @param view The view to be added as a node to the graph.
*/ */
void add(View view) { void add(View view) {
final int id = view.getId(); mNodes.put(view.getId(), Node.acquire(view));
if (id != View.NO_ID) {
mNodes.put(id, Node.acquire(view));
} else {
mNakedRoots.add(view);
}
} }
/** /**
@@ -1162,12 +1158,6 @@ public class RelativeLayout extends ViewGroup {
final LinkedList<Node> roots = findRoots(rules); final LinkedList<Node> roots = findRoots(rules);
int index = 0; int index = 0;
final ArrayList<View> nakedRoots = mNakedRoots;
final int count = nakedRoots.size();
for ( ; index < count; index++) {
sorted[index] = nakedRoots.get(index);
}
while (roots.size() > 0) { while (roots.size() > 0) {
final Node node = roots.removeFirst(); final Node node = roots.removeFirst();
final View view = node.view; final View view = node.view;
@@ -1259,17 +1249,13 @@ public class RelativeLayout extends ViewGroup {
* @param rules The list of rules to take into account. * @param rules The list of rules to take into account.
*/ */
void log(Resources resources, int... rules) { void log(Resources resources, int... rules) {
for (View view : mNakedRoots) {
printViewId(resources, view);
}
final LinkedList<Node> roots = findRoots(rules); final LinkedList<Node> roots = findRoots(rules);
for (Node node : roots) { for (Node node : roots) {
printNode(resources, node); printNode(resources, node);
} }
} }
private static void printViewId(Resources resources, View view) { static void printViewId(Resources resources, View view) {
if (view.getId() != View.NO_ID) { if (view.getId() != View.NO_ID) {
d(LOG_TAG, resources.getResourceEntryName(view.getId())); d(LOG_TAG, resources.getResourceEntryName(view.getId()));
} else { } else {