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.airad.zhonghan.ui.components.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./*w w  w  . java 2  s .co m*/
 * 
 * @param imageView
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.keju.maomao.imagecache.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*  w  ww  .  j  ava2  s. co m*/
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public void setDrawerHeaderBackground() {
    String path1 = mainActivity.getPrefs().getString(PreferencesConstants.PREFERENCE_DRAWER_HEADER_PATH, null);
    if (path1 == null) {
        return;/*ww w. j av  a 2  s.co m*/
    }
    try {
        final ImageView headerImageView = new ImageView(mainActivity);
        headerImageView.setImageDrawable(drawerHeaderParent.getBackground());
        mImageLoader.get(path1, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                headerImageView.setImageBitmap(response.getBitmap());
                drawerHeaderView.setBackgroundResource(R.drawable.amaze_header_2);
            }

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.android.project.imagefetcher.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView.// w w  w.j  a va2 s  .c o m
 * 
 * @param imageView
 * @param bitmap
 */
@SuppressWarnings("deprecation")
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    //- ------------------------------------------------------- //
    String text = rawResult.getText();
    if (text != null && StringUtils.isUrl(text)) {
        if (text.contains("scan_login")) {
            statusView.setVisibility(View.GONE);
            viewfinderView.setVisibility(View.GONE);
            showConfirmLogin(text);//from  w  ww  .j  a v a2s. c  o m
            return;
        }
        if (text.contains("oschina.net")) {
            UIHelper.showUrlRedirect(CaptureActivity.this, text);
            finish();
            return;
        }
    }
    try {
        BarCode2 bc = BarCode2.parse(text);
        int type = bc.getType();
        switch (type) {
        case BarCode2.SIGN_IN:// 
            handleSignIn(bc);
            return;
        default:
            break;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //- ------------------------------------------------------- //
    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
        ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null
            && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
        resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
        return;
    }

    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.app_icon));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    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);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL,
            true)) {
        //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
        //        resultHandler.getResult(),
        //        historyManager,
        //        this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }
}

From source file:camera.AnotherCamera.java

/**
 * Scale the photo down and fit it to our image views.
 *
 * "Drastically increases performance" to set images using this technique.
 * Read more:http://developer.android.com/training/camera/photobasics.html
 *///from  w  ww .j av  a2  s .  com
private void setFullImageFromFilePath(String imagePath, ImageView imageView) {
    // Get the dimensions of the View
    int targetW = imageView.getWidth();
    int targetH = imageView.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;

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

From source file:com.gh4a.utils.ImageDownloader.java

/**
 * Download./*from  w  w w  .j a  v a 2s.co m*/
 * 
 * @param gravatarId the gravatar id
 * @param ivImage the iv image
 */
public void download(String gravatarId, ImageView ivImage) {
    String url = "http://www.gravatar.com/avatar.php?gravatar_id=" + gravatarId + "&size=60&d=mm";

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

    if (bitmap == null) {
        if (cancelPotentialDownload(url, ivImage)) {
            BitmapDownloaderTask task = new BitmapDownloaderTask(ivImage);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            ivImage.setImageDrawable(downloadedDrawable);
            task.execute(url);
        }
    } else {
        cancelPotentialDownload(url, ivImage);
        ivImage.setImageBitmap(bitmap);
    }
}

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

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView.// www. j  a v  a 2 s .c  o m
 * 
 * @param imageView
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

private void attachPhoto(File file) {

    if (file == null || !file.exists() || file.length() < 10) {
        aq.id(R.id.image_box).gone();/* ww w  .  j  a  va2  s .  co  m*/
        return;
    }

    AQUtility.debug("photo", file.length());

    sendEnable(false);
    BitmapAjaxCallback cb = new BitmapAjaxCallback() {

        @Override
        protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

            sendEnable(true);

            if (photo != null && bm != null) {
                iv.setImageBitmap(bm);
                String dim = bm.getWidth() + "x" + bm.getHeight();
                aq.id(R.id.text_dim).text(dim);
                String length = FormatUtility.scientificShort(photo.length()) + "b";
                aq.id(R.id.text_size).text(length);
                PostActivity.this.bm = bm;
            }

        }

    };

    cb.file(file).targetWidth(720);//.targetDim(false);

    aq.id(R.id.image_photo).image(cb);

    clear();

    this.photo = file;

    refreshButtons();
}

From source file:com.ehret.mixit.fragment.SessionDetailFragment.java

private void addSpeakerInfo(Talk conference) {
    //On vide les lments
    sessionPersonList.removeAllViews();//from   w ww .j a v a2s  .  c  om

    List<Member> speakers = new ArrayList<>();
    for (Speaker member : conference.getSpeakers()) {
        Member membre = MembreFacade.getInstance().getMembre(getActivity(), TypeFile.speaker.name(),
                member.getIdMember());

        if (membre != null) {
            speakers.add(membre);
        }
    }

    //On affiche les liens que si on a recuperer des choses
    if (!speakers.isEmpty()) {
        //On utilisait auparavant une liste pour afficher ces lments dans la page mais cette liste
        //empche d'avoir un ScrollView englobant pour toute la page. Nous utilisons donc un tableau

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {
            for (final Member membre : speakers) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_person, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);

                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView userName = (TextView) row.findViewById(R.id.person_user_name);
                TextView descriptif = (TextView) row.findViewById(R.id.person_shortdesciptif);
                TextView level = (TextView) row.findViewById(R.id.person_level);
                ImageView profileImage = (ImageView) row.findViewById(R.id.person_user_image);

                userName.setText(membre.getCompleteName());

                if (membre.getShortDescription() != null) {
                    descriptif.setText(membre.getShortDescription().trim());
                }

                //Recuperation de l'mage liee au profil
                Bitmap image = FileUtils.getImageProfile(getActivity(), membre);
                if (image == null) {
                    profileImage.setImageDrawable(getResources().getDrawable(R.drawable.person_image_empty));
                } else {
                    //On regarde dans les images embarquees
                    profileImage.setImageBitmap(image);
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((HomeActivity) getActivity()).changeCurrentFragment(PeopleDetailFragment
                                .newInstance(TypeFile.speaker.toString(), membre.getLogin(), 7),
                                TypeFile.speaker.toString());
                    }
                });

                tableLayout.addView(row);
            }
        }
        sessionPersonList.addView(tableLayout);
    }
}