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.goliathonline.android.kegbot.ui.WhatsOnFragment.java

private void onTapQueryComplete(Cursor cursor) {
    if (cursor == null)
        return;//from  w w  w.  j a  v a2 s . com
    else if (cursor.getCount() == 0)
        return;

    final LayoutInflater inflater = getActivity().getLayoutInflater();

    final View onTapView = inflater.inflate(R.layout.whats_on_tap, mRootView, false);
    final TextView onTapTitleView = (TextView) onTapView.findViewById(R.id.on_tap);
    final TextView onTapSubTitleView = (TextView) onTapView.findViewById(R.id.whats_on_subtitle);
    final ProgressBar kegProgress = (ProgressBar) onTapView.findViewById(R.id.kegProgress);
    final ImageView tapImage = (ImageView) onTapView.findViewById(R.id.tap_image);
    final TextView degreesText = (TextView) onTapView.findViewById(R.id.temperature);

    cursor.moveToFirst();
    final String tapImageUrl = cursor.getString(TapsQuery.IMAGE_URL);

    if (!TextUtils.isEmpty(tapImageUrl)) {
        BitmapUtils.fetchImage(getActivity(), tapImageUrl, null, null,
                new BitmapUtils.OnFetchCompleteListener() {
                    public void onFetchComplete(Object cookie, Bitmap result) {
                        if (result != null) {
                            tapImage.setImageBitmap(result);
                        }
                    }
                });
    }

    onTapTitleView.setText(cursor.getString(TapsQuery.BEER_NAME));

    final Double mlRemain = cursor.getDouble(TapsQuery.VOL_REMAIN);
    final String pintsRemain = UnitUtils.mlToPint(Double.toString(mlRemain));
    final Double mlTotal = cursor.getDouble(TapsQuery.VOL_SIZE);
    final Double mlPoured = mlTotal - mlRemain;
    final String pintsPoured = UnitUtils.mlToPint(Double.toString(mlPoured));
    final Double lastTemp = cursor.getDouble(TapsQuery.LAST_TEMP);
    final String temperature = UnitUtils.cToF(Double.toString(lastTemp));

    onTapSubTitleView.setText("Pints Poured: " + pintsPoured + " (" + pintsRemain + " remain)");

    kegProgress.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
    kegProgress.setProgress((int) cursor.getDouble(TapsQuery.PERCENT_FULL));

    degreesText.setText(temperature + DEGREES);

    cursor.close();
    mRootView.addView(onTapView);

}

From source file:cn.com.vapk.vstore.client.util.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.
 * /*ww  w  .  j  a  va 2 s .co m*/
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public final void download(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        try {
            forceDownload(url, imageView);
        } catch (RuntimeException e) {
            if (Logger.ERROR)
                L.e("ImageDownloader forceDownload fail.", e);
        }
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.google.identitytoolkit.demo.GitkitDemo.java

private void showAccount(GitkitUser user) {
    ((TextView) findViewById(R.id.account_email)).setText(user.getEmail());

    if (user.getDisplayName() != null) {
        ((TextView) findViewById(R.id.account_name)).setText(user.getDisplayName());
    }//ww w. jav a2 s  . co m

    if (user.getPhotoUrl() != null) {
        final ImageView pictureView = (ImageView) findViewById(R.id.account_picture);
        new AsyncTask<String, Void, Bitmap>() {

            @Override
            protected Bitmap doInBackground(String... arg) {
                try {
                    byte[] result = HttpUtils.get(arg[0]);
                    return BitmapFactory.decodeByteArray(result, 0, result.length);
                } catch (IOException e) {
                    return null;
                }
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {
                if (bitmap != null) {
                    pictureView.setImageBitmap(bitmap);
                }
            }
        }.execute(user.getPhotoUrl());
    }
}

From source file:com.abcs.sociax.gimgutil.ImageWorker.java

public void loadImage(Object data, ImageView imageView) {

    if (data == null) {
        return;//from   w  ww . ja  v  a  2s  . c  om
    }

    Bitmap bitmap = null;

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

    if (bitmap != null) {
        // Bitmap found in memory cache
        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);

        // NOTE: This uses a custom version of AsyncTask that has been
        // pulled from the
        // framework and slightly modified. Refer to the docs at the top of
        // the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data);
    }
}

From source file:com.p2c.thelife.SettingsFragment.java

private void rotateImage(float angle) {
    ImageView imageView = (ImageView) getActivity().findViewById(R.id.settings_image);

    if (m_updatedBitmap == null) {
        m_updatedBitmap = Utilities.getBitmapFromDrawable(imageView.getDrawable());
    }/*ww  w .  j a  v  a  2s.  c  om*/

    // rotate image in memory
    Matrix matrix = new Matrix();
    matrix.setRotate(angle);
    m_updatedBitmap = Bitmap.createBitmap(m_updatedBitmap, 0, 0, m_updatedBitmap.getWidth(),
            m_updatedBitmap.getHeight(), matrix, true);

    // save new image bitmap
    imageView.setImageBitmap(m_updatedBitmap);
}

From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(mContext).inflate(com.alex.view.R.layout.banner_item, container, false);
    final ImageView imageView = (ImageView) view.findViewById(com.alex.view.R.id.iv_banner_item);
    // ???/*w ww . j ava  2s .  co  m*/
    position %= pictureList.size();

    //imageView.setImageResource(pictureList.get(position));
    final int p = position;
    new DownloadPic().getById(pictureList.get(position), new DownloadPic.Listener() {
        @Override
        public void succeed(final Bitmap bm) {
            handler.post(new Runnable() {
                @Override
                public void run() {

                    AppLog.debug("positiont",
                            pictureList.get(p).toString() + " " + pictureList.size() + "+" + p);

                    imageView.setImageBitmap(bm);
                }
            });

        }

        @Override
        public void failed() {

        }
    });
    container.addView(view);
    return view;
}

