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:ac.robinson.ticqr.TicQRActivity.java

private void addTickHighlight(TickBoxHolder tickBox) {
    int tickIcon = R.drawable.ic_highlight_tick;
    Drawable tickDrawable = getResources().getDrawable(tickIcon);

    ImageView tickHighlight = new ImageView(TicQRActivity.this);
    tickHighlight.setImageResource(tickIcon);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = mImageView.getLeft() + Math.round(tickBox.imagePosition.x)
            - (tickDrawable.getIntrinsicWidth() / 2);
    layoutParams.topMargin = mImageView.getTop() + Math.round(tickBox.imagePosition.y)
            - (tickDrawable.getIntrinsicHeight() / 2);

    ((RelativeLayout) findViewById(R.id.tick_highlight_holder)).addView(tickHighlight, layoutParams);
    tickHighlight.startAnimation(AnimationUtils.loadAnimation(this, R.anim.pulse));

    tickHighlight.setOnClickListener(mTickClickListener);
    tickHighlight.setTag(tickBox);
}

From source file:com.nadmm.airports.ActivityBase.java

public void showAirportTitle(Cursor c) {
    View root = findViewById(R.id.airport_title_layout);
    TextView tv = (TextView) root.findViewById(R.id.facility_name);
    String code = c.getString(c.getColumnIndex(Airports.ICAO_CODE));
    if (code == null || code.length() == 0) {
        code = c.getString(c.getColumnIndex(Airports.FAA_CODE));
    }/*w  w w  .  java 2 s . c om*/
    String tower = c.getString(c.getColumnIndex(Airports.TOWER_ON_SITE));
    int color = tower.equals("Y") ? Color.rgb(48, 96, 144) : Color.rgb(128, 72, 92);
    tv.setTextColor(color);
    String name = c.getString(c.getColumnIndex(Airports.FACILITY_NAME));
    String siteNumber = c.getString(c.getColumnIndex(Airports.SITE_NUMBER));
    String type = DataUtils.decodeLandingFaclityType(siteNumber);
    tv.setText(String.format(Locale.US, "%s %s", name, type));
    tv = (TextView) root.findViewById(R.id.facility_id);
    tv.setTextColor(color);
    tv.setText(code);
    tv = (TextView) root.findViewById(R.id.facility_info);
    String city = c.getString(c.getColumnIndex(Airports.ASSOC_CITY));
    String state = c.getString(c.getColumnIndex(States.STATE_NAME));
    if (state == null) {
        state = c.getString(c.getColumnIndex(Airports.ASSOC_COUNTY));
    }
    tv.setText(String.format(Locale.US, "%s, %s", city, state));
    tv = (TextView) root.findViewById(R.id.facility_info2);
    int distance = c.getInt(c.getColumnIndex(Airports.DISTANCE_FROM_CITY_NM));
    String dir = c.getString(c.getColumnIndex(Airports.DIRECTION_FROM_CITY));
    String status = c.getString(c.getColumnIndex(Airports.STATUS_CODE));
    tv.setText(String.format(Locale.US, "%s, %d miles %s of city center", DataUtils.decodeStatus(status),
            distance, dir));
    tv = (TextView) root.findViewById(R.id.facility_info3);
    float elev_msl = c.getFloat(c.getColumnIndex(Airports.ELEVATION_MSL));
    int tpa_agl = c.getInt(c.getColumnIndex(Airports.PATTERN_ALTITUDE_AGL));
    String est = "";
    if (tpa_agl == 0) {
        tpa_agl = 1000;
        est = " (est.)";
    }
    tv.setText(String.format(Locale.US, "%s MSL elev. - %s MSL TPA %s", FormatUtils.formatFeet(elev_msl),
            FormatUtils.formatFeet(elev_msl + tpa_agl), est));

    String s = c.getString(c.getColumnIndex(Airports.EFFECTIVE_DATE));
    GregorianCalendar endDate = new GregorianCalendar(Integer.valueOf(s.substring(6)),
            Integer.valueOf(s.substring(3, 5)), Integer.valueOf(s.substring(0, 2)));
    // Calculate end date of the 56-day cycle
    endDate.add(GregorianCalendar.DAY_OF_MONTH, 56);
    Calendar now = Calendar.getInstance();
    if (now.after(endDate)) {
        // Show the expired warning
        tv = (TextView) root.findViewById(R.id.expired_label);
        tv.setVisibility(View.VISIBLE);
    }

    CheckBox cb = (CheckBox) root.findViewById(R.id.airport_star);
    cb.setChecked(mDbManager.isFavoriteAirport(siteNumber));
    cb.setTag(siteNumber);
    cb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            CheckBox cb = (CheckBox) v;
            String siteNumber = (String) cb.getTag();
            if (cb.isChecked()) {
                mDbManager.addToFavoriteAirports(siteNumber);
                Toast.makeText(ActivityBase.this, "Added to favorites list", Toast.LENGTH_LONG).show();
            } else {
                mDbManager.removeFromFavoriteAirports(siteNumber);
                Toast.makeText(ActivityBase.this, "Removed from favorites list", Toast.LENGTH_LONG).show();
            }
        }

    });

    ImageView iv = (ImageView) root.findViewById(R.id.airport_map);
    String lat = c.getString(c.getColumnIndex(Airports.REF_LATTITUDE_DEGREES));
    String lon = c.getString(c.getColumnIndex(Airports.REF_LONGITUDE_DEGREES));
    if (lat.length() > 0 && lon.length() > 0) {
        iv.setTag("geo:" + lat + "," + lon + "?z=16");
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String tag = (String) v.getTag();
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tag));
                startActivity(intent);
            }

        });
    } else {
        iv.setVisibility(View.GONE);
    }
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

