Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

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

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:androidx.media.widget.VideoView2.java

private void inflateMusicView(int layoutId) {
    removeView(mMusicView);/*from w  w w.ja v a2  s .co  m*/

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(layoutId, null);
    v.setBackgroundColor(mDominantColor);

    ImageView albumView = v.findViewById(R.id.album);
    if (albumView != null) {
        albumView.setImageDrawable(mMusicAlbumDrawable);
    }

    TextView titleView = v.findViewById(R.id.title);
    if (titleView != null) {
        titleView.setText(mMusicTitleText);
    }

    TextView artistView = v.findViewById(R.id.artist);
    if (artistView != null) {
        artistView.setText(mMusicArtistText);
    }

    mMusicView = v;
    addView(mMusicView, 0);
}

From source file:com.android.contacts.list.ContactListItemView.java

private void addStarImageHeader() {
    mHeaderView = new ImageView(getContext());
    final ImageView headerImageView = (ImageView) mHeaderView;
    headerImageView.setImageDrawable(
            getResources().getDrawable(R.drawable.quantum_ic_star_vd_theme_24, getContext().getTheme()));
    headerImageView//  ww  w. j  ava 2s .c o m
            .setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_star_pink)));
    headerImageView.setContentDescription(getContext().getString(R.string.contactsFavoritesLabel));
    headerImageView.setVisibility(View.VISIBLE);
    addView(headerImageView);
}

From source file:com.android.volley.cache.plus.SimpleImageLoader.java

public ImageContainer get(String requestUrl, ImageView imageView, Drawable placeHolder, int maxWidth,
        int maxHeight) {

    // Find any old image load request pending on this ImageView (in case this view was
    // recycled)//w w  w  . ja v a 2 s .c  o  m
    ImageContainer imageContainer = imageView.getTag() != null && imageView.getTag() instanceof ImageContainer
            ? (ImageContainer) imageView.getTag()
            : null;

    // Find image url from prior request
    String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

    // If the new requestUrl is null or the new requestUrl is different to the previous
    // recycled requestUrl
    if (requestUrl == null || !requestUrl.equals(recycledImageUrl)) {
        if (imageContainer != null) {
            // Cancel previous image request
            imageContainer.cancelRequest();
            imageView.setTag(null);
        }
        if (requestUrl != null) {
            // Queue new request to fetch image
            imageContainer = get(requestUrl,
                    getImageListener(getResources(), imageView, placeHolder, mFadeInImage), maxWidth,
                    maxHeight);
            // Store request in ImageView tag
            imageView.setTag(imageContainer);
        } else {
            if (!(imageView instanceof PhotoView)) {
                imageView.setImageDrawable(placeHolder);
            }
            imageView.setTag(null);
        }
    }

    return imageContainer;
}

From source file:com.android.volley.cache.SimpleImageLoader.java

public ImageContainer get(String requestUrl, ImageView imageView, Drawable placeHolder, int maxWidth,
        int maxHeight) {

    // Find any old image load request pending on this ImageView (in case this view was
    // recycled)//ww w  .  j a v a 2  s.  c om
    ImageContainer imageContainer = imageView.getTag() != null && imageView.getTag() instanceof ImageContainer
            ? (ImageContainer) imageView.getTag()
            : null;

    // Find image url from prior request
    String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

    // If the new requestUrl is null or the new requestUrl is different to the previous
    // recycled requestUrl
    if (requestUrl == null || !requestUrl.equals(recycledImageUrl)) {
        if (imageContainer != null) {
            // Cancel previous image request
            imageContainer.cancelRequest();
            imageView.setTag(null);
        }
        if (requestUrl != null) {
            // Queue new request to fetch image
            imageContainer = get(requestUrl,
                    getImageListener(getResources(), imageView, placeHolder, mFadeInImage), maxWidth, maxHeight,
                    imageView.getScaleType());
            // Store request in ImageView tag
            imageView.setTag(imageContainer);
        } else {
            if (!(imageView instanceof PhotoView)) {
                imageView.setImageDrawable(placeHolder);
            }
            imageView.setTag(null);
        }
    }

    return imageContainer;
}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

