Android Open Source - bumper Image Adapter






From Project

Back to project page bumper.

License

The source code is released under:

MIT License

If you think the Android project bumper 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.varwise.bumper;
//w w  w.  j av  a2s .c  om
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;

/**
 * Created by pawel on 12.07.14.
 */
public class ImageAdapter extends BaseAdapter {
    private Context mContext;

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

    public int getCount() {
        return PhotoViewScreen.listFileCount;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {

        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5, 5, 5, 5);
        } else {
            imageView = (ImageView) convertView;
        }

        //if(PhotoViewScreen.listFile[position].exists()){
            //ImageView imageView = (ImageView) findViewById(R.id.imageviewTest);

            //Bitmap myBitmap = BitmapFactory.decodeFile(listFile[position].getAbsolutePath());
            //imageView.setImageBitmap(myBitmap);
            //imageView.setImageURI(Uri.fromFile(PhotoViewScreen.listFile[position]));
            //Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(PhotoViewScreen.listFile[position].getAbsolutePath()), 100, 100);
            Bitmap bitmap = decodeFile(PhotoViewScreen.listFile[position].getAbsolutePath(), 200,  200);
            imageView.setImageBitmap(bitmap);

        //}
        return imageView;
    }


    public static Bitmap decodeFile(String filePath, int WIDTH, int HEIGTH) {
        try {
            File f = new File(filePath);

            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f), null, o);

            int scale = 1;
            while (o.outWidth / scale / 2 >= WIDTH && o.outHeight / scale / 2 >= HEIGTH) {
                scale *= 2;
            }

            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

}




Java Source Code List

com.varwise.bumper.AccidentInformationAdapter.java
com.varwise.bumper.AccidentInformation.java
com.varwise.bumper.ApplicationTest.java
com.varwise.bumper.ChooseLocationScreen.java
com.varwise.bumper.DocumentsCheckScreen.java
com.varwise.bumper.EditScreen.java
com.varwise.bumper.HealthQuestionScreen.java
com.varwise.bumper.ImageAdapter.java
com.varwise.bumper.InsuranceScreen.java
com.varwise.bumper.MainScreen.java
com.varwise.bumper.MoveVehiclesScreen.java
com.varwise.bumper.ObstructQuestionScreen.java
com.varwise.bumper.OffendersStatement.java
com.varwise.bumper.PhotoViewFullScreen.java
com.varwise.bumper.PhotoViewScreen.java
com.varwise.bumper.ScreenCheck.java
com.varwise.bumper.ScreenDB.java
com.varwise.bumper.ScreenInformationAdapter.java
com.varwise.bumper.ScreenInformation.java
com.varwise.bumper.VictimQuestionScreen.java