Example usage for android.widget ImageView getTag

List of usage examples for android.widget ImageView getTag

Introduction

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

Prototype

@ViewDebug.ExportedProperty
public Object getTag() 

Source Link

Document

Returns this view's tag.

Usage

From source file:com.android.calendar.event.EventLocationAdapter.java

private void asyncLoadPhotoAndUpdateView(final Uri contactPhotoUri, final ImageView imageView) {
    AsyncTask<Void, Void, Bitmap> photoUpdaterTask = new AsyncTask<Void, Void, Bitmap>() {
        @Override//from w  ww .  ja  va 2s  .c  om
        protected Bitmap doInBackground(Void... params) {
            Bitmap photo = null;
            InputStream imageStream = Contacts.openContactPhotoInputStream(mResolver, contactPhotoUri);
            if (imageStream != null) {
                photo = BitmapFactory.decodeStream(imageStream);
                mPhotoCache.put(contactPhotoUri, photo);
            }
            return photo;
        }

        @Override
        public void onPostExecute(Bitmap photo) {
            // The View may have already been reused (because using 'convertView' above), so
            // we must check the URI is as expected before setting the icon, or we may be
            // setting the icon in other items.
            if (photo != null && imageView.getTag() == contactPhotoUri) {
                imageView.setImageBitmap(photo);
            }
        }
    }.execute();
}

From source file:m2.android.archetype.example.FacebookSdk.widget.GraphObjectAdapter.java

private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) {
    pendingRequests.remove(graphObjectId);
    if (imageView == null) {
        // This was a pre-fetch request.
        if (response.getBitmap() != null) {
            // Is the cache too big?
            if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) {
                // Find the oldest one and remove it.
                String oldestId = prefetchedProfilePictureIds.remove(0);
                prefetchedPictureCache.remove(oldestId);
            }//from  w w w  .  jav a  2  s. co  m
            prefetchedPictureCache.put(graphObjectId, response);
        }
    } else if (imageView != null && graphObjectId.equals(imageView.getTag())) {
        Exception error = response.getError();
        Bitmap bitmap = response.getBitmap();
        if (error == null && bitmap != null) {
            imageView.setImageBitmap(bitmap);
            imageView.setTag(response.getRequest().getImageUrl());
        }
    }
}

From source file:dynamite.zafroshops.app.MainActivity.java

public void setRating(View view) {
    ImageView self = (ImageView) view;
    final View main = (View) self.getParent();
    ArrayList<ImageView> imageViews = new ArrayList<ImageView>() {
        {/*w w  w  .  j  a v a  2s  .c  o m*/
            add((ImageView) main.findViewById(R.id.star_1));
            add((ImageView) main.findViewById(R.id.star_2));
            add((ImageView) main.findViewById(R.id.star_3));
            add((ImageView) main.findViewById(R.id.star_4));
            add((ImageView) main.findViewById(R.id.star_5));
        }
    };
    int score = Integer.parseInt((String) self.getTag());

    score = ReviewDialogFragment.rating == score ? 0 : score;
    ReviewDialogFragment.rating = score;
    for (int i = 0; i < imageViews.size(); i++) {
        imageViews.get(i).setImageResource(R.drawable.stare);
    }
    ReviewDialogFragment.rating = score;
    for (int i = 0; i < score; i++) {
        imageViews.get(i).setImageResource(R.drawable.star);
    }
}

From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java

private void setOrAnimateReadPubIcon(final ImageView imageView, PublicationState currentState,
        boolean allowAnimate) {
    final int imageResId = currentState.equals(PublicationState.READY_FOR_READING)
            ? R.drawable.read_pub_button_icon_checked
            : currentState.equals(PublicationState.DOWNLOADING) ? R.drawable.download_pub_icon_fab_up
                    : R.drawable.read_pub_button_icon_unchecked;

    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();//from  w w  w. j  a va2s . c o  m
            ViewHelper.setAlpha(imageView, 1f);
        }
    }
    /*
    if (imageView.getBackground() instanceof AnimationDrawable) {
    AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
    frameAnimation.stop();
    imageView.setBackgroundResource(0);
    }*/

    if (allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
        Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f);
        outAnimator.setDuration(duration);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageDrawable(null);
                imageView.setBackgroundResource(imageResId);
                Drawable frameAnimation = imageView.getBackground();
                if (frameAnimation instanceof AnimationDrawable) {
                    ((AnimationDrawable) frameAnimation).start();
                }
            }
        });

        ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f);
        inAnimator.setDuration(duration * 2);
        final AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();

    } else if (allowAnimate && currentState.equals(PublicationState.READY_FOR_READING)) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
        Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f);
        outAnimator.setDuration(duration);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setBackgroundResource(0);
                imageView.setImageResource(imageResId);
            }
        });
        ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f);
        inAnimator.setDuration(duration * 2);
        final AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else if (!allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageDrawable(null);
                imageView.setBackgroundResource(imageResId);
                AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
                frameAnimation.start();
            }
        });
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setBackgroundResource(0);
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java

