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.nttec.everychan.cache.BitmapCache.java

/**
 *   ?  ?  ImageView.<br>/*from  w  w w .  j av  a2s. c  o m*/
 * ? ImageView ??? ?:<ul>
 * <li>? ? ? ,  ?  (? ??,   )</li>
 * <li> {@link Boolean#TRUE},    ?</li>
 * <li> {@link Boolean#FALSE},      ( ?   downloadFromInternet == false)</li></ul>
 * @param hash ? ( ? )
 * @param url ? URL (?  ?)
 * @param maxSize ?   ??,     ,  0, ? ?? ?  ?
 * @param chan   ? ??   
 * @param zipFile - - ?  ? ?  (  null)
 * @param task ?? 
 * @param imageView  {@link ImageView},    
 * @param executor ? ?
 * @param handler Handler UI 
 * @param downloadFromInternet     
 * @param defaultResId ID ?? ?  , ?    ( ?  downloadFromInternet == false),
 *  0 - ?    
 */
public void asyncGet(String hash, String url, int maxSize, ChanModule chan, ReadableContainer zipFile,
        CancellableTask task, ImageView imageView, Executor executor, Handler handler,
        boolean downloadFromInternet, int defaultResId) {
    if (hash == null) {
        Logger.e(TAG, "received null hash for url: " + url);
        imageView.setTag(Boolean.FALSE);
        imageView.setImageResource(defaultResId);
        return;
    }
    Bitmap fromLru = getFromMemory(hash);
    if (fromLru != null) {
        imageView.setTag(Boolean.TRUE);
        imageView.setImageBitmap(fromLru);
        return;
    } else {
        imageView.setImageBitmap(EMPTY_BMP);
    }
    class ImageDownloader implements Runnable {
        private final String hash;
        private final String url;
        private final int maxSize;
        private final ChanModule chan;
        private final ReadableContainer zipFile;
        private final CancellableTask task;
        private final ImageView imageView;
        private final Handler handler;
        private final boolean downloadFromInternet;
        private final int defaultResId;

        public ImageDownloader(String hash, String url, int maxSize, ChanModule chan, ReadableContainer zipFile,
                CancellableTask task, ImageView imageView, Handler handler, boolean downloadFromInternet,
                int defaultResId) {
            this.hash = hash;
            this.url = url;
            this.maxSize = maxSize;
            this.chan = chan;
            this.zipFile = zipFile;
            this.task = task;
            this.imageView = imageView;
            this.handler = handler;
            this.downloadFromInternet = downloadFromInternet;
            this.defaultResId = defaultResId;
        }

        private Bitmap bmp;

        @Override
        public void run() {
            bmp = getFromCache(hash);
            if (bmp == null && zipFile != null)
                bmp = getFromContainer(hash, zipFile);
            if (bmp == null && downloadFromInternet) {
                bmp = download(hash, url, maxSize, chan, task);
            }
            if (task != null && task.isCancelled())
                return;
            if (imageView.getTag() == null || !imageView.getTag().equals(hash))
                return;
            if (bmp == null) {
                if (defaultResId == 0) {
                    imageView.setTag(Boolean.FALSE);
                    return;
                }
            }
            handler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (imageView.getTag() == null || !imageView.getTag().equals(hash))
                            return;
                        if (bmp != null) {
                            imageView.setTag(Boolean.TRUE);
                            imageView.setImageBitmap(bmp);
                        } else {
                            imageView.setTag(Boolean.FALSE);
                            imageView.setImageResource(defaultResId);
                        }
                    } catch (OutOfMemoryError oom) {
                        MainApplication.freeMemory();
                        Logger.e(TAG, oom);
                    }
                }
            });
        }
    }
    if (task != null && task.isCancelled())
        return;
    imageView.setTag(hash);
    executor.execute(new ImageDownloader(hash, url, maxSize, chan, zipFile, task, imageView, handler,
            downloadFromInternet, defaultResId));
}

From source file:com.cleverua.test.thumbs.ImageDownloader.java

/**
 * Same as download but the image is always downloaded and the cache is not used.
 * Kept private at the moment as its interest is not clear.
 *///from   ww w .jav  a 2  s  . c o  m
private void forceDownload(String url, ImageView imageView, Drawable placeHolder) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (removePotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(url, imageView);
        imageView.setImageDrawable(placeHolder);
        imageView.setTag(new WeakReference<BitmapDownloaderTask>(task));

        imageView.setMinimumHeight(156);

        pendingTasks.offerLast(task);
        if (loaderTask == null || loaderTask.getStatus() == AsyncTask.Status.FINISHED) {
            loaderTask = pendingTasks.poll();
            loaderTask.execute();
        }
    }
}

From source file:widgets.QuizWidget.java

