Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.wisc.cs407project.ImageLoader.ImageLoader.java

public void DisplayImage(ScaleObject scaleObject, ImageView imageView) {
    imageViews.put(imageView, scaleObject.imageLocation);
    Bitmap bitmap = memoryCache.get(scaleObject.imageLocation);
    if (bitmap != null) {
        scaleObject.image = bitmap;//from  www  . j  av a 2  s  . co  m
        imageView.setImageBitmap(bitmap);
        imageView.setBackgroundResource(R.drawable.gray_image_border);
    } else {
        queuePhoto(scaleObject, imageView);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from   w  ww .  j  a v a2s .c  o  m
    byte[] raw = obj.getRaw();

    if (raw == null) {
        Pair<JSONObject, byte[]> p = splitRaw(content);
        content = p.first;
        raw = p.second;
    }

    LinearLayout inner = new LinearLayout(context);
    inner.setLayoutParams(CommonLayouts.FULL_WIDTH);
    inner.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(inner);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    BitmapFactory bf = new BitmapFactory();
    imageView.setImageBitmap(bf.decodeByteArray(raw, 0, raw.length));
    inner.addView(imageView);

    ImageView iconView = new ImageView(context);
    iconView.setImageResource(R.drawable.play);
    iconView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    inner.addView(iconView);
}

From source file:com.vk.sdk.dialogs.VKShareDialog.java

private void addBitmapToPreview(Bitmap sourceBitmap) {
    if (getActivity() == null)
        return;/* ww  w.  jav a2 s  .  co m*/
    Bitmap b = VKUIHelper.getRoundedCornerBitmap(sourceBitmap, SHARE_PHOTO_HEIGHT, SHARE_PHOTO_CORNER_RADIUS);
    if (b == null)
        return;
    ImageView iv = new ImageView(getActivity());
    iv.setImageBitmap(b);
    iv.setAdjustViewBounds(true);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(mPhotoLayout.getChildCount() > 0 ? SHARE_PHOTO_MARGIN_LEFT : 0, 0, 0, 0);

    mPhotoLayout.addView(iv, params);
    mPhotoLayout.invalidate();
    mPhotoScroll.invalidate();
}

From source file:com.cleverua.test.thumbs.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the provided ImageView. The
 * binding is immediate if the image is found in the cache and will be done asynchronously
 * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//* w  w  w  . j  a va 2 s .c  o  m*/
public void download(String url, ImageView imageView, Drawable placeHolder) {

    Bitmap bitmap = bitmapCache.getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView, placeHolder);
    } else {
        removePotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:ch.carteggio.ui.ConversationIconLoader.java

/**
 * Load a conversation picture and display it using the supplied {@link ImageView} instance.
 *
 * <p>//from  w  w w.j  a v  a2s.  c om
 * If a picture is found in the cache, it is displayed in the {@code ImageView}
 * immediately. Otherwise a {@link ConversationPictureRetrievalTask} is started to try to load the
 * conversation picture in a background thread. Depending on the result the contact picture, the group
 * picture or a fallback picture is then stored in the bitmap cache.
 * </p>
 *
 * @param conversationId
 *         The id of the conversation for which we need to find the image.
 * @param image
 *         The {@code ImageView} instance to receive the picture.
 *
 * @see #mBitmapCache
 * @see #calculateFallbackBitmap(Address)
 */
public void loadConversationPicture(long conversationId, ImageView image) {
    Bitmap bitmap = getBitmapFromCache(conversationId);
    if (bitmap != null) {
        // The picture was found in the bitmap cache
        image.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(conversationId, image)) {
        ConversationPictureRetrievalTask task = new ConversationPictureRetrievalTask(image, conversationId);
        AsyncDrawable asyncDrawable = new AsyncDrawable(mResources,
                calculateFallbackBitmap(new String[] { "none" }), task);
        image.setImageDrawable(asyncDrawable);
        try {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } catch (RejectedExecutionException e) {
            // We flooded the thread pool queue... use a fallback picture
            image.setImageBitmap(calculateFallbackBitmap(new String[] { "none" }));
        }
    }
}

From source file:com.mallapp.utils.ImageLoader.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageLoader#processBitmap(Object)} to define the processing logic). If the image is
 * found in the memory cache, it is set immediately, otherwise an {@link AsyncTask} will be
 * created to asynchronously load the bitmap.
 *
 * @param data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *///w w  w  .  j  a  va 2  s. co m
public void loadImage(Object data, ImageView imageView) {

    if (data == null) {
        imageView.setImageBitmap(mLoadingBitmap);

        return;
    }

    Bitmap bitmap = null;

    if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (bitmap != null) {
        // Bitmap found in memory cache
        bitmap = getCroppedBitmap(bitmap);
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        task.execute(data);
    }
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodDetail.java

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

    mContext = getActivity();//from   ww w  .  j a  va 2s  .  co m

    isFirstDepth = getArguments().getBoolean("isFirstDepth");
    Bundle bundle = getArguments().getBundle("bundle");

    vodAssetId = bundle.getString("vodAssetId");
    byte[] logoImage = bundle.getByteArray("logoImg");
    String title = bundle.getString("title");
    String hd = bundle.getString("hd");
    String grade = bundle.getString("grade");
    String director = bundle.getString("director");
    String actor = bundle.getString("actor");
    String price = bundle.getString("price");
    String contents = bundle.getString("contents");

    Bitmap bmp = BitmapFactory.decodeByteArray(logoImage, 0, logoImage.length);
    ImageView logoImg = (ImageView) layout.findViewById(R.id.logo_img);
    logoImg.setImageBitmap(bmp);

    if (title != null)
        ((TextView) layout.findViewById(R.id.title)).setText(title);
    if (hd != null) {
        if (hd.equalsIgnoreCase("yes"))
            ((ImageView) layout.findViewById(R.id.hd_icon)).setVisibility(View.VISIBLE);
    }
    if (grade != null)
        ((ImageView) layout.findViewById(R.id.grade_icon)).setBackgroundResource(Util.getGrade(grade));
    if (director != null)
        ((TextView) layout.findViewById(R.id.director_name)).setText(" " + director);
    if (actor != null)
        ((TextView) layout.findViewById(R.id.actor_name)).setText(" " + actor);
    if (grade != null)
        ((TextView) layout.findViewById(R.id.grade_text)).setText(" " + grade);
    if (price != null)
        ((TextView) layout.findViewById(R.id.price_amount)).setText(" " + price);
    if (contents != null)
        ((TextView) layout.findViewById(R.id.contents)).setText(contents);

    // vod 
    ImageButton vod = (ImageButton) layout.findViewById(R.id.vod_zzim);
    vod.setOnClickListener(this);

    // tv? 
    ImageButton tv = (ImageButton) layout.findViewById(R.id.vod_tv_watching);
    tv.setOnClickListener(this);

    return layout;
}

From source file:com.franctan.pdfviewpager.library.adapter.PDFPagerAdapter.java

@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }/*from  w  w  w.java 2s. c o m*/

    PdfRenderer.Page page = getPDFPage(position);

    Bitmap bitmap = mBitmapPool.getBitmap(position);

    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    ((ViewPager) container).addView(v, 0);

    return v;
}

