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.rainmakerlabs.bleepsample.BleepService.java

public void imgShow(Bitmap bitmap, String strImgMsg) {
    MainActivity.adlib.put(strImgMsg, bitmap);
    Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size());
    Log.i("Portal", "Image added for key " + strImgMsg);

    if (MainActivity.myGallery == null)
        return;//from  w w w  .  j a  v a 2 s .  c o  m

    if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized
        LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent();

        if (MainActivity.gal_size < 1) {
            ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash);
            imgSplash.setVisibility(View.INVISIBLE);
        }

        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setGravity(Gravity.CENTER);

        ImageView imageview = new ImageView(getApplicationContext());
        imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000));
        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageview.setImageBitmap(bitmap);

        //Add a button to go with it
        Button btnBuy = new Button(getApplicationContext());
        LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        btnParams.setMargins(-10, -10, -10, -10);
        btnBuy.setLayoutParams(btnParams);
        btnBuy.setText("Buy Now (" + strImgMsg + ")");
        btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap));
        btnBuy.setTextColor(Color.WHITE);

        btnBuy.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent newActivity = new Intent(getApplicationContext(), WebActivity.class);
                newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/");
                startActivity(newActivity);
            }
        });

        layout.addView(imageview);
        layout.addView(btnBuy);
        MainActivity.myGallery.addView(layout);
        MainActivity.gal_size++;
    }

}

From source file:com.baseproject.image.ImageWorker.java

public void loadImage(Object data, ImageView imageView, ImageCallback imageCallback) {
    Bitmap bitmap = null;//  ww  w . java2 s.  co  m

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

    if (bitmap != null) {
        // Bitmap found in memory cache
        if (null != imageView) {
            imageView.setImageBitmap(bitmap);
        }
        if (imageCallback != null) {
            imageCallback.imageLoaded(bitmap, String.valueOf(data));
        }
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, imageCallback);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mContext.getResources(), mLoadingBitmap, task);
        if (null != imageView) {
            imageView.setImageDrawable(asyncDrawable);
        }
        task.execute(data);
    }
}

From source file:com.iped.ipcam.bitmapfun.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#setImageCache(ImageCache)}. 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.//from   w  w  w .j  av  a2  s .c om
 *
 * @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) {
    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);
        if (loadImageListener != null) {
            loadImageListener.updateResolution(String.valueOf(data), bitmap.getWidth(), bitmap.getHeight());
        }
    } 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.airad.zhonghan.ui.components.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#setImageCache(ImageCache)}. 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.
 * //from  w  w w .  java2  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) {
    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, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);
        task.execute(data);
    }
}

From source file:com.he5ed.lib.cloudprovider.picker.PickerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.cp_fragment_picker, container, false);
    mEmptyView = (LinearLayout) rootView.findViewById(android.R.id.empty);
    if (savedInstanceState != null) {
        switch (savedInstanceState.getInt("empty_view_visibility")) {
        case View.VISIBLE:
            mEmptyView.setVisibility(View.VISIBLE);
            ImageView icon = (ImageView) mEmptyView.findViewById(R.id.empty_icon_image_view);
            TextView title = (TextView) mEmptyView.findViewById(R.id.empty_title_text_view);
            TextView detail = (TextView) mEmptyView.findViewById(R.id.empty_detail_text_view);
            Bitmap bitmap = savedInstanceState.getParcelable("icon_drawable");
            icon.setImageBitmap(bitmap);
            title.setText(savedInstanceState.getCharSequence("title_text"));
            detail.setText(savedInstanceState.getCharSequence("detail_text"));
            break;
        case View.INVISIBLE:
            mEmptyView.setVisibility(View.INVISIBLE);
            break;
        case View.GONE:
            mEmptyView.setVisibility(View.GONE);
            break;
        }//from  w  w  w.j  a v a2 s.  co  m
    }
    RecyclerListView recyclerView = (RecyclerListView) rootView.findViewById(R.id.recyler_view);
    recyclerView.setEmptyView(mEmptyView);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(mAdapter);

    return rootView;
}

