Example usage for android.widget ImageView setTag

List of usage examples for android.widget ImageView setTag

Introduction

In this page you can find the example usage for android.widget ImageView setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java

public static void getFileIcon(File file, final ImageView icon) {
    if (Settings.showThumbnail() & isvalidMimeType(file)) {
        icon.setTag(file.getAbsolutePath());
        loadBitmap(file, icon);// w  ww.  j  a  va2  s . co m
    } else {
        loadFromRes(file, icon);
    }
}

From source file:com.conferenceengineer.android.iosched.util.ImageLoader.java

private static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override//from   ww  w. jav a2 s.  c om
        public void onResponse(ImageContainer response, boolean isImmediate) {
            imageView.setTag(null);
            if (response.getBitmap() != null) {
                setImageBitmap(imageView, response.getBitmap(), resources, fadeInImage && !isImmediate);
            } else {
                imageView.setImageDrawable(placeHolder);
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    };
}

From source file:com.android.volley.cache.plus.SimpleImageLoader.java

private static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override/*from   w w w.java 2  s .co m*/
        public void onResponse(ImageContainer response, boolean isImmediate) {
            imageView.setTag(null);
            if (response.getBitmap() != null) {

                if (imageView instanceof PhotoView) {
                    setPhotoImageBitmap((PhotoView) imageView, response.getBitmap(), resources,
                            fadeInImage && !isImmediate);
                } else {
                    setImageBitmap(imageView, response.getBitmap(), resources, fadeInImage && !isImmediate);
                }
            } else {
                if (!(imageView instanceof PhotoView)) {
                    imageView.setImageDrawable(placeHolder);
                }
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    };
}

From source file:com.android.volley.cache.SimpleImageLoader.java

public static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override/* w  ww  .  jav a  2  s  .  c om*/
        public void onResponse(ImageContainer response, boolean isImmediate) {
            imageView.setTag(null);
            if (response.getBitmap() != null) {

                if (imageView instanceof PhotoView) {
                    setPhotoImageBitmap((PhotoView) imageView, response.getBitmap(), resources,
                            fadeInImage && !isImmediate);
                } else {
                    setImageBitmap(imageView, response.getBitmap(), resources, fadeInImage && !isImmediate);
                }
            } else {
                if (!(imageView instanceof PhotoView)) {
                    imageView.setImageDrawable(placeHolder);
                }
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    };
}

From source file:com.DGSD.DGUtils.ImageDownloader.ImageLoader.java

private static void start(String imageUrl, ImageView imageView, ImageLoaderHandler handler,
        Drawable dummyDrawable, Drawable errorDrawable) {
    if (imageView != null) {
        if (imageUrl == null) {
            // In a ListView views are reused, so we must be sure to remove the tag that could
            // have been set to the ImageView to prevent that the wrong image is set.
            imageView.setTag(null);
            imageView.setImageDrawable(dummyDrawable);
            return;
        }/*from   www . ja v a 2  s .c  om*/
        String oldImageUrl = (String) imageView.getTag();
        if (imageUrl.equals(oldImageUrl)) {
            // nothing to do
            return;
        } else {
            // Set the dummy image while waiting for the actual image to be downloaded.
            imageView.setImageDrawable(dummyDrawable);
            imageView.setTag(imageUrl);
        }
    }

    if (imageCache.containsKeyInMemory(imageUrl)) {
        // do not go through message passing, handle directly instead
        handler.handleImageLoaded(imageCache.getBitmap(imageUrl), null);
    } else {
        executor.execute(new ImageLoader(imageUrl, handler));
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

/**
 * @param v the view to bind/*from  w ww  .  j  av  a 2 s.co m*/
 * @param context standard activity context
 * @param c the cursor source for the object in the db object table.
 * Must include _id in the projection.
 * 
 * @param allowInteractions controls whether the bound view is
 * allowed to intercept touch events and do its own processing.
 */
public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) {
    TextView nameText = (TextView) v.findViewById(R.id.name_text);
    ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content);
    frame.removeAllViews();

    // make sure we have all the columns we need
    Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID));
    String[] projection = null;
    String selection = DbObj.COL_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(objId) };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs,
            sortOrder);
    if (!c.moveToFirst()) {
        Log.w(TAG, "could not find obj " + objId);
        c.close();
        return;
    }
    DbObj obj = App.instance().getMusubi().objForCursor(c);
    if (obj == null) {
        nameText.setText("Failed to access database.");
        Log.e("DbObject", "cursor was null for bindView of DbObject");
        return;
    }
    DbUser sender = obj.getSender();
    Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP));
    Long hash = obj.getHash();
    short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED));
    String feedName = obj.getFeedName();
    String type = obj.getType();
    Date date = new Date(timestamp);
    c.close();
    c = null;

    if (sender == null) {
        nameText.setText("Message from unknown contact.");
        return;
    }
    nameText.setText(sender.getName());

    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
    if (sViewProfileAction == null) {
        sViewProfileAction = new OnClickViewProfile((Activity) context);
    }
    icon.setTag(sender.getLocalId());
    if (allowInteractions) {
        icon.setOnClickListener(sViewProfileAction);
        v.setTag(objId);
    }
    icon.setImageBitmap(sender.getPicture());

    if (deleted == 1) {
        v.setBackgroundColor(sDeletedColor);
    } else {
        v.setBackgroundColor(Color.TRANSPARENT);
    }

    TextView timeText = (TextView) v.findViewById(R.id.time_text);
    timeText.setText(RelativeDate.getRelativeDate(date));

    frame.setTag(objId); // TODO: error prone! This is database id
    frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id
    FeedRenderer renderer = DbObjects.getFeedRenderer(type);
    if (renderer != null) {
        renderer.render(context, frame, obj, allowInteractions);
    }

    if (!allowInteractions) {
        v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
        v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
    } else {
        if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) {
            v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
            v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
        } else {
            ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon);
            TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments);
            attachmentCountButton.setVisibility(View.VISIBLE);

            if (hash == 0) {
                attachmentCountButton.setVisibility(View.GONE);
            } else {
                //int color = DbObject.colorFor(hash);
                boolean selfPost = false;
                DBHelper helper = new DBHelper(context);
                try {
                    Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE });
                    try {
                        attachmentCountText.setText("+" + attachments.getCount());

                        if (attachments.moveToFirst()) {
                            while (!attachments.isAfterLast()) {
                                if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) {
                                    selfPost = true;
                                    break;
                                }
                                attachments.moveToNext();

                            }
                        }
                    } finally {
                        attachments.close();
                    }
                } finally {
                    helper.close();
                }
                if (selfPost) {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red);
                } else {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love);
                }
                attachmentCountText.setTag(R.id.object_entry, hash);
                attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName));
                attachmentCountText.setOnClickListener(LikeListener.getInstance(context));
            }
        }
    }
}

