Android Open Source - bv-android-sdk Photo Select Cursor Adapter






From Project

Back to project page bv-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project bv-android-sdk 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.chute.android.photopickerplus.adapter;
//from  ww w . jav  a2 s .  c  om
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;

import com.chute.android.photopickerplus.R;
import com.darko.imagedownloader.ImageLoader;

public class PhotoSelectCursorAdapter extends CursorAdapter implements OnScrollListener {

    public static final String TAG = PhotoSelectCursorAdapter.class.getSimpleName();

    private static LayoutInflater inflater = null;
    public ImageLoader loader;
    private final int dataIndex;
    public HashMap<Integer, String> tick;
    private boolean shouldLoadImages = true;
    private final DisplayMetrics displayMetrics;

    public PhotoSelectCursorAdapter(Context context, Cursor c) {
  super(context, c);
  inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  loader = ImageLoader.getLoader(context);
  dataIndex = c.getColumnIndex(MediaStore.Images.Media.DATA);
  displayMetrics = context.getResources().getDisplayMetrics();
  tick = new HashMap<Integer, String>();
    }

    public static class ViewHolder {
  public ImageView image;
  public ImageView tick;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
  ViewHolder holder = (ViewHolder) view.getTag();
  String path = cursor.getString(dataIndex);
  holder.image.setTag(path);
  holder.tick.setTag(cursor.getPosition());
  if (shouldLoadImages) {
      loader.displayImage(Uri.fromFile(new File(path)).toString(), holder.image);
  } else {
      loader.displayImage(null, holder.image);
  }
  holder.image.setLayoutParams(new RelativeLayout.LayoutParams(
    displayMetrics.widthPixels / 3 - 2, displayMetrics.widthPixels / 3 - 2));
  holder.image.setScaleType(ScaleType.CENTER_CROP);
  if (tick.containsKey(cursor.getPosition())) {
      holder.tick.setVisibility(View.VISIBLE);
      view.setBackgroundColor(context.getResources().getColor(R.color.orange));
  } else {
      holder.tick.setVisibility(View.GONE);
      view.setBackgroundColor(Color.BLACK);
  }
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
  ViewHolder holder;
  View vi = inflater.inflate(R.layout.photos_select_adapter, null);
  holder = new ViewHolder();
  holder.image = (ImageView) vi.findViewById(R.id.imageViewThumb);
  holder.tick = (ImageView) vi.findViewById(R.id.imageTick);
  vi.setTag(holder);
  return vi;
    }

    @Override
    public String getItem(int position) {
  final Cursor cursor = getCursor();
  cursor.moveToPosition(position);
  return cursor.getString(dataIndex);
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
      int totalItemCount) {
  // Do nothing

    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
  switch (scrollState) {
  case OnScrollListener.SCROLL_STATE_FLING:
  case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
      shouldLoadImages = false;
      break;
  case OnScrollListener.SCROLL_STATE_IDLE:
      shouldLoadImages = true;
      notifyDataSetChanged();
      break;
  }
    }

    public ArrayList<String> getSelectedFilePaths() {
  final ArrayList<String> photos = new ArrayList<String>();
  final Iterator<String> iterator = tick.values().iterator();
  while (iterator.hasNext()) {
      photos.add(iterator.next());
  }
  return photos;
    }

    public boolean hasSelectedItems() {
  return tick.size() > 0;
    }

    public int getSelectedItemsCount() {
  return tick.size();
    }

    public void toggleTick(int position) {
  if (tick.containsKey(position)) {
      tick.remove(position);
  } else {
      tick.put(position, getItem(position));
  }
  notifyDataSetChanged();
    }
}




Java Source Code List

