/* ApicAday - Everyday.. is different, your mood, your life. Copyright (c) 2010 Oliver Selinger <oliver.selinger@autburst.com>, Michael Greifeneder <michael.greifeneder@autburst.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.autburst.picture.gallery; import java.io.File; import java.util.Arrays; 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.Gallery; import android.widget.ImageView; import com.autburst.picture.Utilities; public class GalleryImageAdapter extends BaseAdapter { private Context ctx; private File albumDirectory; int imageBackground; File[] listFiles; public GalleryImageAdapter(Context c, File albumDirectory) { ctx = c; this.albumDirectory = albumDirectory; listFiles = this.albumDirectory.listFiles(); Arrays.sort(listFiles, Utilities.getImageNameComparator()); } @Override public int getCount() { return albumDirectory.list().length; } @Override public void notifyDataSetChanged() { listFiles = this.albumDirectory.listFiles(); Arrays.sort(listFiles, Utilities.getImageNameComparator()); super.notifyDataSetChanged(); } @Override public Object getItem(int arg0) { return arg0; } @Override public long getItemId(int arg0) { return arg0; } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { ImageView iv = new ImageView(ctx); // File file = new File(this.albumDirectory, ); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 6; options.inPurgeable = true; Bitmap bm = Bitmap.createBitmap(BitmapFactory.decodeFile(listFiles[arg0] .getAbsolutePath(), options)); iv.setImageBitmap(bm); iv.setScaleType(ImageView.ScaleType.FIT_CENTER); iv.setLayoutParams(new Gallery.LayoutParams(150,120)); // iv.setBackgroundResource(imageBackground); return iv; } /** Returns the size (0.0f to 1.0f) of the views * depending on the 'offset' to the center. */ public float getScale(boolean focused, int offset) { /* Formula: 1 / (2 ^ offset) */ return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset))); } }