Android Open Source - sres View






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 ww .j  av a2s  . c  om*/
import com.google.common.base.CaseFormat;
import org.antlr.v4.runtime.misc.NotNull;

import java.util.*;


/**
 * Created by evan on 2/27/14.
 */
public class View implements Child {
    public final String name;
    public final java.util.Set<Attribute> attributes;
    public final java.util.Set<Binding> bindings;
    public final List<Child> children;
    public final String id;

    public View(@NotNull String name, @NotNull java.util.Set<Attribute> attributes,
                @NotNull List<Child> children) {
        this.name = name;
        this.attributes = Collections.unmodifiableSet(attributes);
        this.children = Collections.unmodifiableList(children);
        this.id = findId();
        this.bindings = findBindings();
    }

    private String findId() {
        for (Attribute attribute : attributes) {
            if (attribute.name.equals(Attribute.ID)) return attribute.value;
        }
        return null;
    }

    private Set<Binding> findBindings() {
        Set<Binding> bindings = new LinkedHashSet<>();
        for (Attribute attribute : attributes) {
            if (attribute.isBinding()) {
                bindings.add(new Binding(attribute.simpleName(), attribute.value));
            }
        }
        return bindings;
    }

    public String qualifiedName() {
        if (name.contains(".")) return name;
        return "android.widget." + name;
    }

    public String idReference() {
        return id.replaceFirst("@\\+?(\\w+:)?id/", "");
    }

    public String variableName() {
        if (id == null) return null;
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, idReference());
    }

    public static Builder of(String name) {
        return new Builder(name);
    }

    public static class Builder implements Child.Builder {
        private String name;
        private java.util.Set<Attribute> attributes = new LinkedHashSet<>();
        private List<Child> children = new ArrayList<>();

        public Builder(String name) {
            this.name = name;
        }

        public Builder id(String id) {
            return attribute(Attribute.ID, id);
        }

        public Builder size(String width, String height) {
            attribute(Attribute.LAYOUT_WIDTH, width);
            attribute(Attribute.LAYOUT_HEIGHT, height);
            return this;
        }

        public Builder bindClass(String bindClass) {
            return attribute(Attribute.BIND_CLASS, bindClass);
        }

        public Builder bind(String name, String value) {
            return attribute(new Attribute(name, value, Attribute.Namespace.BIND));
        }

        public Builder attribute(Attribute attribute) {
            attributes.add(attribute);
            return this;
        }

        public Builder attribute(String name, String value) {
            return attribute(new Attribute(name, value));
        }

        public Builder child(Child child) {
            children.add(child);
            return this;
        }

        public Builder child(Child.Builder child) {
            return child(child.build());
        }

        @Override
        public View build() {
            return new View(name, attributes, children);
        }
    }

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

    @Override
    public boolean equals(Object obj) {
        if (obj == null || obj.getClass() != getClass()) return false;
        View other = (View) obj;
        return Objects.equals(name, other.name)
                && Objects.equals(attributes, other.attributes)
                && Objects.equals(children, other.children);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder(name + "(\n");
        for (Attribute attribute : attributes) {
            builder.append(attribute.toString()).append("\n");
        }
        for (Child child : children) {
            builder.append(child.toString()).append("\n");
        }
        builder.append(")");

        return builder.toString();
    }
}




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