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.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);//from w  w  w.  j  a  va  2s .c o  m
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java

/**
 * /* w  w w.  ja  v  a  2 s . c om*/
 * 
 * @param localThumb
 *            
 * @param iv
 * @param thumbnailUrl
 *            
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // VideoMessageBody videoBody = (VideoMessageBody)
                // message.getBody();
                // System.err.println("video view is on click");
                // Intent intent = new Intent(activity,
                // ShowVideoActivity.class);
                // intent.putExtra("localpath", videoBody.getLocalUrl());
                // intent.putExtra("secret", videoBody.getSecret());
                // intent.putExtra("remotepath", videoBody.getRemoteUrl());
                // if (message != null && message.direct ==
                // EMMessage.Direct.RECEIVE && !message.isAcked
                // && message.getChatType() != ChatType.GroupChat) {
                // message.isAcked = true;
                // try {
                // EMChatManager.getInstance().ackMessageRead(message.getFrom(),
                // message.getMsgId());
                // } catch (Exception e) {
                // e.printStackTrace();
                // }
                // }
                // activity.startActivity(intent);

            }
        });

    } else {
        // new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv,
        // activity, message, this);
    }

}

From source file:com.euphor.paperpad.activities.fragments.GallerySlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    View rootView = inflater.inflate(R.layout.fragment_gallery_slide_page, container, false);

    // Set the title view to show the page number.
    //        ((TextView) rootView.findViewById(android.R.id.text1)).setText(
    //                getString(R.string.title_template_step, mPageNumber + 1));

    /// construct the view 
    final ImageView imag = (TouchImageView) rootView.findViewById(R.id.Image);
    //rootView.findViewById(R.id.container_galerry_img).setPadding(10, 0, 10, 0);

    //        imag.setOnClickListener(new OnClickListener() {
    //         /*from   w  w  w.  j  a  v a 2  s .  c om*/
    //         @Override
    //         public void onClick(View v) {
    //            ///rootView.findViewById(R.id.container_galerry_img).setPadding(10, 10, 10, 10);
    //            Log.e(" OnClickListener : ", " view "+v);
    //            imag.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    //         
    //         }
    //      });
    String path = "";
    boolean isFile = true;
    if (!illustration.getFullPath().isEmpty()) {
        //           path = "file:///"+illustration.getFullPath();
        path = illustration.getFullPath();
    } else if (!illustration.getPath().isEmpty()) {
        //         path = "file:///"+illustration.getPath();
        path = illustration.getPath();
    } else if (!illustration.getLink().isEmpty()) {
        path = illustration.getLink();
        isFile = false;
    } else if (!illustration.getFullLink().isEmpty()) {
        path = illustration.getFullLink();
        isFile = false;
    }
    if (isFile) {
        Glide.with(getActivity()).load(new File(path)).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                imag.setImageBitmap(resource);
            }
        });
    } else {
        Glide.with(getActivity()).load(path).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                imag.setImageBitmap(resource);
            }
        });
    }

    //      imageLoader.displayImage(path , imag);

    /* TextView txt = (TextView)rootView.findViewById(R.id.titleItem);
    txt.setText(str);
            
      ImageView closeImg = (ImageView)rootView.findViewById(R.id.unzoom);
    closeImg.setOnClickListener(new OnClickListener() {
             
     @Override
     public void onClick(View v) {
    activity.finish();
     }
    });*/

    return rootView;
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);//from ww w .ja  v  a  2  s .  co  m
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaButtons();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaButtons();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java

private void setThumbnailImage(ImageView mImageView, String imagePath) {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;//from   www .  ja v  a  2  s.  c o  m

    Bitmap bitmap = BitmapFactory.decodeFile(imagePath, bmOptions);
    mImageView.setImageBitmap(bitmap);
}

From source file:com.easemob.chatui.adapter.MessageAdapter.java

/**
 * /*from   ww  w  .  j  a v  a 2  s.co  m*/
 *
 * @param localThumb   
 * @param iv
 * @param thumbnailUrl 
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:cm.confide.ex.chips.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = getEntries().get(position);
    String displayName = entry.getDisplayName();
    String destination = entry.getDestination();
    if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
        displayName = destination;/*from www.  j a va  2s.c  o  m*/

        // We only show the destination for secondary entries, so clear it
        // only for the first level.
        if (entry.isFirstLevel()) {
            destination = null;
        }
    }

    final View itemView = convertView != null ? convertView : mInflater.inflate(getItemLayout(), parent, false);
    final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
    final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
    final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
    final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
    displayNameView.setText(displayName);
    if (!TextUtils.isEmpty(destination)) {
        destinationView.setText(destination);
    } else {
        destinationView.setText(null);
    }
    if (destinationTypeView != null) {
        final CharSequence destinationType = mQuery
                .getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel())
                .toString().toUpperCase();

        destinationTypeView.setText(destinationType);
    }

    if (entry.isFirstLevel()) {
        displayNameView.setVisibility(View.VISIBLE);
        if (imageView != null) {
            imageView.setVisibility(View.VISIBLE);
            final byte[] photoBytes = entry.getPhotoBytes();
            if (photoBytes != null) {
                final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                imageView.setImageBitmap(photo);
            } else {
                imageView.setImageResource(getDefaultPhotoResource());
            }
        }
    } else {
        displayNameView.setVisibility(View.GONE);
        if (imageView != null) {
            imageView.setVisibility(View.INVISIBLE);
        }
    }
    return itemView;
}

