Android Open Source - JayJayLab-Android-Demo Adapter Main






From Project

Back to project page JayJayLab-Android-Demo.

License

The source code is released under:

Apache License

If you think the Android project JayJayLab-Android-Demo 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.jayjaylab.androiddemo.main.adapter;
// w w w .j a  v  a 2  s.  c om
import android.content.Context;
import android.support.v7.internal.widget.TintImageView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.jayjaylab.androiddemo.R;
import com.jayjaylab.androiddemo.event.OnClickEvent;
import com.jayjaylab.androiddemo.main.model.App;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import roboguice.event.EventManager;
import roboguice.util.Ln;

/**
 * Created by jongjoo on 11/11/14.
 */
public class AdapterMain extends RecyclerView.Adapter<AdapterMain.ViewHolder> {
    List<App> items = new ArrayList<App>(10);
    @Inject Context context;
    @Inject EventManager eventManager;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Ln.i("onCreateViewHolder() : parent.h : " + parent.getHeight());

        View view = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.recyclerview_item_mainapp, parent, false);
        ViewHolder vh = new ViewHolder(view);
        vh.layout = view.findViewById(R.id.layout);
        vh.imageThumbnail = (TintImageView)view.findViewById(R.id.image_thumbnail);
        vh.textTitle = (TextView)view.findViewById(R.id.text_title);
        vh.textDescription = (TextView)view.findViewById(R.id.text_description);
//        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
//                parent.getHeight() / 2));
        return vh;
    }

    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
        final App app = items.get(position);
        if(app != null) {
            try {
                if (app.getThumbnailResId() != 0) {
                    Picasso.with(context).load(app.getThumbnailResId()).
                            into(viewHolder.imageThumbnail);
                } else if (app.getThumbnailUri() != null) {
                    Picasso.with(context).load(app.getThumbnailUri()).
                            into(viewHolder.imageThumbnail);
                }
            } catch(Exception e) {
                Ln.e(e);
            }
            viewHolder.textTitle.setText(app.getTitle());
            viewHolder.textDescription.setText(app.getDescription());
//            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Ln.d("onClick() : v : %s", v);
//                }
//            });
            viewHolder.layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    eventManager.fire(new OnClickEvent(viewHolder.layout, position));
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public void addItems(List<App> apps) {
        items.addAll(apps);
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public View layout;
        public TintImageView imageThumbnail;
        public TextView textTitle;
        public TextView textDescription;

        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}




Java Source Code List

com.jayjaylab.androiddemo.ActivityIntroTest.java
com.jayjaylab.androiddemo.Application.java
com.jayjaylab.androiddemo.DaoMaster.java
com.jayjaylab.androiddemo.DaoSession.java
com.jayjaylab.androiddemo.PathDao.java
com.jayjaylab.androiddemo.Path.java
com.jayjaylab.androiddemo.app.greyhound.activity.ActivityMain.java
com.jayjaylab.androiddemo.app.greyhound.activity.ActivityMap.java
com.jayjaylab.androiddemo.app.greyhound.adapter.AdapterPathHistory.java
com.jayjaylab.androiddemo.app.greyhound.event.OnGPXParsingCompleteEvent.java
com.jayjaylab.androiddemo.app.greyhound.event.OnReceiveResultEvent.java
com.jayjaylab.androiddemo.app.greyhound.fragment.FragmentPathHistory.java
com.jayjaylab.androiddemo.app.greyhound.model.Path.java
com.jayjaylab.androiddemo.app.greyhound.service.ServiceRecordingPath.java
com.jayjaylab.androiddemo.app.greyhound.util.Constants.java
com.jayjaylab.androiddemo.app.greyhound.util.GPXParser.java
com.jayjaylab.androiddemo.app.greyhound.util.GPXWriter.java
com.jayjaylab.androiddemo.app.greyhound.util.MyResultReceiver.java
com.jayjaylab.androiddemo.app.greyhound.util.PreferenceHelper.java
com.jayjaylab.androiddemo.dialog.ProgressDialog.java
com.jayjaylab.androiddemo.event.OnClickEvent.java
com.jayjaylab.androiddemo.event.OnLongClickEvent.java
com.jayjaylab.androiddemo.event.ProgressBarEvent.java
com.jayjaylab.androiddemo.main.activity.ActivityBase.java
com.jayjaylab.androiddemo.main.activity.ActivityIntro.java
com.jayjaylab.androiddemo.main.activity.ActivityMain.java
com.jayjaylab.androiddemo.main.adapter.AdapterMain.java
com.jayjaylab.androiddemo.main.model.App.java
com.jayjaylab.androiddemo.util.AndroidHelper.java
com.jayjaylab.androiddemo.util.NIOHelper.java
com.jayjaylab.androiddemo.view.BubbleViewMaker.java
com.jayjaylab.androiddemo.view.CardView.java
com.jayjaylab.androiddemo.view.ImageViewThreadPool.java
com.jayjaylab.androiddemo.view.ViewThreadPool.java
de.greenrobot.daogenerator.gentest.ExampleDaoGenerator.java