Android Open Source - LollipopShowcase Application Adapter






From Project

Back to project page LollipopShowcase.

License

The source code is released under:

Apache License

If you think the Android project LollipopShowcase 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.mikepenz.lollipopshowcase.adapter;
/*  w  w  w  .  j  a v a 2s .co m*/
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mikepenz.lollipopshowcase.MainActivity;
import com.mikepenz.lollipopshowcase.R;
import com.mikepenz.lollipopshowcase.entity.AppInfo;

import java.util.List;

public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> {

    private List<AppInfo> applications;
    private int rowLayout;
    private MainActivity mAct;

    public ApplicationAdapter(List<AppInfo> applications, int rowLayout, MainActivity act) {
        this.applications = applications;
        this.rowLayout = rowLayout;
        this.mAct = act;
    }


    public void clearApplications() {
        int size = this.applications.size();
        if (size > 0) {
            for (int i = 0; i < size; i++) {
                applications.remove(0);
            }

            this.notifyItemRangeRemoved(0, size);
        }
    }

    public void addApplications(List<AppInfo> applications) {
        this.applications.addAll(applications);
        this.notifyItemRangeInserted(0, applications.size() - 1);
    }

    @Override
    public ViewHolder onCreateViewHolder(final ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, int i) {
        final AppInfo appInfo = applications.get(i);
        viewHolder.name.setText(appInfo.getName());
        viewHolder.image.setImageDrawable(appInfo.getIcon());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAct.animateActivity(appInfo, viewHolder.image);
            }
        });
    }

    @Override
    public int getItemCount() {
        return applications == null ? 0 : applications.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView name;
        public ImageView image;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.countryName);
            image = (ImageView) itemView.findViewById(R.id.countryImage);
        }

    }
}




Java Source Code List

com.mikepenz.lollipopshowcase.AnimListener.java
com.mikepenz.lollipopshowcase.DetailActivity.java
com.mikepenz.lollipopshowcase.MainActivity.java
com.mikepenz.lollipopshowcase.Utils.java
com.mikepenz.lollipopshowcase.adapter.ApplicationAdapter.java
com.mikepenz.lollipopshowcase.entity.AppInfo.java
com.mikepenz.lollipopshowcase.itemanimator.CustomItemAnimator.java
com.mikepenz.lollipopshowcase.itemanimator.ReboundItemAnimator.java
com.mikepenz.lollipopshowcase.util.Network.java
com.mikepenz.lollipopshowcase.util.UploadHelper.java