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

* [Android] Add the ability of FlatGUI #643

Merged
merged 10 commits into from
Sep 13, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

package com.alibaba.weex.benchmark;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static org.hamcrest.MatcherAssert.assertThat;

import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.filters.SdkSuppress;
Expand All @@ -30,29 +34,22 @@
import android.support.test.uiautomator.Until;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.weex.BenchmarkActivity;
import com.taobao.weex.ui.view.listview.WXRecyclerView;
import com.taobao.weex.utils.WXLogUtils;

import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static org.hamcrest.MatcherAssert.assertThat;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class BenchmarkTest {
Expand All @@ -68,9 +65,7 @@ public class BenchmarkTest {
private static List<Long> firstScreenRenderTime = new LinkedList<>();
private static List<Long> flingFrameSeconds = new LinkedList<>();
private static List<Long> scrollFrameSeconds = new LinkedList<>();
private static final String DUMP_START = "Flags,IntendedVsync,Vsync,OldestInputEvent,NewestInputEvent,"
+ "HandleInputStart,AnimationStart,PerformTraversalsStart,DrawStart,"
+ "SyncQueued,SyncStart,IssueDrawCommandsStart,SwapBuffers,FrameCompleted,\n";
private static final String DUMP_START = "QueueBufferDuration,\n";
private static final String DUMP_END = "---PROFILEDATA---";
private static final String DUMP_COMMAND = "dumpsys gfxinfo com.alibaba.weex framestats reset";

Expand Down Expand Up @@ -195,7 +190,7 @@ private List<Long> createList(BufferedReader bufferedReader) throws IOException

private long calcTime() {
BenchmarkActivity benchmarkActivity = mActivityRule.getActivity();
benchmarkActivity.loadWeexPage();
benchmarkActivity.loadWeexPage("http://30.8.53.163:8080/complicated.js");
onView(withClassName(Matchers.is(WXRecyclerView.class.getName()))).perform
(RecyclerViewActions.scrollToPosition(0));
return benchmarkActivity.getWXInstance().getWXPerformance().screenRenderTime;
Expand Down
75 changes: 44 additions & 31 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.taobao.weex;

import static com.taobao.weex.http.WXHttpUtil.KEY_USER_AGENT;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
Expand All @@ -28,13 +30,14 @@
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.IWXHttpAdapter;
Expand Down Expand Up @@ -68,6 +71,7 @@
import com.taobao.weex.ui.component.WXBasicComponentType;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXComponentFactory;
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;
Expand All @@ -76,8 +80,6 @@
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXReflectionUtils;
import com.taobao.weex.utils.WXViewUtils;
import com.taobao.weex.WXSDKEngine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -86,9 +88,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import static com.taobao.weex.http.WXHttpUtil.KEY_USER_AGENT;


/**
* Each instance of WXSDKInstance represents an running weex instance.
* It can be a pure weex view, or mixed with native view
Expand Down Expand Up @@ -120,6 +119,8 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View.
private boolean mNeedReLoad = false;
private static volatile int mViewPortWidth = 750;
private int mInstanceViewPortWidth = 750;
private @NonNull
FlatGUIContext mFlatGUIContext =new FlatGUIContext();

public long mRenderStartNanos;
public int mExecJSTraceId = WXTracing.nextId();
Expand Down Expand Up @@ -200,6 +201,12 @@ public void enableLayerType(boolean enable) {
enableLayerType = enable;
}

@RestrictTo(Scope.LIBRARY)
public @NonNull
FlatGUIContext getFlatUIContext(){
return mFlatGUIContext;
}

public boolean isNeedValidate() {
return mNeedValidate;
}
Expand Down Expand Up @@ -251,6 +258,7 @@ public WXSDKInstance(Context context) {
/**
* For unittest only.
*/
@RestrictTo(Scope.TESTS)
WXSDKInstance(Context context,String id) {
mInstanceId = id;
init(context);
Expand Down Expand Up @@ -1249,36 +1257,41 @@ private void destroyView(View rootView) {
}

public synchronized void destroy() {
WXSDKManager.getInstance().destroyInstance(mInstanceId);
WXComponentFactory.removeComponentTypesByInstanceId(getInstanceId());
if(!isDestroy()) {
WXSDKManager.getInstance().destroyInstance(mInstanceId);
WXComponentFactory.removeComponentTypesByInstanceId(getInstanceId());

if(mGlobalEventReceiver!=null){
getContext().unregisterReceiver(mGlobalEventReceiver);
mGlobalEventReceiver=null;
}
if(mRootComp != null ) {
mRootComp.destroy();
destroyView(mRenderContainer);
mRootComp = null;
}
if (mGlobalEventReceiver != null) {
getContext().unregisterReceiver(mGlobalEventReceiver);
mGlobalEventReceiver = null;
}
if (mRootComp != null) {
mRootComp.destroy();
destroyView(mRenderContainer);
mRootComp = null;
}

if(mGlobalEvents!=null){
mGlobalEvents.clear();
}
if (mGlobalEvents != null) {
mGlobalEvents.clear();
}

if(mComponentObserver != null){
if (mComponentObserver != null) {
mComponentObserver = null;
}

getFlatUIContext().destroy();
mFlatGUIContext = null;

mWXScrollListeners = null;
mRenderContainer = null;
mNestedInstanceInterceptor = null;
mUserTrackAdapter = null;
mScrollView = null;
mContext = null;
mRenderListener = null;
isDestroy = true;
mStatisticsListener = null;
}

mWXScrollListeners = null;
mRenderContainer = null;
mNestedInstanceInterceptor = null;
mUserTrackAdapter = null;
mScrollView = null;
mContext = null;
mRenderListener = null;
isDestroy = true;
mStatisticsListener = null;
}

public boolean isDestroy(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public interface Name {
String ARIA_LABEL = "ariaLabel";
String ARIA_HIDDEN = "ariaHidden";
String UNDEFINED = "undefined";

String FLAT = "flat";
}

public interface Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
package com.taobao.weex.dom;

import android.support.annotation.NonNull;

import com.taobao.weex.dom.flex.Spacing;

import static com.taobao.weex.dom.WXDomObject.DESTROYED;

/**
* Created by sospartan on 25/10/2016.
*/
Expand All @@ -33,8 +30,26 @@ public interface ImmutableDomObject {
@NonNull Spacing getMargin();
float getLayoutWidth();
float getLayoutHeight();

/**
* Use {@link #getCSSLayoutLeft()} ()} instead
*/
@Deprecated
float getLayoutX();

/**
* Use {@link #getCSSLayoutTop()} instead
*/
@Deprecated
float getLayoutY();

public float getCSSLayoutTop();

public float getCSSLayoutBottom();

public float getCSSLayoutLeft();

public float getCSSLayoutRight();
boolean isFixed();
@NonNull WXStyle getStyles();
@NonNull WXEvent getEvents();
Expand Down