Android Open Source - daisy_main Sample Grid View Adapter






From Project

Back to project page daisy_main.

License

The source code is released under:

GNU General Public License

If you think the Android project daisy_main 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 de.uvwxy.daisy.nodemap.listobjects;
/*from w  w w.  j  a  v  a2 s.c  o m*/
import java.io.File;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.Transformation;

import de.uvwxy.daisy.nodemap.R;
import de.uvwxy.helper.BitmapTools;

public class SampleGridViewAdapter extends BaseAdapter {
  private final Context context;
  @SuppressWarnings("unused")
  private final Transformation cropSquare = new CropSquareTransformation();
  private List<String> filePaths = null;

  public SampleGridViewAdapter(Context context, List<String> filePaths) {
    this.context = context;
    this.filePaths = filePaths;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    SquaredImageView view = (SquaredImageView) convertView;
    if (view == null) {
      view = new SquaredImageView(context);
    }

    // Get the image URL for the current position.
    String path = getItem(position);

    // Trigger the download of the URL asynchronously into the image view.
    Picasso.with(context) //
        .load(new File(path)) //
        .error(R.drawable.missing_image) //
        .resize(320, 240)// 800x600 previously
        //.transform(cropSquare) //
        .skipCache() //
        .into(view);

    return view;
  }

  @Override
  public int getCount() {
    return filePaths.size();
  }

  @Override
  public String getItem(int position) {
    return filePaths.get(position);
  }

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

  class SquaredImageView extends ImageView {
    public SquaredImageView(Context context) {
      super(context);
    }

    public SquaredImageView(Context context, AttributeSet attrs) {
      super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
    }
  }

  class CropSquareTransformation implements Transformation {
    @Override
    public Bitmap transform(Bitmap source) {
      int size = BitmapTools.dipToPixels(context, 48);//Math.min(source.getWidth(), source.getHeight());

      int x = (source.getWidth() - size) / 2;
      int y = (source.getHeight() - size) / 2;

      Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
      if (squaredBitmap != source) {
        source.recycle();
      }
      return squaredBitmap;
    }

    @Override
    public String key() {
      return "square()";
    }
  }
}




Java Source Code List

de.uvwxy.daisy.nodemap.gui.ActivityAnnotation.java
de.uvwxy.daisy.nodemap.gui.ActivityNodeDetails.java
de.uvwxy.daisy.nodemap.gui.DetailActivity.java
de.uvwxy.daisy.nodemap.gui.DetailFragment.java
de.uvwxy.daisy.nodemap.gui.MainListActivity.java
de.uvwxy.daisy.nodemap.gui.MainListFragment.java
de.uvwxy.daisy.nodemap.guicontent.CMARView.java
de.uvwxy.daisy.nodemap.guicontent.CMBalloon.java
de.uvwxy.daisy.nodemap.guicontent.CMLocation.java
de.uvwxy.daisy.nodemap.guicontent.CMLogs.java
de.uvwxy.daisy.nodemap.guicontent.CMMap.java
de.uvwxy.daisy.nodemap.guicontent.CMSensors.java
de.uvwxy.daisy.nodemap.guicontent.CMXBee.java
de.uvwxy.daisy.nodemap.guicontent.CM.java
de.uvwxy.daisy.nodemap.guicontent.IDestroy.java
de.uvwxy.daisy.nodemap.guiviews.CVARView.java
de.uvwxy.daisy.nodemap.guiviews.CVBalloonClient.java
de.uvwxy.daisy.nodemap.guiviews.CVBalloon.java
de.uvwxy.daisy.nodemap.guiviews.CVChat.java
de.uvwxy.daisy.nodemap.guiviews.CVDeploymentData.java
de.uvwxy.daisy.nodemap.guiviews.CVDeployment.java
de.uvwxy.daisy.nodemap.guiviews.CVLogs.java
de.uvwxy.daisy.nodemap.guiviews.CVMap.java
de.uvwxy.daisy.nodemap.guiviews.CVMenuItem.java
de.uvwxy.daisy.nodemap.guiviews.CVParticipantScan.java
de.uvwxy.daisy.nodemap.guiviews.CVXBee.java
de.uvwxy.daisy.nodemap.guiviews.CV.java
de.uvwxy.daisy.nodemap.listobjects.APIMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.CVArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.ChatMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.LogMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.SampleGridViewAdapter.java