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:pro.dbro.bart.TheActivity.java

public void displayEtdResponse(etdResponse etdResponse) {
    if (timer != null)
        timer.cancel(); // cancel previous timer
    long now = new Date().getTime();
    timerViews = new ArrayList(); // release old ETA text views
    maxTimer = 0; // reset maxTimer
    fareTv.setText("");
    fareTv.setVisibility(View.GONE);
    tableLayout.removeAllViews();//from w w w  .  j a v a 2s .c o  m
    String lastDestination = "";

    // Display the alert ImageView and create a click listener to display alert html
    if (etdResponse.message != null) {

        // If the response message matches the response for a closed station, 
        // Display "Closed for tonight" and time of next train, if available.
        if (etdResponse.message.contains("No data matched your criteria.")) {
            String message = "This station is closed for tonight";
            TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null);
            specialScheduleTextView.setPadding(0, 0, 0, 0);
            if (etdResponse.etds != null && etdResponse.etds.size() > 0) {
                Date nextTrain = new Date(etdResponse.date.getTime()
                        + ((etd) etdResponse.etds.get(0)).minutesToArrival * 60 * 1000);
                SimpleDateFormat sdf = new SimpleDateFormat("KK:MM a");
                message += ". Next train at " + sdf.format(nextTrain);
            }
            specialScheduleTextView.setText(message);
            tableLayout.addView(specialScheduleTextView);
        } else {
            // Create an imageview that spawns an alertDialog with BART message
            ImageView specialScheduleImageView = (ImageView) View.inflate(c, R.layout.specialschedulelayout,
                    null);
            // Tag the specialScheduleImageView with the message html
            specialScheduleImageView.setTag(Html.fromHtml(etdResponse.message));

            // Set the OnClickListener for the specialScheduleImageView to display the tagged message html
            specialScheduleImageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                    specialScheduleTv.setPadding(0, 0, 0, 0);
                    specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString()));
                    specialScheduleTv.setTextSize(16);
                    specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance());
                    new AlertDialog.Builder(c).setTitle("Station Alerts").setIcon(R.drawable.warning)
                            .setView(specialScheduleTv).setPositiveButton("Bummer", null).show();

                }

            });
            tableLayout.addView(specialScheduleImageView);
        }

    }

    TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow_right, null);
    LinearLayout destinationRow = (LinearLayout) View.inflate(c, R.layout.destination_row, null);
    //TextView timeTv =(TextView) View.inflate(c, R.layout.tabletext, null);
    int numAlt = 0;
    for (int x = 0; x < etdResponse.etds.size(); x++) {
        if (etdResponse.etds.get(x) == null)
            break;
        etd thisEtd = (etd) etdResponse.etds.get(x);
        if (thisEtd.destination != lastDestination) { // new train destination
            numAlt = 0;
            tr = (TableRow) View.inflate(c, R.layout.tablerow_right, null);
            tr.setPadding(0, 0, 10, 0);
            destinationRow = (LinearLayout) View.inflate(c, R.layout.destination_row, null);
            TextView destinationTv = (TextView) View.inflate(c, R.layout.destinationlayout, null);
            if (x == 0)
                destinationTv.setPadding(0, 0, 0, 0);
            //bullet.setWidth(200);
            //destinationTv.setPadding(0, 0, 0, 0);
            destinationTv.setTextSize(28);
            destinationTv.setText(thisEtd.destination);
            TextView timeTv = (TextView) View.inflate(c, R.layout.tabletext, null);
            // Display eta less than 1m as "<1"
            if (thisEtd.minutesToArrival == 0)
                timeTv.setText("<1");
            else
                timeTv.setText(String.valueOf(thisEtd.minutesToArrival));
            timeTv.setSingleLine(false);
            timeTv.setTextSize(36);
            //timeTv.setPadding(30, 0, 0, 0);
            long counterTime = thisEtd.minutesToArrival * 60 * 1000;
            if (counterTime > maxTimer) {
                maxTimer = counterTime;
            }
            timeTv.setTag(counterTime + now);
            timerViews.add(timeTv);
            //new ViewCountDownTimer(timeTv, counterTime, 60*1000).start();
            //text.setWidth(120);
            destinationRow.addView(destinationTv);
            //tr.addView(destinationTv);
            tr.addView(timeTv);
            tr.setTag(thisEtd);
            tableLayout.addView(destinationRow);
            tableLayout.addView(tr);
            tr.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1
                    etd thisEtd = (etd) arg0.getTag();
                    if (!thisEtd.isExpanded) { // if route not expanded
                        thisEtd.isExpanded = true;
                        LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail, null);
                        TextView platformTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                        platformTv.setPadding(0, 0, 0, 0);
                        platformTv.setText("platform " + thisEtd.platform);
                        platformTv.setTextSize(20);
                        routeDetail.addView(platformTv);
                        ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null);
                        if (!thisEtd.bikes)
                            bikeIv.setImageResource(R.drawable.no_bicycle);

                        routeDetail.addView(bikeIv);
                        tableLayout.addView(routeDetail, index + 1);
                    } else {
                        thisEtd.isExpanded = false;
                        tableLayout.removeViewAt(index + 1);
                    }

                }
            });
        } else { // append next trains arrival time to existing destination display
                 //timeTv.append(String.valueOf(", "+thisEtd.minutesToArrival));
            numAlt++;
            TextView nextTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null);
            //nextTimeTv.setTextSize(36-(5*numAlt));
            nextTimeTv.setTextSize(36);
            nextTimeTv.setText(String.valueOf(thisEtd.minutesToArrival));
            //nextTimeTv.setPadding(30, 0, 0, 0);
            if (numAlt == 1) //0xFFF06D2F  C9C7C8
                nextTimeTv.setTextColor(0xFFC9C7C8);
            else if (numAlt == 2)
                nextTimeTv.setTextColor(0xFFA8A7A7);
            long counterTime = thisEtd.minutesToArrival * 60 * 1000;
            nextTimeTv.setTag(counterTime + now);
            if (counterTime > maxTimer) {
                maxTimer = counterTime;
            }
            timerViews.add(nextTimeTv);

            //new ViewCountDownTimer(nextTimeTv, counterTime, 60*1000).start();
            tr.addView(nextTimeTv);
        }
        lastDestination = thisEtd.destination;
    } // end for
      //scrolly.scrollTo(0, 0);
      // Avoid spamming bart.gov. Only re-ping if etd response is valid for at least 3m
    if (maxTimer > 1000 * 60 * 3) {
        timer = new ViewCountDownTimer(timerViews, "etd", maxTimer, 30 * 1000);
        timer.start();
    }
}