/**
 * Display the read receipts within the dedicated vector layout.
 * Console application displays them on the message side.
 * Vector application displays them in a dedicated line under the message
 * @param avatarsListView the read receipts layout
 * @param eventId the event Id./*from   w w  w .  j  a va  2  s  .com*/
 * @param roomState the room state.
 */
private void displayReadReceipts(final View avatarsListView, final String eventId, final RoomState roomState) {
    if (!mSession.isAlive()) {
        return;
    }

    IMXStore store = mSession.getDataHandler().getStore();

    // sanity check
    if (null == roomState) {
        avatarsListView.setVisibility(View.GONE);
        return;
    }

    // hide the read receipts until there is a way to retrieve them
    // without triggering a request per message
    if (mIsPreviewMode) {
        avatarsListView.setVisibility(View.GONE);
        return;
    }

    List<ReceiptData> receipts = store.getEventReceipts(roomState.roomId, eventId, true, true);

    // if there is no receipt to display
    // hide the dedicated layout
    if ((null == receipts) || (0 == receipts.size())) {
        avatarsListView.setVisibility(View.GONE);
        return;
    }

    avatarsListView.setVisibility(View.VISIBLE);

    ArrayList<View> imageViews = new ArrayList<>();

    imageViews.add(avatarsListView.findViewById(R.id.message_avatar_receipt_1)
            .findViewById(org.matrix.androidsdk.R.id.avatar_img));
    imageViews.add(avatarsListView.findViewById(R.id.message_avatar_receipt_2)
            .findViewById(org.matrix.androidsdk.R.id.avatar_img));
    imageViews.add(avatarsListView.findViewById(R.id.message_avatar_receipt_3)
            .findViewById(org.matrix.androidsdk.R.id.avatar_img));
    imageViews.add(avatarsListView.findViewById(R.id.message_avatar_receipt_4)
            .findViewById(org.matrix.androidsdk.R.id.avatar_img));
    imageViews.add(avatarsListView.findViewById(R.id.message_avatar_receipt_5)
            .findViewById(org.matrix.androidsdk.R.id.avatar_img));

    TextView moreText = (TextView) avatarsListView.findViewById(R.id.message_more_than_expected);

    int index = 0;
    int bound = Math.min(receipts.size(), imageViews.size());

    for (; index < bound; index++) {
        final ReceiptData r = receipts.get(index);
        RoomMember member = roomState.getMember(r.userId);
        ImageView imageView = (ImageView) imageViews.get(index);

        imageView.setVisibility(View.VISIBLE);
        imageView.setTag(null);

        if (null != member) {
            VectorUtils.loadRoomMemberAvatar(mContext, mSession, imageView, member);
        } else {
            // should never happen
            VectorUtils.loadUserAvatar(mContext, mSession, imageView, null, r.userId, r.userId);
        }
    }

    moreText.setVisibility((receipts.size() <= imageViews.size()) ? View.GONE : View.VISIBLE);
    moreText.setText((receipts.size() - imageViews.size()) + "+");

    for (; index < imageViews.size(); index++) {
        imageViews.get(index).setVisibility(View.INVISIBLE);
    }

    if (receipts.size() > 0) {
        avatarsListView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mMessagesAdapterEventsListener) {
                    mMessagesAdapterEventsListener.onMoreReadReceiptClick(eventId);
                }
            }
        });
    } else {
        avatarsListView.setOnClickListener(null);
    }
}

