Android Open Source - youku_api_android_framework Movie Adapter






From Project

Back to project page youku_api_android_framework.

License

The source code is released under:

Apache License

If you think the Android project youku_api_android_framework 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.android.intro.movieslist.adpater;
/*from  w  w w .  j ava 2s  .co  m*/

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

import uk.co.senab.bitmapcache.CacheableBitmapDrawable;

import com.android.intro.custorm.imageview.NetworkedCacheableImageView;
import com.android.intro.moiveslist.*;

public class MovieAdapter extends BaseAdapter {

  private final ArrayList<String> movicesUrl;
  
  private final Context mContext;
  
  
  public MovieAdapter(Context context, ArrayList<String> url) {
    movicesUrl = url;
    mContext = context;
    }
  
  public void appendToDataSet(ArrayList<String> url){
    movicesUrl.addAll(url);
  }
  
  @Override
  public int getCount() {
    return null != movicesUrl ? movicesUrl.size() : 0;
  }
  
  @Override
  public String getItem(int position) {
      return movicesUrl.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext)
                    .inflate(R.layout.gridview_item_layout, parent, false);
        }

        NetworkedCacheableImageView imageView = (NetworkedCacheableImageView) convertView
                .findViewById(R.id.nciv_pug);
        
        
        TextView status = (TextView) convertView.findViewById(R.id.tv_status);

        final boolean fromCache = imageView
                .loadImage(movicesUrl.get(position), false, new UpdateTextViewListener(status));
        

        if (fromCache) {
            status.setText("From Memory Cache");
            status.setBackgroundColor(mContext.getResources().getColor(R.color.translucent_green));
        } else {
            status.setText("Loading...");
            status.setBackgroundColor(mContext.getResources().getColor(R.color.translucent_green));
        }

        return convertView;
    }

    static class UpdateTextViewListener
            implements NetworkedCacheableImageView.OnImageLoadedListener {
        private final WeakReference<TextView> mTextViewRef;

        public UpdateTextViewListener(TextView tv) {
            mTextViewRef = new WeakReference<TextView>(tv);
        }

        @Override
        public void onImageLoaded(CacheableBitmapDrawable result) {
            final TextView tv = mTextViewRef.get();
            if (tv == null) {
                return;
            }

            if (result == null) {
                tv.setText("Failed");
                tv.setBackgroundDrawable(null);
                return;
            }

            switch (result.getSource()) {
                case CacheableBitmapDrawable.SOURCE_UNKNOWN:
                case CacheableBitmapDrawable.SOURCE_NEW:
                    tv.setText("From Disk/Network");
                    tv.setBackgroundColor(tv.getResources().getColor(R.color.translucent_red));
                    break;
                case CacheableBitmapDrawable.SOURCE_INBITMAP:
                    tv.setText("Reused Bitmap");
                    tv.setBackgroundColor(tv.getResources().getColor(R.color.translucent_blue));
                    break;
            }
        }
    }

}




Java Source Code List

com.android.intro.custorm.imageview.NetworkedCacheableImageView.java
com.android.intro.custorm.imageview.SDK11.java
com.android.intro.custorm.imageview.SampleApplication.java
com.android.intro.moiveslist.MainActivity.java
com.android.intro.moiveslist.MoiveChannelFragment.java
com.android.intro.moiveslist.MoiveDetailAvctivity.java
com.android.intro.moiveslist.MovieHome.java
com.android.intro.moiveslist.SearchActivity.java
com.android.intro.moiveslist.SplashActivity.java
com.android.intro.moiveslist.YoukuVideoView.java
com.android.intro.moiveslist.models.BaseModel.java
com.android.intro.moiveslist.models.HttpCallBackHandler.java
com.android.intro.moiveslist.models.MoiveModel.java
com.android.intro.moiveslist.models.PlayModel.java
com.android.intro.moiveslist.models.SearchSuggestModel.java
com.android.intro.moviceslist.base.BaseActivity.java
com.android.intro.moviceslist.base.MenuFragment.java
com.android.intro.movieslist.adpater.MovieAdapter.java
com.android.intro.movieslist.adpater.MovieDetailAdapter.java
com.makeramen.RoundedDrawable.java
com.makeramen.RoundedImageView.java
uk.co.senab.bitmapcache.BitmapLruCache.java
uk.co.senab.bitmapcache.BitmapMemoryLruCache.java
uk.co.senab.bitmapcache.CacheableBitmapDrawable.java
uk.co.senab.bitmapcache.CacheableImageView.java
uk.co.senab.bitmapcache.Constants.java
uk.co.senab.bitmapcache.IoUtils.java
uk.co.senab.bitmapcache.Md5.java
uk.co.senab.bitmapcache.SDK11.java
uk.co.senab.bitmapcache.WeakReferenceRunnable.java