using namespace std;
using namespace tinyxml2;
#define LAYOUT_DIR "/data/res/layout"

enum ElementType {
	E_NONE = -1, E_ROOT, E_TEXT, E_REGION, E_IMAGE, E_BACKGROUND, E_NUMS
};
static const char *g_tags[] =
		{ "Layout", "Text", "Region", "Image", "Background" };

typedef struct _UiElement {
	int x;
	int y;
	int w;
	int h;
	const char *id;
	const char *color;
	const char *text;
	const char *img;
	ElementType type;
	struct _UiElement* next;
	_UiElement() {
		x = 0;
		y = 0;
		w = 0;
		h = 0;
		id = NULL;
		color = NULL;
		text = NULL;
		img = NULL;
		type = E_NONE;
		next = NULL;
	}
	void dump(){
		LOGD("[%d,%d,%d,%d] @ %s @ %s @ %s @ %s @ %d\n",x,y,w,h,id,color,text,img,type);
	}
} UiElement;

typedef struct _layout {
	UiElement *ui_list;
	const char *id;
} Layout;

typedef android::List<Layout*> LayoutCollection;

typedef struct _color_struct {
	int r;
	int g;
	int b;
	int a;
	_color_struct() {
		r = g = b = 0;
		a = 255;
	}
	_color_struct(const char *hex_color) {
		if (!hex_color) {
			return;
		}
		// #ff00ff00
		//  a r g b
		sscanf(hex_color, "#%02x%02x%02x%02x", &a, &r, &g, &b);
	}
} Color;


class LayoutManager {
public:

public:

	~ LayoutManager() {
	}

	static LayoutManager* GetInstance();

	Layout* LoadSurface(const char *layout);

	bool LoadAllSurface();
	Layout* FindLayoutById(const char* layoutId);

	bool RenderLayout(Layout *layout);

	void DestroyLayout();
private:
	LayoutManager();
	LayoutCollection *mLayouts;
	static LayoutManager *m_pInstance;
};
