Android Open Source - penmanship Image Group Handler






From Project

Back to project page penmanship.

License

The source code is released under:

Apache License

If you think the Android project penmanship 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.mindsnacks.penmanship.group_handlers;
/*from w ww.  j  a va  2s. c  om*/
import com.mindsnacks.penmanship.AndroidXMLConstants;
import com.mindsnacks.penmanship.AndroidXMLNode;
import java.util.Map;
import org.pegdown.ast.ExpImageNode;
import org.pegdown.ast.Node;

/** Created by Tony Cosentini Date: 12/4/13 Time: 1:14 PM */
public class ImageGroupHandler extends BaseHandler {
  public ImageGroupHandler(Builder builder) {
    super(builder);
  }

  public static class Builder extends BaseHandler.Builder {
    public Builder(Node rootNode) {
      super(rootNode);
    }

    @Override public ImageGroupHandler build() {
      return new ImageGroupHandler(this);
    }
  }

  public static boolean isValidNodeGroup(Node node) {
    if (node.getChildren().size() != 1) return false;

    boolean result = true;

    for (Node child : node.getChildren()) {
      result = result && isValidImageNode(child);
    }

    return result;
  }

  private static boolean isValidImageNode(Node node) {
    return node.getClass().equals(ExpImageNode.class);
  }

  @Override public AndroidXMLNode render() {
    ExpImageNode imageNode = (ExpImageNode)rootNode.getChildren().get(0);

    String imageFilenameWithoutExtension = imageNode.url.substring(0,
        imageNode.url.lastIndexOf('.'));

    String drawableSrc;

    if (namespace != null) {
      drawableSrc = String.format("@drawable/%s_%s", namespace, imageFilenameWithoutExtension);
    } else {
      drawableSrc = String.format("@drawable/%s", imageFilenameWithoutExtension);
    }

    Map<String, String> attributes = AndroidXMLConstants.getDefaultLayoutSizes();
    attributes.put(AndroidXMLConstants.ADJUST_VIEW_BOUNDS, AndroidXMLConstants.TRUE);
    attributes.put(AndroidXMLConstants.SOURCE, drawableSrc);
    attributes.put(AndroidXMLConstants.STYLE, "@style/markdroid_image");

    AndroidXMLNode imageViewNode = new AndroidXMLNode(AndroidXMLConstants.IMAGE_VIEW, attributes);
    return imageViewNode;
  }
}




Java Source Code List

com.mindsnacks.penmanship.AndroidMarkdownVisitor.java
com.mindsnacks.penmanship.AndroidXMLConstants.java
com.mindsnacks.penmanship.AndroidXMLNode.java
com.mindsnacks.penmanship.BaseVisitor.java
com.mindsnacks.penmanship.Penmanship.java
com.mindsnacks.penmanship.Penmanship.java
com.mindsnacks.penmanship.group_handlers.BaseHandler.java
com.mindsnacks.penmanship.group_handlers.ImageGroupHandler.java
com.mindsnacks.penmanship.group_handlers.TextNodeGroupHandler.java
com.penmanship.example.MainActivity.java