Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into orientation-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored Jun 5, 2019
2 parents 8154514 + 7eaee85 commit 9a8362e
Show file tree
Hide file tree
Showing 46 changed files with 718 additions and 213 deletions.
16 changes: 7 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

buildscript {
repositories {
jcenter {
url 'https://maven.aliyun.com/repository/jcenter'
}
mavenLocal()
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
Expand All @@ -41,18 +41,16 @@ subprojects {
}
}
repositories {
mavenLocal()
if(project.hasProperty('external_repositories')){
maven {
url external_repositories
}
}
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com'
jcenter {
url 'https://maven.aliyun.com/repository/jcenter'
}
mavenCentral()
mavenLocal()
}
buildscript {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ protected void onCreate(Bundle savedInstanceState) {

mWxAnalyzerDelegate = new WXAnalyzerDelegate(this);
mWxAnalyzerDelegate.onCreate();

//if (mInstance.isPreDownLoad() || mInstance.isPreInitMode()){
mInstance.onInstanceReady();
//}
}

@Override
Expand Down Expand Up @@ -219,21 +223,36 @@ private void initUIAndData() {
}

private void loadWXfromService(final String url) {

Log.d("test->", "on ActivityCreate ,loadWXfromService: ");

mProgressBar.setVisibility(View.VISIBLE);

if (mInstance != null) {
mInstance.destroy();
}

RenderContainer renderContainer = new RenderContainer(this);
mInstance = new WXSDKInstance(this);
//mInstance = new WXSDKInstance(this);
mInstance = WXPreLoadManager.getInstance().offerPreInitInstance(url);
if (null != mInstance){
mInstance.init(this);
}else {
mInstance = new WXSDKInstance(this);
}

mInstance.setRenderContainer(renderContainer);
mInstance.registerRenderListener(this);
mInstance.setNestedInstanceInterceptor(this);
mInstance.setBundleUrl(url);
mInstance.setTrackComponent(true);
mContainer.addView(renderContainer);

if (mInstance.isPreDownLoad()){
return;
}


WXHttpTask httpTask = new WXHttpTask();
httpTask.url = url;
httpTask.requestListener = new WXRequestListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* 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.alibaba.weex;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import android.util.Log;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.WXRenderStrategy;
import com.taobao.weex.utils.WXLogUtils;

/**
* @author zhongcang
* @date 2019/5/13
*/
public class WXPreLoadManager {

private Map<String, WXSDKInstance> mPreInitInstanceMap;

private static class SingleTonHolder {
private static final WXPreLoadManager INSTANCE = new WXPreLoadManager();
}

private WXPreLoadManager() {
mPreInitInstanceMap = new ConcurrentHashMap<>();
}

public static WXPreLoadManager getInstance() {
return SingleTonHolder.INSTANCE;
}

public WXSDKInstance offerPreInitInstance(String pageName) {
WXSDKInstance instance = mPreInitInstanceMap.remove(pageName);
return instance;
}

public void preLoad(String url) {

boolean preDownLoad = url.contains("preDownLoad=true");
boolean preInit = url.contains("preInitInstance=rax") || url.contains("preInitInstance=vue");
if (!preDownLoad && !preInit){
return;
}


WXSDKInstance instance = new WXSDKInstance();
Map<String, Object> options = new HashMap<>();
options.put("bundleUrl", url);
options.put("render_strategy", WXRenderStrategy.APPEND_ASYNC.toString());
options.put("wxPreInit",preInit);
options.put("wxPreDownLoad",preDownLoad);
String script = null;
if (preInit){
if (url.contains("preInitInstance=rax")) {
script = "// { \"framework\": \"Rax\" }\n";
} else if (url.contains("preInitInstance=vue")) {
script = "// { \"framework\": \"Vue\" }\n";
} else {
WXLogUtils.e("WXPreLoadManager", "unsupport init bundle type :" + url);
}
if (null != script) {
mPreInitInstanceMap.put(url, instance);
Log.d("test->", "start preInit: ");
instance.preInit(url, script, options, null, WXRenderStrategy.APPEND_ASYNC);
}
}
if (preDownLoad){
if (!mPreInitInstanceMap.containsKey(url)) {
mPreInitInstanceMap.put(url, instance);
}
Log.d("test->", "start preDownLoad: ");
instance.preDownLoad(url, options, null, WXRenderStrategy.APPEND_ASYNC);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

import com.alibaba.weex.R;
import com.alibaba.weex.WXPageActivity;
import com.alibaba.weex.WXPreLoadManager;
import com.alibaba.weex.constants.Constants;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
Expand Down Expand Up @@ -587,6 +590,13 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle
finish();
return;
} else {
String urlData = uri.getQueryParameter(Constants.WEEX_TPL_KEY);
if (TextUtils.isEmpty(urlData)){
urlData = code;
}
Log.d("test->", "before nav activity ");

WXPreLoadManager.getInstance().preLoad(urlData);
Toast.makeText(this, rawResult.getText(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(CaptureActivity.this, WXPageActivity.class);
intent.setData(Uri.parse(code));
Expand Down
17 changes: 5 additions & 12 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@
*/

buildscript {
repositories {
mavenLocal()
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
if(!project.disableCov) {
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0'
}
Expand Down Expand Up @@ -246,11 +239,11 @@ if(file('../license/LICENSE').exists()){
'Source/android/jniprebuild/jniheader/*.h',
'Source/base/Compatible.cpp',
'Source/IPC/**/*.h','Source/IPC/**/*.cpp', 'Source/IPC/**/*.c',
'weex_core/Source/android/jsengine/dependence/**/*.h',
'weex_core/Source/android/jsengine/dependence/**/*.cpp',
'weex_core/Source/include/wtf/Optional.h',
'weex_core/Source/include/wtf/Brigand.h',
'weex_core/Source/include/wtf/Variant.h'])
'Source/android/jsengine/dependence/**/*.h',
'Source/android/jsengine/dependence/**/*.cpp',
'Source/include/wtf/Optional.h',
'Source/include/wtf/Brigand.h',
'Source/include/wtf/Variant.h'])
}
preBuild.dependsOn licenseFormat
}
Expand Down
33 changes: 33 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXHttpListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class WXHttpListener implements IWXHttpAdapter.OnHttpListener {
private WXPerformance mWXPerformance;
private WXInstanceApm mApmForInstance;
private IWXUserTrackAdapter mUserTrackAdapter;
public boolean isPreDownLoadMode = false;
private boolean isInstanceReady =false;
private boolean isResponseHasWait = false;
private WXResponse mResponse;

private String mBundleUrl;

Expand Down Expand Up @@ -202,6 +206,35 @@ public void onHttpFinish(WXResponse response) {
}
}
}

if (isPreDownLoadMode){
if (isInstanceReady){
WXLogUtils.e("test->", "DownLoad didHttpFinish on http" );
didHttpFinish(response);
}else {
WXLogUtils.e("test->", "DownLoad end before activity created" );
mResponse = response;
isResponseHasWait = true;
}
}else {
didHttpFinish(response);
}

}

public void onInstanceReady(){
if (!isPreDownLoadMode){
return;
}
this.isInstanceReady = true;
if (isResponseHasWait){
WXLogUtils.e("test->", "preDownLoad didHttpFinish on ready" );
this.didHttpFinish(mResponse);
}

}

private void didHttpFinish(WXResponse response){
String wxErrorCode = WXInstanceApm.VALUE_ERROR_CODE_DEFAULT;
if (response!=null && response.originalData!=null && TextUtils.equals("200", response.statusCode)) {
mApmForInstance.onStage(WXInstanceApm.KEY_PAGE_STAGES_DOWN_BUNDLE_END);
Expand Down
Loading

0 comments on commit 9a8362e

Please sign in to comment.