public void showQuestion() {
    QuizQuestion q = null;//ww  w  .j  a  v  a2 s . co  m
    try {
        q = this.quiz.getCurrentQuestion();
    } catch (InvalidQuizException e) {
        Toast.makeText(super.getActivity(), super.getActivity().getString(R.string.error_quiz_no_questions),
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
        return;
    }
    qText.setVisibility(View.VISIBLE);
    // convert in case has any html special chars
    qText.setText(Html.fromHtml(q.getTitle()).toString());

    if (q.getProp("image") == null) {
        questionImage.setVisibility(View.GONE);
    } else {
        String fileUrl = course.getLocation() + q.getProp("image");
        // File file = new File(fileUrl);
        Bitmap myBitmap = BitmapFactory.decodeFile(fileUrl);
        File file = new File(fileUrl);
        ImageView iv = (ImageView) getView().findViewById(R.id.question_image_image);
        iv.setImageBitmap(myBitmap);
        iv.setTag(file);
        OnImageClickListener oicl = new OnImageClickListener(super.getActivity(), "image/*");
        iv.setOnClickListener(oicl);
        questionImage.setVisibility(View.VISIBLE);
    }

    if (q instanceof MultiChoice) {
        qw = new MultiChoiceWidget(super.getActivity(), getView(), container);
    } else if (q instanceof MultiSelect) {
        qw = new MultiSelectWidget(super.getActivity(), getView(), container);
    } else if (q instanceof ShortAnswer) {
        qw = new ShortAnswerWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Matching) {
        qw = new MatchingWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Numerical) {
        qw = new NumericalWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Description) {
        qw = new DescriptionWidget(super.getActivity(), getView(), container);
    } else {
        Log.d(TAG, "Class for question type not found");
        return;
    }
    qw.setQuestionResponses(q.getResponseOptions(), q.getUserResponses());
    this.setProgress();
    this.setNav();
}

From source file:im.neon.util.VectorUtils.java

/**
 * Set the default vector avatar for a member.
 *
 * @param imageView   the imageView to set.
 * @param userId      the member userId.
 * @param displayName the member display name.
 *///from   w w w  .j av a 2 s. com
private static void setDefaultMemberAvatar(final ImageView imageView, final String userId,
        final String displayName) {
    // sanity checks
    if (null != imageView && !TextUtils.isEmpty(userId)) {
        final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId),
                TextUtils.isEmpty(displayName) ? userId : displayName, true);

        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            imageView.setImageBitmap(bitmap);
        } else {
            final String tag = userId + " - " + displayName;
            imageView.setTag(tag);

            mUIHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (TextUtils.equals(tag, (String) imageView.getTag())) {
                        imageView.setImageBitmap(bitmap);
                    }
                }
            });
        }
    }
}

From source file:org.montanafoodhub.app.utils.ImageCache.java

public void loadImage(ImageView imageView, String url, int defaultId) {

    // The imageView may be being recycled. If there is already a loader associated with this imageView then cancel it.
    AsyncImageLoader asyncLoader = getAsyncLoader(imageView);
    if (asyncLoader != null) {
        asyncLoader.cancel(true);//from  w w w  . j  a v  a  2 s  .com
    }

    // if the image is already in the cache load it, otherwise go get it.
    Bitmap bm = getImageFromCache(url);
    if (bm != null) {
        imageView.setImageBitmap(bm);
    } else {
        imageView.setImageBitmap(null);
        asyncLoader = new AsyncImageLoader(imageView, defaultId, this);
        imageView.setTag(asyncLoader);
        asyncLoader.execute(url);
    }
}

From source file:com.yojiokisoft.yumekanow.activity.MakeCardActivity.java

/**
 * ???// w  w  w . ja va 2  s.c om
 * 
 * @param list
 */
