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:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * After returning from the camera activity, get the photo information
 * and send it into the structure to get it ready.
 *//*w  w w. ja v  a  2 s  .co  m*/

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        Photo photo = new Photo(imageBitmap);
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        //gallery.removeAllViews();
        gallery.addView(newImage);
        photos.add(photo);
    }

}

From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext());
    tab.setImageBitmap(iProvider.getBitmap(resId));

    addTab(position, tab);/*from w  w w.java 2s  .c  om*/
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

private void populateLayoutBlocks() {
    List<BlockContainerEntry> entries;
    try {//from   w w w  . j  ava 2  s .c  o m
        Repository repository = Repository.getDefaultRepository(this);
        BlockContainer blocks = repository.getBlocks();
        entries = blocks.getEntries(true);
    } catch (RepositoryException ex) {
        return;
    }

    LinearLayout layoutRow = null;

    for (BlockContainerEntry entry : entries) {
        View view = QuiltEditActivity.this.getLayoutInflater().inflate(R.layout.listentry_block_selector, null);

        ImageView image_thumbnail = (ImageView) view.findViewById(R.id.image_thumbnail);
        image_thumbnail.setImageBitmap(entry.getThumbnail());

        view.setTag(entry.getBlockName());
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String blockName = (String) v.getTag();
                try {
                    getQuiltEditFragment().setBlock(blockName);
                } catch (Exception e) {
                    Handle.asRuntimeError(e);
                }
            }
        });

        if (m_layout_blocks.getOrientation() == LinearLayout.HORIZONTAL) {
            m_layout_blocks.addView(view);
        } else {
            if (layoutRow != null && layoutRow.getChildCount() == m_layout_blocks.getNumColumns()) {
                layoutRow = null;
            }
            if (layoutRow == null) {
                layoutRow = new LinearLayout(this);
                layoutRow.setOrientation(LinearLayout.HORIZONTAL);
                m_layout_blocks.addView(layoutRow);
            }
            layoutRow.addView(view);
        }
    }
}

From source file:com.daoofdev.weatherday.MainActivity.java

private void setImageForImageViewAndShow(Bitmap bitmap, ImageView imageView) {
    if (bitmap != null) {
        imageView.setImageBitmap(bitmap);
        imageView.setVisibility(View.VISIBLE);
    } else {/*w w  w .  java2 s .c om*/
        imageView.setVisibility(View.GONE);
    }
}

From source file:com.epubtest.hxfy.epubtest.BasePDFPagerAdapter.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;
    }// w  ww  .  j  a  v a2  s.c  o m

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

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

    iv.setImageBitmap(bitmap);
    container.addView(v, 0);

    return v;
}

From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java

private void addIconAndTextTab(int position, int resId, String title) {
    LinearLayout tab = new LinearLayout(getContext());
    tab.setGravity(Gravity.CENTER);/* ww w.j a va 2s .com*/

    TextView text = new TextView(getContext());
    text.setText(title);
    text.setTextColor(Color.WHITE);
    text.setGravity(Gravity.CENTER);
    text.setSingleLine();

    ImageView img = new ImageView(getContext());
    img.setImageBitmap(iProvider.getBitmap(resId));

    tab.addView(img);
    tab.addView(text);
    text.setPadding(10, 0, 0, 0);
    text.setTag("TEXT");

    addTab(position, tab);
}

From source file:com.agiro.scanner.android.CaptureActivity.java