From source file:org.mariotaku.twidere.view.CardMediaContainer.java

public void displayMedia(@NonNull final MediaLoaderWrapper loader, @Nullable final ParcelableMedia[] mediaArray,
        final UserKey accountId, @Nullable final OnMediaClickListener mediaClickListener,
        @Nullable final MediaLoadingHandler loadingHandler, final long extraId, boolean withCredentials) {
    if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) {
        for (int i = 0, j = getChildCount(); i < j; i++) {
            final View child = getChildAt(i);
            child.setTag(null);/* ww w.  j  a  v  a  2s  .  c  o m*/
            child.setVisibility(GONE);
        }
        return;
    }
    final View.OnClickListener clickListener = new ImageGridClickListener(mediaClickListener, accountId,
            extraId);
    for (int i = 0, j = getChildCount(), k = mediaArray.length; i < j; i++) {
        final View child = getChildAt(i);
        if (mediaClickListener != null) {
            child.setOnClickListener(clickListener);
        }
        final ImageView imageView = (ImageView) child.findViewById(R.id.mediaPreview);
        switch (mMediaPreviewStyle) {
        case VALUE_MEDIA_PREVIEW_STYLE_CODE_CROP: {
            imageView.setScaleType(ScaleType.CENTER_CROP);
            break;
        }
        case VALUE_MEDIA_PREVIEW_STYLE_CODE_SCALE: {
            imageView.setScaleType(ScaleType.FIT_CENTER);
            break;
        }
        }
        if (i < k) {
            final ParcelableMedia media = mediaArray[i];
            final String url = TextUtils.isEmpty(media.preview_url) ? media.media_url : media.preview_url;
            if (ObjectUtils.notEqual(url, imageView.getTag()) || imageView.getDrawable() == null) {
                if (withCredentials) {
                    loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler);
                } else {
                    loader.displayPreviewImage(imageView, url, loadingHandler);
                }
            }
            imageView.setTag(url);
            if (imageView instanceof MediaPreviewImageView) {
                ((MediaPreviewImageView) imageView)
                        .setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(media.type));
            }
            if (TextUtils.isEmpty(media.alt_text)) {
                child.setContentDescription(getContext().getString(R.string.media));
            } else {
                child.setContentDescription(media.alt_text);
            }
            child.setTag(media);
            child.setVisibility(VISIBLE);
        } else {
            loader.cancelDisplayTask(imageView);
            imageView.setTag(null);
            child.setVisibility(GONE);
        }
    }
}

From source file:com.bt.download.android.gui.adapters.TransferListAdapter.java

