Android Open Source - LearnByHeart All Phrase Adapter






From Project

Back to project page LearnByHeart.

License

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.

Java Source Code

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();
  }
}




Java Source Code List

com.mps.learn.pb.App.java
com.mps.learn.pb.PhraseManager.java
com.mps.learn.pb.adapter.AllPhraseAdapter.java
com.mps.learn.pb.alarm.ReminderReceiver.java
com.mps.learn.pb.alarm.ReminderUtil.java
com.mps.learn.pb.db.DataSourcePhrase.java
com.mps.learn.pb.db.DatabaseHelper.java
com.mps.learn.pb.db.PhraseReaderContract.java
com.mps.learn.pb.gcm.GcmBroadcastReceiver.java
com.mps.learn.pb.gcm.GcmIntentService.java
com.mps.learn.pb.http.DataUpdaterCallback.java
com.mps.learn.pb.http.DataUpdaterTask.java
com.mps.learn.pb.http.HttpConstant.java
com.mps.learn.pb.http.PhraseParser.java
com.mps.learn.pb.model.PhraseBook.java
com.mps.learn.pb.model.PhraseModel.java
com.mps.learn.pb.ui.activities.AddPhraseActivity.java
com.mps.learn.pb.ui.activities.MainActivity.java
com.mps.learn.pb.ui.activities.PhraseViewActivity.java
com.mps.learn.pb.ui.activities.SettingActivity.java
com.mps.learn.pb.ui.factivities.BaseActivity.java
com.mps.learn.pb.ui.factivities.FActivity.java
com.mps.learn.pb.ui.factivities.FoldableListActivity.java
com.mps.learn.pb.ui.factivities.ItemsAdapter.java
com.mps.learn.pb.ui.factivities.PaintingsAdapter.java
com.mps.learn.pb.ui.factivities.SpannableBuilder.java
com.mps.learn.pb.ui.factivities.UnfoldableDetailsActivity.java
com.mps.learn.pb.ui.views.FoldableItemLayout.java
com.mps.learn.pb.ui.views.FoldableListLayout.java
com.mps.learn.pb.ui.views.UnfoldableView.java
com.mps.learn.pb.ui.views.shading.FoldShading.java
com.mps.learn.pb.ui.views.shading.GlanceFoldShading.java
com.mps.learn.pb.ui.views.shading.SimpleFoldShading.java
com.mps.learn.pb.util.CommonConstants.java
com.mps.learn.pb.util.Debugger.java