use of com.tmall.wireless.tangram3.util.IInnerImageSetter in project Tangram-Android by alibaba.
the class Tangram3Activity method onCreate.
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
recyclerView = (RecyclerView) findViewById(R.id.main_view);
// Step 1: init tangram
TangramBuilder.init(this.getApplicationContext(), new IInnerImageSetter() {
@Override
public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
Picasso.with(Tangram3Activity.this.getApplicationContext()).load(url).into(view);
}
}, ImageView.class);
// Tangram.switchLog(true);
mMainHandler = new Handler(getMainLooper());
// Step 2: register build=in cells and cards
builder = TangramBuilder.newInnerBuilder(this);
// Step 3: register business cells and cards
// recommend to use string type to register component
builder.registerCell("testView", TestBlockView.class);
builder.registerCell("Debug", TestBlockView.class);
builder.registerCell("singleImgView", TestImageView.class);
builder.registerRenderService(new VirtualViewRenderService());
// Step 4: new engine
engine = builder.build();
Utils.setUedScreenWidth(720);
// engine.addSimpleClickSupport(new SampleClickSupport());
// Step 6: enable auto load more if your page's data is lazy loaded
engine.enableAutoLoadMore(true);
// engine.register(InternalErrorSupport.class, new SampleErrorSupport());
// Step 7: bind recyclerView to engine
engine.bindView(recyclerView);
// Step 8: listener recyclerView onScroll event to trigger auto load more
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
engine.onScrolled();
}
});
// Step 9: set an offset to fix card
engine.getLayoutManager().setFixOffset(0, 40, 0, 0);
// Step 10: get tangram data and pass it to engine
String json = new String(getAssertsFile(this, "data3.0.json"));
JSONArray data = null;
try {
data = JSON.parseArray(json);
engine.setData(data);
} catch (Exception e) {
e.printStackTrace();
}
// Demo for component to listen container's event
engine.register(SampleScrollSupport.class, new SampleScrollSupport(recyclerView));
}
Aggregations