Android Open Source - PetBook Records Adapter






From Project

Back to project page PetBook.

License

The source code is released under:

MIT License

If you think the Android project PetBook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.edinubuntu.petlove.adapter;
/*from   ww w.  j a v  a  2 s.  c o  m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.edinubuntu.petlove.PetLove;
import com.edinubuntu.petlove.R;
import com.edinubuntu.petlove.object.Record;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by edward_chiang on 13/8/12.
 */
public class RecordsAdapter extends ArrayAdapter<Record> {

    protected LayoutInflater inflater;

    private int columnPerPage;

    /**
     * Constructor
     *
     * @param context  The current context.
     * @param resource The resource ID for a layout file containing a TextView to use when
     *                 instantiating views.
     * @param objects  The objects to represent in the ListView.
     */
    public RecordsAdapter(Context context, int resource, List<Record> objects) {
        super(context, resource, objects);

        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View contentView = convertView;
        if (contentView == null) {
            contentView = inflater.inflate(R.layout.pet_grid_cell, null);
        }

//        Log.d(PetLove.TAG, "get view get width:" + contentView.getWidth() + ", height:" + contentView.getHeight());

        Record record = this.getItem(position);

        ImageView petImageView = (ImageView)contentView.findViewById(R.id.pet_image_view);

        int height;
        if (contentView.getWidth() == 0) {
            height = getColumnPerPage();
//            Log.d(PetLove.TAG, "Height: " + height);
        } else {
            height = (int)(contentView.getWidth() * PetLove.IMAGE_VIEW_HEIGHT_SCALE_RATE);
        }

        petImageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                height));

        // Load image here
        Picasso.with(getContext())
                .load(record.getImageName())
                .placeholder(R.drawable.ic_card)
                .into(petImageView);

        TextView petNameTextView = (TextView)contentView.findViewById(R.id.pet_name_text_view);
        petNameTextView.setText(record.getName());

        TextView petDescriptionTextView = (TextView)contentView.findViewById(R.id.pet_note_text_view);
        petDescriptionTextView.setText(record.getNote());

        return contentView;
    }

    public int getColumnPerPage() {
        return columnPerPage;
    }

    public void setColumnPerPage(int columnPerPage) {
        this.columnPerPage = columnPerPage;
    }
}




Java Source Code List

com.edinubuntu.petlove.PetLove.java
com.edinubuntu.petlove.active.ActiveObjectLoader.java
com.edinubuntu.petlove.active.ActiveObjectsLoader.java
com.edinubuntu.petlove.activity.MainActivity.java
com.edinubuntu.petlove.adapter.RecordsAdapter.java
com.edinubuntu.petlove.model.AdaptPetsModel.java
com.edinubuntu.petlove.model.AsyncModel.java
com.edinubuntu.petlove.object.Record.java
com.edinubuntu.petlove.util.converter.RecordsJsonConverter.java