From source file:com.android.project.imagefetcher.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#setImageCache(ImageCache)}. 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.
 * //from w ww.j a  va2  s  .c o  m
 * @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) {
    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, 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.openerp.support.listview.OEListViewAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    viewRow = convertView;//from w  w  w. j  a  va 2s  . co  m
    parentView = parent;
    LayoutInflater inflater = ((MainActivity) context).getLayoutInflater();
    if (viewRow == null) {
        viewRow = inflater.inflate(this.resource_id, parent, false);
    }
    row = this.rows.get(position);
    rowdata = row.getRow_data();
    for (final Integer control_id : controlClickHandler.keySet()) {
        viewRow.findViewById(control_id).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                controlClickHandler.get(control_id).controlClicked(position, rows.get(position), viewRow);
            }
        });
    }

    for (int i = 0; i < this.to.length; i++) {
        final String key = from[i];
        if (booleanEvents.contains(from[i])) {
            handleBinaryBackground(row.getRow_id(), key, to[i], viewRow, position);
        } else if (backgroundChange.containsKey(key)) {
            String backFlag = rowdata.get(key).toString();
            if (!backFlag.equals("false")) {
                backFlag = "true";
            }
            int color = backgroundChange.get(key).get(backFlag);
            viewRow.findViewById(this.to[i]).setBackgroundColor(color);
            continue;
        } else if (imageCols.contains(from[i])) {
            String data = rowdata.get(from[i]).toString();
            if (!data.equals("false")) {
                ImageView imgView = (ImageView) viewRow.findViewById(this.to[i]);
                imgView.setImageBitmap(Base64Helper.getBitmapImage(context, data));
            }
        } else {
            TextView txvObj = null;
            WebView webview = null;
            if (!webViewControls.containsKey(this.from[i])) {
                txvObj = (TextView) viewRow.findViewById(this.to[i]);
            } else {
                if (webViewControls.get(this.from[i])) {
                    webview = (WebView) viewRow.findViewById(this.to[i]);
                    webview.getSettings().setJavaScriptEnabled(true);
                    webview.getSettings().setBuiltInZoomControls(true);
                } else {
                    txvObj = (TextView) viewRow.findViewById(this.to[i]);
                }
            }

            String key_col = this.from[i];
            String alt_key_col = key_col;
            if (key_col.contains("|")) {
                String[] splits = key_col.split("\\|");
                key_col = splits[0];
                alt_key_col = splits[1];
            }
            String data = rowdata.get(key_col).toString();
            if (data.equals("false") || TextUtils.isEmpty(data)) {
                data = rowdata.get(alt_key_col).toString();
            }
            if (this.cleanColumn.contains(key_col)) {
                data = HTMLHelper.htmlToString(data);
            }

            if (datecols.contains(key_col)) {
                if (date_format != null) {
                    data = OEDate.getDate(data, TimeZone.getDefault().getID(), date_format);
                } else {
                    data = OEDate.getDate(data, TimeZone.getDefault().getID());
                }
            }

            if (!data.equals("false")) {
                try {
                    StringBuffer inputdata = new StringBuffer();
                    JSONArray tmpData = new JSONArray(data);
                    for (int k = 0; k < tmpData.length(); k++) {
                        if (tmpData.get(k) instanceof JSONArray) {
                            if (tmpData.getJSONArray(k).length() == 2) {
                                inputdata.append(tmpData.getJSONArray(k).getString(1));
                                inputdata.append(",");
                            }
                        } else {
                            inputdata.append(tmpData.getString(0));
                            inputdata.append(",");
                        }
                    }
                    int index = inputdata.lastIndexOf(",");
                    if (index > 0) {
                        inputdata.deleteCharAt(index);
                    }
                    txvObj.setText(inputdata.toString());
                } catch (Exception e) {
                    if (this.toHtml.contains(key_col)) {
                        if (webViewControls.get(this.from[i])) {
                            String customHtml = data;
                            webview.loadData(customHtml, "text/html", "UTF-8");
                        } else {
                            txvObj.setText(HTMLHelper.stringToHtml(data));
                        }
                    } else {
                        txvObj.setText(data);
                    }

                }

            } else {
                txvObj.setText("");
            }
        }
    }
    if (this.canChangeBackground && !viewRow.isSelected()) {
        boolean flag = Boolean.parseBoolean(rowdata.get(conditionKey).toString());
        if (flag) {
            viewRow.setBackgroundResource(colors[1]);

        } else {
            viewRow.setBackgroundResource(colors[0]);
        }
    }
    if (viewListener != null) {
        viewRow = viewListener.listViewOnCreateListener(position, viewRow, this.rows.get(position));
    }

    return viewRow;
}

From source file:com.mobicage.rogerthat.AbstractHomeActivity.java

private void loadQR() {
    if (CloudConstants.isCityApp()) {
        final TextView loyaltyText = (TextView) findViewById(R.id.loyalty_text);
        loyaltyText.setText(getString(R.string.loyalty_card_description, getString(R.string.app_name)));
        final ImageView imageView = (ImageView) findViewById(R.id.qrcode);
        final Bitmap qrBitmap = mService.getIdentityStore().getIdentity().getQRBitmap();
        if (qrBitmap != null) {
            imageView.setImageBitmap(
                    ImageHelper.getRoundedCornerBitmap(qrBitmap, UIUtils.convertDipToPixels(this, 5)));
        }/*from w ww.  java  2  s  .  c  o m*/
    }
}

From source file:com.binomed.showtime.android.util.images.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  w w  w  .  j a v a 2  s. c  om
private void forceDownload(String url, ImageView imageView, Context context) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    Bitmap image = getFileDrawable(url);
    if (image != null) {
        imageView.setImageBitmap(image);
    } else if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

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

From source file:com.elephant.ediyou.imagecache.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#setImageCache(ImageCache)}. 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.//from ww  w .ja v  a  2s .  c  om
 *
 * @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) {
    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.closeTimer();
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        //            imageView.closeTimer();
        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);
    }
}