Skip to content

Sou6900/XHLP_Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Colors Icon XHLP 1.0 : Android XML Layout Preview Engine

A comprehensive, client-side rendering engine designed to parse, calculate, and visualize Android XML layouts within a web-based environment. This system replicates key portions of the Android UI framework, including the complex measurement and layout passes required for ConstraintLayout and MotionLayout.

System Overview

This engine operates by parsing raw Android XML resources and converting them into a DOM structure styled dynamically via JavaScript. It features a custom-built constraint solver, a resource resolution system for handling Android-specific references, and a dual-mode rendering pipeline (Design and Blueprint).

Colors Icon

Core Capabilities

  • XML Parsing & DOM Construction: Converts Android XML hierarchies into web-compatible DOM elements while maintaining attribute integrity.

  • Resource Resolution: Resolves Android resource references including @string, @color, @dimen, and @style. It supports basic theme attribute resolution (?attr).

  • Drawable Rendering: Support for complex Android drawables, including:

  • VectorDrawable (XML to SVG conversion)

  • ShapeDrawable (Gradients, corners, strokes)

  • StateListDrawable (Selector logic)

  • Density Conversion: Automatic pixel-to-dp conversion based on configurable device density buckets (mdpi, hdpi, xhdpi, etc.).

Layout Systems

The engine implements distinct logic for measuring and positioning views based on their parent layout type:

  • ConstraintLayout System: A fully implemented algebraic solver that supports:

  • Relative positioning (Start/End, Top/Bottom).

  • Chains (Spread, Packed, Spread Inside).

  • Guidelines (Vertical/Horizontal, Percent/Dimension).

  • Barriers (Dynamic referencing).

  • Bias settings and Dimension ratios.

  • Circular positioning.

  • Linear & Relative Systems: Logic for weight distribution in linear containers and dependency graph resolution for relative positioning.

  • MotionLayout Support: Parses MotionScene files to handle state transitions and constraint sets, enabling animation previews.

Widget Support

The engine includes a library of renderers for standard Android UI components, ensuring accurate visual representation of attributes:

  • Basic Inputs & Controls: Full support for TextView, Button, EditText, CheckBox, Switch, SeekBar, and ProgressBar.
  • Media & Graphics: Rendering logic for ImageView (supporting various scale types) and ShapeDrawable backgrounds.
  • Complex Containers: Implementation of ScrollView, HorizontalScrollView, CardView, and NavigationView.
  • Collections: Visual placeholders for RecyclerView to assist in list layout design.
  • Constraint Helpers: Functional implementation of non-visual helper widgets including Group, Flow, Layer, and Placeholder.

Visual Tooling

  • Blueprint Mode: A technical view mode that visualizes the relationship between views. It renders constraint connections, spring/zigzag lines for loose connections, anchor points, and chain linkages using a dedicated SVG overlay layer.
  • Attribute Inspector: A sidebar interface for inspecting selected view properties, layout parameters, and active constraints.
  • Constraint Widget: A visual representation of margins, bias, and view dimensions (wrap_content, match_parent, 0dp) for the selected element.
  • Logcat UI: An integrated logging interface to display parsing errors, missing resources, and system warnings.

Architecture

The project is structured into modular components to ensure separation of concerns:

  • Solvers: Contains the mathematical logic for calculating view positions. This includes specialized calculators for flow, chains, and dimension estimation.
  • Parsers: Responsible for reading raw XML content (Manifests, Layouts, Styles, Motion Scenes) and converting them into usable JavaScript objects.
  • Renderers: Handles the drawing logic. This is split into core view rendering and blueprint/overlay rendering.
  • Resolvers: Manages the linking of resources and attributes to the views.
  • UI Controls: Manages the toolbar, zoom controls, device frame simulation, and user interaction events.

Tests & Accuracy

Pass Rate: 95%+ Tested against 300+ complex Android XML layouts, including deeply nested ConstraintLayouts, RTL/LTR combinations, barriers, chains, flows, and edge-case constraint interactions.

Accuracy: 90% – 95% overall Accuracy is measured by comparing computed view geometry

Remember This Engine not Always correct but maximum time perfect preview

Other tests waiting for you ❤️


Component Support Status

The following metrics represent the current implementation maturity of specific Android components within this engine.

ConstraintLayout
92%
LinearLayout
95%
RelativeLayout
85%
MotionLayout
65%
Vector Drawables
80%
Resource Resolution
75%
Standard Widgets
88%

About

XHLP Engine : parses Android XML layouts, resolves constraints using solver-style logic, and computes concrete geometry values (left, top, width, height) for each view. The result is a deterministic, debuggable HTML preview that reflects real constraint relationships, not guesses

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors