public class ViewImmagini extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.immagini);
/* Find the gallery defined in the main.xml
* Apply a new (custom) ImageAdapter to it. */
((Gallery) findViewById(R.id.gallery))
.setAdapter(new ImageAdapter(this));
TextView jpgName = (TextView)findViewById(R.id.jpgname);
String myJpgPath = "/sdcard/Inverno.jpg";
jpgName.setText(myJpgPath);
}
public class ImageAdapter extends BaseAdapter {
/** The parent context */
private Context myContext;
/** URL-Strings to some remote images. */
private String[] myRemoteImages = {
"/sdcard/Multimedia/Immagini/image_LARGE_1.jpg",
"/sdcard/image_LARGE_1.jpg",
"/sdcard/Desert.jpg",
"/sdcard/Inverno.jpg"
};
/** Simple Constructor saving the 'parent' context. */
public ImageAdapter(Context c) { this.myContext = c; }
/** Returns the amount of images we have defined. */
public int getCount() { return this.myRemoteImages.length; }
/* Use the array-Positions as unique IDs */
public Object getItem(int position) { return position; }
public long getItemId(int position) { return position; }
/** Returns a new ImageView to
* be displayed, depending on
* the position passed. */
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(this.myContext);
ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
String myJpgPath = "/sdcard/Multimedia/Immagini/image_LARGE_1.jpg";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm1 = BitmapFactory.decodeFile(myJpgPath, options);
jpgView.setImageBitmap(bm1);
i.setImageBitmap(bm1);
/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* Set the Width/Height of the ImageView. */
i.setLayoutParams(new Gallery.LayoutParams(180, 150));
return i;
}
/** 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)));
}
}
}