网站建设资讯

NEWS

网站建设资讯

关于android树的信息

如何在android上打印dom树,render树,display

在做chromium的时候,我们在debug的时候经常使用dumprendertree去打印网页对应的dom树等内容。

创新互联从2013年开始,先为威县等服务建站,威县等地企业,进行企业商务咨询服务。为威县企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

但是在刚接触android的时候,一直非常烦恼怎么用android自带的browser去打印出来这些内容。

幸好的是,framework里面提供了一些接口,让我们可以实现这个功能。

于是,写了个新的feature,在android的browser里面,按下menu键,就会增加三个新的选项。点击响应的选项,就会打印出来相对应的tree.

废话不多说,直接贴code。

在browser的app中做下列修改:

diff --git a/res/menu/browser.xml b/res/menu/browser.xml

index 49fc4a4..08a240f 100644

--- a/res/menu/browser.xml

+++ b/res/menu/browser.xml

@@ -80,6 +80,18 @@

item

android:id="@+id/save_snapshot_menu_id"

android:title="@string/menu_save_snapshot" /

+ !--Add print_dom_tree by chao S --

+ item

+ android:id="@+id/print_dom_tree"

+ android:title="@string/dom_tree_title" /

+ item

+ android:id="@+id/print_render_tree"

+ android:title="@string/render_tree_title" /

+ item

+ android:id="@+id/print_display_tree"

+ android:title="@string/display_tree_title" /

+

+ !--Add print_dom_tree by chao E --

/group

group

android:id="@+id/SNAPSHOT_MENU"

diff --git a/res/values/strings.xml b/res/values/strings.xml

index 870d0c7..c5dbf50 100644

--- a/res/values/strings.xml

+++ b/res/values/strings.xml

@@ -908,7 +908,11 @@

!-- The description of the suggestion that lets the user search the web for the query currently

in the text field. --

string name="search_the_web"Search the web/string

-

+ !-- Add print_dom_tree by chao S --

+ string name="dom_tree_title"Print Dom tree/string

+ string name="render_tree_title"Print render tree/string

+ string name="display_tree_title"Print display tree/string

+ !-- Add print_dom_tree by chao E --

!-- HTML5 dialogs --

!-- Used as a status bar notification when the browser is running out of space trying to allocate or increase the database quota for an HTML5 databae or application cache. --

string name="webstorage_outofspace_notification_title"Browser storage full/string

diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java

index 358e746..ac3d813 100644

--- a/src/com/android/browser/Controller.java

+++ b/src/com/android/browser/Controller.java

@@ -1967,6 +1967,23 @@ public class Controller extends FjController

if (source == null) break;

new SaveSnapshotTask(source).execute();

break;

+ // -- Add print_dom_tree by chao

+ case R.id.print_dom_tree:

+ final Tab dom = getTabControl().getCurrentTab();

+ dom.getWebViewClassic().dumpDomTree(true);

+ break;

+

+ case R.id.print_render_tree:

+ final Tab render = getTabControl().getCurrentTab();

+ render.getWebViewClassic().dumpRenderTree(true);

+ break;

+

+ case R.id.print_display_tree:

+ final Tab display = getTabControl().getCurrentTab();

+ display.getWebViewClassic().dumpDisplayTree();

+ break;

+

+ // Add print_dom_tree by chao --

case R.id.page_info_menu_id:

showPageInfo();

在framework中做下列修改:

diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java

index 4bfce04..d6c7cf3 100755

--- a/core/java/android/webkit/WebViewClassic.java

+++ b/core/java/android/webkit/WebViewClassic.java

@@ -5339,7 +5339,10 @@ public final class WebViewClassic extends FjWebViewClassic

* debug only

*/

public void dumpDomTree(boolean toFile) {

- mWebViewCore.sendMessage(EventHub.DUMP_DOMTREE, toFile ? 1 : 0, 0);

+ // -- Add print_dom_tree by chao

+ //mWebViewCore.sendMessage(EventHub.DUMP_DOMTREE, toFile ? 1 : 0, 0);

+ mWebViewCore.sendMessage(EventHub.DUMP_DOMTREE, toFile ? 1 : 1, 0);

+ // Add print_dom_tree by chao --

}

