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:im.neon.util.VectorUtils.java

/**
 * Set the call avatar in an imageView.//  ww w.j  a  v a 2s.c o m
 *
 * @param context   the context
 * @param session   the session
 * @param imageView the image view
 * @param room      the room
 */
public static void loadCallAvatar(Context context, MXSession session, ImageView imageView, Room room) {
    // sanity check
    if ((null != room) && (null != session) && (null != imageView) && session.isAlive()) {
        // reset the imageView tag
        imageView.setTag(null);

        String callAvatarUrl = room.getCallAvatarUrl();
        String roomId = room.getRoomId();
        String displayName = VectorUtils.getRoomDisplayName(context, session, room);
        int pixelsSide = imageView.getLayoutParams().width;

        // when size < 0, it means that the render graph must compute it
        // so, we search the valid parent view with valid size
        if (pixelsSide < 0) {
            ViewParent parent = imageView.getParent();

            while ((pixelsSide < 0) && (null != parent)) {
                if (parent instanceof View) {
                    View parentAsView = (View) parent;
                    pixelsSide = parentAsView.getLayoutParams().width;
                }
                parent = parent.getParent();
            }
        }

        // if the avatar is already cached, use it
        if (session.getMediasCache().isAvatarThumbnailCached(callAvatarUrl,
                context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) {
            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView,
                    callAvatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size));
        } else {
            Bitmap bitmap = null;

            if (pixelsSide > 0) {
                // get the avatar bitmap.
                bitmap = VectorUtils.createAvatar(VectorUtils.getAvatarColor(roomId),
                        getInitialLetter(displayName), pixelsSide);
            }

            // until the dedicated avatar is loaded.
            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView,
                    callAvatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size),
                    bitmap);
        }
    }
}

From source file:com.android.ted.sample.viewpager.MainPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView;/*ww  w.j ava 2  s  . c  om*/
    Girl girl = mAllGirlList.get(position);
    if (mAllImageMap.containsKey(position)) {
        View oldView = mAllImageMap.get(position);
        Object tag = oldView.getTag();
        if (null != tag && tag instanceof Girl) {
            if (tag.equals(girl)) {
                itemView = oldView;
                container.addView(itemView);
                return itemView;
            }
        }
        container.removeView(oldView);
        mAllImageMap.remove(position);
    }

    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    Glide.with(mContext).load(girl.getImageUrl()).into(imageView);
    imageView.setTag(girl);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(layoutParams);
    mAllImageMap.put(position, imageView);
    itemView = imageView;
    itemView.setOnClickListener(this);
    container.addView(itemView);
    return itemView;
}

From source file:com.scigames.slidereview.MenuActivity.java

private void displayProfile() {
    setContentView(R.layout.menu_page);/*from  w ww  .jav  a2  s .  c  om*/
    Log.d(TAG, "...setContentView");

    //display name and profile info
    Resources res = getResources();
    greets = (TextView) findViewById(R.id.student_name);
    greets.setText(String.format(res.getString(R.string.profile_name), firstNameIn, lastNameIn));
    setTextViewFont(Museo700Regular, greets);
    Log.d(TAG, "...Profile Info");

    reviewBtn = (Button) findViewById(R.id.btn_review);
    reviewBtn.setOnClickListener(mReview);
    setButtonFont(ExistenceLightOtf, reviewBtn);

    infoDialog = new AlertDialog.Builder(MenuActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
        }
    });

    if (debug) {
        //      infoDialog.setTitle("studentId");
        //      infoDialog.setMessage(studentIdIn);
        //      infoDialog.show();
    }

    task.setOnResultsListener(this);
    task.cancel(true);
    task = new SciGamesHttpPoster(MenuActivity.this, baseDbURL + "/pull/return_profile.php");
    task.setOnResultsListener(MenuActivity.this);

    //download photo
    ImageView profilePhoto = (ImageView) findViewById(R.id.profile_image);
    profilePhoto.setTag(photoUrl);
    profilePhoto.setScaleX(1.4f);
    profilePhoto.setScaleY(1.4f);
    profilePhoto.setX(120f);
    profilePhoto.setY(123f);
    photoTask.cancel(true);
    photoTask = new DownloadProfilePhoto(MenuActivity.this, photoUrl);
    //AsyncTask<ImageView, Void, Bitmap> pPhoto = 
    photoTask.execute(profilePhoto);
}

From source file:com.scigames.slidegame.MenuActivity.java

