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:it.fdev.utils.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//from   w ww  .  ja v a  2s.c o m
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };
    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable drawable = fetchDrawable(urlString);
            if (drawable != null) {
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            }
        }
    };
    thread.start();
}

From source file:com.github.tetravex_android.fragment.HowToFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_howto_page, container, false);

    TextView instructionTv = (TextView) rootView.findViewById(R.id.instruction_text);
    instructionTv.setText(mInstructionText);

    ImageView imageView = (ImageView) rootView.findViewById(R.id.how_to_image);
    Drawable imgDrawable = getHowToDrawable();
    imageView.setImageDrawable(imgDrawable);

    return rootView;
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardMuzeiActivity.java

private void initSettings() {
    int color = ColorHelper.getAttributeColor(this, R.attr.colorAccent);
    int titleColor = ColorHelper.getTitleTextColor(color);

    ImageView icon = ButterKnife.findById(this, R.id.muzei_save_icon);
    icon.setImageDrawable(DrawableHelper.getTintedDrawable(this, R.drawable.ic_toolbar_save, titleColor));
    TextView text = ButterKnife.findById(this, R.id.muzei_save_text);
    text.setTextColor(titleColor);/*w w w . j a v  a2  s .  co  m*/
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.UpgradeMessageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.apptentive_upgrade_message_interaction, container, false);

    ImageView iconView = (ImageView) v.findViewById(R.id.icon);
    Drawable icon = getIconDrawableResourceId();
    if (icon != null) {
        iconView.setImageDrawable(icon);
    } else {/* ww  w  .j av a2s  .  com*/
        iconView.setVisibility(View.GONE);
    }
    WebView webview = (WebView) v.findViewById(R.id.webview);
    webview.loadData(interaction.getBody(), "text/html", "UTF-8");
    webview.setBackgroundColor(Color.TRANSPARENT); // Hack to keep webview background from being colored after load.

    // If branding is not desired, turn the view off.
    final View branding = v.findViewById(R.id.apptentive_branding_view);
    if (branding != null) {
        if (!interaction.isShowPoweredBy() || Configuration.load().isHideBranding(getContext())) {
            branding.setVisibility(View.GONE);
        }
    }

    return v;
}

From source file:com.jameswolfeoliver.pigeon.Utilities.DrawableHelper.java

public void applyTo(@NonNull ImageView imageView) {
    if (mWrappedDrawable == null) {
        throw new NullPointerException();
    }/*from   ww w.  java 2 s  . c o  m*/

    imageView.setImageDrawable(mWrappedDrawable);
}

From source file:com.google.android.leanbackjank.presenter.HeaderItemPresenter.java

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    HeaderItem headerItem = ((ListRow) item).getHeaderItem();
    View rootView = viewHolder.view;
    rootView.setFocusable(true);//w  ww. j a  v  a  2s  .  c om

    ImageView iconView = (ImageView) rootView.findViewById(R.id.header_icon);
    Drawable icon = ResourcesCompat.getDrawable(rootView.getResources(), R.drawable.android_header, null);
    iconView.setImageDrawable(icon);

    TextView label = (TextView) rootView.findViewById(R.id.header_label);
    label.setText(headerItem.getName());
}

From source file:Main.java

public static void scaleImage(ImageView view, int boundBoxInDp) {
    // Get the ImageView and its bitmap
    Drawable drawing = view.getDrawable();
    Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap();
    // Get current dimensions
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    float xScale = ((float) boundBoxInDp) / width;
    float yScale = ((float) boundBoxInDp) / height;
    float scale = (xScale <= yScale) ? xScale : yScale;
    // Create a matrix for the scaling and add the scaling data
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from   w  w  w . ja  va2 s.  c o m*/
    // Create a new bitmap and convert it to a format understood by the ImageView
    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    BitmapDrawable result = new BitmapDrawable(scaledBitmap);
    width = scaledBitmap.getWidth();
    height = scaledBitmap.getHeight();
    // Apply the scaled bitmap
    view.setImageDrawable(result);
    // Now change ImageView's dimensions to match the scaled image
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);
}

From source file:com.mytutor.search.ImageLoader.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        Log.d("IMG 1", "Getting Image");
        imageView.setImageDrawable(drawableMap.get(urlString));
    }/*  w ww  .  ja  v a  2s  .c o m*/

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

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

private static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override//ww  w . j av  a2s.  c  om
        public void onResponse(ImageContainer response, boolean isImmediate) {
            imageView.setTag(null);
            if (response.getBitmap() != null) {

                if (imageView instanceof PhotoView) {
                    setPhotoImageBitmap((PhotoView) imageView, response.getBitmap(), resources,
                            fadeInImage && !isImmediate);
                } else {
                    setImageBitmap(imageView, response.getBitmap(), resources, fadeInImage && !isImmediate);
                }
            } else {
                if (!(imageView instanceof PhotoView)) {
                    imageView.setImageDrawable(placeHolder);
                }
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    };
}

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

/**
 * Updates ({@link ImageView}s) used to submit a rating, using filled drawables to denote the
 * rating created by the user./*from www.  j  a va 2s  . com*/
 */
private void updateRatingViews() {
    for (int i = 0; i < mMaxRating; i++) {
        ImageView view = (ImageView) this.getChildAt(i);
        view.setImageDrawable(i + 1 <= mRating ? mFilledDrawable : mUnfilledDrawable);
    }
}