/**

@@ -5349,7 +5352,10 @@ public final class WebViewClassic extends FjWebViewClassic

* debug only

*/

public void dumpRenderTree(boolean toFile) {

- mWebViewCore.sendMessage(EventHub.DUMP_RENDERTREE, toFile ? 1 : 0, 0);

+ // -- Add print_dom_tree by chao

+ // mWebViewCore.sendMessage(EventHub.DUMP_RENDERTREE, toFile ? 1 : 0, 0);

+ mWebViewCore.sendMessage(EventHub.DUMP_RENDERTREE, toFile ? 1 : 1, 0);

+ // Add print_dom_tree by chao --

}

/**

extern/webkit中的修改如下:

diff --git a/Source/WebKit/android/AndroidLog.h b/Source/WebKit/android/AndroidLog.h

index f034d35..2efab96 100644

--- a/Source/WebKit/android/AndroidLog.h

+++ b/Source/WebKit/android/AndroidLog.h

@@ -37,12 +37,18 @@

#ifdef ANDROID_DOM_LOGGING

#include stdio.h

extern FILE* gDomTreeFile;

-#define DOM_TREE_LOG_FILE "/sdcard/domTree.txt"

+// -- Add print_dom_tree by chao

+// #define DOM_TREE_LOG_FILE "/sdcard/domTree.txt"

+#define DOM_TREE_LOG_FILE "/data/local/domTree.txt"

+// Add print_dom_tree by chao --

#define DUMP_DOM_LOGD(...) { if (gDomTreeFile) \

fprintf(gDomTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); }

extern FILE* gRenderTreeFile;

-#define RENDER_TREE_LOG_FILE "/sdcard/renderTree.txt"

+// -- Add print_dom_tree by chao

+// #define RENDER_TREE_LOG_FILE "/sdcard/renderTree.txt"

+#define RENDER_TREE_LOG_FILE "/data/local/renderTree.txt"

+// Add print_dom_tree by chao --

#define DUMP_RENDER_LOGD(...) { if (gRenderTreeFile) \

fprintf(gRenderTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); }

#else

@@ -50,8 +56,12 @@ extern FILE* gRenderTreeFile;

#define DUMP_RENDER_LOGD(...) ((void)0)

#endif /* ANDROID_DOM_LOGGING */

-#define DISPLAY_TREE_LOG_FILE "/sdcard/displayTree.txt"

-#define LAYERS_TREE_LOG_FILE "/sdcard/layersTree.plist"

+// -- Add print_dom_tree by chao

+//#define DISPLAY_TREE_LOG_FILE "/sdcard/displayTree.txt"

+//#define LAYERS_TREE_LOG_FILE "/sdcard/layersTree.plist"

+#define DISPLAY_TREE_LOG_FILE "/data/local/displayTree.txt"

+#define LAYERS_TREE_LOG_FILE "/data/local/layersTree.plist"

+// Add print_dom_tree by chao --

#define FLOAT_RECT_FORMAT "[x=%.2f,y=%.2f,w=%.2f,h=%.2f]"

#define FLOAT_RECT_ARGS(fr) fr.x(), fr.y(), fr.width(), fr.height()

本文为极度寒冰原创

Android RecyclerView 效果之树形折叠效果

项目中遇到类似,省/市/县/乡/村 这种多层级数据展示的效果.原先处理过两层或者多层数据嵌套展示,没有处理过这种多层数据嵌套展示的效果所以在此记录一下,增强点记忆.

2.1 DemoTreeAdapter.class

2.2 adapter子条目的布局

2.3 holder类

这里简单的运用RecyclerView 实现了简单的树形结构以及处理了经常遇到的问题,一般需求能满足,要是复杂页面需要定制处理

看都看了点个赞再走吧

android 树形ListView 控件怎么做

这个嘛,你可以这么实现,,用SimpleExpandableListAdapte...那里还要自己拼装组件哦.. 好麻烦的.


网站栏目:关于android树的信息
网站URL:http://njwzjz.com/article/dsddjss.html