You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/05/31 12:47:48 UTC
incubator-weex git commit: [WEEX-408][android] weex dev tool update
Repository: incubator-weex
Updated Branches:
refs/heads/master 0cbbfba71 -> 3e002a40a
[WEEX-408][android] weex dev tool update
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/3e002a40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/3e002a40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/3e002a40
Branch: refs/heads/master
Commit: 3e002a40aa1b1394af2e393f20a830f21f0ff125
Parents: 0cbbfba
Author: jianbai.gbj <gu...@163.com>
Authored: Thu May 31 20:32:45 2018 +0800
Committer: jianbai.gbj <gu...@163.com>
Committed: Thu May 31 20:32:45 2018 +0800
----------------------------------------------------------------------
.../com/taobao/weex/bridge/WXJsFunctions.java | 2 +-
.../com/taobao/weex/utils/WXWsonJSONSwitch.java | 15 +++++-
weex_core/Source/CMakeLists.txt | 1 +
.../Source/android/base/jni/jbytearray_ref.cpp | 42 +++++++++++++++
.../Source/android/base/jni/jbytearray_ref.h | 55 ++++++++++++++++++++
.../bridge/impl/jsfunction_impl_android.cpp | 43 +++++++++------
6 files changed, 140 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java
index 3624f23..568560e 100644
--- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java
+++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java
@@ -52,7 +52,7 @@ public class WXJsFunctions implements IWXJsFunctions {
@Override
public void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options){
- jsHandleCallNativeComponent(instanceId, componentRef, method, arguments, options, true);
+ jsHandleCallNativeComponent(instanceId, componentRef, method, WXWsonJSONSwitch.convertJSONToWsonIfUseWson(arguments), WXWsonJSONSwitch.convertJSONToWsonIfUseWson(options), true);
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java
index 1904d3c..7224408 100644
--- a/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java
+++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java
@@ -41,7 +41,11 @@ public class WXWsonJSONSwitch {
if(json == null){
return null;
}
- return WsonUtils.toWson(JSON.parse(json));
+ String str = new String(json);
+ if(str.startsWith("[")){
+ return WsonUtils.toWson(JSON.parseArray(str));
+ }
+ return WsonUtils.toWson(JSON.parse(str));
}
/**
@@ -85,6 +89,15 @@ public class WXWsonJSONSwitch {
}
+ public static final Object convertWXJSObjectDataToJSON(WXJSObject object){
+ if(object.type == WXJSObject.WSON){
+ return JSON.parse(Wson.parse((byte[]) object.data).toString());
+ }else{
+ return JSON.parse(object.data.toString());
+ }
+ }
+
+
/**
* config whether use json or wson, you should update this value by updateGlobalConfig(String config)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/weex_core/Source/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt
index 314b329..f4f399e 100644
--- a/weex_core/Source/CMakeLists.txt
+++ b/weex_core/Source/CMakeLists.txt
@@ -54,6 +54,7 @@ if (ANDROID)
set (ANDROID_SRCS
./android/jniprebuild/jni_load.cc
./android/base/jni/android_jni.cpp
+ ./android/base/jni/jbytearray_ref.cpp
./android/base/jni/scoped_java_ref.cpp
./android/base/base64/base64.cpp
./android/base/base64/modp_base64/modp_b64.cc
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/weex_core/Source/android/base/jni/jbytearray_ref.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/base/jni/jbytearray_ref.cpp b/weex_core/Source/android/base/jni/jbytearray_ref.cpp
new file mode 100644
index 0000000..be3b91e
--- /dev/null
+++ b/weex_core/Source/android/base/jni/jbytearray_ref.cpp
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+//
+// Created by furture on 2018/5/31.
+//
+
+#include "jbytearray_ref.h"
+
+
+namespace WeexCore {
+
+ JByteArrayRef::JByteArrayRef(JNIEnv *env, jbyteArray array) {
+ this->env = env;
+ this->array = array;
+ if(array != nullptr){
+ this->bytes = (char *) env->GetByteArrayElements(array, JNI_FALSE);
+ }
+ }
+
+ JByteArrayRef::~JByteArrayRef() {
+ if(array != nullptr){
+ env->ReleaseByteArrayElements(array, (jbyte*)bytes, 0);
+ array = nullptr;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/weex_core/Source/android/base/jni/jbytearray_ref.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/base/jni/jbytearray_ref.h b/weex_core/Source/android/base/jni/jbytearray_ref.h
new file mode 100644
index 0000000..a7c981a
--- /dev/null
+++ b/weex_core/Source/android/base/jni/jbytearray_ref.h
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+//
+// Created by furture on 2018/5/31.
+//
+
+#ifndef WEEX_PROJECT_JBYTEARRAYREF_H
+#define WEEX_PROJECT_JBYTEARRAYREF_H
+#include <jni.h>
+
+
+namespace WeexCore {
+
+ class JByteArrayRef {
+
+ public:
+ JByteArrayRef(JNIEnv* env, jbyteArray array);
+ ~JByteArrayRef();
+ char* getBytes(){
+ return bytes;
+ }
+ int length(){
+ if(array == nullptr){
+ return 0;
+ }
+ return env->GetArrayLength(array);
+ }
+
+ private:
+ jbyteArray array;
+ JNIEnv* env;
+ char* bytes;
+ };
+}
+
+
+
+
+#endif //WEEX_PROJECT_JBYTEARRAYREF_H
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3e002a40/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp b/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp
index 1a50fb8..3dfdfa0 100644
--- a/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp
+++ b/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp
@@ -17,6 +17,7 @@
* under the License.
*/
+#include <android/base/jni/jbytearray_ref.h>
#include "jsfunction_impl_android.h"
#include "../../base/string/string_utils.h"
#include "../../jniprebuild/jniheader/WXJsFunctions_jni.h"
@@ -41,6 +42,7 @@ static const char *getCharFromJByte(JNIEnv *env, jbyteArray jbyteArray1) {
return jByteArray2Str(env, jbyteArray1).c_str();
}
+
static const int getJByteArraySize(JNIEnv *env, jbyteArray array){
if(array == nullptr){
return 0;
@@ -108,6 +110,9 @@ jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstrin
jString2StrFast(env, instanceId).c_str(), jString2StrFast(env, module).c_str(),
jString2StrFast(env, method).c_str(), jByteArray2Str(env, arguments).c_str());
#endif
+ JByteArrayRef argumentsRef(env, arguments);
+ JByteArrayRef optionsRef(env, options);
+
// add for android support
jobject result;
@@ -115,10 +120,10 @@ jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstrin
getCharFromJString(env, instanceId),
getCharFromJString(env, module),
getCharFromJString(env, method),
- getCharFromJByte(env, arguments),
- getJByteArraySize(env, arguments),
- getCharFromJByte(env, options),
- getJByteArraySize(env, options)));
+ argumentsRef.getBytes(),
+ argumentsRef.length(),
+ optionsRef.getBytes(),
+ optionsRef.length()));
jfieldID jTypeId = env->GetFieldID(jWXJSObject, "type", "I");
jint jTypeInt = env->GetIntField(result, jTypeId);
@@ -158,13 +163,15 @@ jsHandleCallNativeComponent(JNIEnv *env, jobject object, jstring instanceId, jst
jstring method,
jbyteArray arguments, jbyteArray options, jboolean from) {
+ JByteArrayRef argumentsRef(env, arguments);
+ JByteArrayRef optionsRef(env, options);
Bridge_Impl_Android::getInstance()->callNativeComponent(getCharFromJString(env, instanceId),
getCharFromJString(env, componentRef),
getCharFromJString(env, method),
- getCharFromJByte(env, arguments),
- getJByteArraySize(env, arguments),
- getCharFromJByte(env, options),
- getJByteArraySize(env, options));
+ argumentsRef.getBytes(),
+ argumentsRef.length(),
+ optionsRef.getBytes(),
+ optionsRef.length());
}
@@ -174,16 +181,16 @@ jsHandleCallAddElement(JNIEnv *env, jobject object, jstring instanceId, jstring
const char *instanceChar = env->GetStringUTFChars(instanceId, 0);
const char *refChar = env->GetStringUTFChars(ref, 0);
- const char *domChar = getCharFromJByte(env, dom);
+ JByteArrayRef domRef(env, dom);
const char *indexChar = env->GetStringUTFChars(index, 0);
int indexI = atoi(indexChar);
- if (instanceChar == nullptr || refChar == nullptr || domChar == nullptr ||
+ if (instanceChar == nullptr || refChar == nullptr || domRef.length() == 0 ||
indexChar == nullptr ||
indexI < -1)
return;
- RenderManager::GetInstance()->AddRenderObject(instanceChar, refChar, indexI, domChar);
+ RenderManager::GetInstance()->AddRenderObject(instanceChar, refChar, indexI, domRef.getBytes());
}
void jsHandleSetTimeout(JNIEnv *env, jobject object, jstring callbackId, jstring time) {
@@ -202,10 +209,10 @@ void jsFunctionCallCreateBody(JNIEnv *env, jobject object, jstring pageId, jbyte
return;
const char *page = env->GetStringUTFChars(pageId, NULL);
- const char *dom = getCharFromJByte(env, domStr);
- if (page == nullptr || dom == nullptr || strlen(dom) == 0)
+ JByteArrayRef dom(env, domStr);
+ if (page == nullptr || dom.length() == 0)
return;
- RenderManager::GetInstance()->CreatePage(page, dom);
+ RenderManager::GetInstance()->CreatePage(page, dom.getBytes());
}
void
@@ -232,16 +239,20 @@ jsFunctionCallRefreshFinish(JNIEnv *env, jobject object, jstring instanceId, jby
void
jsFunctionCallUpdateAttrs(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from) {
+
+ JByteArrayRef dataRef(env, data);
RenderManager::GetInstance()->UpdateAttr(env->GetStringUTFChars(pageId, 0),
env->GetStringUTFChars(ref, 0),
- getCharFromJByte(env, data));
+ dataRef.getBytes());
}
void
jsFunctionCallUpdateStyle(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from) {
+
+ JByteArrayRef dataRef(env, data);
RenderManager::GetInstance()->UpdateStyle(env->GetStringUTFChars(pageId, 0),
env->GetStringUTFChars(ref, 0),
- getCharFromJByte(env, data));
+ dataRef.getBytes());
}
void jsFunctionCallRemoveElement(JNIEnv *env, jobject object, jstring pageId, jstring ref) {