Android and stuff
Android: Simple Full Screen Image Viewer Activity
Here’s the code for a simple full screen ImageViewerActivity. It uses the SDImageLoader from this post to load the image asynchronously from the SD card.
public class ImageViewerActivity extends Activity {
public static final String IMAGE_PATH = "imagevieweractivityfilepath";
private final SDImageLoader mImageLoader = new SDImageLoader();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imageviewer);
Bundle extras = getIntent().getExtras();
if(extras != null) {
String imagePath = extras.getString(IMAGE_PATH);
if(imagePath != null) {
ImageView i = (ImageView)findViewById(R.id.image_viewer_image);
mImageLoader.load(this, imagePath, i);
}
}
}
}
Here’s an example of how to use this activity:
//load the filepath from the database Cursor c = mDbHelper.fetchCapture(info.id); String filePath = c.getString(c.getColumnIndexOrThrow(SpecimenHunterDatabaseAdapter.KEY_CAPTURES_PHOTO)); //create the new intent Intent it = new Intent(this, ImageViewerActivity.class); //put the filepath into the extras bundle it.putExtra(ImageViewerActivity.IMAGE_PATH, filePath); //start activity. startActivity(it);
Here’s the xml layout file. Use the src of the ImageView to set the image to use as a placeholder while the image you wish to display loads from the SD card.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="center" android:gravity="center"> <ImageView android:id="@+id/image_viewer_image" android:src="@drawable/thumbnail_placeholder" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:layout_gravity="center" android:gravity="center" /> </LinearLayout>