From source file:com.mb.kids_mind.Adapter.SimilarListAdapter.java

public void requestMyImage(ImageView image, String userImagePath) {
    AQuery aq = new AQuery(image);

    if (userImagePath.equals("")) {
        // aq.id(R.id.my_image).image(R.drawable.photo1);  
    } else {/*ww  w  . j av a 2s  .  c  o  m*/
        String url = Const.IMAGE_LOAD_URL + "/" + userImagePath;
        url = url.trim();
        aq.image(url, false, false, 0, 0, new BitmapAjaxCallback() { // my_image <== ImageView
            @Override
            public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                if (bm != null) {
                    iv.setImageBitmap(bm);
                }
            }
        });
    }
}

From source file:com.bonsai.btcreceive.ReceiveFragment.java

public void showAddress() {
    BTCFmt btcfmt = mBase.getBTCFmt();/*  w w  w .  ja  v  a  2s .c om*/

    Address addr = mBase.getWalletService().nextReceiveAddress();
    String addrstr = addr.toString();

    TextView addrtv = (TextView) getActivity().findViewById(R.id.receive_addr);
    addrtv.setText(addrstr);
    addrtv.setVisibility(View.VISIBLE);

    String ss = mBTCAmountEditText.getText().toString();
    long bb = btcfmt.parse(ss.toString());
    BigInteger amt = bb == 0 ? null : BigInteger.valueOf(bb);

    String uri = BitcoinURI.convertToBitcoinURI(addrstr, amt, null, null);

    mLogger.info("view address uri=" + uri);

    final int size = (int) (240 * getResources().getDisplayMetrics().density);

    // Load the QR bitmap.
    Bitmap bm = createBitmap(uri, size);
    if (bm != null) {
        ImageView iv = (ImageView) getActivity().findViewById(R.id.receive_qr_view);
        iv.setImageBitmap(bm);
        iv.setVisibility(View.VISIBLE);
    }

    // Find the HDAddress object associated with this address.
    HDAddressDescription addrdesc = mBase.getWalletService().findAddress(addr);
    mHDAddress = addrdesc.hdAddress;
    mTransitioned = false;

    mFiatAmountEditText.setFocusable(false);
    mFiatAmountEditText.setFocusableInTouchMode(false);
    mBTCAmountEditText.setFocusable(false);
    mBTCAmountEditText.setFocusableInTouchMode(false);
}