private void populateBittorrentDownload(View view, BittorrentDownload download) {
    TextView title = findView(view, R.id.view_transfer_list_item_title);
    ProgressBar progress = findView(view, R.id.view_transfer_list_item_progress);
    TextView status = findView(view, R.id.view_transfer_list_item_status);
    TextView speed = findView(view, R.id.view_transfer_list_item_speed);
    TextView size = findView(view, R.id.view_transfer_list_item_size);
    ImageView buttonAction = findView(view, R.id.view_transfer_list_item_button_action);

    TextView seeds = findView(view, R.id.view_transfer_list_item_seeds);
    TextView peers = findView(view, R.id.view_transfer_list_item_peers);

    seeds.setText(context.get().getString(R.string.seeds_n, download.getSeeds()));
    peers.setText(context.get().getString(R.string.peers_n, download.getPeers()));

    title.setText(download.getDisplayName());
    progress.setProgress(download.getProgress());

    status.setText(TRANSFER_STATE_STRING_MAP.get(download.getStatus()));

    speed.setText(UIUtils.getBytesInHuman(download.getDownloadSpeed()) + "/s");
    size.setText(UIUtils.getBytesInHuman(download.getSize()));

    buttonAction.setTag(download);
    buttonAction.setOnClickListener(viewOnClickListener);
}

From source file:com.syncedsynapse.kore2.ui.AlbumDetailsFragment.java

/**
 * Display the songs/*  w w  w.  ja va 2s .  com*/
 *
 * @param cursor Cursor with the data
 */
private void displaySongsList(Cursor cursor) {
    if (cursor.moveToFirst()) {
        songInfoList = new ArrayList<FileDownloadHelper.SongInfo>(cursor.getCount());
        do {
            View songView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_song, songListView,
                    false);
            TextView songTitle = (TextView) songView.findViewById(R.id.song_title);
            TextView trackNumber = (TextView) songView.findViewById(R.id.track_number);
            TextView duration = (TextView) songView.findViewById(R.id.duration);
            ImageView contextMenu = (ImageView) songView.findViewById(R.id.list_context_menu);

            // Add this song to the list
            FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(albumDisplayArtist,
                    albumTitle, cursor.getInt(AlbumSongsListQuery.SONGID),
                    cursor.getInt(AlbumSongsListQuery.TRACK), cursor.getString(AlbumSongsListQuery.TITLE),
                    cursor.getString(AlbumSongsListQuery.FILE));
            songInfoList.add(songInfo);

            songTitle.setText(songInfo.title);
            trackNumber.setText(String.valueOf(songInfo.track));
            duration.setText(UIUtils.formatTime(cursor.getInt(AlbumSongsListQuery.DURATION)));

            contextMenu.setTag(songInfo);
            contextMenu.setOnClickListener(songItemMenuClickListener);

            songView.setTag(songInfo);
            songView.setOnClickListener(songClickListener);
            songListView.addView(songView);
        } while (cursor.moveToNext());

        if (songInfoList.size() > 0) {
            downloadButton.setVisibility(View.VISIBLE);
            // Check if download dir exists
            FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(albumDisplayArtist,
                    albumTitle, 0, 0, null, null);
            if (songInfo.downloadDirectoryExists()) {
                Resources.Theme theme = getActivity().getTheme();
                TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorAccent });
                downloadButton.setColorFilter(styledAttributes.getColor(0, R.color.accent_default));
                styledAttributes.recycle();
            } else {
                downloadButton.clearColorFilter();
            }
        }
    }
}

From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java