com.bazaarvoice.BazaarException.java
com.bazaarvoice.BazaarParams.java
com.bazaarvoice.BazaarRequest.java
com.bazaarvoice.DisplayParams.java
com.bazaarvoice.Media.java
com.bazaarvoice.OnBazaarResponse.java
com.bazaarvoice.SubmissionMediaParams.java
com.bazaarvoice.SubmissionParams.java
com.bazaarvoice.example.browseproducts.BazaarFunctions.java
com.bazaarvoice.example.browseproducts.BazaarProduct.java
com.bazaarvoice.example.browseproducts.BazaarReview.java
com.bazaarvoice.example.browseproducts.BazaarUIThreadResponse.java
com.bazaarvoice.example.browseproducts.ImageDownloader.java
com.bazaarvoice.example.browseproducts.MainActivity.java
com.bazaarvoice.example.browseproducts.OnImageDownloadComplete.java
com.bazaarvoice.example.browseproducts.ProductAdapter.java
com.bazaarvoice.example.browseproducts.ProductsActivity.java
com.bazaarvoice.example.browseproducts.ReviewAdapter.java
com.bazaarvoice.example.browseproducts.ReviewDisplayActivity.java
com.bazaarvoice.example.browseproducts.ReviewsActivity.java
com.bazaarvoice.example.reviewsubmission.BazaarFunctions.java
com.bazaarvoice.example.reviewsubmission.BazaarReview.java
com.bazaarvoice.example.reviewsubmission.CameraUtils.java
com.bazaarvoice.example.reviewsubmission.ImageDownloader.java
com.bazaarvoice.example.reviewsubmission.MainActivity.java
com.bazaarvoice.example.reviewsubmission.OnImageDownloadComplete.java
com.bazaarvoice.example.reviewsubmission.OnImageUploadComplete.java
com.bazaarvoice.example.reviewsubmission.RatingActivity.java
com.bazaarvoice.example.reviewsubmission.RatingPreviewActivity.java
com.bazaarvoice.example.reviewsubmission.ReviewSubmissionApp.java
com.bazaarvoice.intentexample.BazaarFunctions.java
com.bazaarvoice.intentexample.BazaarUIThreadResponse.java
com.bazaarvoice.intentexample.CameraUtils.java
com.bazaarvoice.intentexample.MainActivity.java
com.bazaarvoice.types.Action.java
com.bazaarvoice.types.ApiVersion.java
com.bazaarvoice.types.Equality.java
com.bazaarvoice.types.FeedbackContentType.java
com.bazaarvoice.types.FeedbackType.java
com.bazaarvoice.types.FeedbackVoteType.java
com.bazaarvoice.types.IncludeStatsType.java
com.bazaarvoice.types.IncludeType.java
com.bazaarvoice.types.MediaParamsContentType.java
com.bazaarvoice.types.RequestType.java
com.chute.android.photopickerplus.adapter.AlbumsAdapter.java
com.chute.android.photopickerplus.adapter.PhotoSelectCursorAdapter.java
com.chute.android.photopickerplus.adapter.PhotosAdapter.java
com.chute.android.photopickerplus.app.AlbumsActivity.java
com.chute.android.photopickerplus.app.ChooseServiceActivity.java
com.chute.android.photopickerplus.app.GridActivity.java
com.chute.android.photopickerplus.app.PhotoPickerPlusApp.java
com.chute.android.photopickerplus.dao.MediaDAO.java
com.chute.android.photopickerplus.util.AppUtil.java
com.chute.android.photopickerplus.util.Constants.java
com.chute.android.photopickerplus.util.NotificationUtil.java
com.chute.android.photopickerplus.util.intent.AlbumsActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.IntentUtil.java
com.chute.android.photopickerplus.util.intent.IntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoPickerPlusIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotosIntentWrapper.java
com.example.productwidgetexample.BazaarFunctions.java
com.example.productwidgetexample.BazaarProduct.java
com.example.productwidgetexample.BazaarReview.java
com.example.productwidgetexample.BazaarUIThreadResponse.java
com.example.productwidgetexample.ImageDownloader.java
com.example.productwidgetexample.OnImageDownloadComplete.java
com.example.productwidgetexample.ProductWidgetProvider.java
com.example.productwidgetexample.ReviewAdapter.java
com.example.productwidgetexample.ReviewsActivity.java