public void handleDecode(Invoice invoice, Bitmap debugBmp) {
    //    inactivityTimer.onActivity();
    //    playBeepSoundAndVibrate();
    ImageView debugImageView = (ImageView) findViewById(R.id.debug_image_view);
    debugImageView.setImageBitmap(debugBmp);

    Log.v(TAG, "Got invoice " + invoice);
    if (invoice.isComplete()) {
        new Thread(new Runnable() {

            public void run() {
                AppEngineClient aec = new AppEngineClient(CaptureActivity.this, "patrik.akerfeldt@gmail.com");
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("reference", "12345678"));
                try {
                    Writer w = new StringWriter();
                    HttpResponse res = aec.makeRequest("/add", params);
                    Reader reader = new BufferedReader(
                            new InputStreamReader(res.getEntity().getContent(), "UTF-8"));
                    int n;
                    char[] buffer = new char[1024];
                    while ((n = reader.read(buffer)) != -1) {
                        w.write(buffer, 0, n);
                    }/*from  w  w  w . ja  v a 2s .c o m*/
                    Log.e(TAG, "Got: " + w.toString());
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }

            }
        }).start();
    }

    //TODO: the isValidCC checking should be optional
    //    if (resultMap.containsKey("reference")) {
    //        String str = resultMap.get("reference").toString();
    //        if (StringDecoder.isValidCC(str)) {
    //           new Thread(new Runnable() {
    //            
    //            public void run() {
    //                 AppEngineClient aec = new AppEngineClient(CaptureActivity.this, "patrik.akerfeldt@gmail.com");
    //                 List<NameValuePair> params = new ArrayList<NameValuePair>();
    //                 params.add(new BasicNameValuePair("reference", "12345678"));
    //                 try {
    //                    Writer w = new StringWriter();
    //                  HttpResponse res = aec.makeRequest("/add", params);
    //                  Reader reader = new BufferedReader(new InputStreamReader(res.getEntity().getContent(), "UTF-8"));
    //                  int n;
    //                  char[] buffer = new char[1024];
    //                  while ((n = reader.read(buffer)) != -1) {
    //                  w.write(buffer, 0, n);
    //                  }
    //                  Log.e(TAG, "Got: " + w.toString());
    //               } catch (Exception e) {
    //                  Log.e(TAG, e.getMessage(), e);
    //               }               
    //
    //            }
    //         }).start();
    //          reference = str;
    //        }
    //    }
    //    if (resultMap.containsKey("amount")) {
    //        String str = resultMap.get("amount").toString();
    //        if (StringDecoder.isValidCC(str)) {
    //            str = str.substring(0,str.length()-1);
    //            str = new StringBuffer(str).insert((str.length()-2), ",").toString();
    //            amount = str;
    //        }
    //    }
    //    if (resultMap.containsKey("account")) {
    //        String str = resultMap.get("account").toString();
    //        if (StringDecoder.isValidCC(str)) {
    //          account = str;
    //        }
    //    }
    //    if (resultMap.containsKey("debug")) {
    //        debug = resultMap.get("debug").toString();
    //    }
    populateList(invoice.getReference(), invoice.getCompleteAmount(), invoice.getGiroAccount(),
            "NOT SUPPORTED");
    onContentChanged();
}

From source file:com.example.android.navigationdrawer.QRCode.java

