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.esource42.whyapp.utility.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.
 *//*from w ww  . java2 s  . c  om*/
public void download(String url, ImageView imageView, ProgressBar progress) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

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

From source file:com.kubotaku.android.sample.sensordataviewer.SensorDataActivity.java

private void showWeatherInfo(WeatherInfo weatherInfo) {

    ViewGroup cardView = (ViewGroup) findViewById(R.id.sensor_data_card_weather);
    cardView.setVisibility(View.VISIBLE);

    final String locationName = weatherInfo.getName();
    final float currentTemp = weatherInfo.getCurrentTempCelsius();
    final Bitmap icon = weatherInfo.getIcon();
    final int humidity = weatherInfo.getHumidity();
    final int pressure = weatherInfo.getPressure();

    TextView textLocation = (TextView) findViewById(R.id.sensor_data_text_weather_location);
    textLocation.setText(locationName);/*from   w w  w.j  a  va  2  s  .  c o  m*/

    TextView textCurrentTemp = (TextView) findViewById(R.id.sensor_data_text_weather_current_temp);
    textCurrentTemp.setText(String.format(Locale.getDefault(), "%.1f", currentTemp));

    TextView textMinMaxTemp = (TextView) findViewById(R.id.sensor_data_text_weather_minmax_temp);
    textMinMaxTemp.setText(String.format(Locale.getDefault(), "%d\n%dhPa", humidity, pressure));

    ImageView imageIcon = (ImageView) findViewById(R.id.sensor_data_img_weather);
    imageIcon.setImageBitmap(icon);
}

From source file:com.layer.atlas.cells.GeoCell.java

@Override
public View onBind(final ViewGroup cellContainer) {

    ViewGroup cellRoot = (ViewGroup) Tools.findChildById(cellContainer, R.id.atlas_view_messages_cell_geo);
    if (cellRoot == null) {
        cellRoot = (ViewGroup) LayoutInflater.from(cellContainer.getContext())
                .inflate(R.layout.atlas_view_messages_cell_geo, cellContainer, false);
        if (debug)
            Log.w(TAG, "geo.onBind() inflated geo cell");
    }/*from w ww  .  j a  va  2  s .  c o m*/

    ImageView geoImageMy = (ImageView) cellRoot.findViewById(R.id.atlas_view_messages_cell_geo_image_my);
    ImageView geoImageTheir = (ImageView) cellRoot.findViewById(R.id.atlas_view_messages_cell_geo_image_their);
    View containerMy = cellRoot.findViewById(R.id.atlas_view_messages_cell_geo_container_my);
    View containerTheir = cellRoot.findViewById(R.id.atlas_view_messages_cell_geo_container_their);

    boolean myMessage = messagesList.getLayerClient().getAuthenticatedUserId()
            .equals(messagePart.getMessage().getSender().getUserId());
    if (myMessage) {
        containerMy.setVisibility(View.VISIBLE);
        containerTheir.setVisibility(View.GONE);
    } else {
        containerMy.setVisibility(View.GONE);
        containerTheir.setVisibility(View.VISIBLE);
    }
    ImageView geoImage = myMessage ? geoImageMy : geoImageTheir;
    ShapedFrameLayout cellCustom = (ShapedFrameLayout) (myMessage ? containerMy : containerTheir);

    Object imageId = messagePart.getId();
    Bitmap bmp = (Bitmap) Atlas.imageLoader.getImageFromCache(imageId);
    if (bmp != null) {
        if (debug)
            Log.d(TAG, "geo.onBind() bitmap: " + bmp.getWidth() + "x" + bmp.getHeight());
        geoImage.setImageBitmap(bmp);
    } else {
        if (debug)
            Log.d(TAG, "geo.onBind() spec: " + spec);
        geoImage.setImageDrawable(Tools.EMPTY_DRAWABLE);
        // schedule image
        File tileFile = getTileFile(cellContainer.getContext());
        if (tileFile.exists()) {
            if (debug)
                Log.d(TAG, "geo.onBind() decodeImage: " + tileFile);
            // request decoding
            spec = Atlas.imageLoader.requestImage(imageId, new Atlas.FileStreamProvider(tileFile),
                    (int) Tools.getPxFromDp(150, cellContainer.getContext()),
                    (int) Tools.getPxFromDp(150, cellContainer.getContext()), false, this);
        } else {
            int width = 300;
            int height = 300;
            int zoom = 16;
            final String url = new StringBuilder().append("https://maps.googleapis.com/maps/api/staticmap?")
                    .append("format=png32&").append("center=").append(lat).append(",").append(lon).append("&")
                    .append("zoom=").append(zoom).append("&").append("size=").append(width).append("x")
                    .append(height).append("&").append("maptype=roadmap&").append("markers=color:red%7C")
                    .append(lat).append(",").append(lon).toString();

            Atlas.downloadQueue.schedule(url, tileFile, this);

            if (debug)
                Log.d(TAG, "geo.onBind() show stub and download image: " + tileFile);
        }
    }

    // clustering
    cellCustom.setCornerRadiusDp(16, 16, 16, 16);
    if (AtlasMessagesList.CLUSTERED_BUBBLES) {
        if (myMessage) {
            if (this.clusterHeadItemId == this.clusterItemId && !this.clusterTail) {
                cellCustom.setCornerRadiusDp(16, 16, 2, 16);
            } else if (this.clusterTail && this.clusterHeadItemId != this.clusterItemId) {
                cellCustom.setCornerRadiusDp(16, 2, 16, 16);
            } else if (this.clusterHeadItemId != this.clusterItemId && !this.clusterTail) {
                cellCustom.setCornerRadiusDp(16, 2, 2, 16);
            }
        } else {
            if (this.clusterHeadItemId == this.clusterItemId && !this.clusterTail) {
                cellCustom.setCornerRadiusDp(16, 16, 16, 2);
            } else if (this.clusterTail && this.clusterHeadItemId != this.clusterItemId) {
                cellCustom.setCornerRadiusDp(2, 16, 16, 16);
            } else if (this.clusterHeadItemId != this.clusterItemId && !this.clusterTail) {
                cellCustom.setCornerRadiusDp(2, 16, 16, 2);
            }
        }
    }

    return cellRoot;
}

