diff options
| author | Romain Guy <romainguy@android.com> | 2009-06-24 12:42:43 -0700 |
|---|---|---|
| committer | Romain Guy <romainguy@android.com> | 2009-06-24 12:44:01 -0700 |
| commit | 9fffa1eb40f5121866cb8e547b8bbd7eafee5281 (patch) | |
| tree | 38aea888abed3aa006fec8f460b5bf11ab1861b5 /core/java/android/widget/RelativeLayout.java | |
| parent | 6f8e592347d463044b7dd8999588840cec6e956e (diff) | |
RelativeLayout was ignoring some dependencies.
This change also improves the speed of RelativeLayout by eliminating calls to
findViewById() whenever possible.
Diffstat (limited to 'core/java/android/widget/RelativeLayout.java')
| -rw-r--r-- | core/java/android/widget/RelativeLayout.java | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index 68dafa134d66..b2aa57420969 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -40,7 +40,6 @@ import java.util.Comparator; import java.util.SortedSet; import java.util.TreeSet; import java.util.LinkedList; -import java.util.ArrayList; import java.util.HashSet; /** @@ -279,6 +278,17 @@ public class RelativeLayout extends ViewGroup { graph.getSortedViews(mSortedVerticalChildren, ABOVE, BELOW, ALIGN_BASELINE, ALIGN_TOP, ALIGN_BOTTOM); 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 @@ -333,7 +343,6 @@ public class RelativeLayout extends ViewGroup { ignore = findViewById(mIgnoreGravity); } - View[] views = mSortedVerticalChildren; int count = views.length; for (int i = 0; i < count; i++) { @@ -755,7 +764,7 @@ public class RelativeLayout extends ViewGroup { private View getRelatedView(int[] rules, int relation) { int id = rules[relation]; if (id != 0) { - View v = findViewById(id); + View v = mGraph.mNodes.get(id).view; if (v == null) { return null; } @@ -763,7 +772,7 @@ public class RelativeLayout extends ViewGroup { // Find the first non-GONE view up the chain while (v.getVisibility() == View.GONE) { rules = ((LayoutParams) v.getLayoutParams()).getRules(); - v = v.findViewById(rules[relation]); + v = mGraph.mNodes.get((rules[relation])).view; if (v == null) { return null; } @@ -1100,12 +1109,6 @@ public class RelativeLayout extends ViewGroup { 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 * view id (see View#getId()). */ @@ -1129,7 +1132,6 @@ public class RelativeLayout extends ViewGroup { } nodes.clear(); - mNakedRoots.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. */ void add(View view) { - final int id = view.getId(); - - if (id != View.NO_ID) { - mNodes.put(id, Node.acquire(view)); - } else { - mNakedRoots.add(view); - } + mNodes.put(view.getId(), Node.acquire(view)); } /** @@ -1162,12 +1158,6 @@ public class RelativeLayout extends ViewGroup { final LinkedList<Node> roots = findRoots(rules); 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) { final Node node = roots.removeFirst(); final View view = node.view; @@ -1259,17 +1249,13 @@ public class RelativeLayout extends ViewGroup { * @param rules The list of rules to take into account. */ void log(Resources resources, int... rules) { - for (View view : mNakedRoots) { - printViewId(resources, view); - } - final LinkedList<Node> roots = findRoots(rules); for (Node node : roots) { printNode(resources, node); } } - private static void printViewId(Resources resources, View view) { + static void printViewId(Resources resources, View view) { if (view.getId() != View.NO_ID) { d(LOG_TAG, resources.getResourceEntryName(view.getId())); } else { |