From source file:co.taqat.call.CallActivity.java

private boolean displayCallStatusIconAndReturnCallPaused(LinearLayout callView, LinphoneCall call) {
    boolean isCallPaused, isInConference;
    ImageView callState = (ImageView) callView.findViewById(R.id.call_pause);
    callState.setTag(call);
    callState.setOnClickListener(this);

    if (call.getState() == State.Paused || call.getState() == State.PausedByRemote
            || call.getState() == State.Pausing) {
        callState.setImageResource(R.drawable.pause);
        isCallPaused = true;/*from ww  w. j a va  2s  .co m*/
        isInConference = false;
    } else if (call.getState() == State.OutgoingInit || call.getState() == State.OutgoingProgress
            || call.getState() == State.OutgoingRinging) {
        isCallPaused = false;
        isInConference = false;
    } else {
        isInConference = isConferenceRunning && call.isInConference();
        isCallPaused = false;
    }

    return isCallPaused || isInConference;
}

From source file:com.travel.ac.utils.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing
 * logic). A memory and disk cache will be used if an {@link ImageCache} has
 * been added using//from  w  w w.j  a va2s .  c o m
 * {@link ImageWorker#addImageCache(android.support.v4.app.FragmentManager, ImageCache.ImageCacheParams)}
 * . If the image is found in the memory cache, it is set immediately,
 * otherwise an {@link AsyncTask} will be created to asynchronously load the
 * bitmap.
 *
 * @param data
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void loadImage(Object data, ImageView imageView) {
    mCircleImageView = null;
    if (data == null) {
        return;
    }
    /*
     * imageView == null ? ?
     */
    if (imageView instanceof CircleImageView) {
        mCircleImageView = (CircleImageView) imageView;
    }
    BitmapDrawable value = null;
    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));

    }
    Log.e(TAG, "value: " + value);
    if (value != null) {
        if (mCircleImageView == null) {
            // Bitmap found in memory cache
            imageView.setImageDrawable(value);
        } else {
            Log.e(TAG, "***********************************getBitmapFromMemCache: ");
            ((CircleImageView) imageView).setImage(value);
        }
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView);
        mAsyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setTag(mAsyncDrawable);
        if (mCircleImageView == null) {
            imageView.setImageDrawable(mAsyncDrawable);
        } else {
            //                Log.e(TAG, "loadImage: ");
            ((CircleImageView) imageView).setImage(mAsyncDrawable);

        }
        // NOTE: This uses a custom version of AsyncTask that has been pulled from the
        // framework and slightly modified. Refer to the docs at the top of the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR);

    }
}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void setGif(final GalleryItemViewTag tag, final File file) {
    if (!settings.useNativeGif()) {
        setWebView(tag, file);//from w w  w  . j  a v a  2  s  .c  o m
        return;
    }
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ImageView iv = Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO
                    ? new ImageView(GalleryActivity.this)
                    : new TouchGifView(GalleryActivity.this);
            try {
                GifDrawable drawable = new GifDrawable(file);
                iv.setTag(drawable);
                iv.setImageDrawable(drawable);
            } catch (Throwable e) {
                System.gc();
                Logger.e(TAG, "cannot init GifDrawable", e);
                if (tag.downloadingTask.isCancelled())
                    return;
                setWebView(tag, file);
                return;
            }

            if (tag.downloadingTask.isCancelled())
                return;

            tag.thumbnailView.setVisibility(View.GONE);
            tag.loadingView.setVisibility(View.GONE);

            tag.layout.setVisibility(View.VISIBLE);
            tag.layout.addView(iv);
        }
    });
}

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);
            }//w  w w  .  j a v 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: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   w w  w.ja  va2s .  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:uk.org.ngo.squeezer.util.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override {@link
 * ImageWorker#processBitmap(BitmapWorkerTaskParams)} to define the processing logic). A memory and disk cache
 * will be used if an {@link ImageCache} has been set using {@link
 * ImageWorker#setImageCache(ImageCache)}. If the image is found in the memory cache, it is set
 * immediately, otherwise an {@link AsyncTask} will be created to asynchronously load the
 * bitmap./*from ww  w .  ja  va  2  s .com*/
 *
 * @param data The URL of the image to download
 * @param imageView The ImageView to bind the downloaded image to
 */
public void loadImage(final Object data, final ImageView imageView) {
    if (data == null) {
        return;
    }

    int width = imageView.getWidth();
    int height = imageView.getHeight();

    // If the dimensions aren't known yet then the view hasn't been measured. Get a
    // ViewTreeObserver and listen for the PreDraw message. Using a GlobalLayoutListener
    // does not work for views that are in the list but drawn off-screen, possibly due
    // to the convertview. See http://stackoverflow.com/a/14325365 for some discussion.
    // The solution there, of posting a runnable, does not appear to reliably work on
    // devices running (at least) API 7. An OnPreDrawListener appears to work, and will
    // be called after measurement is complete.
    if (width == 0 || height == 0) {
        // Store the URL in the imageView's tag, in case the URL assigned to is changed.
        imageView.setTag(data);

        imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                imageView.getViewTreeObserver().removeOnPreDrawListener(this);
                // If the imageView is still assigned to the URL then we can load in to it.
                if (data.equals(imageView.getTag())) {
                    loadImage(data, imageView);
                }
                return true;
            }
        });
        return;
    }

    loadImage(data, imageView, width, height);
}

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());
    }//from   w  ww.  jav a2  s  .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:fr.paug.droidcon.util.LPreviewUtilsBase.java

