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:net.peterkuterna.android.apps.devoxxfrsched.util.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.
 *//*  w w w .  j a v a 2 s .  c  o  m*/
private void forceDownload(String url, ImageView imageView, int emptyResId) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(mContext, task, emptyResId);
        imageView.setImageDrawable(downloadedDrawable);
        imageView.setMinimumHeight(156);
        task.execute(url);
    }
}

From source file:com.aprz.easy_iosched.ui.widget.CustomRatingBar.java

/**
 * Creates ({@link ImageView}s) used to submit a rating using unfilled drawables and adds them to
 * the layout./* w  w w. ja  v  a  2  s  .co m*/
 */
private void createRatingViews() {
    for (int i = 0; i < mMaxRating; i++) {
        ImageView imageView = new ImageView(getContext());
        imageView.setLayoutParams(
                new android.view.ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        int tagValue = i + 1;
        imageView.setTag(tagValue);
        imageView.setContentDescription(getContext().getString(R.string.feedback_rating_value, tagValue));
        imageView.setImageDrawable(mUnfilledDrawable);
        imageView.setOnClickListener(this);
        addView(imageView);
    }
}

From source file:com.baksu.screenbroadcast2.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   ww w  .ja  v  a 2  s  .c  om*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        Log.i("imageUp", "URL? ?");
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Log.i("imageUp", "NO_ASYNC_TASK");
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            Log.i("imageUp", "NO_DOWNLOADED_DRAWABLE");
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            Log.i("imageUp", "CORRECT");
            task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.makotosan.vimeodroid.common.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.
 *//* www . j av a2 s  .c om*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        // imageView.setMinimumHeight(156);
        task.execute(url);
    }
}

From source file:com.arisprung.tailgate.utilities.FacebookImageLoader.java

private void forceLoad(String filename, ImageView imageView) {
    // State sanity: filename is guaranteed to never be null in LoadedDrawable and cache keys.
    if (filename == null) {
        imageView.setImageDrawable(null);
        return;/*w  w w  . j  a  v a  2 s. com*/
    }

    BitmapLoaderTask task = new BitmapLoaderTask(imageView);
    // This is where we tie a reference to the image filename to ImageView.
    LoadedDrawable downloadedDrawable = new LoadedDrawable(filename);
    imageView.setImageDrawable(downloadedDrawable);
    task.execute(filename);
}

From source file:com.example.facebook_volley.widget.SlidingTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from   w  w  w.j  a va 2  s. com*/
        ImageView tabIconView = null;
        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }
        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }
        tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawableId(i)));
        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        // tabView.setOnClickListener(tabClickListener);

        final int index_i = i;

        tabView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mViewPager.setCurrentItem(index_i);
            }
        });
        mTabStrip.addView(tabView);
        //tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
    }
}

From source file:com.battlelancer.seriesguide.util.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.
 */// ww w  . j a  v a  2 s  .  co  m
private void forceDownload(String url, ImageView imageView, boolean isDiskCaching) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, isDiskCaching);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(url);
    }
}

From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java

/** {@inheritDoc} */
@Override// w w  w. ja  v  a 2s .com
public void bindView(View view, Context context, Cursor cursor) {

    String outletName = cursor.getString(OutletDataViewQuery.NAME);
    ((TextView) view.findViewById(R.id.outlet_title)).setText(outletName);

    String deviceId = cursor.getString(OutletDataViewQuery.DEVICE_ID);
    ((TextView) view.findViewById(R.id.outlet_subtitle)).setText(deviceId);

    Spinner spinner = (Spinner) view.findViewById(R.id.spin);
    spinner.setAdapter(adapter);

    Integer controllerId = cursor.getInt(OutletDataViewQuery.CONTROLLER_ID);

    spinner.setOnItemSelectedListener(new myOnItemSelectedListener(outletName, controllerId));

    // Assign track color to visible block
    String val = cursor.getString(OutletDataViewQuery.VALUE);
    final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon1);
    Resources res = mActivity.getResources();

    ////  Axx = Auto-On or Auto-Off
    ////  OFF = Manual Off
    ////  ON = Manual On

    if (val.equalsIgnoreCase("AON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("AOF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("OFF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(1);
    } else if (val.equalsIgnoreCase("ON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(2);
    } else {
        iconView.setImageDrawable(new ColorDrawable(Color.BLUE));
    }
}

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Will set the image of an ImageView from a drawable.
 * /* ww  w.  j a va2s .co m*/
 * @param viewId
 *            The view id.
 * @param drawable
 *            The image drawable.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setImageDrawable(int viewId, Drawable drawable) {
    ImageView view = retrieveView(viewId);
    view.setImageDrawable(drawable);
    return this;
}

From source file:com.android.dialer.filterednumber.BlockedNumbersFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    getListView().addHeaderView(inflater.inflate(R.layout.blocked_number_header, null));
    getListView().addFooterView(inflater.inflate(R.layout.blocked_number_footer, null));
    //replace the icon for add number with LetterTileDrawable(), so it will have identical style
    ImageView addNumberIcon = (ImageView) getActivity().findViewById(R.id.add_number_icon);
    LetterTileDrawable drawable = new LetterTileDrawable(getResources());
    drawable.setLetter(ADD_BLOCKED_NUMBER_ICON_LETTER);
    drawable.setColor(ActivityCompat.getColor(getActivity(), R.color.add_blocked_number_icon_color));
    drawable.setIsCircular(true);//from w  ww.j  a  v a2  s  . c o m
    addNumberIcon.setImageDrawable(drawable);

    if (mAdapter == null) {
        mAdapter = BlockedNumbersAdapter.newBlockedNumbersAdapter(getContext(),
                getActivity().getFragmentManager());
    }
    setListAdapter(mAdapter);

    blockedNumbersText = (TextView) getListView().findViewById(R.id.blocked_number_text_view);
    migratePromoView = getListView().findViewById(R.id.migrate_promo);
    getListView().findViewById(R.id.migrate_promo_allow_button).setOnClickListener(this);
    mImportSettings = getListView().findViewById(R.id.import_settings);
    mBlockedNumbersDisabledForEmergency = getListView()
            .findViewById(R.id.blocked_numbers_disabled_for_emergency);
    mBlockedNumberListDivider = getActivity().findViewById(R.id.blocked_number_list_divider);
    getListView().findViewById(R.id.import_button).setOnClickListener(this);
    getListView().findViewById(R.id.view_numbers_button).setOnClickListener(this);
    getListView().findViewById(R.id.add_number_linear_layout).setOnClickListener(this);

    footerText = (TextView) getActivity().findViewById(R.id.blocked_number_footer_textview);
    mVoicemailEnabledChecker = new VisualVoicemailEnabledChecker(getContext(), this);
    mVoicemailEnabledChecker.asyncUpdate();
    updateActiveVoicemailProvider();
}