Пример #1
0
 /** Adds an image that was just taken with the camera app into the gallery. */
 public void insertIntoGallery(Media image) {
   Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
   File f = new File(image.getPath());
   Uri contentUri = Uri.fromFile(f);
   mediaScanIntent.setData(contentUri);
   this.sendBroadcast(mediaScanIntent);
 }
Пример #2
0
  /**
   * Inserts the bitmap of a Media object onto an imageView to display in the activity. It also puts
   * the Media object as the Tag of the imageView so that later on if the image needs to be deleted
   * or the text field needs to be read, we will know which object the bitmap belongs to. </br></br>
   *
   * <p>CODE REUSE </br> URL: http://android-er.blogspot.ca/2012/07/implement-gallery-like.html
   * </br> Date: Nov. 7, 2013 </br> Author: Andr.oid Eric
   */
  protected View insertImage(Media img, Context context, LinearLayout main) {
    Bitmap bm = decodeSampledBitmapFromUri(Uri.parse(img.getPath()), 250, 250);
    LinearLayout layout = new LinearLayout(context);

    layout.setLayoutParams(new LayoutParams(250, 250));
    layout.setGravity(Gravity.CENTER);

    imageView = new ImageView(context);
    imageView.setLayoutParams(new LayoutParams(250, 250));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageBitmap(bm);
    imageView.setTag(img);

    layout.addView(imageView);
    main.addView(layout);

    return (View) imageView;
  }