From source file:com.justwayward.reader.view.pdfview.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 ww  . j  ava 2 s.com*/

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            pageClickListener.onClick(view);
        }
    });
    attacher.update();
    ((ViewPager) container).addView(v, 0);

    return v;
}

From source file:zxing.util.CaptureActivity.java

License:asdf

/**
 * A valid barcode has been found, so give an indication of success and show
 * the results.//from   w w w.j  a v  a  2  s  . c  o m
 * 
 * @param rawResult
 *            The contents of the barcode.
 * @param scaleFactor
 *            amount by which thumbnail was scaled
 * @param barcode
 *            A greyscale bitmap of the camera data which was decoded.
 */
public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
    inactivityTimer.onActivity();
    //lastResult = rawResult;
    String url = "http://192.168.1.105:8080/ExTraceWebService_war/REST/Domain";
    beepManager.playBeepSoundAndVibrate();
    String resultString = rawResult.getText();
    Intent mIntent = getIntent();
    if (mIntent.getStringExtra("Action").equals("Pkg")) {
        switch (Integer.parseInt(mIntent.getStringExtra("role").toString().substring(0, 1))) {
        //(
        //
        case 1:
            Log.i("teasdfjsadf", mIntent.getStringExtra("role").toString());
            if (resultString.startsWith("1")) {

                url = url + "/receiveExpressSheetId/id/" + resultString + "/uid/"
                        + mIntent.getStringExtra("role").toString();
                startOnePkgExp(url);//
                //            Intent intentTest=new Intent(this,BaiduActivity.class);
                //            startActivity(intentTest);
                break;
            } else if (resultString.startsWith("8")) {
                url = url + "/dispatchExpressSheetId/id/" + resultString + "/uid/"
                        + mIntent.getStringExtra("role").toString();
                changePkgToStatus4(url);//
                break;
            } else {
                break;
            }
            //
        case 2:
            if (resultString.startsWith("8")) {

                url = url + "/receiveExpressSheetId/id/" + resultString + "/uid/"
                        + mIntent.getStringExtra("role").toString();
                startOnePkgExp(url);//
                //               Intent intentTest=new Intent(this,BaiduActivity.class);
                //               startActivity(intentTest);
                break;
            }

            break;
        //
        case 3:
            if (resultString.startsWith("1")) {
                url = url + "/packTransPackage/PackageID/" + "8001" + "/ExpressID/" + resultString;
                //               Intent intentTest=new Intent(this,BaiduActivity.class);
                //               startActivity(intentTest);
                break;
            } else if (resultString.startsWith("8")) {
                url = url + "/unpackTransPackage/" + resultString + "/uid/"
                        + mIntent.getStringExtra("role").toString();
                break;
            } else {
                break;
            }

        }
    } else if (mIntent.getStringExtra("Action").equals("exp")) {
        //
        switch (Integer.parseInt(mIntent.getStringExtra("role"))) {
        case 1:
            //finsh();
            break;
        case 2:
            if (resultString.startsWith("8")) {
                url = url + "/unpackTransPackage/" + "8001";
                //               Intent intentTest=new Intent(this,BaiduActivity.class);
                //               startActivity(intentTest);
                break;
            } else {

            }
            //finsh();
            break;
        //
        case 3:

        }
    }

    drawResultPoints(barcode, scaleFactor, rawResult);
    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    ParsedResult result = ResultParser.parseResult(rawResult);
    String contents = result.getDisplayResult().replace("\r", "");
    CharSequence displayContents = contents;
    lastResult = contents;
    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);
}

From source file:com.thx.bizcat.util.ImageDownloader.java

public void download(String url, ImageView imageView, String files) {
    resetPurgeTimer();/*from  w  w  w.  j  a v a  2s.  c  om*/
    Bitmap bitmap = getBitmapFromCache(url);
    this.files = files;

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

From source file:com.fivehundredpxdemo.android.storage.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing logic). A memory and disk
 * cache will be used if an {@link ImageCache} has been set using
 * {@link ImageWorker#addImageCache}. If the image is found in the memory cache, it
 * is set immediately, otherwise an {@link android.os.AsyncTask} will be created to asynchronously load the
 * bitmap./*from  w  ww .j a v  a2  s .  com*/
 *
 * @param data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 */
public void loadImage(Object data, ImageView imageView, Bitmap loadingBitmap) {
    if (data == null) {
        return;
    }

    Bitmap bitmap = null;

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

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

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // On HC+ we execute on a quad thread executor. There really isn't much extra
            // benefit to having a really large pool of threads. Having more than one will
            // likely benefit network bottlenecks though.
            task.executeOnExecutor(QUAD_THREAD_EXECUTOR, data);
        } else {
            // Otherwise pre-HC the default is a thread pool executor (not ideal, serial
            // execution or a smaller number of threads would be better).
            task.execute(data);
        }
    }
}