aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/AbsoluteLayoutRuleTest.java
Commit message (Collapse)AuthorAgeFilesLines
* Constants refactoring.Tor Norbye2012-09-131-1/+1
| | | | | | | | | | | | | | | | This changeset moves most constants into the SdkConstants class, and gets rid of AndroidConstants and LintConstants. It also migrates all non-ADT specific constants from AdtConstants into SdkConstants. It furthermore moves various other constants (such as those in XmlUtils and ValuesDescriptors) into the constants class. It also fixes the modifier order to be the canonical modifier order (JLS 8.x). Finally, it removes redundancy and combines various constant aliases such that we don't have both NAME_ATTR and ATTR_NAME pointing to "name", etc. Change-Id: Ifd1755016f62ce2dd80e5c76130d6de4b0e32161
* Refactor common.jarXavier Ducrohet2012-08-071-1/+1
| | | | | | | | | | | | | | | Move resources and com.android.util.Pair into layoutlib_api where they belong since layoutlib depends on them and we need to control the API. Made a copy of Pair to stay in common.jar but moved it to com.android.utils.Pair (the one in com.android.util.Pair is marked as deprecated to prevent usage where applicable). Also moved XmlUtil and PositionXmlParser to com.android.utils to match Pair. Change-Id: I21d7057d3f2ce604f86a3bb1fa3c130948c93b89
* Move XML code to the common libraryTor Norbye2012-05-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The ManifestMerger library needs to look up the prefix to use for the Android namespace, and the Document.lookupPrefix method is not implemented by the Eclipse DOM implementation (which throws an exception). However, we have an implementation of this in the ADT plugin. This changeset creates a new XmlUtils class in the common/ library (which is accessible by both ADT and the manifest merger, and the anttasks where the manifest merger is used), and moves the namespace prefix lookup code in there. It also moves the XML escape methods into that class. It also adds a new method to the ManifestMerger for merging directly from documents (rather than files), and makes sure that all the merging code goes via the prefix utility method rather than calling the document.lookupPrefix method. Finally, it moves the various string constants associated with XML namespaces into the single XmlUtils class, since these were spread across several different classes before (and many of them are needed in the XmlUtils class). The vast majority of the diffs in this changeset are related to simple import statement changes to reflect the new locations of these constants. Change-Id: Ib8f3d0e5c89e47e61ea509a23925af7b6580abee
* Fix linear layout and frame layout unit testsTor Norbye2011-08-051-1/+1
| | | | | | | | | I changed the code which draws drop feedback recently to use a more efficient call (calling drawRect(x1,y1,x2,y2) directly instead of constructing a new Rectangle object and calling drawRect(Rect). Some golden files checking graphics output needs to be updated. Change-Id: I369fed9cb0756ff4f3aa970c1bdd552d0f55faaa
* XML code completion improvementsTor Norbye2011-03-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset contains a number of improvements to the code completion in XML files. (1) Add suffix completion in attribute values. For dimensional attributes, this will add in (or complete prefixes of) units like "dp", "sp", etc. For fractional attributes, the % and %p suffixes are completed. (In both cases, there is also a tooltip message provided shown in the completion documentation popup). In addition, for flag values, when completing at the end of a flag, then the separator character (|) along with the other flag values (except those already set) are offered. (2) Handle completion when the caret is not at the end. For example, if you have the following source: layout_w^idth="wrap_content" (^ = caret position) then if you invoke code completion you will also be offered the attribute layout_weight, and selecting it will -replace- the layout_width attribute with layout_height, it will not insert layout_weight in the middle of layout_width. This handling is done not just for attribute names as shown here but for attribute values and element tag names as well. (3) Improve @resource/ completion sorting. When completing resources, consider which attribute is being completed, and use that information to sort the resources. For example, if completing a "text" attribute then @string/, and @android:string/ resources will be listed first. For attributes like margins @dimen will be first, for include layout the @layout attributes will be listed first, and so on. Also, the resources are sorted alphabetically as the second sort key. (4) Hide some builtin Eclipse code completion items. In particular, the default code completion provider for Eclipse will always add the current attribute value as a completion. This is extremely confusing since if you have a typo, code completion will tell you that what you have is okay. I personally witnessed this confusing a user who had typed something from memory and code completion seemed to him to "confirm" that he had it right. To fix this, the code which installs completion providers, will identify the builting WST completion provider, and when found, replace it with a "filtering" wrapper. This completion provider delegates all its calls to the WST completion provider, but it recognizes a few patterns, in particular the above attribute value completion proposal as well as some namespace and schema ones, and removes these. (The reason we only filter out these items instead of removing it completely is that the completion provider also appears to be responsible for inserting code templates defined by the user, and we don't want to neuter those if defined by the user.) (5) Fix a bunch of corner cases - flags could only have a single separator (|), resource attribute completion items were missing icons, and completion in some positions was not working. (6) Unit tests. There are now comprehensive unit tests for code completion. Each unit test points to a particular source file and a particular position within the source file, and code completion is invoked for that position. A set of unit tests dump out the allowed completion items for each such position, and these are compared against golden files. A second set of unit tests then specify a particular code completion item among the choices to be applied, and then applies that completion item to the document. This, along with the caret position (indicated as ^) is written into a golden file and used for comparisons. To make it easy to see what these tests do, the golden file is actually recorded as a diff, so in the test you will see something like this: Code completion in completion1.xml for android:gravity="left|b^ottom" selecting bottom: < android:gravity="left|bottom" --- > android:gravity="left|bottom^" (6) There are some other misc changes. We had some code which used "dip" for device indepdendent pixels (such as the AbsoluteLayout handler). Since "dp" seems to be preferred, the code will now use that instead. Change-Id: I8bd5c8336d8747dac1f10a9269ea4197f304cb70
* Various layout fixesTor Norbye2010-12-141-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, fix absolute layout such that it properly handles both screen scaling as well as various screen resolution densities when it computes the dip positions. Second, pass the bounds surrounding the mouse position when a drag is initiated to the view rules. This is used by both absolute layout and relative layout to properly handle dragging bounds. In particular, in relative layout this is used to match a border not only when the mouse cursor gets near the edge, but when the bound edges also get near the edge. In absolute layout this is used to show a correct bound rectangle that has the proper offset from the original drag position (which may not be the center, which until now it was assuming). Third, in RelativeLayout, when there are no children, offer a left alignment regardless of where you are within the rectangle. This is similar to how LinearLayout works. In addition, two internal changes: * Factor the various RelativeLayout string constants into the LayoutConstants class. This had the nice side effect of revealing a typo where we were referencing a non-existing value! Constants FTW! * Make the RulesEngine log the exceptions, not just the error messages, thrown by IViewRule calls. That way the full stack trace is available in the Error Viewer, including line numbers etc. Change-Id: I0b83df71b36741e65a1eb2003ed044157eb6f0cd
* Extract layout constants into a separate constants classTor Norbye2010-11-281-4/+6
| | | | | | | | | Combine the constants in BaseView and a LayoutConstants class over in the internal packages into a new LayoutConstants class, and reference these constants elsewhere (statically imported). This was suggested by in the feedback to review #18971. Change-Id: I40b76f8f6045c34a98f7a2363f96d2942360d1f3
* Unit test fixesTor Norbye2010-11-241-1/+1
| | | | | | | | | | | | | | | | | | First, the AddonsListFetcherTest#testLoadSample_1 was failing on the Mac, because the source code contained non-ASCII unicode characters, and the encoding differs between Windows, Linux and Mac -- and on the Mac the characters were garbage (not the intended Japanese characters). Fixed by using unicode escape sequences to define the expected output instead. Second, rename the AbstractLayoutTest to LayoutTestBase; the test runner (for plugins, not unit tests) was assuming this was a test case (even though it's an abstract class!) so it was emitting a warning about the class containing no test cases. This is simply a base class for all the individual layout tests defining a bunch of useful inherited shared behavior, so rename to avoid the warning. Change-Id: I6e29316c5644db35051218aef8b99ac41ab0cda4
* Add per-view custom initialization logicTor Norbye2010-11-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds support for adding custom-logic to initialize views, both to add children and default attributes and to customize layout attributes when added to a new parent. First, there is a new "onCreate" hook which is called to notify a view rule that an instance of its corresponding view has been created. This lets the ViewRule perform custom initialization of the object. The ViewRule is told what type of insertion occurred, such that it can distinguish between a newly created view, a view that is the result of a copy/paste, and a view that is part of a move operation. The changeset adds a number of new ViewRules which take advantage of this: - A TabHost rule creates the various skeleton children that are required, such as a TabWidget child with id @android:id/tabs and a FrameLayout child with id @android:id/tabcontent - A DialerFilter rule creates the mandatory EditText children ("hint" and "primary") - The HorizontalScrollView rule creates a horizontal LinearLayout child - The ImageButton and ImageViewButtons initialize the "src" attribute to a sample image - The MapViewRule initializes the apiKey attribute In addition, views are also notified when a new view is added as a child, such that they can perform additional customizations, in the form of an "onInsert" event. The most important application of this is LinearLayoutRule, which uses this to set reasonable defaults for the layout_width and layout_height parameters. It uses metadata (which is currently built into ADT but would ideally migrate into our XML config files) to determine whether a given child prefers to grow horizontally, grow vertically, both, or neither, depending on the surrounding parent context. For example, an EditText will default to filling the parent width if it is in a vertical LinearLayout, but it will not grow vertically in a horizontal linear layout. And so on. Various other rules also use the onInsert event to tweak children attributes. A ScrollView will for example always initialize its single child to match parent. Views can now also add plain menu items into the context menu, and the TableViewRule adds one such action: "Add Row", which appends a new row into the table. The Palette Preview code also invokes these creation hooks, such that if you for example drag a DialerFilter it can properly render since the mandatory children are created up front. This required various changes to the preview code to be able to handle XML edits by the rules. Finally, this changeset includes various other misc changes that I performed at the same time: - Removed SWT dependency from the ViewRule classes (SWT Rectangle use in Rect) - Fixed AbsoluteLayout unit test (issue 3203560) - Fixed positioning of the preview outline in LinearLayout when only one of the dimensions are clipped due to a smaller target layout Change-Id: I5956fe4e7a31a20b8dd2f9d9b0c1f90e2f75d68a
* Add layout unit testsTor Norbye2010-10-251-0/+73
Add layout unit tests, and some infrastructure for testing. Also fix some formatting errors (>100 column lines) in the previous commit. Change-Id: I3eabf30998ab7deb84df57e4d0c10cf57ee399d5