private void setPictureToImageView(String pictureName, ImageView imageView) {
    Bitmap picture = null;/* w w  w .  j  av a 2 s  . com*/

    try {
        InputStream in = openFileInput(pictureName);
        picture = BitmapFactory.decodeStream(in);
        in.close();

        LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.editable_picture_frame);
        if (picture.getHeight() > picture.getWidth()) {
            Matrix m = new Matrix();
            m.postRotate(-90);
            picture = Bitmap.createBitmap(picture, 0, 0, picture.getWidth(), picture.getHeight(), m, true);
        }
        picture = Bitmap.createScaledBitmap(picture, d.getIntrinsicWidth(), d.getIntrinsicHeight(), true);

        d.setDrawableByLayerId(R.id.picture, new BitmapDrawable(picture));
        imageView.setImageDrawable(d);

        if (!hasPic)
            hasPic = (imageView.getId() == R.id.ImageView_far);

        // WTF ?
        // if (hasPic && (imageView.getId() == R.id.ImageView_far)) {
        // loadZoom();
        // }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from w ww  . j  a va  2s.c  o m
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if ("0".equals(imageView.getTag())) {
        // ??
        bitmap = toGrayscale(bitmap);
    }
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //TODO: miaolikui delete 20121229
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

        Log.d(TAG, tagStr + ":imageView.setImageDrawable:" + System.currentTimeMillis());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        Log.d(TAG, tagStr + ":imageView.setImageBitmap:" + System.currentTimeMillis());
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.gustavofao.materialtabs.SlidingTabLayout.java

private void populateTabStrip() {
    final SlidingFragmentPagerAdapter adapter = (SlidingFragmentPagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    if (tabType == null)
        tabType = TEXT_ONLY;//ww  w  .  jav  a  2  s. c  o  m

    int focused_color = customFocusedColor != 0 ? customFocusedColor : FOCUSED_WHITE;
    int unfocused_color = customUnfocusedColor != 0 ? customUnfocusedColor : NOT_FOCUSED_WHITE;

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        ImageView tabImageView = null;

        switch (tabType) {
        case TEXT_ONLY:
            tabView = LayoutInflater.from(getContext()).inflate(TEXT_ONLY_TAB, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(TEXT_ID);
            break;

        case ICON_ONLY:
            tabView = LayoutInflater.from(getContext()).inflate(ICON_ONLY_TAB, mTabStrip, false);
            tabImageView = (ImageView) tabView.findViewById(ICON_ID);
            break;

        case TEXT_ICON:
            tabView = LayoutInflater.from(getContext()).inflate(TEXT_ICON_TAB, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(TEXT_ID);
            tabImageView = (ImageView) tabView.findViewById(ICON_ID);
            break;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (i == mViewPager.getCurrentItem())
            tabView.setSelected(true);

        if (tabTitleView != null && adapter.getPageTitle(i) != null) {
            tabTitleView.setText(adapter.getPageTitle(i));
            tabTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, this.textSize);
            tabTitleView.setTextColor(i == mViewPager.getCurrentItem() ? focused_color : unfocused_color);
        }

        if (tabImageView != null && adapter.getPageDrawable(i) != null) {
            tabImageView.setImageDrawable(adapter.getPageDrawable(i));
            tabImageView.setColorFilter(i == mViewPager.getCurrentItem() ? focused_color : unfocused_color,
                    PorterDuff.Mode.MULTIPLY);
        }

        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    }
}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *///from w w w .jav a 2 s  .c  om
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ImageView.ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.fastbootmobile.encore.app.fragments.ArtistFragment.java

/**
 * {@inheritDoc}//ww w.  j a  va  2  s  .c o m
 */
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mHandler = new Handler();

    // Setup the inside fragments
    mArtistTracksFragment = new ArtistTracksFragment();
    mArtistTracksFragment.setParentFragment(this);

    mArtistInfoFragment = new ArtistInfoFragment();
    mArtistInfoFragment.setArguments(mArtist);

    mArtistSimilarFragment = new ArtistSimilarFragment();
    mArtistSimilarFragment.setArguments(mArtist);

    // Inflate the main fragment view
    mRootView = (ParallaxScrollView) inflater.inflate(R.layout.fragment_artist, container, false);

    // Set the hero image and artist from arguments
    mHeroImageView = (ImageView) mRootView.findViewById(R.id.ivHero);
    if (mHeroImage != null) {
        mHeroImageView.setImageBitmap(mHeroImage);

        // The hero image that comes from a transition might be low in quality, so load
        // the higher quality and fade it in
        loadArt(false);
    } else {
        // Display placeholder and try to get the real art
        mHeroImageView.setImageResource(R.drawable.album_placeholder);
        loadArt(true);
    }

    final TextView tvArtist = (TextView) mRootView.findViewById(R.id.tvArtist);
    tvArtist.setBackgroundColor(mBackgroundColor);
    tvArtist.setText(mArtist.getName());

    final PagerTabStrip strip = (PagerTabStrip) mRootView.findViewById(R.id.pagerArtistStrip);
    strip.setDrawFullUnderline(false);
    strip.setAlpha(0.0f);
    strip.setTranslationY(-20);
    strip.animate().alpha(1.0f).setDuration(ANIMATION_DURATION).setStartDelay(500).translationY(0).start();

    if (!Utils.hasLollipop()) {
        tvArtist.setAlpha(0);
        tvArtist.animate().alpha(1).setDuration(ANIMATION_DURATION).setStartDelay(500).start();
    }

    // Setup the subfragments pager
    final WrapContentHeightViewPager pager = (WrapContentHeightViewPager) mRootView
            .findViewById(R.id.pagerArtist);
    pager.setAdapter(new ViewPagerAdapter(getChildFragmentManager()));
    pager.setOffscreenPageLimit(FRAGMENT_COUNT);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int i) {
            if (mRootView.getScrollY() > tvArtist.getTop()) {
                mRootView.smoothScrollTo(0, tvArtist.getTop());
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    pager.setMinimumHeight(500);
                    pager.requestLayout();
                }
            });

            boolean hasRosetta = ProviderAggregator.getDefault().getRosettaStonePrefix().size() > 0;

            if (hasRosetta) {
                if (i == FRAGMENT_ID_BIOGRAPHY) {
                    mArtistInfoFragment.notifyActive();
                } else if (i == FRAGMENT_ID_SIMILAR) {
                    mArtistSimilarFragment.notifyActive();
                }
            } else {
                if (i == FRAGMENT_ID_SIMILAR) {
                    // This is actually BIOGRAPHY if rosetta is not available
                    mArtistInfoFragment.notifyActive();
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    mRootView.setOnScrollListener(new ObservableScrollView.ScrollViewListener() {
        @Override
        public void onScroll(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
            final ActionBar ab = ((AppActivity) getActivity()).getSupportActionBar();
            if (ab != null) {
                if (y >= tvArtist.getTop()) {
                    ab.hide();
                } else {
                    ab.show();
                }
            }
        }
    });

    // Setup the source logo
    final ImageView ivSource = (ImageView) mRootView.findViewById(R.id.ivSourceLogo);
    mLogoBitmap = PluginsLookup.getDefault().getCachedLogo(getResources(), mArtist);
    ivSource.setImageDrawable(mLogoBitmap);

    // Outline is required for the FAB shadow to be actually oval
    mFabPlay = (FloatingActionButton) mRootView.findViewById(R.id.fabPlay);
    showFab(false, false);

    // Set the FAB animated drawable
    mFabDrawable = new PlayPauseDrawable(getResources(), 1);
    mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY);
    mFabDrawable.setYOffset(6);

    final Song currentTrack = PlaybackProxy.getCurrentTrack();
    if (currentTrack != null && currentTrack.getArtist() != null
            && currentTrack.getArtist().equals(mArtist.getRef())) {
        int state = PlaybackProxy.getState();
        if (state == PlaybackService.STATE_PLAYING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
        } else if (state == PlaybackService.STATE_PAUSED) {
            mFabShouldResume = true;
        } else if (state == PlaybackService.STATE_BUFFERING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY);
            mFabDrawable.setBuffering(true);
            mFabShouldResume = true;
        } else if (state == PlaybackService.STATE_PAUSING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
            mFabDrawable.setBuffering(true);
            mFabShouldResume = true;
        }
    }

    mFabPlay.setImageDrawable(mFabDrawable);
    mFabPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mFabDrawable.getCurrentShape() == PlayPauseDrawable.SHAPE_PLAY) {
                if (mFabShouldResume) {
                    PlaybackProxy.play();
                } else {
                    mArtistTracksFragment.playRecommendation();
                }
            } else {
                mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
                mFabShouldResume = true;
                PlaybackProxy.pause();
            }
        }
    });

    return mRootView;
}

From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java

/**
 * Show image Product from URL//from  ww w  .  j a v  a2s  .  c o m
 *
 * @param imageUrl    image url
 * @param imageView
 * @param progressBar
 * @param productCode product code to find
 */
protected void loadProductImage(String imageUrl, final ImageView imageView, final ProgressBar progressBar,
        String productCode) {

    // Loading the product image
    if (CommerceApplication.isOnline()) {
        if (StringUtils.isNotBlank(imageUrl)) {
            CommerceApplication.getContentServiceHelper().loadImage(imageUrl,
                    "product_list_image_" + productCode, imageView, 0, 0, true, new OnRequestListener() {

                        @Override
                        public void beforeRequest() {
                            imageView.setImageResource(android.R.color.transparent);
                            imageView.setVisibility(View.GONE);
                            progressBar.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void afterRequestBeforeResponse() {

                        }

                        @Override
                        public void afterRequest(boolean isDataSynced) {
                            imageView.setVisibility(View.VISIBLE);
                        }
                    }, true);
        }
    } else {
        Log.i(TAG, "Application offline, displaying no image for product " + productCode);
        imageView.setImageDrawable(getContext().getResources().getDrawable(R.drawable.no_image_product));
        imageView.setVisibility(View.VISIBLE);
    }
}