ImageAdapter.java :  » App » atoom-android » net » atoom » android » knn » Android Open Source

Android Open Source » App » atoom android 
atoom android » net » atoom » android » knn » ImageAdapter.java
/**
 *    Copyright 2010 Bram de Kruijff <bdekruijff [at] gmail [dot] com>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package net.atoom.android.knn;

import java.util.LinkedList;
import java.util.List;

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

public class ImageAdapter extends BaseAdapter {

  private Context m_Context;
  private List<Bitmap> m_Bitmaps = new LinkedList<Bitmap>();

  public ImageAdapter(Context c) {
    m_Context = c;
  }

  public void addImageFile(String imageFile) {
    m_Bitmaps.add(BitmapFactory.decodeFile(imageFile));
  }

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

  @Override
  public Object getItem(int index) {
    return m_Bitmaps.get(index);
  }

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

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ImageView i = new ImageView(m_Context);
    i.setImageBitmap(m_Bitmaps.get(position));
    // i.setLayoutParams(new Gallery.LayoutParams(150, 100));
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    return i;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.