Android Open Source - tdpforce Development Cards Adapter






From Project

Back to project page tdpforce.

License

The source code is released under:

Apache License

If you think the Android project tdpforce 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 org.telugudesam.cadre.adapters;
//from   w w  w.  j  a  v  a2s  .  c om
import java.lang.ref.WeakReference;
import java.util.ArrayList;

import org.telugudesam.cadre.Constants.BundleExtras;
import org.telugudesam.cadre.R;
import org.telugudesam.cadre.activity.PreviewActivity;
import org.telugudesam.cadre.components.MemCache;
import org.telugudesam.cadre.objects.DevelopmentCard;
import org.telugudesam.cadre.objects.Section;
import org.telugudesam.cadre.util.L;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class DevelopmentCardsAdapter extends BaseAdapter {

  private ArrayList<DevelopmentCard> cards;
  private WeakReference<Activity> activityRef;
  private LayoutInflater inflater;
  private Section section;

  public DevelopmentCardsAdapter(Activity activity, Section section) {
    this.section = section;
    L.d("DevelopmentCardsAdapter: section = " + section.name());
    this.activityRef = new WeakReference<Activity>(activity);
    inflater = LayoutInflater.from(activity);
    cards = MemCache.getDevelopmentCards(section);
  }

  public void refreshCards() {
    cards = MemCache.getDevelopmentCards(section);
  }

  @Override
  public int getCount() {
    L.d("getCount = " + cards.size());
    return cards.size();
  }

  @Override
  public DevelopmentCard getItem(int position) {
    return cards.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View v, ViewGroup viewGroup) {
    ViewHolder holder = null;
    if (v == null) {
      v = inflater.inflate(R.layout.adapter_dev_card, null);
      holder = new ViewHolder(v, getItem(position));
      v.setTag(holder);
    } else {
      holder = (ViewHolder) v.getTag();
      holder.isExpanded = false;
      holder.updateView(getItem(position));
    }
    return v;
  }

  public class ViewHolder implements OnClickListener {

    private ImageView picImageView;
    private TextView titleTextView;
    private TextView subTitleTextView;
    private ImageView expandCollapseImageView;
    private DevelopmentCard card;
    private boolean isExpanded;

    public ViewHolder(View v, DevelopmentCard card) {
      L.d(card);
      picImageView = (ImageView) v.findViewById(R.id.picImageView);
      titleTextView = (TextView) v.findViewById(R.id.title_textview);
      subTitleTextView = (TextView) v
          .findViewById(R.id.sub_title_textview);
      expandCollapseImageView = (ImageView) v
          .findViewById(R.id.expand_collapse_imageview);
      updateView(card);
    }

    public void updateView(DevelopmentCard item) {
      this.card = item;
      ArrayList<String> pics = item.getPics();
      boolean isPicAvailable = false;
      for (String aPic : pics) {
        Picasso.with(activityRef.get()).load(aPic).into(picImageView);
        picImageView.setTag(aPic);
        isPicAvailable = true;
        break;
      }

      handleSubTitleTextToggle(subTitleTextView);

      picImageView.setOnClickListener(this);
      expandCollapseImageView.setOnClickListener(this);
      subTitleTextView.setOnClickListener(this);

      if (isPicAvailable) {
        picImageView.setVisibility(View.VISIBLE);
      } else {
        picImageView.setVisibility(View.GONE);
      }

      if (TextUtils.isEmpty(item.getTitle())) {
        titleTextView.setVisibility(View.GONE);
      } else {
        titleTextView.setText(item.getTitle());
        titleTextView.setVisibility(View.VISIBLE);
      }

      if (TextUtils.isEmpty(item.getSubTitle())) {
        subTitleTextView.setVisibility(View.GONE);
        expandCollapseImageView.setVisibility(View.GONE);
      } else {
        subTitleTextView.setText(item.getSubTitle());
        subTitleTextView.setVisibility(View.VISIBLE);
        expandCollapseImageView.setVisibility(View.VISIBLE);
      }
    }

    @Override
    public void onClick(View v) {
      switch (v.getId()) {
      case R.id.picImageView:
        showFullScreenPic((ImageView) v, card);
      case R.id.sub_title_textview:
      case R.id.expand_collapse_imageview:
        handleSubTitleTextToggle(subTitleTextView);
        break;

      default:
        break;
      }
    }

    public void handleSubTitleTextToggle(TextView subTitleTextView) {
      if (isExpanded) {
        isExpanded = false;
        subTitleTextView.setMaxLines(Integer.MAX_VALUE);
        subTitleTextView.scrollTo(0, 0);
        subTitleTextView.setHorizontallyScrolling(false);
        subTitleTextView.setEllipsize(null);
        expandCollapseImageView
            .setImageResource(R.drawable.ic_action_navigation_collapse);
      } else {
        isExpanded = true;
        subTitleTextView.scrollTo(0, 0);
        subTitleTextView.setMaxLines(2);
        subTitleTextView.setHorizontallyScrolling(true);
        subTitleTextView.setEllipsize(TruncateAt.END);
        expandCollapseImageView
            .setImageResource(R.drawable.ic_action_navigation_expand);
      }
    }
  }

  public void showFullScreenPic(ImageView v, DevelopmentCard card) {
    String url = (String) v.getTag();
    Intent intent = new Intent(activityRef.get(), PreviewActivity.class);
    intent.putExtra(BundleExtras.PIC_URL, url);
    intent.putExtra(BundleExtras.CARD, card);
    String title = activityRef.get().getResources()
        .getStringArray(R.array.section_headings)[section.ordinal()];
    intent.putExtra(BundleExtras.CATEGORY_TITLE, title);
    activityRef.get().startActivity(intent);
  }

}




