| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.test.uibench; |
| 17 |
|
| 18 |
import android.content.Context; |
| 19 |
import android.os.Trace; |
| 20 |
import androidx.recyclerview.widget.GridLayoutManager; |
| 21 |
import androidx.recyclerview.widget.RecyclerView; |
| 22 |
import com.android.test.uibench.recyclerview.RvBoxAdapter; |
| 23 |
import com.android.test.uibench.recyclerview.RvCompatListActivity; |
| 24 |
|
| 25 |
import java.util.concurrent.TimeUnit; |
| 26 |
|
| 27 |
public class SlowBindRecyclerViewActivity extends RvCompatListActivity { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
private static void spinWaitMs(long ms) { |
| 33 |
long start = System.nanoTime(); |
| 34 |
while (System.nanoTime() - start < TimeUnit.MILLISECONDS.toNanos(ms)); |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
protected RecyclerView.LayoutManager createLayoutManager(Context context) { |
| 39 |
return new GridLayoutManager(context, 3); |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
protected RecyclerView.Adapter createAdapter() { |
| 44 |
return new RvBoxAdapter(this, TextUtils.buildSimpleStringList()) { |
| 45 |
@Override |
| 46 |
public void onBindViewHolder(ViewHolder holder, int position) { |
| 47 |
Trace.beginSection("bind item " + position); |
| 48 |
|
| 49 |
spinWaitMs(3); |
| 50 |
super.onBindViewHolder(holder, position); |
| 51 |
Trace.endSection(); |
| 52 |
} |
| 53 |
}; |
| 54 |
} |
| 55 |
} |