Android Open Source - sres Attribute






From Project

Back to project page sres.

License

The source code is released under:

Apache License

If you think the Android project sres 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

package me.tatarka.sres.ast;
/* w  w w .ja va 2 s .c om*/
import java.util.Objects;

/**
 * Created by evan on 2/27/14.
 */
public class Attribute {
    public static final String ID = "android:id";
    public static final String LAYOUT_WIDTH = "android:layout_width";
    public static final String LAYOUT_HEIGHT = "android:layout_height";
    public static final String LAYOUT = "layout";
    public static final String BIND_CLASS = "bind:class";

    public final String name;
    public final String value;

    public Attribute(String name, String value) {
        this(name, value, Namespace.ANDROID);
    }

    public Attribute(String name, String value, Namespace namespace) {
        this.name = normalizeName(name, namespace);
        this.value = normalizeValue(this.name, value, namespace);
    }

    private static String normalizeName(String name, Namespace namespace) {
        if (namespace == Namespace.NONE || name.contains(":")) return name;
        return namespace + ":" + name;
    }

    private static String normalizeValue(String name, String value, Namespace namespace) {
        if (namespace != Namespace.ANDROID) return value;

        if (name.equals(LAYOUT_WIDTH) || name.equals(LAYOUT_HEIGHT)) {
            if (value.equals("match")) return "match_parent";
            if (value.equals("wrap")) return "wrap_content";
            return value;
        } else {
            return value;
        }
    }

    public String simpleName() {
        if (name.contains(":")) return name.split(":")[1];
        return name;
    }

    public boolean isBinding() {
        return name.startsWith(Namespace.BIND.toString()) && !name.equals(BIND_CLASS);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, value);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || obj.getClass() != getClass()) return false;
        Attribute other = (Attribute) obj;
        return Objects.equals(name, other.name) && Objects.equals(value, other.value);
    }

    @Override
    public String toString() {
        return name + "=" + value;
    }

    public static enum Namespace {
        ANDROID, BIND, APP, NONE;

        @Override
        public String toString() {
            switch (this) {
                case ANDROID:return "android";
                case BIND: return "bind";
                case APP: return "app";
            }
            return "";
        }
    }
}




Java Source Code List

me.tatarka.sres.AbstractTrackable.java
me.tatarka.sres.Bindable.java
me.tatarka.sres.ChangeTracker.java
me.tatarka.sres.FileFilter.java
me.tatarka.sres.LayoutGenerator.java
me.tatarka.sres.LayoutParser.java
me.tatarka.sres.LayoutSelectorHelper.java
me.tatarka.sres.LayoutSelector.java
me.tatarka.sres.ListView.java
me.tatarka.sres.Main.java
me.tatarka.sres.ObservableAdapter.java
me.tatarka.sres.ObservableArrayList.java
me.tatarka.sres.ObservableListViewHelper.java
me.tatarka.sres.ObservableList.java
me.tatarka.sres.ObservablePagerAdapter.java
me.tatarka.sres.SResBaseVisitor.java
me.tatarka.sres.SResLexer.java
me.tatarka.sres.SResOutput.java
me.tatarka.sres.SResParser.java
me.tatarka.sres.SResVisitor.java
me.tatarka.sres.SRes.java
me.tatarka.sres.SourceInfo.java
me.tatarka.sres.ThreadHandlerImpl.java
me.tatarka.sres.ThreadHandlerProvider.java
me.tatarka.sres.ThreadHandler.java
me.tatarka.sres.Trackable.java
me.tatarka.sres.ViewPager.java
me.tatarka.sres.ast.Attribute.java
me.tatarka.sres.ast.Binding.java
me.tatarka.sres.ast.Child.java
me.tatarka.sres.ast.Converter.java
me.tatarka.sres.ast.Include.java
me.tatarka.sres.ast.RootView.java
me.tatarka.sres.ast.View.java
me.tatarka.sres.idea.SResFileTypeFactory.java
me.tatarka.sres.idea.SResFileType.java
me.tatarka.sres.idea.SResFile.java
me.tatarka.sres.idea.SResIcons.java
me.tatarka.sres.idea.SResLanguage.java
me.tatarka.sres.idea.SResLexer.java
me.tatarka.sres.idea.SResParserDefinition.java
me.tatarka.sres.idea._SResLexer.java
me.tatarka.sres.idea.psi.SResElementType.java
me.tatarka.sres.idea.psi.SResTokenType.java
me.tatarka.sres.impl.SResCodeLayoutGenerator.java
me.tatarka.sres.impl.SResLayoutParser.java
me.tatarka.sres.impl.SResVisitor.java
me.tatarka.sres.impl.SResXmlLayoutGenerator.java
me.tatarka.sres.impl.WriterCodeWriter.java
me.tatarka.sres.property.BooleanProperty.java
me.tatarka.sres.property.ByteProperty.java
me.tatarka.sres.property.CharProperty.java
me.tatarka.sres.property.DoubleProperty.java
me.tatarka.sres.property.FloatProperty.java
me.tatarka.sres.property.IntProperty.java
me.tatarka.sres.property.LongProperty.java
me.tatarka.sres.property.Property.java
me.tatarka.sres.property.ShortProperty.java
me.tatarka.sres.sample.MainActivity.java
me.tatarka.sres.sample.MyListItemView.java
me.tatarka.sres.sample.MyListItem.java
me.tatarka.sres.sample.MyMainView.java
me.tatarka.sres.sample.MyModel.java
me.tatarka.sres.sample.MyView.java
me.tatarka.sres.util.PathTransformer.java