public void setCards(List<CardInfo> cards) { listCardNames_ = cards; Bitmap cardBm; cardsInHand_.clear(); for (CardInfo card : cards) { if ((cardHeight_ == 0) && (cardWidth_ == 0)) { cardBm = CardLoader.getInstance().getBitmap(getContext(), card.getName()); } else { // Resize Bitmap cardBm = Bitmap.createScaledBitmap( CardLoader.getInstance().getBitmap(getContext(), card.getName()), (int) cardWidth_, (int) cardHeight_, false); } cardsInHand_.put(card, cardBm); } }
@Override public void onDraw(Canvas canvas) { invalidate(); // Calcul top, left int top = getHeight() / 6; // 40 int left = 0; for (CardInfo card : listCardNames_) { canvas.drawBitmap(cardsInHand_.get(card), left, top, null); left += (int) cardWidth_; } }
private int findSelectedCard(float x, float y) { for (int i = 0; i < cardsInHand_.size(); i++) { if ((i * cardWidth_ < x) && (x < (i + 1) * cardWidth_)) return i; } return -1; }