Android Open Source - android-shape-imageview Id Handler






From Project

Back to project page android-shape-imageview.

License

The source code is released under:

Apache License

If you think the Android project android-shape-imageview 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 com.github.siyamed.shapeimageview.path.parser;
/*  w w  w . j a v  a 2  s .  c o m*/
import android.util.Log;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Stack;

@SuppressWarnings("StatementWithEmptyBody")
class IdHandler {
    private static final String TAG = SvgToPath.TAG;

    final HashMap<String, String> idXml = new HashMap<String, String>();
    private final Stack<IdRecording> idRecordingStack = new Stack<IdRecording>();

    private final XmlPullParser atts;

    IdHandler(XmlPullParser atts) {
        this.atts = atts;
    }

    class IdRecording {
        final String id;
        int level;
        final StringBuilder sb;

        public IdRecording (String id) {
            this.id = id;
            this.level = 0;
            this.sb = new StringBuilder();
        }
    }

    public void processIds() throws XmlPullParserException, IOException {
        int eventType = atts.getEventType();
        do {
            if(eventType == XmlPullParser.START_DOCUMENT) {
                // no op
            } else if(eventType == XmlPullParser.END_DOCUMENT) {
                // no op
            } else if(eventType == XmlPullParser.START_TAG) {
                startElement();
            } else if(eventType == XmlPullParser.END_TAG) {
                endElement();
            } else if(eventType == XmlPullParser.TEXT) {
                // not implemented
            }
            eventType = atts.next();
        } while (eventType != XmlPullParser.END_DOCUMENT);
    }


    private void appendElementString(StringBuilder sb, String localName, XmlPullParser atts) {
        sb.append("<");
        sb.append(localName);
        for (int i = 0; i < atts.getAttributeCount(); i++) {
            sb.append(" ");
            sb.append(atts.getAttributeName(i));
            sb.append("='");
            sb.append(ParseUtil.escape(atts.getAttributeValue(i)));
            sb.append("'");
        }
        sb.append(">");
    }

    void startElement() {
        String localName = atts.getName();
        String id = ParseUtil.getStringAttr("id", atts);
        if (id != null) {
            IdRecording ir = new IdRecording(id);
            idRecordingStack.push(ir);
        }
        if (idRecordingStack.size() > 0){
            IdRecording ir = idRecordingStack.lastElement();
            ir.level++;
            //appendElementString(ir.sb, atts.getNamespace(), localName, atts.getName(), atts);
            appendElementString(ir.sb, localName, atts);
        }
    }

    void endElement() {
        String localName = atts.getName();
        if (idRecordingStack.size() > 0){
            IdRecording ir = idRecordingStack.lastElement();
            ir.sb.append("</");
            ir.sb.append(localName);
            ir.sb.append(">");
            ir.level--;
            if (ir.level == 0) {
                String xml = ir.sb.toString();
                //Log.d(TAG, "Added element with id " + ir.id + " and content: " + xml);
                idXml.put(ir.id, xml);
                idRecordingStack.pop();
                if (idRecordingStack.size() > 0){
                    idRecordingStack.lastElement().sb.append(xml);
                }
                Log.w(TAG, xml);
            }
        }
    }
}




Java Source Code List

com.github.siyamed.shapeimageview.BubbleImageView.java
com.github.siyamed.shapeimageview.CircularImageView.java
com.github.siyamed.shapeimageview.DiamondImageView.java
com.github.siyamed.shapeimageview.HeartImageView.java
com.github.siyamed.shapeimageview.HexagonImageView.java
com.github.siyamed.shapeimageview.OctogonImageView.java
com.github.siyamed.shapeimageview.PentagonImageView.java
com.github.siyamed.shapeimageview.RoundedImageView.java
com.github.siyamed.shapeimageview.ShaderImageView.java
com.github.siyamed.shapeimageview.ShapeImageView.java
com.github.siyamed.shapeimageview.StarImageView.java
com.github.siyamed.shapeimageview.mask.PorterCircularImageView.java
com.github.siyamed.shapeimageview.mask.PorterImageView.java
com.github.siyamed.shapeimageview.mask.PorterShapeImageView.java
com.github.siyamed.shapeimageview.path.SvgUtil.java
com.github.siyamed.shapeimageview.path.parser.CopyInputStream.java
com.github.siyamed.shapeimageview.path.parser.IdHandler.java
com.github.siyamed.shapeimageview.path.parser.IoUtil.java
com.github.siyamed.shapeimageview.path.parser.NumberParse.java
com.github.siyamed.shapeimageview.path.parser.ParseUtil.java
com.github.siyamed.shapeimageview.path.parser.ParserHelper.java
com.github.siyamed.shapeimageview.path.parser.PathInfo.java
com.github.siyamed.shapeimageview.path.parser.PathParser.java
com.github.siyamed.shapeimageview.path.parser.SvgToPath.java
com.github.siyamed.shapeimageview.path.parser.TransformParser.java
com.github.siyamed.shapeimageview.sample.SampleActivity.java
com.github.siyamed.shapeimageview.sample.SampleBubbleFragment.java
com.github.siyamed.shapeimageview.sample.SampleFragment.java
com.github.siyamed.shapeimageview.sample.SampleListFragment.java
com.github.siyamed.shapeimageview.shader.BubbleShader.java
com.github.siyamed.shapeimageview.shader.CircleShader.java
com.github.siyamed.shapeimageview.shader.RoundedShader.java
com.github.siyamed.shapeimageview.shader.ShaderHelper.java
com.github.siyamed.shapeimageview.shader.SvgShader.java