public void onQR(View v) {
    switch (v.getId()) {
    case R.id.button1:
        String qrInputText = MidiFile.readString;

        //Find screen size
        WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);//from   ww w . j  av  a  2s  .  c  o  m
        int width = point.x;
        int height = point.y;
        int smallerDimension = width < height ? width : height;
        smallerDimension = smallerDimension * 3 / 4;
        //Encode with a QR Code image
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT,
                BarcodeFormat.QR_CODE.toString(), smallerDimension);
        try {
            Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
            ImageView myImage = (ImageView) findViewById(R.id.imageView1);
            myImage.setImageBitmap(bitmap);

            // Get screen size
            Display display1 = this.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display1.getSize(size);
            int screenWidth = size.x;
            int screenHeight = size.y;

            // Get target image size
            Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap();
            int bitmapHeight = bitmap1.getHeight();
            int bitmapWidth = bitmap1.getWidth();

            // Scale the image down to fit perfectly into the screen
            // The value (250 in this case) must be adjusted for phone/tables displays
            while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) {
                bitmapHeight = bitmapHeight / 2;
                bitmapWidth = bitmapWidth / 2;
            }

            // Create resized bitmap image
            BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(),
                    Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));

            // Create dialog
            Dialog dialog = new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.thumbnail);

            ImageView image = (ImageView) dialog.findViewById(R.id.imageview);

            // !!! Do here setBackground() instead of setImageDrawable() !!! //
            image.setBackground(resizedBitmap);

            // Without this line there is a very small border around the image (1px)
            // In my opinion it looks much better without it, so the choice is up to you.
            dialog.getWindow().setBackgroundDrawable(null);
            dialog.show();

        } catch (WriterException e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.example.parking.ParkingInformationActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDBAdapter = new DBAdapter(this);
    setContentView(R.layout.activity_parking_information);
    mParkNameTV = (TextView) findViewById(R.id.tv_parking_name);
    mParkNameTV.setText(R.string.park_name_fixed);
    mParkNumberTV = (TextView) findViewById(R.id.tv_parking_number);
    mParkNumberTV.setText("?:" + this.getString(R.string.park_number_fixed));
    mCarType = (Spinner) findViewById(R.id.sp_car_type);
    mParkingType = (Spinner) findViewById(R.id.sp_parking_type);
    mLocationNumber = (Spinner) findViewById(R.id.sp_parking_location);
    mLicensePlateNumberTV = (TextView) findViewById(R.id.tv_license_plate_number);
    Intent intent = getIntent();//from  w  w  w  . ja v  a2  s  .  co m
    Bundle bundle = intent.getExtras();
    mLicensePlateNumberTV.setText(bundle.getString("licensePlate"));
    mStartTime = (TextView) findViewById(R.id.tv_start_time_arriving);
    new TimeThread().start();
    mOkButton = (Button) findViewById(R.id.bt_confirm_arriving);
    mOkButton.setOnClickListener(new InsertOnclickListener(mLicensePlateNumberTV.getText().toString(),
            mCarType.getSelectedItem().toString(), mParkingType.getSelectedItem().toString(),
            Integer.parseInt(mLocationNumber.getSelectedItem().toString()),
            DateFormat.format("yyyy-MM-dd HH:mm:ss", System.currentTimeMillis()).toString(), null, null,
            ""));
    mPhotoBT = (Button) findViewById(R.id.bt_camera_arriving);
    mPhotoBT.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mEnterImage != null) {
                Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT)
                        .show();
            } else {
                openTakePhoto();
            }
        }
    });
    mPhotoTitleTV = (TextView) findViewById(R.id.tv_photo_title_arriving);
    mEnterImageIV = (ImageView) findViewById(R.id.iv_photo_arriving);
    mEnterImageIV.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
            View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null); // 
            final AlertDialog dialog = new AlertDialog.Builder(ParkingInformationActivity.this).create();
            ImageView img = (ImageView) imgEntryView.findViewById(R.id.iv_large_image);
            Button deleteBT = (Button) imgEntryView.findViewById(R.id.bt_delete_image);
            img.setImageBitmap(mEnterImage);
            dialog.setView(imgEntryView); // dialog
            dialog.show();
            imgEntryView.setOnClickListener(new OnClickListener() {
                public void onClick(View paramView) {
                    dialog.cancel();
                }
            });
            deleteBT.setOnClickListener(new OnClickListener() {
                public void onClick(View paramView) {
                    mEnterImage = null;
                    mEnterImageIV.setImageResource(drawable.ic_photo_background_64px);
                    dialog.cancel();
                }
            });
        }
    });
    getActionBar().setDisplayHomeAsUpEnabled(true);
    IntentFilter filter = new IntentFilter();
    filter.addAction("ExitApp");
    registerReceiver(mReceiver, filter);
}

From source file:com.amaze.filemanager.ui.icons.IconHolder.java

/**
 * Method that returns a drawable reference of a FileSystemObject.
 *
 * @param iconView View to load the drawable into
 * @param fso The FileSystemObject reference
 * @param defaultIcon Drawable to be used in case no specific one could be found
 * @return Drawable The drawable reference
 *///from  w  w  w.ja  v  a2s . c  o m
public void loadDrawable(ImageView iconView, final String fso, Drawable defaultIcon) {
    if (!mUseThumbs) {
        return;
    }

    // Is cached?
    final String filePath = fso;
    if (this.mAppIcons.containsKey(filePath)) {
        iconView.setImageBitmap(this.mAppIcons.get(filePath));
        return;
    }
    mRequests.put(iconView, fso);
    new Thread(new Runnable() {
        @Override
        public void run() {

            mHandler.removeMessages(MSG_DESTROY);
            if (mWorkerThread == null || mWorkerHandler == null) {
                mWorkerThread = new HandlerThread("IconHolderLoader");
                mWorkerThread.start();
                mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper());
            }
            Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso);
            msg.sendToTarget();

        }
    }).start();
}