private void onPopulateShowData(Cursor show) {
    if (show == null || !show.moveToFirst()) {
        return;/* w w w  . ja v a2 s.co m*/
    }
    mShowCursor = show;

    // set show title in action bar
    mShowTitle = show.getString(ShowQuery.SHOW_TITLE);
    ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
    actionBar.setTitle(mShowTitle);

    // status
    final TextView statusText = (TextView) getView().findViewById(R.id.showStatus);
    int status = show.getInt(ShowQuery.SHOW_STATUS);
    if (status == 1) {
        statusText.setTextColor(getResources().getColor(
                Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.textColorSgGreen)));
        statusText.setText(getString(R.string.show_isalive));
    } else if (status == 0) {
        statusText.setTextColor(Color.GRAY);
        statusText.setText(getString(R.string.show_isnotalive));
    }

    // favorite
    final ImageView favorited = (ImageView) getView().findViewById(R.id.imageViewFavorite);
    boolean isFavorited = show.getInt(ShowQuery.SHOW_FAVORITE) == 1;
    if (isFavorited) {
        favorited.setImageResource(
                Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableStar));
    } else {
        favorited.setImageResource(
                Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableStar0));
    }
    CheatSheet.setup(favorited, isFavorited ? R.string.context_unfavorite : R.string.context_favorite);
    favorited.setTag(isFavorited);

    // poster background
    Utils.loadPosterBackground(getActivity(), mBackgroundImage, show.getString(ShowQuery.SHOW_POSTER));

    // air time and network
    final StringBuilder timeAndNetwork = new StringBuilder();
    final long releaseTime = show.getLong(ShowQuery.SHOW_RELEASE_TIME);
    final String releaseCountry = show.getString(ShowQuery.SHOW_RELEASE_COUNTRY);
    final String releaseDay = show.getString(ShowQuery.SHOW_RELEASE_DAY);
    if (!TextUtils.isEmpty(releaseDay) && releaseTime != -1) {
        String[] values = TimeTools.formatToShowReleaseTimeAndDay(getActivity(), releaseTime, releaseCountry,
                releaseDay);
        timeAndNetwork.append(values[1]).append(" ").append(values[0]).append(" ");
    }
    final String network = show.getString(ShowQuery.SHOW_NETWORK);
    if (!TextUtils.isEmpty(network)) {
        timeAndNetwork.append(getString(R.string.show_on_network, network));
    }
    ((TextView) getActivity().findViewById(R.id.showmeta)).setText(timeAndNetwork.toString());
}

From source file:com.sim2dial.dialer.InCallActivity.java

private boolean displayCallStatusIconAndReturnCallPaused(LinearLayout callView, LinphoneCall call) {
    boolean isCallPaused, isInConference;
    ImageView callState = (ImageView) callView.findViewById(R.id.callStatus);
    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;//w w  w. j  ava 2 s . c  o  m
        isInConference = false;
    } else if (call.getState() == State.OutgoingInit || call.getState() == State.OutgoingProgress
            || call.getState() == State.OutgoingRinging) {
        callState.setImageResource(R.drawable.call_state_ringing_default);
        isCallPaused = false;
        isInConference = false;
    } else {
        if (isConferenceRunning && call.isInConference()) {
            callState.setImageResource(R.drawable.remove);
            isInConference = true;
        } else {
            callState.setImageResource(R.drawable.play);
            isInConference = false;
        }
        isCallPaused = false;
    }

    return isCallPaused || isInConference;
}

From source file:cn.com.wo.bitmap.ImageWorker.java

public void loadImage(String url, ImageView imageView, boolean isBackground) {
    //      url = Images.getUrl();
    if (url == null || url.trim().length() == 0 || !url.startsWith("http"))
        return;//from   w w  w  .j  a  va 2 s .co m
    if (ImageFetcher.isDebug)
        Log.i(ImageFetcher.TAG, "loadImage " + url + "; isBg=" + isBackground);
    //    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 (isBackground)
            imageView.setBackgroundDrawable(value);
        else
            imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(url, imageView, isBackground)) {
        imageView.setTag(0);
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, 0, isBackground);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap[0], task);
        //          imageView.setImageDrawable(asyncDrawable);

        if (isBackground)
            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);
    }
}

From source file:com.listviewaddheader.cache.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  w w w .  ja  va  2s.c  o  m*/
private void forceDownload(String url, ImageView imageView, String cookie, int defaultPicType) {
    try {

        // State sanity: url is guaranteed to never be null in
        if (url == null && imageView != null) {
            // 
            imageView.setImageBitmap(getDefaultBitmap(mContext));
            return;
        }

        if (cancelPotentialDownload(url, imageView)) {

            // mBitmapDownloaderTaskCache.remove(url);

            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);

            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, mContext, defaultPicType);

            // imageView.setImageDrawable(downloadedDrawable);

            imageView.setTag(downloadedDrawable);

            task.execute(url, cookie);

            // 
            // mBitmapDownloaderTaskCache.put(url, task);
        }

    } catch (RejectedExecutionException localRejectedExecutionException) {
        Logger.w(TAG, "localRejectedExecutionException");
    }
}