use of com.tmall.wireless.tangram3.dataparser.concrete.Card 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));
}
use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.
the class GridCard method offsetChildCard.
@Override
public void offsetChildCard(Card anchorCard, int offset) {
if (anchorCard == null) {
return;
}
ArrayMap<Range<Integer>, Card> newChildren = new ArrayMap<>();
boolean startOffset = false;
for (int i = 0, size = mChildren.size(); i < size; i++) {
Range<Integer> key = mChildren.keyAt(i);
Card child = mChildren.valueAt(i);
if (child == anchorCard) {
Range<Integer> newKey = Range.create(key.getLower().intValue(), key.getUpper().intValue() + offset);
newChildren.put(newKey, child);
startOffset = true;
continue;
}
if (startOffset) {
Range<Integer> newKey = Range.create(key.getLower().intValue() + offset, key.getUpper().intValue() + offset);
newChildren.put(newKey, child);
} else {
newChildren.put(key, child);
}
}
mChildren.clear();
mChildren.putAll((SimpleArrayMap<? extends Range<Integer>, ? extends Card>) newChildren);
}
use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.
the class PojoGroupBasicAdapter method insertComponents.
@Override
public void insertComponents(int pos, List<BaseCell> components) {
if (mData != null && mData.size() > 0 && components != null && !components.isEmpty() && pos >= 0) {
int newItemSize = components.size();
if (mCards != null) {
List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>();
for (int i = 0, size = mCards.size(); i < size; i++) {
Pair<Range<Integer>, Card> pair = mCards.get(i);
int start = pair.first.getLower();
int end = pair.first.getUpper();
if (end < pos) {
// do nothing
newCards.add(pair);
} else if (start <= pos && pos < end) {
Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start, end + newItemSize), pair.second);
newCards.add(newPair);
} else if (pos <= start) {
Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start + newItemSize, end + newItemSize), pair.second);
newCards.add(newPair);
}
}
mCards.clear();
mCards.addAll(newCards);
}
for (int i = 0, size = components.size(); i < size; i++) {
BaseCell cell = components.get(i);
if (cell != null) {
cell.added();
}
}
for (int i = 0; i < newItemSize; i++) {
if ((pos + i) < mData.size()) {
mData.add(pos + i, components.get(i));
} else {
mData.add(components.get(i));
}
}
notifyItemRangeInserted(pos, newItemSize);
}
}
use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.
the class GridCard method addChildCard.
@Override
public void addChildCard(Card card) {
if (card == null) {
return;
}
List<BaseCell> subCells = card.getCells();
if (subCells != null && !subCells.isEmpty()) {
addCells(card.getCells());
int startOffset = mCells.indexOf(subCells.get(0));
int endOffset = mCells.indexOf(subCells.get(subCells.size() - 1));
Range range = Range.create(startOffset, endOffset);
mChildren.put(range, card);
}
}
use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.
the class Card method addCellInternal.
public boolean addCellInternal(Card parent, int index, @Nullable BaseCell cell, boolean silent) {
if (cell != null) {
cell.parentId = parent.id;
cell.parent = parent;
cell.serviceManager = serviceManager;
MVHelper mvHelper = getMVHelper();
if (mvHelper != null) {
if (mvHelper.isValid(cell, serviceManager)) {
if (cell.position >= 0 && !TextUtils.isEmpty(load)) {
cell.pos = cell.position;
mPendingCells.add(cell);
return true;
} else {
// FixMe pos not correct when insert cell
cell.pos = mHeader != null ? this.mCells.size() + 1 : this.mCells.size();
}
if (!silent && mIsActivated) {
// do cell added
cell.added();
}
this.mCells.add(index, cell);
if (mFooter != null) {
mFooter.pos = cell.pos + 1;
}
if (mHeader != null) {
mHeader.pos = 0;
}
return true;
}
}
}
return false;
}
Aggregations