Java Source Code List

com.etsy.android.grid.ClassLoaderSavedState.java
com.etsy.android.grid.ExtendableListView.java
com.etsy.android.grid.HeaderViewListAdapter.java
com.etsy.android.grid.StaggeredGridView.java
com.etsy.android.grid.util.DynamicHeightImageView.java
com.etsy.android.grid.util.DynamicHeightTextView.java
com.polites.android.Animation.java
com.polites.android.Animator.java
com.polites.android.FlingAnimationListener.java
com.polites.android.FlingAnimation.java
com.polites.android.FlingListener.java
com.polites.android.GestureImageViewListener.java
com.polites.android.GestureImageViewTouchListener.java
com.polites.android.GestureImageView.java
com.polites.android.MathUtils.java
com.polites.android.MoveAnimationListener.java
com.polites.android.MoveAnimation.java
com.polites.android.VectorF.java
com.polites.android.ZoomAnimationListener.java
com.polites.android.ZoomAnimation.java
com.readystatesoftware.systembartint.SystemBarTintManager.java
org.telugudesam.cadre.App.java
org.telugudesam.cadre.Config.java
org.telugudesam.cadre.Constants.java
org.telugudesam.cadre.activity.BaseTdpActivity.java
org.telugudesam.cadre.activity.ConversionCounterActivity.java
org.telugudesam.cadre.activity.ConversionRegistrationActivity.java
org.telugudesam.cadre.activity.PreviewActivity.java
org.telugudesam.cadre.activity.TdpMainActivity.java
org.telugudesam.cadre.adapters.DevelopmentCardsAdapter.java
org.telugudesam.cadre.components.MemCache.java
org.telugudesam.cadre.database.DbHelper.java
org.telugudesam.cadre.database.DbUtils.java
org.telugudesam.cadre.database.Tdp_cadre_boxFactory.java
org.telugudesam.cadre.fragments.DevelopmentCardsFragment.java
org.telugudesam.cadre.objects.DevelopmentCard.java
org.telugudesam.cadre.objects.Events.java
org.telugudesam.cadre.objects.Section.java
org.telugudesam.cadre.objects.dao.DevelopmentCardDao.java
org.telugudesam.cadre.objects.dao.DevelopmentCardTable.java
org.telugudesam.cadre.util.L.java
org.telugudesam.cadre.util.SystemUiHiderBase.java
org.telugudesam.cadre.util.SystemUiHiderHoneycomb.java
org.telugudesam.cadre.util.SystemUiHider.java
org.telugudesam.cadre.util.Utils.java