public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate,
        int resIdChecked) {

    final int imageResId = isCheck ? resIdChecked : 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 ww  . 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:cn.com.wo.bitmap.ImageWorker.java

public void loadImageByIndex(String url, ImageView imageView, int loadingIndex, boolean isBackground) {
    //      url = Images.getUrl();
    if (url == null || url.trim().length() == 0 || !url.startsWith("http"))
        return;/*from   w ww .  j  av a2 s.  co m*/
    if (ImageFetcher.isDebug)
        Log.i(ImageFetcher.TAG, "loadImage " + url + "; isBg=" + isBackground + "; " + (imageView == null));
    //    url = "http://58.254.132.169/picture/90755000/copyright/singer/2012032806/23280.jpg";

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(url);
    }

    if (value != null) {
        // Bitmap found in memory cache
        if (ImageFetcher.isDebug)
            Log.i(ImageFetcher.TAG, "value is null ?  " + (value == null));
        if (isBackground) {
            imageView.setBackgroundDrawable(null);
            imageView.setBackgroundDrawable(value);
        } else
            imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(url, imageView, isBackground)) {
        if (ImageFetcher.isDebug)
            Log.i(ImageFetcher.TAG, "value is null ?  " + (value == null));
        imageView.setTag(loadingIndex);
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, 0, isBackground);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap[loadingIndex], task);
        //          imageView.setImageDrawable(asyncDrawable);
        if (isBackground) {
            imageView.setBackgroundDrawable(null);
            imageView.setBackgroundDrawable(asyncDrawable);
        } else
            imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been pulled from the
        // framework and slightly modified. Refer to the docs at the top of the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, url);
    }
}