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.google.samples.apps.iosched.util.LPreviewUtilsBase.java

public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate) {
    final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked
            : R.drawable.add_schedule_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  v  a2  s .  c  o m*/
            imageView.setAlpha(1f);
        }
    }

    if (allowAnimate && isCheck) {
        int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        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 {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * This method is used in MovieDetails, CastDetails and TVDetails.
 * We set url tag on the imageView. So when we tap later on it we known which url to load.
 * runOnUiThread() is called because we can't update it from async task.
 *
 * @param img the ImageView we display image on.
 * @param url the url to set tag./*  ww w.j ava2  s .  c o m*/
 *            R.string.imageSize defines the size of our images.
 */
public void setImageTag(final ImageView img, final String url) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            img.setTag(url);
        }
    });
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();//  ww w .  j a  v  a 2 s .  c  o m
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        inAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        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 {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addFinalImages() {
    addNextImages(1);//  w  ww  .  j a va  2s .  co  m
    addNextImages(1);

    // Add presents
    addFinalPresentRun();

    // Add final screen.  This is a two screen background.
    ImageView iv = new ImageView(this);
    iv.setTag(true);
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bg_finish);
    if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) {
        Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false);
        if (bmp != tmp) {
            bmp.recycle();
        }
        bmp = tmp;
    }
    iv.setImageBitmap(bmp);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    mBackgroundLayout.addView(iv, lp);
    View view = new View(this);
    lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10);
    mForegroundLayout.addView(view, lp);
    addNextObstacleSpacer(2);
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addNextTransitionImages(int level) {
    mTransitionImagesCount = 0;/*from w  ww .  j  a va 2s  .  co  m*/
    if ((level > 0) && ((level - 1) < EXIT_TRANSITIONS.length)) {
        if (EXIT_TRANSITIONS[level - 1] != -1) {
            // Add the exit transition image
            ImageView iv = new ImageView(this);
            iv.setTag(new Pair<Integer, Integer>(1, (level - 1)));
            // This is being background loaded.  Should already be loaded, but if not, wait.
            while (mExitTransitions[level - 1] == null) {
                synchronized (mExitTransitions) {
                    if (mExitTransitions[level - 1] == null) {
                        try {
                            mExitTransitions.wait();
                        } catch (InterruptedException e) {
                            continue;
                        }
                    }
                }
            }
            iv.setImageBitmap(mExitTransitions[level - 1]);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            mBackgroundLayout.addView(iv, lp);

            // No foreground on transistions.  Transition images are a single screen long
            View view = new View(this);
            lp = new LinearLayout.LayoutParams(mScreenWidth, 10);
            mForegroundLayout.addView(view, lp);
            mTransitionImagesCount++;
        }
    }
    if ((level > 0) && (level < ENTRY_TRANSITIONS.length)) {
        if (ENTRY_TRANSITIONS[level] != -1) {
            // Add the exit transition image
            ImageView iv = new ImageView(this);
            iv.setTag(new Pair<Integer, Integer>(2, level));
            // This is being background loaded.  Should already be loaded, but if not, wait.
            while (mEntryTransitions[level] == null) {
                synchronized (mEntryTransitions) {
                    if (mEntryTransitions[level] == null) {
                        try {
                            mEntryTransitions.wait();
                        } catch (InterruptedException e) {
                            continue;
                        }
                    }
                }
            }
            iv.setImageBitmap(mEntryTransitions[level]);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            mBackgroundLayout.addView(iv, lp);
            // No foreground on transistions.  Transition images are a single screen long
            View view = new View(this);
            lp = new LinearLayout.LayoutParams(mScreenWidth, 10);
            mForegroundLayout.addView(view, lp);
            mTransitionImagesCount++;
        }
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*from   w  ww  . j a  va 2s . c  o m*/
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        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 {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

protected void loadScreenSizedImageInBackground(ImageView imageView, String imagePath,
        boolean forceReloadSameImage, boolean fadeIn) {
    // forceReloadSameImage is for, e.g., reloading image after rotation (normally this extra load would be ignored)
    if (cancelExistingTask(imagePath, imageView, forceReloadSameImage)) {
        final BitmapLoaderTask task = new BitmapLoaderTask(imageView, fadeIn);
        final BitmapLoaderHolder loaderTaskHolder = new BitmapLoaderHolder(task);
        imageView.setTag(loaderTaskHolder);
        task.execute(imagePath);//w ww.j a v a 2  s . co  m
    }
}

From source file:com.hybris.mobile.lib.commerce.service.OCCServiceHelper.java

@Override
public boolean loadImage(String url, String requestId, ImageView imageView, int width, int height,
        boolean shouldUseCache, OnRequestListener onRequestListener, boolean forceImageTagToMatchRequestId) {

    if (StringUtils.isBlank(url) || imageView == null) {
        throw new IllegalArgumentException(
                "The url and/or imageView parameter(s) is/are missing from the query");
    }//from w  w w .ja  v  a 2  s . co  m

    // We set the image tag if we want the request id to match the tag before loading the image within the image view
    if (forceImageTagToMatchRequestId) {
        imageView.setTag(requestId);
    }

    return mPersistenceHelper.setImageFromUrl(UrlHelper.getImageUrl(mConfiguration, url), requestId, imageView,
            width, height, CONFIG_IMAGES_QUALITY, shouldUseCache, onRequestListener,
            forceImageTagToMatchRequestId);
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addNextImages(int level, boolean recycle) {
    if (level < BACKGROUNDS.length) {
        // Add the background image
        ImageView iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        // This is being background loaded.  Should already be loaded, but if not, wait.
        while (mBackgrounds[level] == null) {
            synchronized (mBackgrounds) {
                if (mBackgrounds[level] == null) {
                    try {
                        mBackgrounds.wait();
                    } catch (InterruptedException e) {
                    }/*from w  w  w.  j  a va 2 s  .c o m*/
                }
            }
        }
        iv.setImageBitmap(mBackgrounds[level]);
        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        mBackgroundLayout.addView(iv, lp);
        iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        iv.setImageBitmap(mBackgrounds2[level]);
        mBackgroundLayout.addView(iv, lp);

        // Add the foreground image
        if (FOREGROUNDS[level] == -1) {
            View view = new View(this);
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10);
            mForegroundLayout.addView(view, lp);
        } else {
            iv = new ImageView(this);
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            if (recycle) {
                iv.setTag(level);
            }
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT);
            mForegroundLayout.addView(iv, lp);
            iv = new ImageView(this);
            if (recycle) {
                iv.setTag(level);
            }
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            mForegroundLayout.addView(iv, lp);
        }
    }
}

From source file:com.mdlive.sav.MDLiveProviderDetails.java

/**
 *  Successful Response Handler for getting the Affillitations and the provider image.
 *  This method will give the successful response of the Provider's affilitations.
 *  This response is for the Affilations Purpose.The image can be placed one below the other
 *
 */// www  .j a  v a2 s.  co m
private void getProviderImageArrayResponse(JsonObject providerdetObj) {
    JsonArray ProviderImageArray = providerdetObj.get("provider_groups").getAsJsonArray();
    if (ProviderImageArray.size() != 0) {
        providerImageCollectionHolder.removeAllViews();
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                100);
        params.setMargins(5, 10, 5, 10);
        for (int i = 0; i < ProviderImageArray.size(); i++) {
            try {
                if (!ProviderImageArray.get(i).getAsJsonObject().get("logo").isJsonNull()) {
                    final ImageView imageView = new ImageView(MDLiveProviderDetails.this);
                    //imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    imageView.setLayoutParams(params);
                    ImageRequest request = new ImageRequest(
                            ProviderImageArray.get(i).getAsJsonObject().get("logo").getAsString(),
                            new Response.Listener<Bitmap>() {
                                @Override
                                public void onResponse(Bitmap bitmap) {
                                    imageView.setImageBitmap(bitmap);
                                }
                            }, 0, 0, null, new Response.ErrorListener() {
                                public void onErrorResponse(VolleyError error) {
                                }
                            });
                    ApplicationController.getInstance().getRequestQueue(this).add(request);
                    imageView.setTag(ProviderImageArray.get(i).getAsJsonObject().get("url").getAsString());
                    imageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(MDLiveProviderDetails.this,
                                    MDLiveProviderGroupDetailsAffiliations.class);
                            intent.putExtra("affurl",
                                    (imageView.getTag() != null) ? imageView.getTag().toString() : "");
                            startActivity(intent);
                            MdliveUtils.startActivityAnimation(MDLiveProviderDetails.this);
                        }
                    });
                    providerImageCollectionHolder.addView(imageView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        if (!isCignaCoachUser)
            findViewById(R.id.providerGroupAffiliation).setVisibility(View.GONE);
    }
}