From source file:com.dp.chapter01.part1.ImageLoader.java

public void displayImage(final String url, final ImageView imageView) {
    imageView.setTag(url);
    mExecutorService.submit(new Runnable() {

        @Override//from ww  w . j a  v a 2  s.  c  om
        public void run() {
            Bitmap bitmap = downloadImage(url);
            if (bitmap == null) {
                return;
            }
            if (imageView.getTag().equals(url)) {
                updateImageView(imageView, bitmap);
            }
            mImageCache.put(url, bitmap);
        }
    });
}

From source file:org.matrix.matrixandroidsdk.db.ConsoleMediasCache.java

/**
 * Load a bitmap from an url./*from w w  w.  j  av  a  2 s .c om*/
 * The imageView image is updated when the bitmap is loaded or downloaded.
 * The width/height parameters are optional. If they are > 0, download a thumbnail.
 * @param context the context
 * @param imageView the imageView to fill when the image is downloaded
 * @param url the image url
 * @param width the expected image width
 * @param height the expected image height
 * @param rotationAngle the rotation angle (degrees)
 * @return a download identifier if the image is not cached
 */
public static String loadBitmap(Context context, ImageView imageView, String url, int width, int height,
        int rotationAngle) {
    if (null == url) {
        return null;
    }

    // request invalid bitmap size
    if ((0 == width) || (0 == height)) {
        return null;
    }

    String downloadableUrl = downloadableUrl(context, url, width, height);

    if (null != imageView) {
        imageView.setTag(downloadableUrl);
    }

    // check if the bitmap is already cached
    Bitmap bitmap = BitmapWorkerTask.bitmapForURL(context.getApplicationContext(), downloadableUrl,
            rotationAngle);

    if (null != bitmap) {
        if (null != imageView) {
            // display it
            imageView.setImageBitmap(bitmap);
        }
        downloadableUrl = null;
    } else {
        BitmapWorkerTask currentTask = BitmapWorkerTask.bitmapWorkerTaskForUrl(downloadableUrl);

        if (null != currentTask) {
            if (null != imageView) {
                currentTask.addImageView(imageView);
            }
        } else {
            // download it in background
            BitmapWorkerTask task = new BitmapWorkerTask(context, downloadableUrl, rotationAngle);

            if (null != imageView) {
                task.addImageView(imageView);
            }
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
        }
    }

    return downloadableUrl;
}

From source file:org.uis.luu.PicActivity.java

private ImageView createPager(String url) {
    LinearLayout.LayoutParams dotParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    ImageView imageView = new ImageView(this);
    imageView.setLayoutParams(dotParams);
    imageView.setTag(url);
    imageView.setImageResource(R.mipmap.ic_launcher);

    //imageView.setImageBitmap(null);
    return imageView;
}

From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java

private void addAudibleToLayout(int type, MediaPlayer mp) {
    View view = View.inflate(getActivity(), R.layout.audible_preview_item, null);
    TextView tv = (TextView) view.findViewById(R.id.audible_name);
    switch (type) {
    case RingtoneManager.TYPE_ALARM:
        tv.setText(R.string.alarm_label);
        break;/*from   w  w w .  jav  a2s  . c  o m*/
    case RingtoneManager.TYPE_NOTIFICATION:
        tv.setText(R.string.notification_label);
        break;
    case RingtoneManager.TYPE_RINGTONE:
        tv.setText(R.string.ringtone_label);
        break;
    }
    ImageView iv = (ImageView) view.findViewById(R.id.btn_play_pause);
    iv.setTag(mp);
    iv.setOnClickListener(mPlayPauseClickListener);
    mContent.addView(view, ITEM_LAYOUT_PARAMS);
}