private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) {
    pendingRequests.remove(graphObjectId);
    if (response.getError() != null) {
        callOnErrorListener(response.getError());
    }/*from ww w.  j av a 2s  . c  o m*/

    if (imageView == null) {
        // This was a pre-fetch request.
        if (response.getBitmap() != null) {
            // Is the cache too big?
            if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) {
                // Find the oldest one and remove it.
                String oldestId = prefetchedProfilePictureIds.remove(0);
                prefetchedPictureCache.remove(oldestId);
            }
            prefetchedPictureCache.put(graphObjectId, response);
        }
    } else if (graphObjectId.equals(imageView.getTag())) {
        Exception error = response.getError();
        Bitmap bitmap = response.getBitmap();
        if (error == null && bitmap != null) {
            imageView.setImageBitmap(bitmap);
            imageView.setTag(response.getRequest().getImageUri());
        }
    }
}

From source file:com.trk.aboutme.facebook.widget.GraphObjectAdapter.java

private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) {
    pendingRequests.remove(graphObjectId);
    if (response.getError() != null) {
        callOnErrorListener(response.getError());
    }/*w  w  w  .j a v a2s  .  c  om*/

    if (imageView == null) {
        // This was a pre-fetch request.
        if (response.getBitmap() != null) {
            // Is the cache too big?
            if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) {
                // Find the oldest one and remove it.
                String oldestId = prefetchedProfilePictureIds.remove(0);
                prefetchedPictureCache.remove(oldestId);
            }
            prefetchedPictureCache.put(graphObjectId, response);
        }
    } else if (imageView != null && graphObjectId.equals(imageView.getTag())) {
        Exception error = response.getError();
        Bitmap bitmap = response.getBitmap();
        if (error == null && bitmap != null) {
            imageView.setImageBitmap(bitmap);
            imageView.setTag(response.getRequest().getImageUrl());
        }
    }
}

From source file:com.umeng.comm.ui.imagepicker.adapters.ImagePagerAdapter.java

/**
 * ,ImageItem?,originImage?true.//from w w w .ja v  a2s .c  o  m
 * 
 * @param imageView ImageView
 * @param progressBar ?
 * @param image ImageItem
 * @param originImage ?
 */
private void displayImage(ImageView imageView, final ProgressBar progressBar, final ImageItem image,
        boolean originImage) {
    String imageUrl = originImage ? image.originImageUrl : image.middleImageUrl;
    // URLMD5,
    storeImageItemMd5(imageUrl);
    // 
    Bitmap bitmap = LocalImageLoader.getInstance().loadBitmap(imageUrl, getSize(imageView));
    ImgDisplayOption option = null;
    if (bitmap == null) {
        option = ImgDisplayOption.getCommonDisplayOption();
    } else {
        imageView.setImageBitmap(bitmap);
        option = new ImgDisplayOption();
    }
    // ?
    option.requestOrigin = true;
    mImageLoader.displayImage(imageUrl, imageView, option, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String imageUri, View view) {
            // Dialog
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view) {

        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            // Dialog
            progressBar.setVisibility(View.GONE);
            if (view == null) {
                return;
            }

            ScaleImageView imageView = (ScaleImageView) view;
            if (isUriEqualsWithImageViewTag(imageView.getTag(), imageUri) && loadedImage != null) {
                imageView.setImageBitmap(loadedImage);
                imageView.updateScale();
            }
        }
    });
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

public void refreshActionBarColumns() {

    int currentPosition = pager.getCurrentItem();

    layoutBackgroundColumnsBar.removeAllViews();

    int padding = (int) getResources().getDimension(R.dimen.default_padding);
    //int sizeButton = (int) getResources().getDimension(R.dimen.actionbar_columns_height);

    for (int i = 1; i < fragmentAdapter.getFragmentList().size(); i++) {

        ImageView view = new ImageView(this);
        view.setPadding(padding, padding, padding, padding);
        view.setImageBitmap(ColumnsUtils.getButtonWithTitle(this, fragmentAdapter.getFragmentList().get(i),
                true, currentPosition == i ? Color.GREEN : Color.BLACK));
        view.setTag(i);// ww  w  .  ja  v  a 2  s .  c  om
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (layoutMainOptionsColumns.getVisibility() != View.VISIBLE) {
                    showActionBarIndicatorAndMovePager((Integer) view.getTag());
                }
            }
        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                int pos = (Integer) view.getTag();
                int[] loc = new int[2];
                view.getLocationOnScreen(loc);
                showOptionsColumns(loc[0], pos, true);
                return false;
            }
        });
        layoutBackgroundColumnsBar.addView(view);
    }
}

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