private void displayProfile() {
    setContentView(R.layout.menu_page);/*  w  w  w . j a va2s.c o  m*/
    Log.d(TAG, "...setContentView");

    //display name and profile info
    Resources res = getResources();
    greets = (TextView) findViewById(R.id.student_name);
    greets.setText(String.format(res.getString(R.string.profile_name), firstNameIn, lastNameIn));
    setTextViewFont(Museo700Regular, greets);
    Log.d(TAG, "...Profile Info");

    playBtn = (Button) findViewById(R.id.btn_play);
    playBtn.setOnClickListener(mPlay);
    setButtonFont(ExistenceLightOtf, playBtn);

    infoDialog = new AlertDialog.Builder(MenuActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
        }
    });

    if (debug) {
        //      infoDialog.setTitle("studentId");
        //      infoDialog.setMessage(studentIdIn);
        //      infoDialog.show();
    }

    task.setOnResultsListener(this);
    task.cancel(true);
    task = new SciGamesHttpPoster(MenuActivity.this, baseDbURL + "/pull/return_profile.php");
    task.setOnResultsListener(MenuActivity.this);

    //download photo
    ImageView profilePhoto = (ImageView) findViewById(R.id.profile_image);
    profilePhoto.setTag(photoUrl);
    profilePhoto.setScaleX(1.4f);
    profilePhoto.setScaleY(1.4f);
    profilePhoto.setX(120f);
    profilePhoto.setY(123f);
    photoTask.cancel(true);
    photoTask = new DownloadProfilePhoto(MenuActivity.this, photoUrl);
    //AsyncTask<ImageView, Void, Bitmap> pPhoto = 
    photoTask.execute(profilePhoto);
}

From source file:org.apps8os.motivator.ui.ImagesPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup viewGroup, int position) {
    ImageView carouselImage = (ImageView) mInflater.inflate(R.layout.element_mood_selection_image, viewGroup,
            false);/*from  ww w. j  a  va2s.c  om*/

    // Set the correct image and a tag for the position
    carouselImage.setImageDrawable(mResources.getDrawable(mImages[position]));
    carouselImage.setTag(position);
    viewGroup.addView(carouselImage);

    return carouselImage;
}

From source file:org.alfresco.mobile.android.application.fragments.node.rendition.PreviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(false);//from   ww  w  . j  ava 2 s. co m

    if (container != null) {
        container.setVisibility(View.VISIBLE);
    }

    setRootView(inflater.inflate(R.layout.app_preview, container, false));

    if (getSession() == null) {
        return getRootView();
    }
    if (node == null) {
        return null;
    }

    // Detect if isRestrictable
    isRestrictable = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    ImageView iv = (ImageView) viewById(R.id.preview);
    int iconId = R.drawable.mime_folder;
    iv.setTag(viewById(R.id.preview_message));
    if (node.isDocument() && node instanceof NodeImpl) {
        iconId = MimeTypeManager.getInstance(getActivity()).getIcon(node.getName(), true);
        if (((Document) node).isLatestVersion()) {
            ((ImageViewTouch) iv).setScaleEnabled(false);
            ((ImageViewTouch) iv).setDoubleTapEnabled(false);
            ((ImageViewTouch) iv).setDisplayType(DisplayType.NONE);

            RenditionBuilder request = RenditionManager.with(getActivity()).loadNode(node).placeHolder(iconId)
                    .rendition(RenditionRequest.RENDITION_PREVIEW);
            if (touchEnabled) {
                request.touchViewEnable(true);
            }
            request.into(iv);
        }
    } else if (node.isDocument() && node instanceof NodeSyncPlaceHolder) {
        iv.setImageResource(MimeTypeManager.getInstance(getActivity()).getIcon(node.getName(), true));
    } else {
        iv.setImageResource(iconId);
    }

    return getRootView();
}

From source file:com.yanzhenjie.album.task.ImageLocalLoader.java

/**
 * According to the specified width high loading pictures, wide high, the greater the picture clearer, more memory.
 *
 * @param imageView    {@link ImageView}.
 * @param imagePath    path from local SDCard.
 * @param width        target width.//from   w w  w .  j a  v a 2 s  .  c  o m
 * @param height       target height.
 * @param loadListener {@link LoadListener}.
 */
public void loadImage(ImageView imageView, String imagePath, int width, int height, LoadListener loadListener) {
    imageView.setTag(imagePath);
    Bitmap bitmap = getImageFromCache(imagePath, width, height);
    if (bitmap == null) {
        imageView.setImageDrawable(DEFAULT_DRAWABLE);
        mExecutorService.execute(new TaskThread(imageView, imagePath, width, height, loadListener));
    } else {
        ImgBeanHolder holder = new ImgBeanHolder();
        holder.imageView = imageView;
        holder.imagePath = imagePath;
        holder.bitmap = bitmap;
        holder.loadListener = loadListener;
        Poster.getInstance().post(holder);
    }
}