private void setBackImageList(List<BackImageEntity> list) {
    int cnt = mBackImgContainer.getChildCount();
    if (cnt > 0) {
        mBackImgContainer.removeAllViews();
    }
    int w = MyResource.dip2Px(53);
    int h = MyResource.dip2Px(80);
    int p = MyResource.dip2Px(3);
    int size = list.size();
    for (int i = 0; i < size; i++) {
        ImageView image = new ImageView(this);
        MyImage.setImageThum(image, list.get(i));
        image.setLayoutParams(new LinearLayout.LayoutParams(w, h));
        image.setPadding(p, p, p, p);
        image.setTag(i);
        image.setOnClickListener(mBackImageClicked);
        mBackImgContainer.addView(image);
    }
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void populateKeyboardRow(KeyboardRow keyboardRow, int keyHeight) {
    Context context = getContext();
    LinearLayout keyContainer = new LinearLayout(context);
    keyContainer.setOrientation(HORIZONTAL);
    keyContainer.setGravity(Gravity.CENTER);

    List<KeyboardKey> keyList = keyboardRow.getKeyList();
    if (keyList != null) {
        for (int i = 0; i < keyList.size(); i++) {
            KeyboardKey keyboardKey = keyList.get(i);
            if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_NORMAL) {
                TextView key = new TextView(context);
                key.setGravity(Gravity.CENTER);
                key.setTypeface(mCharTypeface, Typeface.BOLD);
                key.setText(keyboardKey.getCharCode());
                key.setTextSize(16f);//from w  ww .j av  a  2 s.  c  o m
                key.setTextColor(
                        ContextCompat.getColorStateList(context, R.color.amharic_key_text_color_selector));
                key.setTag(keyboardKey);
                key.setIncludeFontPadding(false);
                keyContainer.setBaselineAligned(false);
                handleChild(key, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            } else if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_BACKSPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_SPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_NEW_LINE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_ENTER
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_HIDE_KEYBOARD) {
                ImageView child = new ImageView(context);
                child.setImageResource(keyboardKey.getCommandImage());
                int padding = getCustomSize(6);
                child.setPadding(padding, padding, padding, padding);
                child.setTag(keyboardKey);
                handleChild(child, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            }
        }
    }
    addView(keyContainer, new LayoutParams(LayoutParams.MATCH_PARENT, keyHeight));
}

From source file:baasi.hackathon.sja.TalkActivity.java

/**
 * ???? ? ?//w w w . j  a  va 2 s .  c o m
 * @param resId
 */
private void addToContainer(int resId) {

    if (containerLayout != null && containerLayout.getChildCount() <= 4) {

        ImageView image = new ImageView(getBaseContext());
        image.setImageResource(resId);
        LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(170, 170);

        image.setLayoutParams(parms);
        image.setScaleType(ImageView.ScaleType.CENTER_CROP);

        PlayAnim(image, this, R.anim.slide_right_in, 0);

        image.setTag(resId);
        containerLayout.addView(image);

    }
}

From source file:cn.edu.szjm.support.images.remote.RemoteImageLoader.java

/**
 * Triggers the image loader for the given image and view. The image loading will be performed
 * concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be
 * posted back to the given ImageView upon completion. While waiting, the dummyDrawable is
 * shown.//from  w w w.j a v a 2 s.co m
 * 
 * @param imageUrl
 *            the URL of the image to download
 * @param imageView
 *            the ImageView which should be updated with the new image
 * @param dummyDrawable
 *            the Drawable to be shown while the image is being downloaded.
 * @param handler
 *            the handler that will process the bitmap after completion
 */
public void loadImage(String imageUrl, ImageView imageView, Drawable dummyDrawable,
        RemoteImageLoaderHandler handler) {
    this.imageUrl = imageUrl;
    this.handler = handler;
    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);
            if (dummyDrawable != null) {
                imageView.setImageDrawable(dummyDrawable);
            }
            return;
        }
        String oldImageUrl = (String) imageView.getTag();
        if (imageUrl.equals(oldImageUrl)) {
            // nothing to do
            return;
        } else {
            if (dummyDrawable != null) {
                // Set the dummy image while waiting for the actual image to be downloaded.
                imageView.setImageDrawable(dummyDrawable);
            }
            imageView.setTag(imageUrl);
        }
    }

    ImageCache cache = SharedImageCache.getSharedImageCache();
    if (usingCache) {
        if (cache != null && cache.containsKeyInMemory(imageUrl)) {
            // do not go through message passing, handle directly instead
            handler.handleImageLoaded(cache.getBitmap(imageUrl), null);
            return;
        }
    }
    task.execute();
}

From source file:com.gh4a.fragment.PullRequestFragment.java

private void fillData() {
    ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar);
    AvatarHandler.assignAvatar(ivGravatar, mPullRequest.getUser());
    ivGravatar.setTag(mPullRequest.getUser());
    ivGravatar.setOnClickListener(this);

    TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra);
    tvExtra.setText(mPullRequest.getUser().getLogin());

    TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp);
    tvTimestamp.setText(StringUtils.formatRelativeTime(getActivity(), mPullRequest.getCreatedAt(), true));

    String body = mPullRequest.getBodyHtml();
    TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc);
    descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
    if (!StringUtils.isBlank(body)) {
        body = HtmlUtils.format(body).toString();
        mImageGetter.bind(descriptionView, body, mPullRequest.getId());
    }//from  w ww .  ja  va  2 s  .c o  m

    View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container);
    if (mPullRequest.getMilestone() != null) {
        TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone);
        tvMilestone.setText(mPullRequest.getMilestone().getTitle());
        milestoneGroup.setVisibility(View.VISIBLE);
    } else {
        milestoneGroup.setVisibility(View.GONE);
    }

    View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container);
    if (mPullRequest.getAssignee() != null) {
        TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee);
        tvAssignee.setText(mPullRequest.getAssignee().getLogin());

        ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee);
        AvatarHandler.assignAvatar(ivAssignee, mPullRequest.getAssignee());
        ivAssignee.setTag(mPullRequest.getAssignee());
        ivAssignee.setOnClickListener(this);
        assigneeGroup.setVisibility(View.VISIBLE);
    } else {
        assigneeGroup.setVisibility(View.GONE);
    }

    if (mPullRequest.isMerged()) {
        setHighlightColors(R.attr.colorPullRequestMerged, R.attr.colorPullRequestMergedDark);
    } else if (Constants.Issue.STATE_CLOSED.equals(mPullRequest.getState())) {
        setHighlightColors(R.attr.colorIssueClosed, R.attr.colorIssueClosedDark);
    } else {
        setHighlightColors(R.attr.colorIssueOpen, R.attr.colorIssueOpenDark);
    }
}