/**
 * Set the user avatar in an imageView./*ww w. java 2s.  co m*/
 *
 * @param context     the context
 * @param session     the session
 * @param imageView   the image view
 * @param avatarUrl   the avatar url
 * @param userId      the user id
 * @param displayName the user display name
 */
public static void loadUserAvatar(final Context context, final MXSession session, final ImageView imageView,
        final String avatarUrl, final String userId, final String displayName) {
    // sanity check
    if ((null == session) || (null == imageView) || !session.isAlive()) {
        return;
    }

    // reset the imageView tag
    imageView.setTag(null);

    if (session.getMediasCache().isAvatarThumbnailCached(avatarUrl,
            context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) {
        session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView, avatarUrl,
                context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size));
    } else {
        if (null == mImagesThread) {
            mImagesThread = new HandlerThread("ImagesThread", Thread.MIN_PRIORITY);
            mImagesThread.start();
            mImagesThreadHandler = new android.os.Handler(mImagesThread.getLooper());
            mUIHandler = new Handler(Looper.getMainLooper());
        }

        final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId),
                TextUtils.isEmpty(displayName) ? userId : displayName, false);

        // test if the default avatar has been computed
        if (null != bitmap) {
            imageView.setImageBitmap(bitmap);

            final String tag = avatarUrl + userId + displayName;
            imageView.setTag(tag);

            if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                mImagesThreadHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (TextUtils.equals(tag, (String) imageView.getTag())) {
                            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(),
                                    imageView, avatarUrl,
                                    context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size),
                                    bitmap);
                        }
                    }
                });
            }
        } else {
            final String tmpTag0 = "00" + avatarUrl + "-" + userId + "--" + displayName;
            imageView.setTag(tmpTag0);

            // create the default avatar in the background thread
            mImagesThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (TextUtils.equals(tmpTag0, (String) imageView.getTag())) {
                        imageView.setTag(null);
                        setDefaultMemberAvatar(imageView, userId, displayName);

                        if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                            final String tmpTag1 = "11" + avatarUrl + "-" + userId + "--" + displayName;
                            imageView.setTag(tmpTag1);

                            // wait that it is rendered to load the right one
                            mUIHandler.post(new Runnable() {
                                @Override
                                public void run() {
                                    // test if the imageView tag has not been updated
                                    if (TextUtils.equals(tmpTag1, (String) imageView.getTag())) {
                                        final String tmptag2 = "22" + avatarUrl + userId + displayName;
                                        imageView.setTag(tmptag2);

                                        mImagesThreadHandler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                // test if the imageView tag has not been updated
                                                if (TextUtils.equals(tmptag2, (String) imageView.getTag())) {
                                                    final Bitmap bitmap = VectorUtils.getAvatar(
                                                            imageView.getContext(),
                                                            VectorUtils.getAvatarColor(userId),
                                                            TextUtils.isEmpty(displayName) ? userId
                                                                    : displayName,
                                                            false);
                                                    session.getMediasCache().loadAvatarThumbnail(
                                                            session.getHomeserverConfig(), imageView, avatarUrl,
                                                            context.getResources().getDimensionPixelSize(
                                                                    R.dimen.profile_avatar_size),
                                                            bitmap);
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    }
}

From source file:org.egov.android.view.activity.CreateComplaintActivity.java

/**
 * Function used to show the image added to complaint in image view. A close icon is shown at
 * the top right corner of the image to delete it
 * /* w w  w.  ja  va 2  s.c o m*/
 * @param imagePath
 */
@SuppressLint("InflateParams")
private void _addImageView(String imagePath) {
    final ImageView image_container = (ImageView) findViewById(R.id.image_container);
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_photo, null);

    RelativeLayout inner_container = (RelativeLayout) view.findViewById(R.id.inner_container);
    LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(100),
            _dpToPix(100));

    inner_container.setLayoutParams(inner_container_params);

    ImageView image = (ImageView) view.findViewById(R.id.image);
    image.setImageBitmap(_getBitmapImage(imagePath));
    image.setTag(imagePath);
    container.addView(inner_container);
    imageUrl.add(imagePath);

    image_container.setImageBitmap(_getBitmapImage(imagePath));

    ImageView delete_icon = (ImageView) view.findViewById(R.id.delete_photo);
    delete_icon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            file_upload_limit--;
            RelativeLayout deleteView = (RelativeLayout) v.getParent();
            ((LinearLayout) findViewById(R.id.container)).removeView(deleteView);
            ImageView image = (ImageView) deleteView.findViewById(R.id.image);
            _deleteFile(image.getTag().toString());
            _reorderFiles();
        }
    });
    inner_container.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ImageView image = (ImageView) v.findViewById(R.id.image);
            ((ImageView) findViewById(R.id.image_container))
                    .setImageBitmap(_getBitmapImage(image.getTag().toString()));
        }
    });

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hr_scroll);
            hsv.scrollTo(hsv.getWidth() + 600, 0);
        }
    }, 500);
}