From source file:com.quran.labs.androidquran.widgets.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from ww  w  .  java2 s  .  c om
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext(), null, R.attr.actionButtonStyle);
        view.setImageResource(iconAdapter.getIconResId(i));
        view.setTag(i);
        view.setOnClickListener(this);
        mIconsLayout.addView(view, new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.mk27manoj.crewtools.fragments.CreateViewCompanyFragment.java

private void addService(String name) {
    LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View baseView = layoutInflater.inflate(R.layout.row_create_company_add_service, null);
    TextView txtService = (TextView) baseView.findViewById(R.id.textview_create_company_add_service_name);
    ImageView imgRemove = (ImageView) baseView.findViewById(R.id.imageview_create_company_add_service_remove);
    baseView.setTag(serviceContainer.getChildCount());
    imgRemove.setTag(serviceContainer.getChildCount());

    txtService.setText(name);/* w  ww.ja v a  2  s  .  co m*/
    imgRemove.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((LinearLayout) baseView.getParent()).removeView(baseView);
            services.remove(serviceContainer.indexOfChild(v));
            mCompany.setServiceTypes(services);
        }
    });
    serviceContainer.addView(baseView);
}

From source file:es.ubiqua.atractivas.GaleryPageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Imagen imagen = ((GaleryActivity) getActivity()).m_parts.get(mPageNumber);
    Rss rss = ((GaleryActivity) getActivity()).rss;

    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_galery_page, container, false);

    FontLoader.overrideFonts(rootView, "normal");

    NoAutoScrollView scroll = (NoAutoScrollView) rootView.findViewById(R.id.content);

    scroll.setOnEndScrollListener(new NoAutoScrollView.OnEndScrollListener() {
        @Override//w w w.  ja v  a  2 s  . com
        public void onEndScroll(boolean home, boolean end) {
            if (home || end) {
                ((GaleryActivity) getActivity()).showButtons();
            } else {
                ((GaleryActivity) getActivity()).hideButtons();
            }
        }
    });

    // Set the title view to show the page number.
    ((TextView) rootView.findViewById(R.id.DetalleCategoria)).setText(rss.getCategory());
    ImageView favorito = (ImageView) rootView.findViewById(R.id.DetalleFavorito);
    favorito.setTag(rss);
    if (rss.getFavorito()) {
        favorito.setImageDrawable(ApplicationApp.getDrawable("favoritos_selected"));
    } else {
        favorito.setImageDrawable(ApplicationApp.getDrawable("favoritos"));
    }
    ((TextView) rootView.findViewById(R.id.DetalleTitulo)).setText(rss.getTitle());

    favorito.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageView imagen = (ImageView) view;

            RssDataSource _rssDataSource = new RssDataSource(getActivity().getApplicationContext());
            try {
                _rssDataSource.open();
            } catch (SQLException e) {
                //                  Log.d( "action fragment_category", "Enter: handleMessage -> " + e.getMessage() );
            }
            Rss rss = (Rss) imagen.getTag();
            rss.setFavorito(!rss.getFavorito());
            _rssDataSource.updateFavorito(rss.getId(), rss.getFavorito());

            if (rss.getFavorito()) {
                imagen.setImageDrawable(ApplicationApp.getDrawable("favoritos_selected"));
            } else {
                imagen.setImageDrawable(ApplicationApp.getDrawable("favoritos"));
            }
            ((GaleryActivity) getActivity()).rss = rss;
            _rssDataSource.close();
        }
    });
    // whenever you want to load an image from url
    // call DisplayImage function
    // url - image url to load
    // loader - loader image, will be displayed before getting image
    // image - ImageView

    imgLoader.DisplayImage(imagen.getUrl(), R.drawable.placeholder_detalle,
            (ImageView) rootView.findViewById(R.id.DetalleImagen));

    ((WebView) rootView.findViewById(R.id.DestalleFulltext)).loadData(HEADER + imagen.getTexto() + FOOTER,
            "text/html; charset=UTF-8", null);

    yocAdBannerViewb = (YocAdViewContainer) rootView.findViewById(R.id.baner_publicidad);
    if (rss.getParentCategory().equals(new String("En Forma"))) {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_ENFORMA_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    } else if (rss.getParentCategory().equals(new String("Salud"))) {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_SALUD_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    } else if (rss.getParentCategory().equals(new String("Moda"))) {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_MODA_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    } else if (rss.getParentCategory().equals(new String("Nutricin"))) {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_NUTRI_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    } else if (rss.getParentCategory().equals(new String("Belleza"))) {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_BELLEZA_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    } else {
        _yocAdManagerb = new YocAdManager(getActivity(), ApplicationApp.YOC_TAG_GENERAL_BANNER,
                AdSize.BANNER_SMARTPHONE_480x80, new AdBanner());
    }

    createLigAdView(ApplicationApp.LigatusId, rootView);

    return rootView;
}