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:com.idt.ontomedia.geoconsum.BaseActivity.java

private Dialog setDialogWithCheck(int _id) {
    final Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dialog_with_check);

    TextView textViewInfo = (TextView) dialog.findViewById(R.id.text_layout);
    CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.checkBox1);

    switch (_id) {
    case DIALOG_ABOUT_ID: {
        dialog.setTitle(getResources().getString(R.string.dialog_title_about) + " "
                + getResources().getString(R.string.app_name));
        dialog.setCancelable(true);/*from   w  w  w .  j  a v a  2 s .co  m*/

        checkBox.setVisibility(View.GONE);

        ImageView imageViewBanner = (ImageView) dialog.findViewById(R.id.imageViewBanner);
        imageViewBanner.setImageDrawable(getResources().getDrawable(R.drawable.logo_idt));
        imageViewBanner.setVisibility(View.VISIBLE);

        textViewInfo.setText(R.string.dialog_text_about);
    }
    case DIALOG_WARNING_ID: {
        dialog.setTitle(getResources().getString(R.string.dialog_title_warning));
        dialog.setCancelable(false);

        textViewInfo.setText(R.string.dialog_text_warning);

        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton _buttonView, boolean _isChecked) {
                SharedPreferences sharedPreferences = PreferenceManager
                        .getDefaultSharedPreferences(getBaseContext());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean(DialogPreferenceActivity.PREF_DIALOG_CHECK, _isChecked);
                editor.commit();
            }
        });
    }
    }

    Button acceptButton = (Button) dialog.findViewById(R.id.button1);
    acceptButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
        }

    });

    return dialog;
}

From source file:com.ferg.awful.async.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (urlString == null) {
        imageView.setImageDrawable(null);
        return;/*from ww w. j a va  2  s  . com*/
    }

    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }

    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.justwayward.reader.view.recyclerview.adapter.BaseViewHolder.java

public BaseViewHolder setImageDrawable(int viewId, Drawable drawable) {
    ImageView view = getView(viewId);
    view.setImageDrawable(drawable);
    return this;
}

From source file:com.android.argb.edhlc.Utils.java

public static void expand(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.accent_color_dark));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_anticlockwise);
    selector.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.arrow_up));
    selector.setRotation(0);/*from   w  w  w.j a v a 2s .  co  m*/
    selector.startAnimation(rotation);
    selector.setColorFilter(ContextCompat.getColor(context, R.color.accent_color_dark));

    ValueAnimator anim = ValueAnimator.ofInt(minHeight, maxHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
            Utils.makeViewVisible(card);
        }
    });
    anim.start();
}

From source file:Main.java

public static void scaleImageWithOriRatio(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  www.j  a  v  a  2  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.temboo.example.YouTubeResultView.java

/**
 * A utility method to retrieve the thumbnail image on a separate thread, and populate
 * the image view with that thumbnail/*from   w  ww . ja  v a2  s  .  c  o m*/
 * @param urlString - the URL of the thumbnail to retrieve
 * @param imageView - the view to populate with the thumbnail
 */
private void fetchDrawableOnThread(final String urlString, final ImageView imageView) {

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

    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpGet request = new HttpGet(urlString);
                HttpResponse response = httpClient.execute(request);
                InputStream is = response.getEntity().getContent();
                Drawable drawable = Drawable.createFromStream(is, "src");

                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            } catch (Exception e) {
                Toast.makeText(getContext(), "An error occurred retrieving the video thumbnail",
                        Toast.LENGTH_LONG).show();
            }
        }
    };
    thread.start();
}

From source file:com.angelatech.yeyelive.view.PeriscopeLayout.java

public void addHeart() {
    ImageView imageView = new ImageView(getContext());
    //?/*from   ww  w  . j a  va2s  . c om*/
    imageView.setImageDrawable(drawables[random.nextInt(7)]);
    imageView.setLayoutParams(lp);
    addView(imageView);
    Animator set = getAnimator(imageView);
    set.addListener(new AnimEndListener(imageView));
    set.start();
}

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

public static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override//w  w w . j  av a2 s . com
        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.fabbychat.utils.DrawableManager.java

public void fetchDrawableOnThread(final DrawableProducer dp, final ImageView imageView) {

    String key = dp.getKey();//w ww.  j a  v a2s .  c  o  m
    if (drawableMap.containsKey(key)) {
        Drawable d = drawableMap.get(key);
        if (d != null) {
            imageView.setImageDrawable(drawableMap.get(key));
        }
        return;
    }

    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(dp);
            if (drawable != null) {
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            }
        }
    };
    thread.start();
}

From source file:com.hookedonplay.decoviewsample.SamplePeopleFragment.java

@Override
protected void setupEvents() {
    final DecoView arcView = getDecoView();
    final View view = getView();
    if (arcView == null || arcView.isEmpty() || view == null) {
        return;/*from  w w w  .  java  2 s  .c o  m*/
    }
    arcView.executeReset();

    final ImageView imgView = (ImageView) view.findViewById(R.id.imageViewAvatar);
    imgView.setImageDrawable(null);
    imgView.setVisibility(View.INVISIBLE);

    addAnimation(arcView, mSeries1Index, 19, 3000, imgView, R.drawable.ic_avatar_man, COLOR_BLUE);
    addAnimation(arcView, mSeries2Index, 45, 11000, imgView, R.drawable.ic_avatar_woman, COLOR_PINK);

    arcView.addEvent(
            new DecoEvent.Builder(64).setIndex(mSeries1Index).setDelay(11000).setDuration(5000).build());

    addAnimation(arcView, mSeries3Index, 36, 19000, imgView, R.drawable.ic_avatar_child, COLOR_YELLOW);

    arcView.addEvent(
            new DecoEvent.Builder(79).setIndex(mSeries2Index).setDelay(19000).setDuration(5000).build());

    arcView.addEvent(
            new DecoEvent.Builder(100).setIndex(mSeries1Index).setDelay(19000).setDuration(5000).build());

    arcView.addEvent(new DecoEvent.Builder(EventType.EVENT_COLOR_CHANGE, COLOR_BACK).setIndex(mBack1Index)
            .setDelay(27000).setDuration(2000).setListener(new DecoEvent.ExecuteEventListener() {
                @Override
                public void onEventStart(DecoEvent event) {
                    imgView.setImageDrawable(
                            ContextCompat.getDrawable(getActivity(), R.drawable.ic_avatar_group));
                    showAvatar(true, imgView);
                }

                @Override
                public void onEventEnd(DecoEvent event) {

                }
            }).build());

    addFinishAnimation(arcView, mSeries3Index, 1250, 30000, imgView);
    addFinishAnimation(arcView, mSeries2Index, 1500, 30000, null);
    addFinishAnimation(arcView, mSeries1Index, 1750, 30000, null);
}