From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java

private void bindRcsFileTransferOutView(View view, Cursor cursor) {
    RcsFileTransferOutViewHolder holder = (RcsFileTransferOutViewHolder) view.getTag();
    holder.getTimestampText()/* w w w .  j  a v a  2s.  co m*/
            .setText(DateUtils.getRelativeTimeSpanString(cursor.getLong(holder.getColumnTimestampIdx()),
                    System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
    String mimeType = cursor.getString(holder.getColumnMimetypeIdx());
    StringBuilder sb = new StringBuilder(cursor.getString(holder.getColumnFilenameIdx()));
    long filesize = cursor.getLong(holder.getColumnFilesizeIdx());
    long transferred = cursor.getLong(holder.getColumnTransferredIdx());
    final ImageView imageView = holder.getFileImageView();
    imageView.setOnClickListener(null);
    imageView.setLayoutParams(mImageParamsDefault);
    imageView.setImageResource(R.drawable.ri_filetransfer_on);
    if (filesize != transferred) {
        holder.getProgressText()
                .setText(sb.append(" : ").append(Utils.getProgressLabel(transferred, filesize)).toString());
    } else {
        holder.getProgressText().setText(sb.append(" (")
                .append(FileUtils.humanReadableByteCount(filesize, true)).append(")").toString());
    }
    final Uri file = Uri.parse(cursor.getString(holder.getColumnContentIdx()));
    if (Utils.isImageType(mimeType)) {
        String filePath = FileUtils.getPath(mContext, file);
        Bitmap imageBitmap = null;
        if (filePath != null) {
            LruCache<String, BitmapCacheInfo> memoryCache = bitmapCache.getMemoryCache();
            BitmapCacheInfo bitmapCacheInfo = memoryCache.get(filePath);
            if (bitmapCacheInfo == null) {
                ImageBitmapLoader loader = new ImageBitmapLoader(mContext, memoryCache, MAX_IMAGE_WIDTH,
                        MAX_IMAGE_HEIGHT, new BitmapLoader.SetViewCallback() {
                            @Override
                            public void loadView(BitmapCacheInfo cacheInfo) {
                                imageView.setImageBitmap(cacheInfo.getBitmap());
                                imageView.setLayoutParams(mImageParams);
                            }
                        });
                loader.execute(filePath);
            } else {
                imageBitmap = bitmapCacheInfo.getBitmap();
            }
            if (imageBitmap != null) {
                imageView.setImageBitmap(imageBitmap);
                imageView.setLayoutParams(mImageParams);
            }
            imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Utils.showPicture(mActivity, file);
                }
            });
        }
    } else if (Utils.isAudioType(mimeType)) {
        imageView.setImageResource(R.drawable.headphone);
        imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Utils.playAudio(mActivity, file);
            }
        });
    }
    holder.getStatusText().setText(getRcsFileTransferStatus(cursor, holder));
    boolean undeliveredExpiration = cursor.getInt(holder.getColumnExpiredDeliveryIdx()) == 1;
    holder.getStatusText().setCompoundDrawablesWithIntrinsicBounds(
            undeliveredExpiration ? R.drawable.chat_view_undelivered : 0, 0, 0, 0);
}

From source file:biz.bokhorst.xprivacy.ActivityApp.java

@Override
protected void onNewIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*ww w  .j  a va  2  s  .com*/
    if (extras != null && extras.containsKey(cAction) && extras.getInt(cAction) == cActionRefresh) {
        // Update on demand check box
        ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand);
        boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
                false);
        imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());

        // Update restriction list
        if (mPrivacyListAdapter != null)
            mPrivacyListAdapter.notifyDataSetChanged();
    } else {
        setIntent(intent);
        recreate();
    }
}

From source file:com.c4mprod.utils.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.
 * // www. ja v a  2 s  .c o m
 * @param url
 * @param imageView
 * @param subfolder
 *            the subfolder in sdcard cache
 * 
 */
public void download(String url, ImageView imageView, String subfolder) {
    if (subfolder != null) {
        mSubfolder = "/" + subfolder;
    } else {
        mSubfolder = "";
    }

    mfolder = Environment.getExternalStorageDirectory().getPath() + "/Android/data/"
            + imageView.getContext().getPackageName() + "/files/images" + mSubfolder;

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
        try {
            (new File(mfolder)).mkdirs();
            (new File(mfolder + "/.nomedia")).createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but
        // all we need
        // to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        imageView.setBackgroundDrawable(null);
        if (listener != null) {
            listener.onImageDownloaded(imageView, url, mfolder + "/" + URLEncoder.encode(url),
                    imageView.getDrawable().getIntrinsicWidth(), imageView.getDrawable().getIntrinsicWidth());
        }
    }
}