my goal is to display images(thumbnails) from SD card in smooth list so i edited the demo sample(loading images from web to gridview) a bit to load the images from SD card to see the performance , and when the images are not cached (first time) it's pretty slow since it should be loading the images from local SD card not the web, but after the images are cached iam pretty happy with the results,please take a look and let me know if iam doing anything wrong, or how can i increase performance at first loading, also iam open for other libraries that maybe more specialized in loading images form SD card,here is the code :-
public class ImageGridActivity extends AbsListViewBaseActivity {
// get files path in camera folder
public String[] getimages() {
String[] images=new String[175];
String path="file:///mnt/sdcard/DCIM/Camera/";
int counter=0;
String name;
File sdCardRoot = Environment.getExternalStorageDirectory();
File yourDir = new File(sdCardRoot, "dcim/camera");
for (File f : yourDir.listFiles()) {
if (f.isFile()){
name = path + f.getName().toString() ;
images[counter]=name;
// make something with the name
counter++;}
}
return images;
}
String[] imageUrls= getimages();
DisplayImageOptions options;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_image_grid);
Bundle bundle = getIntent().getExtras();
// imageUrls = bundle.getStringArray(Extra.IMAGES);
// imageUrls[0]="file:///mnt/sdcard/DCIM/Camera/abc.jpg";
options = new DisplayImageOptions.Builder()
/* .showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build(); */
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.showImageOnFail(R.drawable.ic_launcher).cacheInMemory()
.cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext()).discCacheExtraOptions(720 , 1280 , CompressFormat.PNG, 0, null).build();
ImageLoader.getInstance().init(config);
listView = (GridView) findViewById(R.id.gridview);
((GridView) listView).setAdapter(new ImageAdapter());
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startImagePagerActivity(position);
}
});
}
private void startImagePagerActivity(int position) {
Intent intent = new Intent(this, ImagePagerActivity.class);
intent.putExtra(Extra.IMAGES, imageUrls);
intent.putExtra(Extra.IMAGE_POSITION, position);
startActivity(intent);
}
public class ImageAdapter extends BaseAdapter {
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView imageView;
if (convertView == null) {
imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
} else {
imageView = (ImageView) convertView;
}
imageLoader.displayImage(imageUrls[position], imageView, options);
return imageView;
}
}
}
item_grid_image
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:adjustViewBounds="true"
android:contentDescription="@string/descr_image"
android:scaleType="centerCrop" />
thank you in advance,