http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/build.gradle ---------------------------------------------------------------------- diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index 7e05943..f277443 100755 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -1,10 +1,6 @@ buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3' + classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0' } } @@ -15,7 +11,6 @@ plugins { apply plugin: 'com.android.library' apply plugin: 'checkstyle' -apply plugin: 'com.getkeepsafe.dexcount' ext.disableCov = project.hasProperty('disableCov') ? project.getProperty('disableCov') : 'false' if(!disableCov.toBoolean()){ @@ -40,13 +35,17 @@ checkstyle { toolVersion = '6.9' } -version = "0.18.0-beta-3" + +version = "Devtool-WeexCore-1.0.3-SNAPSHOT" android { + + publishNonDefault true compileSdkVersion project.compileSdkVersion buildToolsVersion project.buildToolsVersion resourcePrefix "weex" + delete 'libs/armeabi/libweexjsc.so' useLibrary 'org.apache.http.legacy' copy { from '../../pre-build' @@ -57,7 +56,7 @@ android { def line new File(projectDir,"assets/main.js").withReader { line = it.readLine() } def m = line =~ /[A-Z\s]+\s+([0-9\.]+),\s+Build\s+[0-9]+/; - def jsfmVersion = m[0][1] + def jsfmVersion // = m[0][1] println jsfmVersion copy { @@ -92,7 +91,6 @@ android { println "ARMEABI_Size: "+ARMEABI_Size; println "X86_Size:" + X86_Size; - defaultConfig { buildConfigField "long", "ARMEABI_Size", "${ARMEABI_Size}" buildConfigField "long", "X86_Size", "${X86_Size}" @@ -100,22 +98,43 @@ android { buildConfigField "String", "buildVersion", "\"${version}\"" minSdkVersion 14 targetSdkVersion project.targetSdkVersion + + multiDexEnabled true + versionCode 1 versionName "1.0" ndk { abiFilters "armeabi","x86" } + + externalNativeBuild { + cmake { + arguments '-DANDROID_PLATFORM=android-19', + '-DANDROID_TOOLCHAIN=gcc', + '-DANDROID_STL=c++_static' + } + } } buildTypes { release { minifyEnabled false + testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "boolean", "ENABLE_TRACE", "false" + consumerProguardFiles 'proguard-rules.pro' } debug { - testCoverageEnabled true buildConfigField "boolean", "ENABLE_TRACE", "true" + jniDebuggable true + debuggable true + consumerProguardFiles 'proguard-rules.pro' + } + } + + externalNativeBuild { + cmake { + path '../../weex_core/CMakeLists.txt' } } @@ -140,7 +159,6 @@ android { targetCompatibility JavaVersion.VERSION_1_7 } testOptions { - unitTests.returnDefaultValues = true unitTests.all { maxHeapSize = "1024m" jvmArgs += ['-XX:-UseSplitVerifier', '-noverify','-Xverify:none']/* fix VerifyError */ @@ -179,4 +197,4 @@ if(file('../license/LICENSE').exists()){ excludes(["com/taobao/weex/dom/flex/*.java"]) } preBuild.dependsOn licenseFormat -} +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/gradle/wrapper/gradle-wrapper.jar ---------------------------------------------------------------------- diff --git a/android/sdk/gradle/wrapper/gradle-wrapper.jar b/android/sdk/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b5166da Binary files /dev/null and b/android/sdk/gradle/wrapper/gradle-wrapper.jar differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/gradle/wrapper/gradle-wrapper.properties ---------------------------------------------------------------------- diff --git a/android/sdk/gradle/wrapper/gradle-wrapper.properties b/android/sdk/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d649982 --- /dev/null +++ b/android/sdk/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed May 03 18:06:49 CST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http://gw.alicdn.com/bao/uploaded/LB1J5WLJVXXXXcMXpXXXXXXXXXX.zip http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/libs/armeabi/libweexjsc.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi/libweexjsc.so b/android/sdk/libs/armeabi/libweexjsc.so deleted file mode 100755 index 96fe1c2..0000000 Binary files a/android/sdk/libs/armeabi/libweexjsc.so and /dev/null differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/libs/armeabi/libweexjss.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi/libweexjss.so b/android/sdk/libs/armeabi/libweexjss.so index f91f45a..719678e 100755 Binary files a/android/sdk/libs/armeabi/libweexjss.so and b/android/sdk/libs/armeabi/libweexjss.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/libs/x86/libweexjsb.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjsb.so b/android/sdk/libs/x86/libweexjsb.so old mode 100755 new mode 100644 http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/libs/x86/libweexjsc.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjsc.so b/android/sdk/libs/x86/libweexjsc.so deleted file mode 100755 index b86a821..0000000 Binary files a/android/sdk/libs/x86/libweexjsc.so and /dev/null differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/libs/x86/libweexjss.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjss.so b/android/sdk/libs/x86/libweexjss.so old mode 100755 new mode 100644 index fc8e5f6..9a4f570 Binary files a/android/sdk/libs/x86/libweexjss.so and b/android/sdk/libs/x86/libweexjss.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/proguard-rules.pro ---------------------------------------------------------------------- diff --git a/android/sdk/proguard-rules.pro b/android/sdk/proguard-rules.pro index 2814dc7..73247bc 100755 --- a/android/sdk/proguard-rules.pro +++ b/android/sdk/proguard-rules.pro @@ -16,4 +16,7 @@ # public *; #} -keep class com.taobao.weex.bridge.** { *; } --dontwarn com.taobao.weex.bridge.** +-keep class com.taobao.weex.layout.** { *; } +-keep class com.taobao.weex.WXSDKEngine { *; } +-keep class com.taobao.weex.base.SystemMessageHandler { *; } +-dontwarn com.taobao.weex.bridge.** \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/AndroidManifest.xml ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/AndroidManifest.xml b/android/sdk/src/main/AndroidManifest.xml index 9897b6a..9d6cb35 100755 --- a/android/sdk/src/main/AndroidManifest.xml +++ b/android/sdk/src/main/AndroidManifest.xml @@ -18,7 +18,7 @@ specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.taobao.weappplus_sdk" + package="com.taobao.weex" android:versionCode="1" android:versionName="1.0"> @@ -32,6 +32,7 @@ under the License. android:enabled="true" android:exported="false"> </receiver> - </application> + + </application> </manifest> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/InitConfig.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/InitConfig.java b/android/sdk/src/main/java/com/taobao/weex/InitConfig.java index aaa2dd0..9ff1377 100644 --- a/android/sdk/src/main/java/com/taobao/weex/InitConfig.java +++ b/android/sdk/src/main/java/com/taobao/weex/InitConfig.java @@ -180,7 +180,7 @@ public class InitConfig { config.framework=this.framework; config.mURIAdapter = this.mURIAdapter; config.webSocketAdapterFactory = this.webSocketAdapterFactory; - config.mJSExceptionAdapter= this.mJSExceptionAdapter; + config.mJSExceptionAdapter=this.mJSExceptionAdapter; config.classLoaderAdapter = this.classLoaderAdapter; return config; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/LayoutFinishListener.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/LayoutFinishListener.java b/android/sdk/src/main/java/com/taobao/weex/LayoutFinishListener.java deleted file mode 100644 index b863316..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/LayoutFinishListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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. - */ -package com.taobao.weex; - -import android.support.annotation.NonNull; - -public interface LayoutFinishListener { - - void onLayoutFinish(@NonNull WXSDKInstance instance); -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/RenderContainer.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/RenderContainer.java b/android/sdk/src/main/java/com/taobao/weex/RenderContainer.java index a37a47e..978d2c1 100644 --- a/android/sdk/src/main/java/com/taobao/weex/RenderContainer.java +++ b/android/sdk/src/main/java/com/taobao/weex/RenderContainer.java @@ -23,34 +23,42 @@ import android.content.Context; import android.os.Build; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.View; import android.widget.FrameLayout; +import com.taobao.weex.bridge.WXBridgeManager; + import java.lang.ref.WeakReference; /** * Created by sospartan on 08/10/2016. */ -public class RenderContainer extends FrameLayout { +public class RenderContainer extends FrameLayout implements WeexFrameRateControl.VSyncListener{ private WeakReference<WXSDKInstance> mSDKInstance; + private WeexFrameRateControl mFrameRateControl; private boolean mPageHasEvent = false; public RenderContainer(Context context) { super(context); + mFrameRateControl = new WeexFrameRateControl(this); } public RenderContainer(Context context, AttributeSet attrs) { super(context, attrs); + mFrameRateControl = new WeexFrameRateControl(this); } public RenderContainer(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + mFrameRateControl = new WeexFrameRateControl(this); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public RenderContainer(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + mFrameRateControl = new WeexFrameRateControl(this); } public void setSDKInstance(WXSDKInstance instance) { @@ -68,6 +76,42 @@ public class RenderContainer extends FrameLayout { } @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mFrameRateControl != null) { + mFrameRateControl.start(); + } + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (mFrameRateControl != null) { + mFrameRateControl.stop(); + } + } + @Override + public void dispatchWindowVisibilityChanged(int visibility) { + super.dispatchWindowVisibilityChanged(visibility); + if (visibility == View.GONE) { + if (mFrameRateControl != null) { + mFrameRateControl.stop(); + } + } else if (visibility == View.VISIBLE) { + if (mFrameRateControl != null) { + mFrameRateControl.start(); + } + } + } + + @Override + public void OnVSync() { + if (mSDKInstance != null && mSDKInstance.get() != null) { + mSDKInstance.get().OnVSync(); + } + } + + @Override public boolean dispatchTouchEvent(MotionEvent ev) { mPageHasEvent = true; return super.dispatchTouchEvent(ev); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java b/android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java index 96ca990..2f6420a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java @@ -28,13 +28,10 @@ import android.os.Environment; import android.telephony.TelephonyManager; import android.text.TextUtils; -import com.taobao.weappplus_sdk.BuildConfig; import com.taobao.weex.common.WXConfig; import com.taobao.weex.utils.FontDO; -import com.taobao.weex.common.WXErrorCode; import com.taobao.weex.utils.LogLevel; import com.taobao.weex.utils.TypefaceUtil; -import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXSoInstallMgrSdk; import com.taobao.weex.utils.WXUtils; @@ -70,7 +67,7 @@ public class WXEnvironment { * Debug model */ public static boolean sDebugMode = false; - public static boolean sForceEnableDevTool = false; + public static final boolean sForceEnableDevTool = false; public static String sDebugWsUrl = ""; public static boolean sDebugServerConnectable = false; public static boolean sRemoteDebugMode = false; @@ -129,7 +126,7 @@ public class WXEnvironment { } configs.putAll(options); if(configs!=null&&configs.get(WXConfig.appName)==null && sApplication!=null){ - configs.put(WXConfig.appName, sApplication.getPackageName()); + configs.put(WXConfig.appName, sApplication.getPackageName()); } return configs; } @@ -209,7 +206,7 @@ public class WXEnvironment { boolean isCPUSupport = WXSoInstallMgrSdk.isCPUSupport() && !isX86AndExcluded; if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("WXEnvironment.sSupport:" + isCPUSupport - + "isX86AndExclueded: "+ isX86AndExcluded); + + "isX86AndExclueded: "+ isX86AndExcluded); } return isCPUSupport; } @@ -245,7 +242,7 @@ public class WXEnvironment { private static String getDevId() { return sApplication == null ? "" : ((TelephonyManager) sApplication - .getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); + .getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); } public static Application getApplication() { @@ -322,8 +319,7 @@ public class WXEnvironment { public static void setApkDebugable(boolean debugable){ isApkDebug = debugable; if(!isApkDebug){ - openDebugLog = false; + openDebugLog = false; } } - } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java index ef87679..4fef0c3 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java @@ -21,9 +21,10 @@ package com.taobao.weex; import android.app.Application; import android.content.Context; import android.content.Intent; -import android.os.Looper; +import android.content.res.Resources; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; +import android.util.Log; import com.taobao.weex.adapter.IDrawableLoader; import com.taobao.weex.adapter.IWXHttpAdapter; @@ -48,16 +49,6 @@ import com.taobao.weex.common.WXException; import com.taobao.weex.common.WXInstanceWrap; import com.taobao.weex.common.WXModule; import com.taobao.weex.common.WXPerformance; -import com.taobao.weex.dom.BasicEditTextDomObject; -import com.taobao.weex.dom.TextAreaEditTextDomObject; -import com.taobao.weex.dom.WXCellDomObject; -import com.taobao.weex.dom.WXDomObject; -import com.taobao.weex.dom.WXDomRegistry; -import com.taobao.weex.dom.WXListDomObject; -import com.taobao.weex.dom.WXRecyclerDomObject; -import com.taobao.weex.dom.WXScrollerDomObject; -import com.taobao.weex.dom.WXSwitchDomObject; -import com.taobao.weex.dom.WXTextDomObject; import com.taobao.weex.http.WXStreamModule; import com.taobao.weex.ui.ExternalLoaderComponentHolder; import com.taobao.weex.ui.IExternalComponentGetter; @@ -103,10 +94,11 @@ import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXSoInstallMgrSdk; import com.taobao.weex.utils.batch.BatchOperationHelper; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; -public class WXSDKEngine { +public class WXSDKEngine implements Serializable { public static final String JS_FRAMEWORK_RELOAD="js_framework_reload"; @@ -137,9 +129,9 @@ public class WXSDKEngine { @Deprecated public static void init(Application application, IWXUserTrackAdapter utAdapter, String framework) { initialize(application, - new InitConfig.Builder() - .setUtAdapter(utAdapter) - .build() + new InitConfig.Builder() + .setUtAdapter(utAdapter) + .build() ); } @@ -166,31 +158,49 @@ public class WXSDKEngine { if(WXEnvironment.isApkDebugable()){ WXEnvironment.sLogLevel = LogLevel.DEBUG; }else{ - if(WXEnvironment.sApplication != null){ - WXEnvironment.sLogLevel = LogLevel.WARN; - }else { - WXLogUtils.e(TAG,"WXEnvironment.sApplication is " + WXEnvironment.sApplication); - } + if(WXEnvironment.sApplication != null){ + WXEnvironment.sLogLevel = LogLevel.WARN; + }else { + WXLogUtils.e(TAG,"WXEnvironment.sApplication is " + WXEnvironment.sApplication); + } } doInitInternal(application,config); + registerApplicationOptions(application); WXEnvironment.sSDKInitInvokeTime = System.currentTimeMillis()-start; WXLogUtils.renderPerformanceLog("SDKInitInvokeTime", WXEnvironment.sSDKInitInvokeTime); WXPerformance.init(); - mIsInit = true; } } + private static void registerApplicationOptions(final Application application) { + + if (application == null) { + WXLogUtils.e(TAG, "RegisterApplicationOptions application is null"); + return; + } + + Resources resources = application.getResources(); + registerCoreEnv("screen_width_pixels", String.valueOf(resources.getDisplayMetrics().widthPixels)); + registerCoreEnv("screen_height_pixels", String.valueOf(resources.getDisplayMetrics().heightPixels)); + + int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + int statusBarHeight = resources.getDimensionPixelSize(resourceId); + registerCoreEnv("status_bar_height", String.valueOf(statusBarHeight)); + } + } + private static void doInitInternal(final Application application,final InitConfig config){ WXEnvironment.sApplication = application; - if(application == null){ - WXLogUtils.e(TAG, " doInitInternal application is null"); - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, - "doInitInternal", - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT.getErrorMsg() + "WXEnvironment sApplication is null", - null); - } + if(application == null){ + WXLogUtils.e(TAG, " doInitInternal application is null"); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, + "doInitInternal", + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT.getErrorMsg() + "WXEnvironment sApplication is null", + null); + } WXEnvironment.JsFrameworkInit = false; WXBridgeManager.getInstance().post(new Runnable() { @@ -203,15 +213,15 @@ public class WXSDKEngine { sm.setInitConfig(config); } WXSoInstallMgrSdk.init(application, - sm.getIWXSoLoaderAdapter(), - sm.getWXStatisticsListener()); + sm.getIWXSoLoaderAdapter(), + sm.getWXStatisticsListener()); boolean isSoInitSuccess = WXSoInstallMgrSdk.initSo(V8_SO_NAME, 1, config!=null?config.getUtAdapter():null); if (!isSoInitSuccess) { - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, - "doInitInternal", - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT.getErrorMsg() + "isSoInit false", - null); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, + "doInitInternal", + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT.getErrorMsg() + "isSoInit false", + null); return; } @@ -227,11 +237,11 @@ public class WXSDKEngine { @Deprecated public static void init(Application application, String framework, IWXUserTrackAdapter utAdapter, IWXImgLoaderAdapter imgLoaderAdapter, IWXHttpAdapter httpAdapter) { initialize(application, - new InitConfig.Builder() - .setUtAdapter(utAdapter) - .setHttpAdapter(httpAdapter) - .setImgAdapter(imgLoaderAdapter) - .build() + new InitConfig.Builder() + .setUtAdapter(utAdapter) + .setHttpAdapter(httpAdapter) + .setImgAdapter(imgLoaderAdapter) + .build() ); } @@ -243,57 +253,57 @@ public class WXSDKEngine { BatchOperationHelper batchHelper = new BatchOperationHelper(WXBridgeManager.getInstance()); try { registerComponent( - new SimpleComponentHolder( - WXText.class, - new WXText.Creator() - ), - false, - WXBasicComponentType.TEXT + new SimpleComponentHolder( + WXText.class, + new WXText.Creator() + ), + false, + WXBasicComponentType.TEXT ); registerComponent( - new SimpleComponentHolder( - WXDiv.class, - new WXDiv.Ceator() - ), - false, - WXBasicComponentType.CONTAINER, - WXBasicComponentType.DIV, - WXBasicComponentType.HEADER, - WXBasicComponentType.FOOTER + new SimpleComponentHolder( + WXDiv.class, + new WXDiv.Ceator() + ), + false, + WXBasicComponentType.CONTAINER, + WXBasicComponentType.DIV, + WXBasicComponentType.HEADER, + WXBasicComponentType.FOOTER ); registerComponent( - new SimpleComponentHolder( - WXImage.class, - new WXImage.Ceator() - ), - false, - WXBasicComponentType.IMAGE, - WXBasicComponentType.IMG + new SimpleComponentHolder( + WXImage.class, + new WXImage.Creator() + ), + false, + WXBasicComponentType.IMAGE, + WXBasicComponentType.IMG ); registerComponent( - new SimpleComponentHolder( - WXScroller.class, - new WXScroller.Creator() - ), - false, - WXBasicComponentType.SCROLLER + new SimpleComponentHolder( + WXScroller.class, + new WXScroller.Creator() + ), + false, + WXBasicComponentType.SCROLLER ); registerComponent( - new SimpleComponentHolder( - WXSlider.class, - new WXSlider.Creator() - ), - true, - WXBasicComponentType.SLIDER, - WXBasicComponentType.CYCLE_SLIDER + new SimpleComponentHolder( + WXSlider.class, + new WXSlider.Creator() + ), + true, + WXBasicComponentType.SLIDER, + WXBasicComponentType.CYCLE_SLIDER ); registerComponent( - new SimpleComponentHolder( - WXSliderNeighbor.class, - new WXSliderNeighbor.Creator() - ), - true, - WXBasicComponentType.SLIDER_NEIGHBOR + new SimpleComponentHolder( + WXSliderNeighbor.class, + new WXSliderNeighbor.Creator() + ), + true, + WXBasicComponentType.SLIDER_NEIGHBOR ); String simpleList = "simplelist"; registerComponent(SimpleListComponent.class,false,simpleList); @@ -317,7 +327,7 @@ public class WXSDKEngine { registerModule("modal", WXModalUIModule.class, false); registerModule("instanceWrap", WXInstanceWrap.class, true); - registerModule("animation", WXAnimationModule.class, false); + registerModule("animation", WXAnimationModule.class, true); registerModule("webview", WXWebViewModule.class, true); registerModule("navigator", WXNavigatorModule.class); registerModule("stream", WXStreamModule.class); @@ -329,24 +339,6 @@ public class WXSDKEngine { registerModule("meta", WXMetaModule.class,true); registerModule("webSocket", WebSocketModule.class); registerModule("locale", WXLocaleModule.class); - - - registerDomObject(simpleList, WXListDomObject.class); - registerDomObject(WXBasicComponentType.INDICATOR, WXIndicator.IndicatorDomNode.class); - registerDomObject(WXBasicComponentType.TEXT, WXTextDomObject.class); - registerDomObject(WXBasicComponentType.HEADER, WXCellDomObject.class); - registerDomObject(WXBasicComponentType.CELL, WXCellDomObject.class); - registerDomObject(WXBasicComponentType.CELL_SLOT, WXCellDomObject.class); - registerDomObject(WXBasicComponentType.INPUT, BasicEditTextDomObject.class); - registerDomObject(WXBasicComponentType.TEXTAREA, TextAreaEditTextDomObject.class); - registerDomObject(WXBasicComponentType.SWITCH, WXSwitchDomObject.class); - registerDomObject(WXBasicComponentType.LIST, WXListDomObject.class); - registerDomObject(WXBasicComponentType.RECYCLE_LIST, WXRecyclerDomObject.class); - registerDomObject(WXBasicComponentType.VLIST, WXListDomObject.class); - registerDomObject(WXBasicComponentType.HLIST, WXListDomObject.class); - registerDomObject(WXBasicComponentType.SCROLLER, WXScrollerDomObject.class); - registerDomObject(WXBasicComponentType.RECYCLER, WXRecyclerDomObject.class); - registerDomObject(WXBasicComponentType.WATERFALL, WXRecyclerDomObject.class); } catch (WXException e) { WXLogUtils.e("[WXSDKEngine] register:", e); } @@ -354,7 +346,6 @@ public class WXSDKEngine { batchHelper.flush(); } - /** * * Register component. The registration is singleton in {@link WXSDKEngine} level @@ -465,10 +456,6 @@ public class WXSDKEngine { } } - public static boolean registerDomObject(String type, Class<? extends WXDomObject> clazz) throws WXException { - return WXDomRegistry.registerDomObject(type, clazz); - } - public static void callback(String instanceId, String funcId, Map<String, Object> data) { WXSDKManager.getInstance().callback(instanceId, funcId, data); } @@ -535,7 +522,6 @@ public class WXSDKEngine { WXBridgeManager.getInstance().restart(); WXBridgeManager.getInstance().initScriptsFramework(framework); - WXServiceManager.reload(); WXModuleManager.reload(); WXComponentRegistry.reload(); WXSDKManager.getInstance().postOnUiThread(new Runnable() { @@ -546,10 +532,14 @@ public class WXSDKEngine { }, 0); } public static void reload(final Context context, boolean remoteDebug) { - reload(context,null,remoteDebug); + reload(context,null,remoteDebug); } public static void reload() { reload(WXEnvironment.getApplication(), WXEnvironment.sRemoteDebugMode); } + + public static void registerCoreEnv(String key, String value) { + WXBridgeManager.getInstance().registerCoreEnv(key, value); + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 5f0cd14..7271186 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -27,11 +27,16 @@ import android.content.IntentFilter; import android.graphics.Color; import android.graphics.Paint; import android.net.Uri; -import android.os.Message; +import android.support.v4.util.ArrayMap; + +import com.taobao.weex.bridge.WXBridge; +import com.taobao.weex.common.WXPerformance.Dimension; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; +import android.support.annotation.UiThread; +import android.support.annotation.WorkerThread; import android.text.TextUtils; import android.view.Menu; import android.view.View; @@ -43,7 +48,6 @@ import com.taobao.weex.adapter.IWXHttpAdapter; import com.taobao.weex.adapter.IWXImgLoaderAdapter; import com.taobao.weex.adapter.IWXUserTrackAdapter; import com.taobao.weex.adapter.URIAdapter; -import com.taobao.weex.performance.IWXAnalyzer; import com.taobao.weex.appfram.websocket.IWebSocketAdapter; import com.taobao.weex.bridge.EventResult; import com.taobao.weex.bridge.NativeInvokeHelper; @@ -57,19 +61,15 @@ import com.taobao.weex.common.OnWXScrollListener; import com.taobao.weex.common.WXErrorCode; import com.taobao.weex.common.WXModule; import com.taobao.weex.common.WXPerformance; -import com.taobao.weex.common.WXPerformance.Dimension; import com.taobao.weex.common.WXRefreshData; import com.taobao.weex.common.WXRenderStrategy; import com.taobao.weex.common.WXRequest; import com.taobao.weex.common.WXResponse; -import com.taobao.weex.dom.DomContext; -import com.taobao.weex.dom.WXDomHandler; -import com.taobao.weex.dom.WXDomObject; -import com.taobao.weex.dom.WXDomTask; import com.taobao.weex.dom.WXEvent; import com.taobao.weex.http.WXHttpUtil; import com.taobao.weex.performance.WXAnalyzerDataTransfer; import com.taobao.weex.tracing.WXTracing; +import com.taobao.weex.ui.action.GraphicActionAddElement; import com.taobao.weex.ui.component.NestedContainer; import com.taobao.weex.ui.component.WXBasicComponentType; import com.taobao.weex.ui.component.WXComponent; @@ -77,14 +77,12 @@ import com.taobao.weex.ui.component.WXComponentFactory; import com.taobao.weex.ui.component.WXEmbed; import com.taobao.weex.ui.flat.FlatGUIContext; import com.taobao.weex.ui.view.WXScrollView; -import com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener; import com.taobao.weex.utils.Trace; import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXFileUtils; import com.taobao.weex.utils.WXJsonUtils; import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXReflectionUtils; -import com.taobao.weex.utils.WXViewUtils; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; @@ -96,11 +94,12 @@ import java.util.PriorityQueue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + /** * Each instance of WXSDKInstance represents an running weex instance. * It can be a pure weex view, or mixed with native view */ -public class WXSDKInstance implements IWXActivityStateListener,DomContext, View.OnLayoutChangeListener { +public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChangeListener { private static final String SOURCE_TEMPLATE_BASE64_MD5 = "templateSourceBase64MD5"; @@ -128,7 +127,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. private boolean enableLayerType = true; private boolean mNeedValidate = false; private boolean mNeedReLoad = false; - private static volatile int mViewPortWidth = 750; private int mInstanceViewPortWidth = 750; private @NonNull FlatGUIContext mFlatGUIContext =new FlatGUIContext(); @@ -160,7 +158,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. private long mRefreshStartTime; private WXPerformance mWXPerformance; private ScrollView mScrollView; - private WXScrollViewListener mWXScrollViewListener; + private WXScrollView.WXScrollViewListener mWXScrollViewListener; private List<OnWXScrollListener> mWXScrollListeners; @@ -169,11 +167,9 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. * */ private volatile boolean isPreRenderMode; - private LayoutFinishListener mLayoutFinishListener; - private boolean mCurrentGround = false; private ComponentObserver mComponentObserver; - private boolean mIsCommitedDomAtionExp = false; + private Map<String, GraphicActionAddElement> inactiveAddElementAction = new ArrayMap<>(); /** * set open SandBox @@ -182,25 +178,35 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. public void setUseSandBox(boolean flag) { WXBridgeManager.getInstance().setSandBoxContext(flag); } + public PriorityQueue<WXEmbed> hiddenEmbeds; private int maxHiddenEmbedsNum = -1; //max hidden embed num, -1 standard for ulimit + public int getMaxHiddenEmbedsNum() { + return maxHiddenEmbedsNum; + } - public boolean getismIsCommitedDomAtionExp() { - return mIsCommitedDomAtionExp; + public void setMaxHiddenEmbedsNum(int maxHiddenEmbedsNum) { + this.maxHiddenEmbedsNum = maxHiddenEmbedsNum; } - public void setmIsCommitedDomAtionExp(boolean mIsCommitedDomAtionExp) { - this.mIsCommitedDomAtionExp = mIsCommitedDomAtionExp; + @WorkerThread + @RestrictTo(Scope.LIBRARY) + public void addInActiveAddElementAction(String ref, GraphicActionAddElement action){ + inactiveAddElementAction.put(ref, action); } - public int getMaxHiddenEmbedsNum() { - return maxHiddenEmbedsNum; + @WorkerThread + @RestrictTo(Scope.LIBRARY) + public void removeInActiveAddElmentAction(String ref){ + inactiveAddElementAction.remove(ref); } - public void setMaxHiddenEmbedsNum(int maxHiddenEmbedsNum) { - this.maxHiddenEmbedsNum = maxHiddenEmbedsNum; + @WorkerThread + @RestrictTo(Scope.LIBRARY) + public GraphicActionAddElement getInActiveAddElementAction(String ref){ + return inactiveAddElementAction.get(ref); } /** @@ -213,11 +219,26 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. a.setSDKInstance(this); a.addOnLayoutChangeListener(this); } + mRenderContainer = a; + if (mRenderContainer != null && mRenderContainer.getLayoutParams() != null + && mRenderContainer.getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) { + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().setRenderContentWrapContentToCore(true, getInstanceId()); + } + }); + } else { + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().setRenderContentWrapContentToCore(false, getInstanceId()); + } + }); + } } - - private int mMaxDeepLayer; private int mMaxVDomDeepLayer; @@ -252,7 +273,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. enableLayerType = enable; } - @RestrictTo(Scope.LIBRARY) + @RestrictTo(RestrictTo.Scope.LIBRARY) public @NonNull FlatGUIContext getFlatUIContext(){ return mFlatGUIContext; @@ -269,26 +290,10 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. public void setNeedLoad(boolean load) { mNeedReLoad = load; } - /* - * Warning: use setInstanceViewPortWidth instead. - * store custom ViewPort Width - */ - @Deprecated - public void setViewPortWidth(int viewPortWidth) { - mViewPortWidth = viewPortWidth; - } - - /** - * Warning: use getInstanceViewPortWidth instead. - * @return - */ - @Deprecated - public static int getViewPortWidth() { - return mViewPortWidth; - } public void setInstanceViewPortWidth(int instanceViewPortWidth) { this.mInstanceViewPortWidth = instanceViewPortWidth; + WXSDKManager.getInstance().getWXBridgeManager().setViewPortWidth(getInstanceId(), instanceViewPortWidth); } public int getInstanceViewPortWidth(){ @@ -315,7 +320,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. init(context); } - public WXComponent getRootComponent() { return mRootComp; } @@ -329,6 +333,9 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. if(mNestedInstanceInterceptor != null){ mNestedInstanceInterceptor.onCreateNestInstance(sdkInstance,container); } + if(sdkInstance != null){ + sdkInstance.setComponentObserver(this.getComponentObserver()); + } return sdkInstance; } @@ -393,12 +400,12 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } @Deprecated - public void registerScrollViewListener(WXScrollViewListener scrollViewListener) { + public void registerScrollViewListener(WXScrollView.WXScrollViewListener scrollViewListener) { mWXScrollViewListener = scrollViewListener; } @Deprecated - public WXScrollViewListener getScrollViewListener() { + public WXScrollView.WXScrollViewListener getScrollViewListener() { return mWXScrollViewListener; } @@ -475,11 +482,11 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. if (getUIContext() != null) { new AlertDialog.Builder(getUIContext()) - .setTitle("Error: Missing pageName") - .setMessage("We highly recommend you to set pageName. Call" + - "\nWXSDKInstance#render(String pageName, String template, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag)\n" + - "to fix it.") - .show(); + .setTitle("Error: Missing pageName") + .setMessage("We highly recommend you to set pageName. Call" + + "\nWXSDKInstance#render(String pageName, String template, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag)\n" + + "to fix it.") + .show(); } return; @@ -490,7 +497,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. private void ensureRenderArchor(){ if(mRenderContainer == null){ if (getContext() != null) { - mRenderContainer = new RenderContainer(getContext()); + setRenderContainer(new RenderContainer(getContext())); mRenderContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mRenderContainer.setBackgroundColor(Color.TRANSPARENT); mRenderContainer.setSDKInstance(this); @@ -508,12 +515,12 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. return; } - mWXPerformance.pageName = (TextUtils.isEmpty(pageName) ? "defaultBundleUrl":pageName); - if (TextUtils.isEmpty(mBundleUrl)) { - mBundleUrl = mWXPerformance.pageName; - } + mWXPerformance.pageName = (TextUtils.isEmpty(pageName) ? "defaultBundleUrl":pageName); + if (TextUtils.isEmpty(mBundleUrl)) { + mBundleUrl = mWXPerformance.pageName; + } - WXLogUtils.d("WXSDKInstance", "Start render page: " + pageName); + WXLogUtils.d("WXSDKInstance", "Start render page: " + pageName); if (WXTracing.isAvailable()) { WXTracing.TraceEvent traceEvent = WXTracing.newEvent("executeBundleJS", mInstanceId, -1); @@ -580,11 +587,11 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. WXRequest wxRequest = new WXRequest(); wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString(); - if(wxRequest != null && !TextUtils.isEmpty(wxRequest.url)){ - requestUrl = wxRequest.url; - }else { - requestUrl = pageName; - } + if(wxRequest != null && !TextUtils.isEmpty(wxRequest.url)){ + requestUrl = wxRequest.url; + }else { + requestUrl = pageName; + } if (wxRequest.paramMap == null) { wxRequest.paramMap = new HashMap<String, String>(); @@ -592,7 +599,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. wxRequest.instanceId = getInstanceId(); wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig())); WXHttpListener httpListener = - new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()); + new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()); httpListener.setSDKInstance(this); adapter.sendRequest(wxRequest, (IWXHttpAdapter.OnHttpListener) httpListener); } @@ -653,7 +660,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. private String wrapPageName(String pageName, String url) { if(TextUtils.equals(pageName, WXPerformance.DEFAULT)){ pageName = url; - WXExceptionUtils.degradeUrl = pageName; + WXExceptionUtils.degradeUrl = pageName; try { Uri uri=Uri.parse(url); if(uri!=null){ @@ -693,6 +700,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. // refreshInstance("{}"); } } + /** * Refresh instance asynchronously. * @param data the new data @@ -727,7 +735,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. return mRenderStrategy; } - @Override public Context getUIContext() { return mContext; } @@ -822,15 +829,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. mStatisticsListener = listener; } - public void setLayoutFinishListener(@Nullable LayoutFinishListener listener) { - this.mLayoutFinishListener = listener; - } - - public LayoutFinishListener getLayoutFinishListener() { - return this.mLayoutFinishListener; - } - - /**set render start time*/ public void setRenderStartTime(long renderStartTime) { this.mRenderStartTime = renderStartTime; @@ -845,7 +843,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. * begin hook Activity life cycle callback ********************************************************/ - @Override public void onActivityCreate() { @@ -886,7 +883,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. return true; } - @Override public void onActivityPause() { onViewDisappear(); @@ -918,12 +914,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. Intent intent = new Intent(WXGlobalEventReceiver.EVENT_ACTION); intent.putExtra(WXGlobalEventReceiver.EVENT_NAME, Constants.Event.PAUSE_EVENT); intent.putExtra(WXGlobalEventReceiver.EVENT_WX_INSTANCEID, getInstanceId()); - //todo tmp solution for gray version - if (null != mContext){ - mContext.sendBroadcast(intent); - }else { - WXEnvironment.getApplication().sendBroadcast(intent); - } + mContext.sendBroadcast(intent); this.mCurrentGround = true; } } @@ -946,13 +937,16 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. Intent intent = new Intent(WXGlobalEventReceiver.EVENT_ACTION); intent.putExtra(WXGlobalEventReceiver.EVENT_NAME, Constants.Event.RESUME_EVENT); intent.putExtra(WXGlobalEventReceiver.EVENT_WX_INSTANCEID, getInstanceId()); - mContext.sendBroadcast(intent); - mCurrentGround = false; + //todo tmp solution for gray version + if (null != mContext){ + mContext.sendBroadcast(intent); + }else { + WXEnvironment.getApplication().sendBroadcast(intent); + } + this.mCurrentGround = false; } onViewAppear(); - - setViewPortWidth(mInstanceViewPortWidth); } @Override @@ -1000,7 +994,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. public boolean onBackPressed() { WXComponent comp = getRootComponent(); if(comp != null) { - WXEvent events= comp.getDomObject().getEvents(); + WXEvent events= comp.getEvents(); boolean hasBackPressed = events.contains(Constants.Event.CLICKBACKITEM); if (hasBackPressed) { fireEvent(comp.getRef(), Constants.Event.CLICKBACKITEM,null, null); @@ -1010,7 +1004,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. return false; } - public void onActivityResult(int requestCode, int resultCode, Intent data){ + public void onActivityResult(int requestCode, int resultCode, Intent data){ WXModuleManager.onActivityResult(getInstanceId(),requestCode,resultCode,data); if(mRootComp != null) { @@ -1061,7 +1055,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. public void onCreateFinish() { if (null != mWXPerformance){ mWXPerformance.callCreateFinishTime=System.currentTimeMillis()-mWXPerformance - .renderTimeOrigin; + .renderTimeOrigin; } if (mContext != null) { runOnUiThread(new Runnable() { @@ -1100,14 +1094,13 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. long time = System.currentTimeMillis() - mRenderStartTime; WXLogUtils.renderPerformanceLog("onRenderSuccess", time); + WXLogUtils.renderPerformanceLog(" firstCallAddElementSumTimeï¼"+mWXPerformance.mActionAddElementCount+"ï¼", mWXPerformance.mCallAddElementSumTime); + WXLogUtils.renderPerformanceLog(" firstCallLayoutSumTimeï¼"+mWXPerformance.mActionLayoutCount+"ï¼", mWXPerformance.mCallLayoutSumTime); WXLogUtils.renderPerformanceLog(" invokeCreateInstance",mWXPerformance.communicateTime); - WXLogUtils.renderPerformanceLog(" TotalCallNativeTime", mWXPerformance.callNativeTime); - WXLogUtils.renderPerformanceLog(" TotalJsonParseTime", mWXPerformance.parseJsonTime); - WXLogUtils.renderPerformanceLog(" TotalBatchTime", mWXPerformance.batchTime); - WXLogUtils.renderPerformanceLog(" TotalCssLayoutTime", mWXPerformance.cssLayoutTime); - WXLogUtils.renderPerformanceLog(" TotalApplyUpdateTime", mWXPerformance.applyUpdateTime); - WXLogUtils.renderPerformanceLog(" TotalUpdateDomObjTime", mWXPerformance.updateDomObjTime); + WXLogUtils.renderPerformanceLog(" TotalApplyUpdateTime", mWXPerformance.applyUpdateTime); + WXLogUtils.renderPerformanceLog(" TotalUpdateDomObjTime", mWXPerformance.updateDomObjTime); + WXBridgeManager.getInstance().printRenderFinishTime(getInstanceId()); mWXPerformance.totalTime = time; if(mWXPerformance.screenRenderTime<0.001){ @@ -1161,11 +1154,11 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. */ public void onElementChange(){ if (isDestroy() || !mEnd ||null == mRenderContainer || mRenderContainer.isPageHasEvent() || - mWXPerformance == null){ + mWXPerformance == null){ return; } long lazyLoadTime = System.currentTimeMillis()- mWXPerformance.renderTimeOrigin - mWXPerformance - .callCreateFinishTime; + .callCreateFinishTime; if (lazyLoadTime > 8000){ //bad case return; @@ -1207,7 +1200,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. @Override public final void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int - oldTop, int oldRight, int oldBottom) { + oldTop, int oldRight, int oldBottom) { if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) { onLayoutChange(v); } @@ -1243,56 +1236,105 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } } - public void jsonParseTime(long time) { - mWXPerformance.parseJsonTime += time; - } + public void callCreateBodyTime(long time) { + mWXPerformance.mCallCreateBodySumTime += time; + } - public void firstScreenRenderFinished() { - if(mEnd) - return; + public void callAddElementTime(long time) { + mWXPerformance.mCallAddElementSumTime += time; + } - mEnd = true; + public void callLayoutTime(long time) { + mWXPerformance.mCallLayoutSumTime += time; + } - if (mStatisticsListener != null && mContext != null) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (mStatisticsListener != null && mContext != null) { - Trace.beginSection("onFirstScreen"); - mStatisticsListener.onFirstScreen(); - Trace.endSection(); - } - } - }); - } + public void callLayoutUpdateDemissionTime(long time) { + mWXPerformance.mCallLayoutUpdateDemissionSumTime += time; + } - mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime; - mWXPerformance.fsRenderTime = System.currentTimeMillis(); - WXLogUtils.renderPerformanceLog("firstScreenRenderFinished", mWXPerformance.screenRenderTime); - WXLogUtils.renderPerformanceLog(" firstScreenJSFExecuteTime", mWXPerformance.firstScreenJSFExecuteTime); - WXLogUtils.renderPerformanceLog(" firstScreenCallNativeTime", mWXPerformance.callNativeTime); - WXLogUtils.renderPerformanceLog(" firstScreenJsonParseTime", mWXPerformance.parseJsonTime); - WXLogUtils.renderPerformanceLog(" firstScreenBatchTime", mWXPerformance.batchTime); - WXLogUtils.renderPerformanceLog(" firstScreenCssLayoutTime", mWXPerformance.cssLayoutTime); - WXLogUtils.renderPerformanceLog(" firstScreenApplyUpdateTime", mWXPerformance.applyUpdateTime); - WXLogUtils.renderPerformanceLog(" firstScreenUpdateDomObjTime", mWXPerformance.updateDomObjTime); + public void callLayoutaAplyLayoutAndEventTime(long time) { + mWXPerformance.mCallLayoutApplyLayoutAndEventSumTime += time; } - public void batchTime(long time) { - mWXPerformance.batchTime += time; + public void callLayoutBindDataCoreTime(long time) { + mWXPerformance.mCallLayoutBindDataSumTime += time; } - public void cssLayoutTime(long time) { - mWXPerformance.cssLayoutTime += time; + + public void callActionLayoutTime(long time) { + mWXPerformance.mActionLayoutSumTime += time; + } + + public void callActionAddElementTime(long time) { + mWXPerformance.mActionAddElementSumTime += time; } - public void applyUpdateTime(long time) { - mWXPerformance.applyUpdateTime += time; + public void callActionCreateBodyTime(long time) { + mWXPerformance.mActionCreateBodySumTime += time; } - public void updateDomObjTime(long time) { - mWXPerformance.updateDomObjTime += time; + public void callActionOtherTime(long time) { + mWXPerformance.mActionOtherSumTime += time; + } + + public void callActionAddElementCount() { + mWXPerformance.mActionAddElementCount++; } + public void callActionCreateBodyCount() { + mWXPerformance.mActionCreateBodyCount++; + } + + public void callActionLayoutCount() { + mWXPerformance.mActionLayoutCount++; + } + + public void callActionOtherCount() { + mWXPerformance.mActionOtherCount++; + } + + public void jsonParseTime(long time) { + mWXPerformance.parseJsonTime += time; + } + + public void firstScreenRenderFinished() { + if (mEnd) + return; + + mEnd = true; + + if (mStatisticsListener != null && mContext != null) { + runOnUiThread(new Runnable() { + @Override + public void run() { + if (mStatisticsListener != null && mContext != null) { + Trace.beginSection("onFirstScreen"); + mStatisticsListener.onFirstScreen(); + Trace.endSection(); + } + } + }); + } + + mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime; + mWXPerformance.fsRenderTime = System.currentTimeMillis(); + WXLogUtils.renderPerformanceLog("firstScreenJSFAndWeexCoreExecuteTime", mWXPerformance.firstScreenJSFExecuteTime); + WXLogUtils.renderPerformanceLog("firstScreenRenderFinished", mWXPerformance.screenRenderTime); + WXLogUtils.renderPerformanceLog(" firstScreenApplyUpdateTime", mWXPerformance.applyUpdateTime); + WXLogUtils.renderPerformanceLog(" firstScreenUpdateDomObjTime", mWXPerformance.updateDomObjTime); + WXLogUtils.renderPerformanceLog(" firstCallCreateBodySumTimeï¼"+mWXPerformance.mActionCreateBodyCount+"ï¼", mWXPerformance.mCallCreateBodySumTime); + WXLogUtils.renderPerformanceLog(" firstCallAddElementSumTimeï¼"+mWXPerformance.mActionAddElementCount+"ï¼", mWXPerformance.mCallAddElementSumTime); + WXLogUtils.renderPerformanceLog(" firstCallLayoutSumTimeï¼"+mWXPerformance.mActionLayoutCount+"ï¼", mWXPerformance.mCallLayoutSumTime); + WXLogUtils.renderPerformanceLog(" firstScreenRenderSumTime", mWXPerformance.renderSumTime()); + WXLogUtils.renderPerformanceLog(" firstActionCreateBodySumTime", mWXPerformance.mActionCreateBodySumTime); + WXLogUtils.renderPerformanceLog(" firstActionAddElementSumTime", mWXPerformance.mActionAddElementSumTime); + WXLogUtils.renderPerformanceLog(" firstActionLayoutSumTime", mWXPerformance.mActionLayoutSumTime); + WXLogUtils.renderPerformanceLog(" firstCallLayoutUpdateDemissionSumTime", mWXPerformance.mCallLayoutUpdateDemissionSumTime); + WXLogUtils.renderPerformanceLog(" firstCallLayoutApplyLayoutAndEventSumTime", mWXPerformance.mCallLayoutApplyLayoutAndEventSumTime); + WXLogUtils.renderPerformanceLog(" firstCallLayoutBindDataSumTime", mWXPerformance.mCallLayoutBindDataSumTime); + WXLogUtils.renderPerformanceLog(" firstActionOtherSumTimeï¼"+mWXPerformance.mActionOtherCount+"ï¼", mWXPerformance.mActionOtherSumTime); + + WXBridgeManager.getInstance().printFirstScreenRenderTime(getInstanceId()); + } public void createInstanceFinished(long time) { if (time > 0) { @@ -1300,40 +1342,6 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } } - /** - * UserTrack Log instead by {@code WXExceptionUtils#commitCriticalExceptionRT} - */ -// public void commitUTStab(final String type, final WXErrorCode errorCode) { -// if (TextUtils.isEmpty(type) || errorCode == null) { -// return; -// } -// -// runOnUiThread(new Runnable() { -// @Override -// public void run() { -// // Record exception if a render error happened. -// if (mStatisticsListener != null && errorCode != WXErrorCode.WX_SUCCESS) { -// mStatisticsListener.onException(mInstanceId, -// errorCode.getErrorCode(), -// errorCode.getErrorMsg()); -// } -// -// WXPerformance performance = new WXPerformance(); -// performance.errCode = errorCode.getErrorCode(); -// performance.args = errorCode.getArgs(); -// if (errorCode != WXErrorCode.WX_SUCCESS) { -// performance.errMsg = errorCode.getErrorMsg(); -// if (WXEnvironment.isApkDebugable()) { -// WXLogUtils.d(performance.toString()); -// } -// } -// if( mUserTrackAdapter!= null) { -// mUserTrackAdapter.commit(mContext, null, type, performance, getUserTrackParams()); -// } -// } -// }); -// } - private void destroyView(View rootView) { try { if (rootView instanceof ViewGroup) { @@ -1393,12 +1401,20 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. isDestroy = true; mStatisticsListener = null; if(responseHeaders != null){ - responseHeaders.clear(); + responseHeaders.clear(); } if(templateRef != null){ templateRef = null; } mWXPerformance.afterInstanceDestroy(mInstanceId); + + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().onInstanceClose(getInstanceId()); + inactiveAddElementAction.clear(); + } + }); } } @@ -1414,6 +1430,8 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } public View getRootView() { + if (mRootComp == null) + return null; return mRootComp.getRealView(); } @@ -1459,6 +1477,20 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } } + public int getRenderContainerPaddingLeft() { + if(mRenderContainer != null) { + return mRenderContainer.getPaddingLeft(); + } + return 0; + } + + public int getRenderContainerPaddingTop() { + if(mRenderContainer != null) { + return mRenderContainer.getPaddingTop(); + } + return 0; + } + public synchronized List<OnWXScrollListener> getWXScrollListeners() { return mWXScrollListeners; } @@ -1470,46 +1502,30 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. mWXScrollListeners.add(wxScrollListener); } - private void updateRootComponentStyle(JSONObject style) { - Message message = Message.obtain(); - WXDomTask task = new WXDomTask(); - task.instanceId = getInstanceId(); - if (task.args == null) { - task.args = new ArrayList<>(); - } - task.args.add(WXDomObject.ROOT); - task.args.add(style); - message.obj = task; - message.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE; - WXSDKManager.getInstance().getWXDomManager().sendMessage(message); - } - public void setSize(int width, int height) { - if (width < 0 || height < 0 || isDestroy || !mRendered) { - return; - } - float realWidth = WXViewUtils.getWebPxByWidth(width,getInstanceViewPortWidth()); - float realHeight = WXViewUtils.getWebPxByWidth(height,getInstanceViewPortWidth()); - - View godView = mRenderContainer; - if (godView != null) { - ViewGroup.LayoutParams layoutParams = godView.getLayoutParams(); + if (width > 0 && height > 0 & !isDestroy && mRendered && mRenderContainer != null) { + ViewGroup.LayoutParams layoutParams = mRenderContainer.getLayoutParams(); if (layoutParams != null) { - if(godView.getWidth() != width || godView.getHeight() != height) { + final float realWidth = width; + final float realHeight = height; + if (mRenderContainer.getWidth() != width || mRenderContainer.getHeight() != height) { layoutParams.width = width; layoutParams.height = height; - godView.setLayoutParams(layoutParams); + mRenderContainer.setLayoutParams(layoutParams); } - JSONObject style = new JSONObject(); - WXComponent rootComponent = mRootComp; + if (mRootComp != null && layoutParams != null) { + final boolean isWidthWrapContent = layoutParams.width == ViewGroup.LayoutParams.WRAP_CONTENT; + final boolean isHeightWrapContent = layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT; - if(rootComponent == null){ - return; + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().setDefaultRootSize(getInstanceId(), realWidth, realHeight, isWidthWrapContent, + isHeightWrapContent); + } + }); } - style.put(Constants.Name.DEFAULT_WIDTH, realWidth); - style.put(Constants.Name.DEFAULT_HEIGHT, realHeight); - updateRootComponentStyle(style); } } } @@ -1551,7 +1567,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. * @param domChanges */ public void fireEvent(String elementRef,final String type, final Map<String, Object> data,final Map<String, Object> domChanges){ - fireEvent(elementRef, type, data, domChanges, null); + fireEvent(elementRef, type, data, domChanges, null); } public void fireEvent(String elementRef,final String type, final Map<String, Object> data){ @@ -1623,7 +1639,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. * Check whether the current module registered the event * @param eventName EventName register in weex * @param module Events occur in this Module - * @return boolean true + * @return register->true */ public boolean checkModuleEventRegistered(String eventName,WXModule module) { if (module != null) { @@ -1723,17 +1739,17 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. @Override public void onHttpStart() { if (this.instance != null - && this.instance.getWXStatisticsListener() != null) { + && this.instance.getWXStatisticsListener() != null) { this.instance.getWXStatisticsListener().onHttpStart(); - this.instance.onHttpStart(); } } @Override public void onHeadersReceived(int statusCode, Map<String,List<String>> headers) { if (this.instance != null - && this.instance.getWXStatisticsListener() != null) { + && this.instance.getWXStatisticsListener() != null) { this.instance.getWXStatisticsListener().onHeadersReceived(); + this.instance.onHttpStart(); } if(this.instance != null && this.instance.responseHeaders != null @@ -1755,7 +1771,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. @Override public void onHttpFinish(WXResponse response) { if (this.instance != null - && this.instance.getWXStatisticsListener() != null) { + && this.instance.getWXStatisticsListener() != null) { this.instance.getWXStatisticsListener().onHttpFinish(); } @@ -1822,7 +1838,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. performance.appendErrMsg("|template is null!"); }else { performance.errCode=WXErrorCode.WX_SUCCESS.getErrorCode(); - } + } if (mUserTrackAdapter != null) { mUserTrackAdapter.commit(getContext(), null, IWXUserTrackAdapter.JS_DOWNLOAD, performance, null); @@ -1834,29 +1850,29 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. String template = new String(response.originalData); render(pageName, template, options, jsonInitData, flag); - // check content-type + // check content-type } else if (TextUtils.equals(WXErrorCode.WX_DEGRAD_ERR_BUNDLE_CONTENTTYPE_ERROR.getErrorCode(), - response.statusCode)) { + response.statusCode)) { WXLogUtils.e("user intercept: WX_DEGRAD_ERR_BUNDLE_CONTENTTYPE_ERROR"); onRenderError(WXErrorCode.WX_DEGRAD_ERR_BUNDLE_CONTENTTYPE_ERROR.getErrorCode(), - "|response.errorMsg==" + response.errorMsg + - "|instance.getTemplateInfo == \n" + instance.getTemplateInfo() + - "|instance bundleUrl = \n" + instance.getBundleUrl() + - "|instance requestUrl = \n" + Uri.decode(WXSDKInstance.requestUrl) - ); + "|response.errorMsg==" + response.errorMsg + + "|instance.getTemplateInfo == \n" + instance.getTemplateInfo() + + "|instance bundleUrl = \n" + instance.getBundleUrl() + + "|instance requestUrl = \n" + Uri.decode(WXSDKInstance.requestUrl) + ); - // check content-length + // check content-length } else if (response!=null && response.originalData!=null && TextUtils.equals("-206", response.statusCode)) { - WXLogUtils.e("user intercept: WX_DEGRAD_ERR_NETWORK_CHECK_CONTENT_LENGTH_FAILED"); - onRenderError( - WXErrorCode.WX_DEGRAD_ERR_NETWORK_CHECK_CONTENT_LENGTH_FAILED.getErrorCode(), + WXLogUtils.e("user intercept: WX_DEGRAD_ERR_NETWORK_CHECK_CONTENT_LENGTH_FAILED"); + onRenderError( + WXErrorCode.WX_DEGRAD_ERR_NETWORK_CHECK_CONTENT_LENGTH_FAILED.getErrorCode(), WXErrorCode.WX_DEGRAD_ERR_NETWORK_CHECK_CONTENT_LENGTH_FAILED.getErrorCode() + - "|response.errorMsg==" + response.errorMsg + - "|instance.getTemplateInfo == \n" + instance.getTemplateInfo()); - } + "|response.errorMsg==" + response.errorMsg + + "|instance.getTemplateInfo == \n" + instance.getTemplateInfo()); + } else { onRenderError(WXErrorCode.WX_DEGRAD_ERR_NETWORK_BUNDLE_DOWNLOAD_FAILED.getErrorCode(), - response.errorMsg); + response.errorMsg); } } } @@ -1864,8 +1880,8 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. private boolean isNet(String requestType){ return "network".equals(requestType) || "2g".equals(requestType) || "3g".equals(requestType) - || "4g".equals(requestType) || "wifi".equals(requestType) || "other".equals(requestType) - || "unknown".equals(requestType); + || "4g".equals(requestType) || "wifi".equals(requestType) || "other".equals(requestType) + || "unknown".equals(requestType); } /** @@ -1891,7 +1907,7 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. responseHeaders.put(SOURCE_TEMPLATE_BASE64_MD5, sourceBase64MD5List); return " template md5 " + sourceMD5 + " length " + bts.length + " base64 md5 " + sourceBase64MD5 - + " response header " + JSONObject.toJSONString(responseHeaders); + + " response header " + JSONObject.toJSONString(responseHeaders); } catch (UnsupportedEncodingException e) { return "template md5 getBytes error"; } @@ -1933,10 +1949,22 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View. } public void setTemplate(String template) { - this.templateRef = new WeakReference<>(template); + this.templateRef = new WeakReference<String>(template); } public interface NestedInstanceInterceptor { void onCreateNestInstance(WXSDKInstance instance, NestedContainer container); } + + public void OnVSync() { + boolean forceLayout = WXBridgeManager.getInstance().notifyLayout(getInstanceId()); + if(forceLayout) { + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().forceLayout(getInstanceId()); + } + }); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java index b9a0913..1823ef2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java @@ -48,7 +48,6 @@ import com.taobao.weex.common.WXRefreshData; import com.taobao.weex.common.WXRuntimeException; import com.taobao.weex.common.WXThread; import com.taobao.weex.common.WXWorkThreadManager; -import com.taobao.weex.dom.WXDomManager; import com.taobao.weex.performance.IWXAnalyzer; import com.taobao.weex.ui.WXRenderManager; import com.taobao.weex.utils.WXLogUtils; @@ -68,7 +67,6 @@ public class WXSDKManager { private static volatile WXSDKManager sManager; private static AtomicInteger sInstanceId = new AtomicInteger(0); - private final WXDomManager mWXDomManager; private final WXWorkThreadManager mWXWorkThreadManager; private WXBridgeManager mBridgeManager; /** package **/ WXRenderManager mWXRenderManager; @@ -106,7 +104,6 @@ public class WXSDKManager { private WXSDKManager(WXRenderManager renderManager) { mWXRenderManager = renderManager; - mWXDomManager = new WXDomManager(mWXRenderManager); mBridgeManager = WXBridgeManager.getInstance(); mWXWorkThreadManager = new WXWorkThreadManager(); mWXAnalyzerList = new ArrayList<>(); @@ -196,10 +193,6 @@ public class WXSDKManager { mBridgeManager.restart(); } - public WXDomManager getWXDomManager() { - return mWXDomManager; - } - public WXBridgeManager getWXBridgeManager() { return mBridgeManager; } @@ -221,9 +214,6 @@ public class WXSDKManager { } public void destroy() { - if (mWXDomManager != null) { - mWXDomManager.destroy(); - } if (mWXWorkThreadManager != null) { mWXWorkThreadManager.destroy(); } @@ -307,7 +297,6 @@ public class WXSDKManager { } } mWXRenderManager.removeRenderStatement(instanceId); - mWXDomManager.removeDomStatement(instanceId); mBridgeManager.destroyInstance(instanceId); WXModuleManager.destroyInstanceModules(instanceId); } @@ -352,7 +341,7 @@ public class WXSDKManager { public ClassLoaderAdapter getClassLoaderAdapter() { if(mClassLoaderAdapter == null){ - mClassLoaderAdapter = new ClassLoaderAdapter(); + mClassLoaderAdapter = new ClassLoaderAdapter(); } return mClassLoaderAdapter; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/WeexFrameRateControl.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WeexFrameRateControl.java b/android/sdk/src/main/java/com/taobao/weex/WeexFrameRateControl.java new file mode 100644 index 0000000..61f47eb --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/WeexFrameRateControl.java @@ -0,0 +1,88 @@ +/** + * 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. + */ +package com.taobao.weex; + +/** + * Created by shiwentao on 2017/8/24. + */ + +import android.annotation.TargetApi; +import android.os.Build; +import android.view.Choreographer; + +import java.lang.ref.WeakReference; + +public class WeexFrameRateControl { + private static final long VSYNC_FRAME = 1000 / 16; + private WeakReference<VSyncListener> mListener; + private final Choreographer mChoreographer; + private final Choreographer.FrameCallback mVSyncFrameCallback; + private final Runnable runnable; + + public interface VSyncListener { + void OnVSync(); + } + + public WeexFrameRateControl(VSyncListener listener) { + mListener = new WeakReference<>(listener); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + mChoreographer = Choreographer.getInstance(); + mVSyncFrameCallback = new Choreographer.FrameCallback() { + @Override + public void doFrame(long frameTimeNanos) { + mChoreographer.postFrameCallback(mVSyncFrameCallback); + if (mListener != null && mListener.get() != null) { + mListener.get().OnVSync(); + } + } + }; + runnable = null; + } else { + // For API 15 or lower + runnable = new Runnable() { + @Override + public void run() { + WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(runnable, VSYNC_FRAME); + if (mListener != null && mListener.get() != null) { + mListener.get().OnVSync(); + } + } + }; + mChoreographer = null; + mVSyncFrameCallback = null; + } + } + + public void start() { + if (mChoreographer != null) { + mChoreographer.postFrameCallback(mVSyncFrameCallback); + } + else if(runnable!=null){ + WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(runnable, VSYNC_FRAME); + } + } + + public void stop() { + if (mChoreographer != null) { + mChoreographer.removeFrameCallback(mVSyncFrameCallback); + }else if(runnable!=null){ + WXSDKManager.getInstance().getWXRenderManager().removeTask(runnable); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/adapter/ClassLoaderAdapter.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/adapter/ClassLoaderAdapter.java b/android/sdk/src/main/java/com/taobao/weex/adapter/ClassLoaderAdapter.java index fcd1956..7d6a854 100644 --- a/android/sdk/src/main/java/com/taobao/weex/adapter/ClassLoaderAdapter.java +++ b/android/sdk/src/main/java/com/taobao/weex/adapter/ClassLoaderAdapter.java @@ -23,7 +23,6 @@ import android.content.Context; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.common.WXModule; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.utils.WXLogUtils; /** * Created by furture on 2018/2/7. http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/appfram/websocket/WebSocketCloseCodes.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/websocket/WebSocketCloseCodes.java b/android/sdk/src/main/java/com/taobao/weex/appfram/websocket/WebSocketCloseCodes.java index 0f742ae..6251399 100644 --- a/android/sdk/src/main/java/com/taobao/weex/appfram/websocket/WebSocketCloseCodes.java +++ b/android/sdk/src/main/java/com/taobao/weex/appfram/websocket/WebSocketCloseCodes.java @@ -20,7 +20,7 @@ package com.taobao.weex.appfram.websocket; /** * Created by moxun on 17/1/3. - * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent">CloseEvent</a> + * @link {https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent} */ public enum WebSocketCloseCodes { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/base/CalledByNative.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/base/CalledByNative.java b/android/sdk/src/main/java/com/taobao/weex/base/CalledByNative.java new file mode 100644 index 0000000..15fa920 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/base/CalledByNative.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +package com.taobao.weex.base; +public @interface CalledByNative { +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/base/FloatUtil.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/base/FloatUtil.java b/android/sdk/src/main/java/com/taobao/weex/base/FloatUtil.java new file mode 100755 index 0000000..ecbeeb4 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/base/FloatUtil.java @@ -0,0 +1,31 @@ +/** + * 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. + */ +package com.taobao.weex.base; + +public class FloatUtil { + + private static final float EPSILON = .00001f; + + public static boolean floatsEqual(float f1, float f2) { + if (Float.isNaN(f1) || Float.isNaN(f2)) { + return Float.isNaN(f1) && Float.isNaN(f2); + } + return Math.abs(f2 - f1) < EPSILON; + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java b/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java new file mode 100644 index 0000000..6a408fb --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java @@ -0,0 +1,106 @@ +/** + * 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. + */ +package com.taobao.weex.base; + +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + + +public class SystemMessageHandler extends Handler implements Serializable { + + private static final String TAG = "SystemMessageHandler"; + + private static final int SCHEDULED_WORK = 1; + + private long mMessagePumpDelegateNative = 0; + + private boolean mIsRunning = false; + + private Method mMessageMethodSetAsynchronous; + + private native void nativeRunWork(long delegateNative); + + private SystemMessageHandler(long messagePumpDelegateNative) { + this.mMessagePumpDelegateNative = messagePumpDelegateNative; + try { + Class<?> messageClass = Class.forName("android.os.Message"); + mMessageMethodSetAsynchronous = messageClass.getMethod( + "setAsynchronous", new Class[]{boolean.class}); + } catch (ClassNotFoundException e) { + Log.e(TAG, "Failed to find android.os.Message class:" + e); + } catch (NoSuchMethodException e) { + Log.e(TAG, "Failed to load Message.setAsynchronous method:" + e); + } catch (RuntimeException e) { + Log.e(TAG, "Exception while loading Message.setAsynchronous method: " + e); + } + mIsRunning = true; + } + + @CalledByNative + public static SystemMessageHandler create(long messagePumpDelegateNative) { + return new SystemMessageHandler(messagePumpDelegateNative); + } + + @CalledByNative + private void scheduleWork() { + sendMessage(obtainAsyncMessage(SCHEDULED_WORK)); + } + + @CalledByNative + private void stop() { + mIsRunning = false; + } + + private Message obtainAsyncMessage(int what) { + Message msg = Message.obtain(); + msg.what = what; + if (mMessageMethodSetAsynchronous != null) { + // If invocation fails, assume this is indicative of future + // failures, and avoid log spam by nulling the reflected method. + try { + mMessageMethodSetAsynchronous.invoke(msg, true); + } catch (IllegalAccessException e) { + Log.e(TAG, "Illegal access to asynchronous message creation, disabling."); + mMessageMethodSetAsynchronous = null; + } catch (IllegalArgumentException e) { + Log.e(TAG, "Illegal argument for asynchronous message creation, disabling."); + mMessageMethodSetAsynchronous = null; + } catch (InvocationTargetException e) { + Log.e(TAG, "Invocation exception during asynchronous message creation, disabling."); + mMessageMethodSetAsynchronous = null; + } catch (RuntimeException e) { + Log.e(TAG, "Runtime exception during asynchronous message creation, disabling."); + mMessageMethodSetAsynchronous = null; + } + } + return msg; + } + + @Override + public void handleMessage(Message msg) { + if(mIsRunning) { + nativeRunWork(mMessagePumpDelegateNative); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/bridge/JSCallback.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/JSCallback.java b/android/sdk/src/main/java/com/taobao/weex/bridge/JSCallback.java index 4bf8412..d0ccb69 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/JSCallback.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/JSCallback.java @@ -18,8 +18,6 @@ */ package com.taobao.weex.bridge; -import java.util.Map; - /** * Created by sospartan on 5/24/16. */ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/bridge/ModuleFactoryImpl.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/ModuleFactoryImpl.java b/android/sdk/src/main/java/com/taobao/weex/bridge/ModuleFactoryImpl.java index fe0e00a..da26f14 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/ModuleFactoryImpl.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/ModuleFactoryImpl.java @@ -23,16 +23,15 @@ package com.taobao.weex.bridge; */ public class ModuleFactoryImpl { - public ModuleFactory mFactory = null; - public boolean hasRigster = false; + public ModuleFactory mFactory = null; + public boolean hasRigster = false; - public ModuleFactoryImpl(ModuleFactory factory) { - mFactory = factory; - } - - public ModuleFactoryImpl(ModuleFactory factory, boolean rigister) { - mFactory = factory; - hasRigster = rigister; - } -} + public ModuleFactoryImpl(ModuleFactory factory) { + mFactory = factory; + } + public ModuleFactoryImpl(ModuleFactory factory, boolean rigister) { + mFactory = factory; + hasRigster = rigister; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/bridge/NativeInvokeHelper.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/NativeInvokeHelper.java b/android/sdk/src/main/java/com/taobao/weex/bridge/NativeInvokeHelper.java index dc38025..0480aaa 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/NativeInvokeHelper.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/NativeInvokeHelper.java @@ -34,21 +34,23 @@ public final class NativeInvokeHelper { private String mInstanceId; public NativeInvokeHelper(String instanceId){ - mInstanceId = instanceId; + mInstanceId = instanceId; } public Object invoke(final Object target,final Invoker invoker,JSONArray args) throws Exception { final Object[] params = prepareArguments( - invoker.getParameterTypes(), - args); + invoker.getParameterTypes(), + args); if (invoker.isRunOnUIThread()) { WXSDKManager.getInstance().postOnUiThread(new Runnable() { @Override public void run() { - try { - invoker.invoke(target, params); - } catch (Exception e) { - throw new RuntimeException(target + "Invoker " + invoker.toString() ,e); + if (invoker != null) { + try { + invoker.invoke(target, params); + } catch (Exception e) { + throw new RuntimeException(target + "Invoker " + invoker.toString(), e); + } } } }, 0);
