private static final String SDK_URL =
"http://d.android.com/guide/topics/resources/color-list-resource.html"; //$NON-NLS-1$
+ public static final String SELECTOR_TAG = "selector"; //$NON-NLS-1$
+ public static final String ATTR_COLOR = "color"; //$NON-NLS-1$
+
/** The root element descriptor */
private ElementDescriptor mDescriptor = new ElementDescriptor(
- "selector", "Selector",
+ SELECTOR_TAG, "Selector",
"Required. This must be the root element. Contains one or more <item> elements.",
SDK_URL,
new AttributeDescriptor[] { new XmlnsAttributeDescriptor(ANDROID_NS_NAME,
+ "its attributes. Must be a child of a <selector> element.",
SDK_URL,
new ReferenceAttributeDescriptor(
- ResourceType.COLOR, "color", "color", //$NON-NLS-1$ //$NON-NLS-2$
+ ResourceType.COLOR, ATTR_COLOR, ATTR_COLOR,
SdkConstants.NS_RESOURCES,
"Hexadeximal color. Required. The color is specified with an RGB value and "
+ "optional alpha channel.\n"
import static com.android.ide.eclipse.adt.internal.editors.AndroidXmlAutoEditStrategy.findLineStart;
import static com.android.ide.eclipse.adt.internal.editors.AndroidXmlAutoEditStrategy.findTextStart;
+import static com.android.ide.eclipse.adt.internal.editors.color.ColorDescriptors.SELECTOR_TAG;
import static org.eclipse.jface.text.formatter.FormattingContextProperties.CONTEXT_MEDIUM;
import static org.eclipse.jface.text.formatter.FormattingContextProperties.CONTEXT_PARTITION;
import static org.eclipse.jface.text.formatter.FormattingContextProperties.CONTEXT_REGION;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.ui.internal.XMLFormattingStrategy;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
// The "resource" style is used for most value-based XML files:
// strings, dimensions, booleans, colors, integers, plurals,
// integer-arrays, string-arrays, and typed-arrays
- if (domDocument.getDocumentElement() != null
- && ResourcesDescriptors.ROOT_ELEMENT.equals(domDocument.getDocumentElement()
- .getTagName())) {
+ Element rootElement = domDocument.getDocumentElement();
+ if (rootElement != null
+ && ResourcesDescriptors.ROOT_ELEMENT.equals(rootElement.getTagName())) {
+ style = XmlFormatStyle.RESOURCE;
+ }
+
+ // Selectors are also used similar to resources
+ if (rootElement != null && SELECTOR_TAG.equals(rootElement.getTagName())) {
style = XmlFormatStyle.RESOURCE;
}
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH;
import static com.android.ide.common.layout.LayoutConstants.ATTR_STYLE;
+import static com.android.ide.eclipse.adt.internal.editors.color.ColorDescriptors.ATTR_COLOR;
import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
return 50;
}
+ // "color" sorts to the end
+ if (ATTR_COLOR.equals(name)) {
+ return 100;
+ }
+
return 60;
}
}
"<selector xmlns:android=\"http://schemas.android.com/apk/res/android\" >\n" +
"\n" +
" <item\n" +
- " android:color=\"#ffff0000\"\n" +
- " android:state_pressed=\"true\"></item> <!-- pressed -->\n" +
+ " android:state_pressed=\"true\"\n" +
+ " android:color=\"#ffff0000\"></item> <!-- pressed -->\n" +
"\n" +
" <item\n" +
- " android:color=\"#ff0000ff\"\n" +
- " android:state_focused=\"true\"></item> <!-- focused -->\n" +
+ " android:state_focused=\"true\"\n" +
+ " android:color=\"#ff0000ff\"></item> <!-- focused -->\n" +
"\n" +
" <item android:color=\"#ff000000\"></item> <!-- default -->\n" +
"\n" +
"</selector>");
}
+ public void testFormatColorList() throws Exception {
+ checkFormat(
+ XmlFormatStyle.RESOURCE,
+ "<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
+ "<item android:state_activated=\"true\" android:color=\"#FFFFFF\"/>\n" +
+ "<item android:color=\"#777777\" /> <!-- not selected -->\n" +
+ "</selector>",
+
+ "<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
+ "\n" +
+ " <item android:state_activated=\"true\" android:color=\"#FFFFFF\"/>\n" +
+ " <item android:color=\"#777777\"/> <!-- not selected -->\n" +
+ "\n" +
+ "</selector>");
+ }
+
public void testPreserveNewlineAfterComment() throws Exception {
checkFormat(
XmlFormatStyle.RESOURCE,