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

Commit

Permalink
Merge branch 'feature/enable_monitor_api'
Browse files Browse the repository at this point in the history
  • Loading branch information
longerian committed May 17, 2018
2 parents 66ce6af + 1677d73 commit 79af704
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.alibaba.android.vlayout.RecyclablePagerAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams;
import com.alibaba.android.vlayout.extend.PerformanceMonitor;
import com.alibaba.android.vlayout.layout.ColumnLayoutHelper;
import com.alibaba.android.vlayout.layout.FixLayoutHelper;
import com.alibaba.android.vlayout.layout.FloatLayoutHelper;
Expand Down Expand Up @@ -119,7 +120,22 @@ protected void onCreate(Bundle savedInstanceState) {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);

final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
layoutManager.setPerformanceMonitor(new PerformanceMonitor() {

long start;
long end;

@Override
public void recordStart(String phase, View view) {
start = System.currentTimeMillis();
}

@Override
public void recordEnd(String phase, View view) {
end = System.currentTimeMillis();
Log.d("VLayoutActivity", view.getClass().getName() + " " + (end - start));
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
GROUP=com.alibaba.android
ARTIFACT=vlayout
VERSION=1
VERSION_NAME=1.2.13
VERSION_NAME=1.2.14
PACKAGING_TYPE=aar
useNewSupportLibrary=true
systemProp.compileSdkVersion=25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Map;

import com.alibaba.android.vlayout.extend.PerformanceMonitor;
import com.alibaba.android.vlayout.layout.BaseLayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;
import com.alibaba.android.vlayout.layout.FixAreaAdjuster;
Expand Down Expand Up @@ -67,6 +68,8 @@
public class VirtualLayoutManager extends ExposeLinearLayoutManagerEx implements LayoutManagerHelper {
protected static final String TAG = "VirtualLayoutManager";

private static final String PHASE_MEASURE = "measure";
private static final String PHASE_LAYOUT = "layout";
private static final String TRACE_LAYOUT = "VLM onLayoutChildren";
private static final String TRACE_SCROLL = "VLM scroll";

Expand Down Expand Up @@ -94,6 +97,7 @@ public static void enableDebugging(boolean isDebug) {

private int mMaxMeasureSize = -1;

private PerformanceMonitor mPerformanceMonitor;

public VirtualLayoutManager(@NonNull final Context context) {
this(context, VERTICAL);
Expand Down Expand Up @@ -121,6 +125,9 @@ public VirtualLayoutManager(@NonNull final Context context, int orientation, boo
setHelperFinder(new RangeLayoutHelperFinder());
}

public void setPerformanceMonitor(PerformanceMonitor performanceMonitor) {
mPerformanceMonitor = performanceMonitor;
}

public void setNoScrolling(boolean noScrolling) {
this.mNoScrolling = noScrolling;
Expand Down Expand Up @@ -1265,14 +1272,26 @@ public boolean canScrollVertically() {
@Override
public void layoutChildWithMargins(View child, int left, int top, int right, int bottom) {
final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordStart(PHASE_LAYOUT, child);
}
layoutDecorated(child, left + lp.leftMargin, top + lp.topMargin,
right - lp.rightMargin, bottom - lp.bottomMargin);
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordEnd(PHASE_LAYOUT, child);
}
}

@Override
public void layoutChild(View child, int left, int top, int right, int bottom) {
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordStart(PHASE_LAYOUT, child);
}
layoutDecorated(child, left, top,
right, bottom);
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordEnd(PHASE_LAYOUT, child);
}
}

@Override
Expand Down Expand Up @@ -1390,7 +1409,13 @@ private void measureChildWithDecorations(View child, int widthSpec, int heightSp
calculateItemDecorationsForChild(child, mDecorInsets);
widthSpec = updateSpecWithExtra(widthSpec, mDecorInsets.left, mDecorInsets.right);
heightSpec = updateSpecWithExtra(heightSpec, mDecorInsets.top, mDecorInsets.bottom);
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordStart(PHASE_MEASURE, child);
}
child.measure(widthSpec, heightSpec);
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordEnd(PHASE_MEASURE, child);
}
}

private void measureChildWithDecorationsAndMargin(View child, int widthSpec, int heightSpec) {
Expand All @@ -1405,7 +1430,13 @@ private void measureChildWithDecorationsAndMargin(View child, int widthSpec, int
heightSpec = updateSpecWithExtra(heightSpec, mDecorInsets.top,
mDecorInsets.bottom);
}
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordStart(PHASE_MEASURE, child);
}
child.measure(widthSpec, heightSpec);
if (mPerformanceMonitor != null) {
mPerformanceMonitor.recordEnd(PHASE_MEASURE, child);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.alibaba.android.vlayout.extend;

import android.view.View;

/**
* Add callback during measure and layout, help you to monitor your view's performance.<br />
* Designed as Class instead of Interface is able to extend api in future. <br />
*
* Created by longerian on 2018/5/16.
*
* @author longerian
* @date 2018/05/16
*/
public class PerformanceMonitor {

/**
* Record the start time
* @param phase
* @param viewType
*/
public void recordStart(String phase, String viewType) {

}

/**
* Record the end time
* @param phase
* @param viewType
*/
public void recordEnd(String phase, String viewType) {

}

/**
* Record the start time
* @param phase
* @param view
*/
public void recordStart(String phase, View view) {

}

/**
* Record the end time
* @param phase
* @param view
*/
public void recordEnd(String phase, View view) {

}

}

0 comments on commit 79af704

Please sign in to comment.