Back to project page LearnByHeart.
The source code is released under:
Apache License
If you think the Android project LearnByHeart listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mps.learn.pb.adapter; // w w w.j a v a 2 s. c o m import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import com.mps.learn.pb.App; import com.mps.learn.pb.PhraseManager; import com.mps.learn.pb.R; import com.mps.learn.pb.model.PhraseModel; import com.squareup.picasso.Picasso; public class AllPhraseAdapter extends BaseAdapter { private List<PhraseModel> items; public AllPhraseAdapter() { // get the phrases stored in db this.items = PhraseManager.getInstance().getAllPhrases(); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; PhraseModel rowItem = getItem(position); LayoutInflater mInflater = (LayoutInflater) App.INSTANCE.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { convertView = mInflater.inflate(R.layout.list_row, null); holder = new ViewHolder(); holder.card = convertView.findViewById(R.id.card); holder.image = (ImageView) convertView.findViewById(R.id.list_image); holder.title = (TextView) convertView.findViewById(R.id.title); holder.usage_eng = (TextView) convertView.findViewById(R.id.usage_eng); holder.usage_pb = (TextView) convertView.findViewById(R.id.usage_pb); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); if( rowItem.getResourceUrl().equalsIgnoreCase(PhraseModel.TYPE_LOCAL_URL) ){ holder.image.setImageResource(rowItem.getImageId()); holder.image.setVisibility(View.VISIBLE); }else if( rowItem.getResourceUrl().contains("http") ){ Picasso.with(App.INSTANCE). load(rowItem.getResourceUrl()). resize(350, 200). into(holder.image); holder.image.setVisibility(View.VISIBLE); }else{ holder.image.setVisibility(View.GONE); } holder.title.setText(rowItem.getTitle()); holder.usage_eng.setText(rowItem.getUsageEnglish()); holder.usage_pb.setText(rowItem.getUsagePunjabi()); int cardLayoutIndex = position%10; if( cardLayoutIndex >= PhraseManager.CARD_COLOR_CODES.length) { cardLayoutIndex = cardLayoutIndex - PhraseManager.CARD_COLOR_CODES.length; } holder.card.setBackgroundResource(PhraseManager.CARD_COLOR_CODES[cardLayoutIndex]); Animation animation = AnimationUtils.loadAnimation(App.INSTANCE,R.anim.card_animation); holder.card.startAnimation(animation); return convertView; } public class ViewHolder { ImageView image; TextView title; TextView usage_eng; TextView usage_pb; View card; } public void notifyDataChanged() { // get updated list from db this.items = PhraseManager.getInstance().getAllPhrases(); // update the views in a list view this.notifyDataSetChanged(); } @Override public int getCount() { return items.size(); } @Override public PhraseModel getItem(int position) { return items.get(position); } @Override public long getItemId(int position) { return items.get(position).getId(); } }