* [doc] Update android apil
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/commit/a6c603ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/tree/a6c603ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex-site/diff/a6c603ba Branch: refs/heads/master Commit: a6c603bab2a17f22d565594fe517b5396e8641a8 Parents: d6503a1 Author: york.sy <york...@alibaba-inc.com> Authored: Thu May 10 20:15:28 2018 +0800 Committer: york.sy <york...@alibaba-inc.com> Committed: Thu May 10 20:15:28 2018 +0800 ---------------------------------------------------------------------- source/cn/references/android-apis.md | 288 +++++++++++++++-------------- source/references/android-apis.md | 292 +++++++++++++++--------------- 2 files changed, 299 insertions(+), 281 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex-site/blob/a6c603ba/source/cn/references/android-apis.md ---------------------------------------------------------------------- diff --git a/source/cn/references/android-apis.md b/source/cn/references/android-apis.md index a00b83b..3c24a4f 100644 --- a/source/cn/references/android-apis.md +++ b/source/cn/references/android-apis.md @@ -10,100 +10,141 @@ version: 2.1 Weex åæ¥æ¥å ¥è¯·åèï¼https://github.com/weexteam/article/issues/25 -## WXSDKEngine æ¯ Weex 对å¤çæ»å ¥å£ã +## WXSDKEngine +WXSDKEngine æ¯ Weex 对å¤çæ»å ¥å£ã 主è¦æä¾äºä¸ä¸åè½ï¼ -1. 设置ç¸å ³ Adapter åè·å adapterã -2. 注åèªå®ä¹ module å component -3. éç½® JSFramework +1. 注åèªå®ä¹ module å component +1. 设置ç¸å ³ adapter åè·å adapterã -## Adapter ä»ç» -Weex 为äºéç¨ Native éç¨åºæä¾äºå¯¹åºçæ¥å£è¿è¡è®¾ç½®ã -1. IWXImgLoaderAdapter å¾çéé å¨ã +### 注åèªå®ä¹ module å component +#### component +Weexæä¾å¤ç§æ³¨å Componentçæ¹å¼ï¼å ¶ä¸æçæé«ç为 - Weex ä¼æéè¦è®¾ç½®å¾çç View å URL éé²åºæ¥ï¼Native 端éè¦å®ç°è¿ä¸ªæ¥å£è¿è¡å¾çä¸è½½ã Weex 没ææä¾å¾çé»è®¤å®ç°ã + public static boolean registerComponent(IFComponentHolder holder, boolean appendTree, String ... names) - æ¥å£å®ä¹å¦ä¸ï¼ +* holder 为ä¸ä¸ªæ½è±¡å·¥åï¼ç¨äºå建componentï¼å¯ä½¿ç¨ SimpleComponentHolder æ¥å¿«éçæ建该对象ã +* appendTree 为ä¸ä¸ªæ©å±æ è®°ä½ï¼ç®åææ æä¹ã +* names 表示该 component å¨å端代ç ä¸å称ï¼å¯æå¤ä¸ªå端ç»ä»¶æ å°æä¸ä¸ª component ã - ```java - public interface IWXImgLoaderAdapter { - void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy); - } - ``` +#### module +Weex æä¾å¦ä¸æ³¨å Module çæ¹å¼ï¼ - `WXImageQuality` 表示å¾ççè´¨éï¼`WXImageQuality` åå¦ä¸å¼ `LOW`, `NORMAL`, `HIGH`, `ORIGINAL` å¾çè´¨éä¾æ¬¡åé«ãé»è®¤ä¸º `LOW`ã`WXImageStrategy` 为æ©å±ç±»ï¼è¡¨ç¤ºäºå¾çæ¯å¦å¯ä»¥è£åª (isClipping) éå (isSharpen) å ä½ç¬¦ (placeHolder) çã + public static <T extends WXModule> boolean registerModule(String moduleName, Class<T> moduleClass,boolean global) throws WXException -2. IWXHttpAdapter ç½ç»ä¸è½½éé å¨ã +* moduleName å端代ç ä¸moduleçå称 +* moduleClass module对åºçClassï¼éè¦æä¾ä¸ä¸ªä¸å«åæ°çæé å½æ°ï¼æ使ç¨é»è®¤æé å½æ°ã +* global æ¯å¦ä¸ºå ¨å±å¯ä¸ï¼true ä¸ºå ¨å±å¯ä¸ï¼false 表示å WXSDKInstance ç»å®ã - Weex èªå®ä¹äº `WXRequest` å `OnHttpListener`ï¼Native éè½½æ¥å£åå¯ä»¥ä» Request ä¸è·åURLï¼Header çåæ°ï¼ç½ç»è¯·æ±å®æåå¯ä»¥éè¿ `OnHttpListener` è¿è¡åè°éç¥ãWeex æä¾äºé»è®¤ç½ç»è¯·æ±ï¼`DefaultWXHttpAdapter`ï¼ ä½¿ç¨çæ¯ `HttpURLConnection` è¿è¡ç½ç»è¯·æ±ã +### Adapter ä»ç» +第ä¸æ¹ App å¯è½éè¦å®ç°ä¸è¿°ç Adapterï¼æè½å®æ´ç使ç¨Weexçè½åã - æ¥å£å®ä¹å¦ä¸ï¼ +#### å¾çéé å¨ +Weex å¾çéé å¨è´è´£æ ¹æ®URLï¼å 载对åºçå¾çï¼å¾çéé å¨å为两ç§ï¼ +1. å° URL 对åºçå¾çå è½½å° View ä¸ +1. å° URL 对åºçå¾çå è½½å° Drawable 对象ä¸ã - ```java - public interface IWXHttpAdapter { - void sendRequest(WXRequest request, OnHttpListener listener); - } - ``` +第ä¸ç§å¾çéé å¨æ¯å¿ é¡»å®ç°ï¼ç¬¬äºç§å¾çéé å¨æ¯å¯éå®ç°ãWeex对äºè¿ä¸¤ç§å¾çéé å¨å没æé»è®¤å®ç°ã - `WXRequest` å®ä¹äºç½ç»è¯·æ±ç¸å ³çåæ°ï¼è¯·æ±æ¹æ³ï¼è¯·æ±ä¸»ä½ï¼è¶ æ¶æ¶é´ãWeexé»è®¤è¶ æ¶æ¶é´æ¯3000. +##### IWXImgLoaderAdapter +Weex ä¼æéè¦è®¾ç½®å¾çç View å URL éé²åºæ¥ï¼Native 端éè¦å®ç°è¿ä¸ªæ¥å£è¿è¡å¾çä¸è½½ã - `OnHttpListener` å®ä¹äºç½ç»è¯·æ±ç»æå对åºæ¹æ³ãå®ä¹å¦ä¸ï¼ +æ¥å£å®ä¹å¦ä¸ï¼ - ```java - interface OnHttpListener { - /** - * start request - */ - void onHttpStart(); + public interface IWXImgLoaderAdapter { + void setImage(String url, ImageView view, WXImageQuality quality,WXImageStrategy strategy); + } + +* `WXImageQuality` 表示å¾ççè´¨éï¼`WXImageQuality` åå¦ä¸å¼ `LOW`, `NORMAL`, `HIGH`, `ORIGINAL` å¾çè´¨éä¾æ¬¡åé«ãé»è®¤ä¸º `LOW`ã +* `WXImageStrategy` 为æ©å±ç±»ï¼è¡¨ç¤ºäºå¾çæ¯å¦å¯ä»¥è£åª (isClipping) éå (isSharpen) å ä½ç¬¦ (placeHolder) çã - /** - * headers received - */ - void onHeadersReceived(int statusCode,Map<String,List<String>> headers); +##### IDrawableLoader +Weex ä¼æéè¦è®¾ç½®å¾çç 对象(DrawableTarget) å URL éé²åºæ¥ï¼Native 端éè¦å®ç°è¿ä¸ªæ¥å£è¿è¡å¾çä¸è½½ã - /** - * post progress - * @param uploadProgress - */ - void onHttpUploadProgress(int uploadProgress); +æ¥å ¥è éè¦å®ç°DrawableTargetè¿ä¸ªç±»ï¼å¹¶å®ç° + void setDrawable(String url, DrawableTarget drawableTarget, DrawableStrategy drawableStrategy); +* `DrawableTarget` è¡¨ç¤ºå¾ å è½½ç对象ï¼éè¦æ¯`StaticTarget`æ`AnimatedTarget`ä¸çä¸ä¸ªã - /** - * response loaded length (bytes), full length should read from headers (content-length) - * @param loadedLength - */ - void onHttpResponseProgress(int loadedLength); +#### IWXHttpAdapter ç½ç»ä¸è½½éé å¨ - /** - * http response finish - * @param response - */ - void onHttpFinish(WXResponse response); - } - ``` +Weex èªå®ä¹äº `WXRequest` å `OnHttpListener`ï¼Native éè½½æ¥å£åå¯ä»¥ä» Request ä¸è·åURLï¼Header çåæ°ï¼ç½ç»è¯·æ±å®æåå¯ä»¥éè¿ `OnHttpListener` è¿è¡åè°éç¥ãWeex æä¾äºé»è®¤ç½ç»è¯·æ±ï¼`DefaultWXHttpAdapter`ï¼ ä½¿ç¨çæ¯ `HttpURLConnection` è¿è¡ç½ç»è¯·æ±ã + +æ¥å£å®ä¹å¦ä¸ï¼ -3. IWXUserTrackAdapter Weex ç¸å ³æ§è½æ°æ® (é¦å±å è½½æ¶é´ãJS-Native éä¿¡æ¶é´ãdom æ´æ°æ¶é´ç) åå ¶ä»éç¨ä¿¡æ¯ (JSLib æ件大å°, Weex SDK çæ¬å·ç)ã + public interface IWXHttpAdapter { + void sendRequest(WXRequest request, OnHttpListener listener); + } + +`WXRequest` å®ä¹äºç½ç»è¯·æ±ç¸å ³çåæ°ï¼è¯·æ±æ¹æ³ï¼è¯·æ±ä¸»ä½ï¼è¶ æ¶æ¶é´ãWeexé»è®¤è¶ æ¶æ¶é´æ¯3000. + +`OnHttpListener` å®ä¹äºç½ç»è¯·æ±ç»æå对åºæ¹æ³ãå®ä¹å¦ä¸ï¼ + + interface OnHttpListener { + /** + * start request + */ + void onHttpStart(); + + /** + * headers received + */ + void onHeadersReceived(int statusCode,Map<String,List<String>> headers); + + /** + * post progress + * @param uploadProgress + */ + void onHttpUploadProgress(int uploadProgress); + + /** + * response loaded length (bytes), full length should read from headers (content-length) + * @param loadedLength + */ + void onHttpResponseProgress(int loadedLength); + + /** + * http response finish + * @param response + */ + void onHttpFinish(WXResponse response); + } - æ¥å£å®ä¹ï¼ +#### IWXUserTrackAdapter åç¹éé å¨ - ```java - public interface IWXUserTrackAdapter { - void commit(Context context, String eventId, String type, WXPerformance perf, Map<String, Serializable> params); - } - ``` - Native å®ç°æ¥å£åå¯ä»¥éè¿ `WXPerformance` å `params` è·å对åºçä¿¡æ¯ã - WXPerformane 对åºå段表示å«ä¹è¯·åèææ¡£ï¼https://github.com/weexteam/article/issues/124 +æ¥å£å®ä¹ï¼ + + public interface IWXUserTrackAdapter { + void commit(Context context, String eventId, String type, WXPerformance perf, Map<String, Serializable> params); + } - åç»éçå¼å Weex è¿ä¼å®ä¹æ´å¤ç Adapterï¼æ¤ææ¡£ä¹ä¼å®æ¶æ´æ°ã +* Native å®ç°æ¥å£åå¯ä»¥éè¿ `WXPerformance` å `params` è·å对åºçä¿¡æ¯ã +* WXPerformane 对åºå段表示å«ä¹è¯·åèææ¡£ï¼https://github.com/weexteam/article/issues/124 -## Native å JS éä¿¡ +åç»éçå¼å Weex è¿ä¼å®ä¹æ´å¤ç Adapterï¼æ¤ææ¡£ä¹ä¼å®æ¶æ´æ°ã -1. èªå®ä¹äºä»¶éç¥ +#### IActivityNavBarSetter Weex导èªéé å¨ + +Weex æä¾äº `WXNavigatorModule` è¿è¡å¯¼èªæ§å¶ï¼å¯¹åºçæ¹æ³å¯ä»¥éè¿è®¾ç½® `IActivityNavBarSetter` æ¥å£è¿è¡å®å¶ã + +使ç¨æ¹æ³: - å¤ç¨äºæ个èªå®ä¹æ§ä»¶è¿è¡äºä»¶éç¥ï¼ä¾å¦èªå®ä¹ç¹å»äºä»¶ï¼ååºä¸æäºä»¶çã + WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter(){}); + +#### IWXStorageAdapter +Weexæä¾äº`WXStorageModule`å°ä¸äºæ°æ®åå¨å°æ¬å°ï¼WXStorageModuleä¾èµ`IWXStorageAdapter`æ¥æä½æ¬å°åå¨ç³»ç»ã Weexæä¾äºä¸ä¸ªé»è®¤çå®ç°ï¼DefaultWXStorageã + +#### IWXJSExceptionAdapter +Weexä¾èµ`IWXJSExceptionAdapter`æ¥å®ç°JavaScriptå¼å¸¸çå¤çï¼é»è®¤è¡ä¸ºæ¯å¿½ç¥JavaScriptå¼å¸¸ã + +## WXSDKInstance + +### Weex ä¸ Native å JS éä¿¡ + +#### èªå®ä¹äºä»¶éç¥ +å¤ç¨äºæ个èªå®ä¹æ§ä»¶è¿è¡äºä»¶éç¥ï¼ä¾å¦èªå®ä¹ç¹å»äºä»¶ï¼ååºä¸æäºä»¶çã WXSDKInstance.java - ```java public void fireEvent(String elementRef,final String type, final Map<String, Object> data,final Map<String, Object> domChanges){ } public void fireEvent(String elementRef,final String type, final Map<String, Object> data){ @@ -113,21 +154,15 @@ Weex 为äºéç¨ Native éç¨åºæä¾äºå¯¹åºçæ¥å£è¿è¡è®¾ç½®ã public void fireEvent(String elementRef, String type){ fireEvent(ref,type,new HashMap<String, Object>()); } - ``` - - `elementRef`ï¼äºä»¶åççæ§ä»¶ IDã - - `type`: èªå®ä¹äºä»¶ï¼Weex é»è®¤ä»¥ onXxxxx å¼å¤´ä¸ºèªå®ä¹äºä»¶ãonPullDown (ä¸æäºä»¶)ã - - `data`: éè¦éåºçåæ°ï¼ä¾å¦å½åæ§ä»¶ç大å°ï¼åæ çå ¶ä»ä¿¡æ¯ã - - `domChanges`ï¼æ´æ° ref 对åºæ§ä»¶ç Attribute å Styleã -2. äºä»¶åè° +* `elementRef`ï¼äºä»¶åççæ§ä»¶ IDã +* `type`: èªå®ä¹äºä»¶ï¼Weex é»è®¤ä»¥ onXxxxx å¼å¤´ä¸ºèªå®ä¹äºä»¶ãonPullDown (ä¸æäºä»¶)ã +* `data`: éè¦éåºçåæ°ï¼ä¾å¦å½åæ§ä»¶ç大å°ï¼åæ çå ¶ä»ä¿¡æ¯ã +* `domChanges`ï¼æ´æ° ref 对åºæ§ä»¶ç Attribute å Styleã - å¤ç¨äº Module åè°ï¼ä¾å¦å®ä½ Module å®æåéè¦éç¥ JSã使ç¨æ¹æ³å¦ä¸ï¼ +#### äºä»¶åè° +å¤ç¨äº Module åè°ï¼ä¾å¦å®ä½ Module å®æåéè¦éç¥ JSã使ç¨æ¹æ³å¦ä¸ï¼ - ```java public class WXLocation extends WXModule { @JSMethod @@ -143,60 +178,47 @@ Weex 为äºéç¨ Native éç¨åºæä¾äºå¯¹åºçæ¥å£è¿è¡è®¾ç½®ã //invokeæ¹æ³åinvokeAndKeepAlive两个æ¹æ³äºéä¸ } - } - ``` -## 注åæ»å¨äºä»¶ +### Weex åå ¶ä» Native ç»ä»¶é讯 + +#### 注åæ»å¨äºä»¶ Weex è·åæ»å¨äºä»¶å¯ä»¥éè¿ `WXSDKInstance` 注å `registerOnWXScrollListener` çå¬ æ¥å£å®ä¹å¦ä¸ï¼ -```java -public interface OnWXScrollListener { - - /** - * The view is not currently scrolling. - */ - int IDLE = RecyclerView.SCROLL_STATE_IDLE; - /** - * The view is currently being dragged by outside input such as user touch input. - */ - int DRAGGING = RecyclerView.SCROLL_STATE_DRAGGING; - /** - * The view is currently animating to a final position while not under - * outside control. - */ - int SETTLING = RecyclerView.SCROLL_STATE_SETTLING; - - /** - * Callback method to be invoked when the view has been scrolled. This will be - * called after the scroll has completed. - * <p> - * This callback will also be called if visible item range changes after a layout - * calculation. In that case, dx and dy will be 0. - * - */ - void onScrolled(View view, int x, int y); - - /** - * Callback method to be invoked when view's scroll state changes. - * - */ - void onScrollStateChanged(View view, int x, int y, int newState); -} -``` - -## èªå®ä¹NavBar - -Weex æä¾äº `WXNavigatorModule` è¿è¡å¯¼èªæ§å¶ï¼å¯¹åºçæ¹æ³å¯ä»¥éè¿è®¾ç½® `IActivityNavBarSetter` æ¥å£è¿è¡å®å¶ã - -使ç¨æ¹æ³: - -```java -WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter(){ -}); -``` + public interface OnWXScrollListener { + + /** + * The view is not currently scrolling. + */ + int IDLE = RecyclerView.SCROLL_STATE_IDLE; + /** + * The view is currently being dragged by outside input such as user touch input. + */ + int DRAGGING = RecyclerView.SCROLL_STATE_DRAGGING; + /** + * The view is currently animating to a final position while not under + * outside control. + */ + int SETTLING = RecyclerView.SCROLL_STATE_SETTLING; + + /** + * Callback method to be invoked when the view has been scrolled. This will be + * called after the scroll has completed. + * <p> + * This callback will also be called if visible item range changes after a layout + * calculation. In that case, dx and dy will be 0. + * + */ + void onScrolled(View view, int x, int y); + + /** + * Callback method to be invoked when view's scroll state changes. + * + */ + void onScrollStateChanged(View view, int x, int y, int newState); + } ## å ¶ä»ä»ç» ### å¨æéé å®¹å¨ @@ -204,14 +226,12 @@ WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter(){ å 为 Android ææºçç¢çå导è´å±å¹éé å¾å°é¾ãWeex 对å¤æä¾çæ¥å£ render éè¦å¨æä¼ å ¥å®¹å¨ç宽é«ï¼ä½æ¯ä¼ å ¥ç宽é«ææ¶ä¼åçååï¼ä¾å¦ ActionBar éèçï¼è¿æ¯ä¼ å ¥ç Weex 容å¨ä¹è¦è¿è¡å¯¹åºçååã 为äºéåºè¿ç§ååï¼Weex æä¾äºæ¥å£ `WXSDKInstance.setSize(int width, int height)` æ¥æ¹å容å¨ç大å°ã -```java -/** - * - * @param width 容å¨å®½åº¦ - * @param height 容å¨é«åº¦ - */ - public void setSize(int width, int height){}; -``` + /** + * + * @param width 容å¨å®½åº¦ + * @param height 容å¨é«åº¦ + */ + public void setSize(int width, int height){}; ### éçº§ä½¿ç¨ http://git-wip-us.apache.org/repos/asf/incubator-weex-site/blob/a6c603ba/source/references/android-apis.md ---------------------------------------------------------------------- diff --git a/source/references/android-apis.md b/source/references/android-apis.md index 44d1fe2..e262b39 100644 --- a/source/references/android-apis.md +++ b/source/references/android-apis.md @@ -10,203 +10,201 @@ version: 2.1 ## WXSDKEngine +1. Register the module and component 1. Set up various adapters -```java -WXSDKEngine.initialize(this, new InitConfig.Builder().setImgAdapter(new ImageAdapter()).setDebugAdapter(new PlayDebugAdapter()).build()); -``` +### Module & Component +#### Component +One can register a component using the following function: -2. Register the module and component + public static boolean registerComponent(IFComponentHolder holder, boolean appendTree, String ... names) -```java -WXSDKEngine.registerComponent("richtext", RichText.class); -WXSDKEngine.registerModule("event", WXEventModule.class); -``` -3. Overloading framework +* holder is a abstract factory designed for create Component, and SimpleComponentHolder is the a simple way to achieve IFComponentHolder. +* appendTree is an additional flag which is unused now. +* names is the component's name in front end template file. A Android component could be mapped into multiple names. -```java -WXSDKEngine.reload(this,framework,false); -``` +#### Module +One can register a module using the following way: -## Adapter + public static <T extends WXModule> boolean registerModule(String moduleName, Class<T> moduleClass,boolean global) throws WXException -1. IWXImgLoaderAdapter +* moduleName is the name in front end template. +* moduleClass is the Java class of the module, which provide a constructor with an empty parameter. +* global is a flag, true for singleton in the whole app, false for creating an object for each WXSDKIntance. - Weex need to implement this interface to download the picture - The interface is defined as follows: +### Adapter +#### ImageAdapter +Image adapter is responsible for loading images according to URLs. There are two types of image adapter: +1. Loading a image to a view according to URL. +1. Loading a image to a specified object according to URL. - ```java - public interface IWXImgLoaderAdapter { +In order to use image component, one must implement the first adapter, while the second adapter is optional. - void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy); - } - ``` +##### IWXImgLoaderAdapter - `WXImageQuality` that the quality of the picture variables, take the following values `LOW`, `NORMAL`, `HIGH`, `ORIGINAL` picture quality in turn higher. The default is `LOW`. + public interface IWXImgLoaderAdapter { + void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy); + } - `WXImageStrategy` is an extension class that indicates whether the image can be cut (isClipping) sharpening (isSharpen) placeholder (placeHolder) and so on. + * `WXImageQuality` that the quality of the picture variables, take the following values `LOW`, `NORMAL`, `HIGH`, `ORIGINAL` picture quality in turn higher. The default is `LOW`. + * `WXImageStrategy` is an extension class that indicates whether the image can be cut (isClipping) sharpening (isSharpen) placeholder (placeHolder) and so on. -2. IWXHttpAdapter +##### IDrawableLoaderAdapter +This adapter is optional. - Weex custom `WXRequest` and `OnHttpListener`, Native reload interface can be obtained from the Request URL, Header and other parameters, the network request can be completed through `OnHttpListener` callback notification. Weex provides the default network request: `DefaultWXHttpAdapter`, using `HttpURLConnection` for network requests. + void setDrawable(String url, DrawableTarget drawableTarget, DrawableStrategy drawableStrategy); - The interface is defined as follows: +* `DrawableTarget` is a object into where will load an image. `DrawableTarget` is one of `StaticTarget` or `AnimatedTarget`. - ```java - public interface IWXHttpAdapter { - void sendRequest(WXRequest request, OnHttpListener listener); - } - ``` +#### IWXHttpAdapter - `WXRequest` defines the parameters related to the network request, the request method, the request body, and the timeout time. Weex default timeout is 3000. +Weex custom `WXRequest` and `OnHttpListener`, Native reload interface can be obtained from the Request URL, Header and other parameters, the network request can be completed through `OnHttpListener` callback notification. Weex provides the default network request: `DefaultWXHttpAdapter`, using `HttpURLConnection` for network requests. - `OnHttpListener` defines the corresponding method after the network request ends. Defined as follows: +The interface is defined as follows: - ```java - interface OnHttpListener { + public interface IWXHttpAdapter { + void sendRequest(WXRequest request, OnHttpListener listener); + } - /** - * start request - */ - void onHttpStart(); +* `WXRequest` defines the parameters related to the network request, the request method, the request body, and the timeout time. Weex default timeout is 3000. - /** - * headers received - */ - void onHeadersReceived(int statusCode,Map<String,List<String>> headers); +* `OnHttpListener` defines the corresponding method after the network request ends. Defined as follows: - /** - * post progress - * @param uploadProgress - */ - void onHttpUploadProgress(int uploadProgress); + interface OnHttpListener { - /** - * response loaded length (bytes), full length should read from headers (content-length) - * @param loadedLength - */ - void onHttpResponseProgress(int loadedLength); + /** + * start request + */ + void onHttpStart(); - /** - * http response finish - * @param response - */ - void onHttpFinish(WXResponse response); + /** + * headers received + */ + void onHeadersReceived(int statusCode,Map<String,List<String>> headers); + + /** + * post progress + * @param uploadProgress + */ + void onHttpUploadProgress(int uploadProgress); + + /** + * response loaded length (bytes), full length should read from headers (content-length) + * @param loadedLength + */ + void onHttpResponseProgress(int loadedLength); + + /** + * http response finish + * @param response + */ + void onHttpFinish(WXResponse response); + } + +#### IWXUserTrackAdapter +Weex related performance data (first screen loading time, JS-Native communication time, dom update time, etc.) and other general information (JSLib file size, Weex SDK version number, etc.). + + public interface IWXUserTrackAdapter { + void commit(Context context, String eventId, String type, WXPerformance perf, Map<String, Serializable> params); } - ``` -3. IWXUserTrackAdapter - Weex related performance data (first screen loading time, JS-Native communication time, dom update time, etc.) and other general information (JSLib file size, Weex SDK version number, etc.). - Interface definition: +Native implementation interface can be obtained through `WXPerformance` and `params` corresponding information. + +#### IActivityNavBarSetter +Weex provided the ability of navigation through `WXNavigatorModule` which relys on IActivityNavBarSetter. +Usage: - ```java - public interface IWXUserTrackAdapter { - void commit(Context context, String eventId, String type, WXPerformance perf, Map<String, Serializable> params); - } - ``` + WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter(){}); - Native implementation interface can be obtained through `WXPerformance` and `params` corresponding information. +#### IWXStorageAdapter +Weex provided the ability of local storage through `WXStorageModule` which depends on IWXStorageAdapter. One can use `DefaultWXStorage` as the default implementation of IWXStorageAdapter. -## Native interacts with JavaScript -### Custom events +#### IWXJSExceptionAdapter +IWXJSExceptionAdapter is used to handle JavaScript exception. +## WXSDKInstace +### Weex Native and JavaScript communication. + +#### Custom events Used for a custom control for event notifications, such as custom click events, response drop events, and so on. `WXSDKInstance.java ` -```java - public void fireEvent(String elementRef,final String type, final Map<String, Object> data,final Map<String, Object> domChanges){ } + public void fireEvent(String elementRef,final String type, final Map<String, Object> data,final Map<String, Object> domChanges){ } - public void fireEvent(String elementRef,final String type, final Map<String, Object> data){ - fireEvent(elementRef,type,data,null); - } + public void fireEvent(String elementRef,final String type, final Map<String, Object> data){ + fireEvent(elementRef,type,data,null); + } - public void fireEvent(String elementRef, String type){ - fireEvent(ref,type,new HashMap<String, Object>()); - } -``` + public void fireEvent(String elementRef, String type){ + fireEvent(ref,type,new HashMap<String, Object>()); + } -`elementRef`ï¼The event occurred for the control IDã +* `elementRef`ï¼The event occurred for the control IDã -`type`: Custom events, Weex defaults to a custom event starting with onXxxxx. OnPullDown (drop-down event) +* `type`: Custom events, Weex defaults to a custom event starting with onXxxxx. OnPullDown (drop-down event) -`data`: Need to reveal the parameters, such as the current control of the size, coordinates and other informationã +* `data`: Need to reveal the parameters, such as the current control of the size, coordinates and other informationã -`domChanges`ï¼Update ref for the control's Attribute and Style +* `domChanges`ï¼Update ref for the control's Attribute and Style -## Event callback +#### Event callback Used for Module callback, for example, after the completion of positioning Module need to notify JS. Use as follows: -```java -public class WXLocation extends WXModule { + public class WXLocation extends WXModule { + + @JSMethod + public void getLocation(JSCallback callback){ + //Get the code for the location information ..... + Map<String,String> data=new HashMap<>(); + data.put("x","x"); + data.put("y","y"); + //notify once + callback.invoke(data); + //Continuous connection + callback.invokeAndKeepAlive(data); + //Invoke method and invokeAndKeepAlive two methods of choice } + } - @JSMethod - public void getLocation(JSCallback callback){ - //Get the code for the location information ..... - Map<String,String> data=new HashMap<>(); - data.put("x","x"); - data.put("y","y"); - //notify once - callback.invoke(data); - //Continuous connection - callback.invokeAndKeepAlive(data); +### Weex Native and other Native code communication +#### OnWXScrollListener +Weex gets the scroll event You can register `registerOnWXScrollListener` via `WXSDKInstance` +The interface is defined as follows: - //Invoke method and invokeAndKeepAlive two methods of choice } -} -``` + public interface OnWXScrollListener { -# OnWXScrollListener + /** + * The view is not currently scrolling. + */ + int IDLE = RecyclerView.SCROLL_STATE_IDLE; + /** + * The view is currently being dragged by outside input such as user touch input. + */ + int DRAGGING = RecyclerView.SCROLL_STATE_DRAGGING; + /** + * The view is currently animating to a final position while not under + * outside control. + */ + int SETTLING = RecyclerView.SCROLL_STATE_SETTLING; -Weex gets the scroll event You can register `registerOnWXScrollListener` via `WXSDKInstance` -The interface is defined as follows: + /** + * Callback method to be invoked when the view has been scrolled. This will be + * called after the scroll has completed. + * <p> + * This callback will also be called if visible item range changes after a layout + * calculation. In that case, dx and dy will be 0. + * + */ + void onScrolled(View view, int x, int y); -```java -public interface OnWXScrollListener { - - /** - * The view is not currently scrolling. - */ - int IDLE = RecyclerView.SCROLL_STATE_IDLE; - /** - * The view is currently being dragged by outside input such as user touch input. - */ - int DRAGGING = RecyclerView.SCROLL_STATE_DRAGGING; - /** - * The view is currently animating to a final position while not under - * outside control. - */ - int SETTLING = RecyclerView.SCROLL_STATE_SETTLING; - - /** - * Callback method to be invoked when the view has been scrolled. This will be - * called after the scroll has completed. - * <p> - * This callback will also be called if visible item range changes after a layout - * calculation. In that case, dx and dy will be 0. - * - */ - void onScrolled(View view, int x, int y); - - /** - * Callback method to be invoked when view's scroll state changes. - * - */ - void onScrollStateChanged(View view, int x, int y, int newState); -} -``` - -## IActivityNavBarSetter - -Weex provides `WXNavigatorModule` for navigation control, and the corresponding method can be customized by setting the `IActivityNavBarSetter` interface. - -Instructions: - -```java - WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter(){ -}); -``` + /** + * Callback method to be invoked when view's scroll state changes. + * + */ + void onScrollStateChanged(View view, int x, int y, int newState); + } ## Other Introduction ### setSize