Skip to content

Commit

Permalink
Merge branch '0.5.0' of github.com:alibaba/weex into 0.5.0
Browse files Browse the repository at this point in the history
Conflicts:
	android/sdk/assets/main.js
  • Loading branch information
luics committed Apr 13, 2016
2 parents 5d4e088 + e02a113 commit 86a32a8
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 78 deletions.
7 changes: 7 additions & 0 deletions android/playground/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Weex android playground
Copyright 2016 Alibaba Group

This product includes software developed at Alibaba Group. (http://www.alibabagroup.com)

This product contains software zxing(https://github.com/zxing/zxing) developed
by Google Inc. , licensed under the Apache License.
4 changes: 1 addition & 3 deletions android/sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ build
captures
local.properties
target
gradle/wrapper
bin
.classpath
.project
.settings
gen
*.iml
lint.xml
project.properties
main.js
project.properties
2 changes: 1 addition & 1 deletion android/sdk/NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Weex JSFramework
Weex Sdk Android
Copyright 2016 Alibaba Group

This product includes software developed at Alibaba Group. (http://www.alibabagroup.com)
Expand Down
2 changes: 1 addition & 1 deletion android/sdk/assets/main.js

Large diffs are not rendered by default.

Binary file added android/sdk/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions android/sdk/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
143 changes: 70 additions & 73 deletions doc/advanced/extend-to-android.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
##Extend to Android

### Module extend
weex sdk support Moulde extend,
Weex SDK provides only rendering capabilities, rather than have other capabilities, such as network, picture, and URL redirection. If you want the these features, you need to implement it.

For example: If you want to implement an address jumping function, you can achieve a Module Follow the steps below.
#### eventModule
First, you need to inherit the class “WXModule”.
Second, you need to define a method that is called in JavaScript, and you need to add @WXModuleAnno this comment, so we think this is a method that can be called Module.
Here is the code:

```
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
#### Step to customize a module
1. Customize module must extend WXModule
2. @WXModuleAnno annotation must be added, as it is the only the way to recognized by Weex
3. The access levels of mehtod must be **public**
4. The module class also can not be an inner class
5. Customize can not be obfuscated by tools like ProGuard
6. Module methods will be invoked in UI thread, do not put time consuming operation there
7. Weex params can be int, double, float, String, Map, List, self-defined class that implements WXObject interface

import com.taobao.weex.common.WXModuleAnno;
import com.taobao.weex.common.WXModule;
Refer to the following example

```
import android.content.Intent;
import android.net.Uri;
……………………
public class WXEventModule extends WXModule{
public class WXEventModule extends WXModule{
private static final String WEEX_CATEGORY="com.taobao.android.intent.category.WEEX";
@WXModuleAnno
public void openURL(String url){
if (TextUtils.isEmpty(url)) {
Expand All @@ -30,60 +37,57 @@ public class WXEventModule extends WXModule{
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addCategory(WEEX_CATEGORY);
mWXSDKInstance.getContext().startActivity(intent);
}
}
}
}
```
After Module code is written, you need to be registered with WXSDKEngine, so we can call WEEX Module achieved by way of reflection.
Here is the code:

#### Register the moulde

```
public class WXApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
WXSDKEngine.init(this);
try {
WXSDKEngine.registerModule("event", WXEventModule.class);
} catch (WXException e) {
e.printStackTrace();
}
}
}
/**
* Register module. This is a wrapper method for
* {@link WXModuleManager#registerModule(String, Class)}.
* The module register here only needto
* be singleton in {@link WXSDKInstance} level.
* @param moduleName module name
* @param moduleClass module to be registered.
* @return true for registration success, false for otherwise.
* @see {@link WXModuleManager#registerModule(String, Class, boolean)}
*/
WXSDKEngine.registerModule("event", WXEventModule.class);
```
##### <font color="red"> Custom module you need to note the following points:
1. Customize components must extend WXModule
2. @WXModuleAnno annotation must be added, as it is the only the way to recognized by Weex
3. The access levels of mehtod must be **public**
4. The module class also can not be an inner class
5. Customize can not be obfuscated by tools like ProGuard
6. Module methods will be invoked in UI thread, do not put time consuming operation there
7. Weex params can be int, double, float, String, Map, List, self-defined class that implements WXObject interface

#### Component extend

### Component extend
<font color="gray">
There are label, image, div, scroll, ect. components in weex, you can also customize your own components.

To implement a custom Component that you need to follow the following steps:

First: You need to inherit the class WX Component. WX Component is our base class, similar to Android in the base class View.
Second: You need to override the init View method, "mHost" be assigned to the Native View.
Next: custom attributes method to add annotations @WXComponentProp
#### Step to customize a module

1. Customize components must extend WXComponent or WXContainer
2. @WXComponentProp(name=value(value is attr or style of dsl)) for it be recognized by weex SDK.
3. The access levels of mehtod must be **public**
4. The component class can not be an inner class
5. Customize can not be obfuscated by tools like ProGuard
6. Component methods will be invoked in UI thread, do not put time consuming operation there.
7. Weex params can be int, double, float, String, Map, List, self-defined class that implements WXObject interface


Refer to the following example

```
package com.taobao.weextest;
import android.widget.TextView;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.WXDomPropConstant;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXComponentProp;
import com.taobao.weex.ui.component.WXVContainer;
………………
public class MyViewComponent extends WXComponent{
public MyViewComponent(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy)
public MyViewComponent(WXSDKInstance instance, WXDomObject dom,
WXVContainer parent, String instanceId, boolean isLazy)
{
public MyViewComponent(WXSDKInstance instance, WXDomObject dom,
public MyViewComponent(WXSDKInstance instance, WXDomObject dom,
WXVContainer parent, String instanceId, boolean isLazy) {
super(instance, dom, parent, instanceId, isLazy);
}
Expand All @@ -98,33 +102,26 @@ Refer to the following example
((TextView)mHost).setText(value);
}
}
```

After Native code is written, you need to be registered, so that we can find it.
#### Register the Component


```
public class WXApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
WXSDKEngine.init(this);
try {
WXSDKEngine.registerComponent("MyView", MyViewComponent.class);
} catch (WXException e) {
e.printStackTrace();
}
}
}
/**
* Register component. The registration is singleton in {@link WXSDKEngine} level
* @param type name of component. Same as type filed in the JS.
* @param clazz the class of the {@link WXComponent} to be registered.
* @param appendTree true for appendTree flag
* @return true for registration success, false for otherwise.
* @throws WXException Throws exception if type conflicts.
*/
WXSDKEngine.registerComponent("MyView", MyViewComponent.class);
```

##### <font color="red">Custom Component you need to note the following points

1. Customize components must extend WXComponent or WXContainer
2. @WXComponentProp(name=value(value is attr or style of dsl)) for it be recognized by weex SDK.
3. The access levels of mehtod must be **public**
4. The component class can not be an inner class
5. Customize can not be obfuscated by tools like ProGuard
6. Component methods will be invoked in UI thread, do not put time consuming operation there.
7. Weex params can be int, double, float, String, Map, List, self-defined class that implements WXObject interface
### Adapter extend

#### ImagedownloadAdapter
<font color="gray">
Expand Down

0 comments on commit 86a32a8

Please sign in to comment.