private void populateWallpapersFromAdapter(
     ViewGroup parent, BaseAdapter adapter, boolean addLongPressHandler) {
   for (int i = 0; i < adapter.getCount(); i++) {
     FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
     parent.addView(thumbnail, i);
     WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i);
     thumbnail.setTag(info);
     info.setView(thumbnail);
     if (addLongPressHandler) {
       addLongPressHandler(thumbnail);
     }
     thumbnail.setOnClickListener(mThumbnailOnClickListener);
   }
 }
  private void addTemporaryWallpaperTile(final Uri uri, boolean fromRestore) {
    mTempWallpaperTiles.add(uri);
    // Add a tile for the image picked from Gallery
    final FrameLayout pickedImageThumbnail =
        (FrameLayout)
            getLayoutInflater().inflate(R.layout.wallpaper_picker_item, mWallpapersView, false);
    pickedImageThumbnail.setVisibility(View.GONE);
    setWallpaperItemPaddingToZero(pickedImageThumbnail);
    mWallpapersView.addView(pickedImageThumbnail, 0);

    // Load the thumbnail
    final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
    final Point defaultSize = getDefaultThumbnailSize(this.getResources());
    final Context context = this;
    new AsyncTask<Void, Bitmap, Bitmap>() {
      protected Bitmap doInBackground(Void... args) {
        int rotation = WallpaperCropActivity.getRotationFromExif(context, uri);
        return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false);
      }

      protected void onPostExecute(Bitmap thumb) {
        if (thumb != null) {
          image.setImageBitmap(thumb);
          Drawable thumbDrawable = image.getDrawable();
          thumbDrawable.setDither(true);
          pickedImageThumbnail.setVisibility(View.VISIBLE);
        } else {
          Log.e(TAG, "Error loading thumbnail for uri=" + uri);
        }
      }
    }.execute();

    UriWallpaperInfo info = new UriWallpaperInfo(uri);
    pickedImageThumbnail.setTag(info);
    info.setView(pickedImageThumbnail);
    addLongPressHandler(pickedImageThumbnail);
    updateTileIndices();
    pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener);
    if (!fromRestore) {
      mThumbnailOnClickListener.onClick(pickedImageThumbnail);
    }
  }