Android Open Source - kluster-android Event Grid Adapter






From Project

Back to project page kluster-android.

License

The source code is released under:

Apache License

If you think the Android project kluster-android 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.cs446.kluster.views.fragments;
/* w  w  w  . j  av  a  2s  .c  om*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.cs446.kluster.R;
import com.cs446.kluster.data.EventProvider.EventOpenHelper;
import com.cs446.kluster.models.Event;
import com.cs446.kluster.views.activities.MainActivity;
import com.cs446.kluster.views.activities.PhotoGridActivity;
import com.squareup.picasso.Picasso;

public class EventGridAdapter extends SimpleCursorAdapter {
  private final LayoutInflater mInflator;
  private MainActivity mActivity;
  
  public EventGridAdapter(Context context, int layout, Cursor c,
      String[] from, int[] to, int flags) {
    super(context, layout, c, from, to, flags);
    
    mInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mActivity = (MainActivity)context;
  }
  
  @Override
  public Object getItem(int position) {
    getCursor().moveToPosition(position);
    
    return getCursor().getString(getCursor().getColumnIndex(EventOpenHelper.COLUMN_EVENT_ID));
  }
  
  @Override
    public void bindView(View view, Context context, Cursor cursor) { 
    SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy hh:mmaa", Locale.US);
        TextView txtTitle = (TextView)view.getTag(R.id.eventgrid_txtTitle);
        TextView txtDate = (TextView)view.getTag(R.id.eventgrid_txtDate);
        ViewPager mPager = (ViewPager)view.getTag(R.id.eventgrid_pager);
        
      String id = cursor.getString(cursor.getColumnIndex(EventOpenHelper.COLUMN_EVENT_ID));
      String name = cursor.getString(cursor.getColumnIndex(EventOpenHelper.COLUMN_EVENT_NAME));
      String photos = cursor.getString(cursor.getColumnIndex(EventOpenHelper.COLUMN_PHOTOS));   

      EventPagerAdapter pager = new EventPagerAdapter(id, name, photos); 

        mPager.setAdapter(pager);
        txtTitle.setText(cursor.getString(cursor.getColumnIndex(EventOpenHelper.COLUMN_EVENT_NAME)));   
    try {
      txtDate.setText(df.format(Event.getDateFormat().parse(cursor.getString(cursor.getColumnIndex(EventOpenHelper.COLUMN_STARTTIME)))));
    } catch (ParseException e) {
      Log.e("EventGridAdapter", e.toString());
    }
  }
  
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
      View view = mInflator.inflate(R.layout.eventgridcell_layout, parent, false);

        view.setTag(R.id.eventgrid_pager, view.findViewById(R.id.eventgrid_pager));
        view.setTag(R.id.eventgrid_txtTitle, view.findViewById(R.id.eventgrid_txtTitle));
        view.setTag(R.id.eventgrid_txtDate, view.findViewById(R.id.eventgrid_txtDate));
        
      return view;
    }
  
    private class EventPagerAdapter extends PagerAdapter {
      String mEventId;
      String mEventName;
      String[] mPhotos;
      
        public EventPagerAdapter(String eventid, String eventname, String photos) {
          mEventId = eventid;
          mEventName = eventname;
          mPhotos = TextUtils.split(photos, ",");
        }

        public void destroyItem(View view, int position, Object object) {
            ((ViewPager)view).removeView((ImageView)object);
        }
        
        @Override
        public Object instantiateItem(View view, int position) {

          ImageView imgMain = new ImageView(mActivity);
            imgMain.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT)); 
            imgMain.setScaleType(ScaleType.CENTER_CROP);
            
            
            imgMain.setOnClickListener(new OnClickListener() {
          
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(mActivity, PhotoGridActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("eventid", mEventId);
            bundle.putString("eventname", mEventName);
            intent.putExtra("events", bundle);
            
            mActivity.startActivity(intent);
          }
        });

            Picasso.with(mActivity).load(mPhotos[position]).into(imgMain);

            ((ViewPager)view).addView(imgMain);
            
            return imgMain;
        }

        @Override
        public int getCount() {
          return mPhotos.length;
        }

    @Override
    public boolean isViewFromObject(View view, Object object) {
      return view == object;
    }
    }
}




Java Source Code List

android.app.GridFragment.java
android.app.NonSwipeableViewPager.java
android.app.ScaleImageView.java
com.cs446.kluster.ConfigManager.java
com.cs446.kluster.KlusterApplication.java
com.cs446.kluster.cache.CacheUtils.java
com.cs446.kluster.cache.DiskLruCache.java
com.cs446.kluster.cache.DiskLruImageCache.java
com.cs446.kluster.cache.KlusterCache.java
com.cs446.kluster.data.AbstractContentStorageAdapter.java
com.cs446.kluster.data.EventProvider.java
com.cs446.kluster.data.EventStorageAdapter.java
com.cs446.kluster.data.PhotoProvider.java
com.cs446.kluster.data.PhotoStorageAdapter.java
com.cs446.kluster.data.SearchProvider.java
com.cs446.kluster.data.SearchStorageAdapter.java
com.cs446.kluster.data.StorageAdapter.java
com.cs446.kluster.data.StorageConstants.java
com.cs446.kluster.data.serialize.AuthUserAdapter.java
com.cs446.kluster.data.serialize.EventAdapter.java
com.cs446.kluster.data.serialize.PhotoAdapter.java
com.cs446.kluster.data.serialize.SerializerUtils.java
com.cs446.kluster.data.serialize.UserAdapter.java
com.cs446.kluster.map.MapUtils.java
com.cs446.kluster.models.AuthUser.java
com.cs446.kluster.models.Event.java
com.cs446.kluster.models.Photo.java
com.cs446.kluster.models.User.java
com.cs446.kluster.net.AuthInterceptor.java
com.cs446.kluster.net.AuthKlusterRestAdapter.java
com.cs446.kluster.net.EventsCallback.java
com.cs446.kluster.net.KlusterRestAdapter.java
com.cs446.kluster.net.KlusterService.java
com.cs446.kluster.net.NetworkUtils.java
com.cs446.kluster.net.PhotosCallback.java
com.cs446.kluster.net.UploadService.java
com.cs446.kluster.views.activities.LoginActivity.java
com.cs446.kluster.views.activities.MainActivity.java
com.cs446.kluster.views.activities.PhotoFactory.java
com.cs446.kluster.views.activities.PhotoGridActivity.java
com.cs446.kluster.views.fragments.DiscoverFragment.java
com.cs446.kluster.views.fragments.EventDialogFragment.java
com.cs446.kluster.views.fragments.EventGridAdapter.java
com.cs446.kluster.views.fragments.EventGridFragment.java
com.cs446.kluster.views.fragments.EventMapFragment.java
com.cs446.kluster.views.fragments.FilterDialogFragment.java
com.cs446.kluster.views.fragments.PhotoGridAdapter.java
com.cs446.kluster.views.fragments.PhotoGridFragment.java
com.cs446.kluster.views.fragments.PhotoViewerFragment.java
com.cs446.kluster.views.fragments.SearchFragment.java
com.cs446.kluster.views.fragments.SearchGridFragment.java
com.cs446.kluster.views.fragments.SearchMapFragment.java
com.cs446.kluster.views.fragments.SignupFragment.java
com.cs446.kluster.views.fragments.UserProfileFragment.java
com.cs446.kluster.views.map.PhotoInfoWindowAdapter.java