50 lines
1.6 KiB
Java
50 lines
1.6 KiB
Java
|
package com.codigoparallevar.minicards;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.support.annotation.NonNull;
|
||
|
import android.support.v7.widget.CardView;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.ArrayAdapter;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
class CardPreviewArrayAdapter extends ArrayAdapter<PreviewCard> {
|
||
|
private final PreviewCard[] cards;
|
||
|
|
||
|
public CardPreviewArrayAdapter(@NonNull Context context, PreviewCard[] cards) {
|
||
|
super(context, R.layout.card_preview);
|
||
|
|
||
|
this.cards = cards;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getCount() {
|
||
|
return this.cards.length;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||
|
View row = inflater.inflate(R.layout.card_preview, parent, false);
|
||
|
PreviewCard card = this.cards[position];
|
||
|
|
||
|
row.setOnClickListener(new View.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
Intent i = new Intent(CardActivity.INTENT);
|
||
|
CardPreviewArrayAdapter.this.getContext().startActivity(i);
|
||
|
}
|
||
|
});
|
||
|
CardView cardView = (CardView) row.findViewById(R.id.card_preview_card);
|
||
|
TextView nameView = (TextView) row.findViewById(R.id.card_preview_name);
|
||
|
|
||
|
cardView.setBackgroundColor(card.getColor());
|
||
|
nameView.setText(card.getName());
|
||
|
nameView.setTextColor(0xFFFFFF ^ card.getColor());
|
||
|
|
||
|
return row;
|
||
|
}
|
||
|
}
|