From source file:com.waveface.installer.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.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *///from   w w  w.j  a v a  2  s.c  o  m
public void download(String url, ImageView imageView, int resId) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

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

From source file:com.example.feed.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.
 *//*from ww w  . j a v a 2s. com*/
public void download(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
        Log.d(LOG_TAG, "cache miss for " + url);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);

    }
}

From source file:com.baksu.screenbroadcast2.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.
 *///from www  .jav  a  2 s. c om
public void download(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        Log.i("imageUp", "? ?");
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.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.
 * /*w  w w  .ja v  a2 s.com*/
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 * @param emptyResId
 *            The resource id to use as empty view
 */
public void download(String url, ImageView imageView, int emptyResId) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

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

From source file:com.cube.storm.ui.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, Bitmap bitmap) {
    ImageView tab = new ImageView(getContext());
    tab.setImageBitmap(bitmap);
    tab.setColorFilter(tabIconTint);//from   www.  j  a  v  a  2  s .co  m
    tab.setScaleType(ScaleType.FIT_CENTER);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm);

    tab.setPadding(padding + tabPadding, padding, padding + tabPadding, padding);

    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.ab.view.sliding.AbSlidingPlayView.java

/**
 * ./*from  ww  w . j  av  a2 s .  co  m*/
 */
public void creatIndex() {
    //?
    navLinearLayout.removeAllViews();
    mNavLayoutParent.setHorizontalGravity(navHorizontalGravity);
    navLinearLayout.setGravity(Gravity.CENTER);
    navLinearLayout.setVisibility(View.VISIBLE);
    count = mListViews.size();
    navLayoutParams.setMargins(5, 5, 5, 5);
    for (int j = 0; j < count; j++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(navLayoutParams);
        if (j == 0) {
            imageView.setImageBitmap(displayImage);
        } else {
            imageView.setImageBitmap(hideImage);
        }
        navLinearLayout.addView(imageView, j);
    }
}

From source file:com.example.hifadhi.utils.CacheImageDownloader.java

/**
 * Same as {@link #download(String, ImageView)}, with the possibility to
 * provide an additional cookie that will be used when the image will be
 * retrieved.//  w  w  w .  j a  va2s.c  o  m
 * 
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 * @param cookie
 *            A cookie String that will be used by the http connection.
 */
public void download(final String url, final ImageView imageView, final String cookie) {
    resetPurgeTimer();
    final Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView, cookie);
    } else {
        CacheImageDownloader.cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        imageView.setVisibility(View.VISIBLE);

    }
}