List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:se.droidgiro.scanner.CaptureActivity.java
public void handleDecode(final Invoice invoice, int fieldsFound, Bitmap debugBmp) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); ImageView debugImageView = (ImageView) findViewById(R.id.debug_image_view); if (prefs.getBoolean(PreferencesActivity.KEY_DEBUG_IMAGE, false) && (debugBmp != null)) { debugImageView.setVisibility(View.VISIBLE); debugImageView.setImageBitmap(debugBmp); } else if (debugImageView.getVisibility() != View.GONE) { debugImageView.setVisibility(View.GONE); }/*w w w . ja v a2 s. co m*/ int fieldsScanned = invoice.getLastFieldsDecoded(); if (fieldsScanned > 0) { boolean scanContainsNewData = false; /* * The following segment will copy data from scanned invoice object * into our currentInvoice and keep track of new data read. * Beep/Vibrate will only occur if scan contains new data. */ if ((fieldsScanned & Invoice.AMOUNT_FIELD) == Invoice.AMOUNT_FIELD) { if (!(currentInvoice.getAmount() == invoice.getAmount() && currentInvoice.getAmountFractional() == invoice.getAmountFractional())) { currentInvoice.setAmount(invoice.getAmount(), invoice.getAmountFractional()); scanContainsNewData = true; } } if ((fieldsScanned & Invoice.DOCUMENT_TYPE_FIELD) == Invoice.DOCUMENT_TYPE_FIELD) { if (currentInvoice.getInternalDocumentType() != invoice.getInternalDocumentType()) { currentInvoice.setDocumentType(invoice.getInternalDocumentType()); scanContainsNewData = true; } } if ((fieldsScanned & Invoice.GIRO_ACCOUNT_FIELD) == Invoice.GIRO_ACCOUNT_FIELD) { Log.v(TAG, "Giro accout scanned. Current account = " + currentInvoice.getGiroAccount() + ". New invoice giro account = " + invoice.getGiroAccount()); if (!invoice.getGiroAccount().equals(currentInvoice.getGiroAccount())) { currentInvoice.setRawGiroAccount(invoice.getRawGiroAccount()); Log.v(TAG, "Copied giro account = " + invoice.getGiroAccount()); scanContainsNewData = true; } } if ((fieldsScanned & Invoice.REFERENCE_FIELD) == Invoice.REFERENCE_FIELD) { if (!invoice.getReference().equals(currentInvoice.getReference())) { currentInvoice.setReference(invoice.getReference()); scanContainsNewData = true; } } if (scanContainsNewData) playBeepSoundAndVibrate(); } Log.v(TAG, "CurrentInvoice = " + currentInvoice); if (currentInvoice.isReferenceDefined()) resultListHandler.setReference(currentInvoice.getReference()); if (currentInvoice.isAmountDefined()) resultListHandler.setAmount(currentInvoice.getCompleteAmount()); if (currentInvoice.isGiroAccountDefined()) resultListHandler.setAccount(currentInvoice.getGiroAccount()); if (resultListHandler.hasNewData()) { resultListHandler.setNewData(false); } Log.v(TAG, "Got invoice " + invoice); /* If scan on every hit */ // int fieldsScanned = invoice.getLastFieldsDecoded(); // if (fieldsScanned > 0) { // playBeepSoundAndVibrate(); // final List<NameValuePair> params = new ArrayList<NameValuePair>(); // if ((fieldsScanned & Invoice.AMOUNT_FIELD) == Invoice.AMOUNT_FIELD) // params.add(new BasicNameValuePair("amount", invoice // .getCompleteAmount())); // if ((fieldsScanned & Invoice.DOCUMENT_TYPE_FIELD) == // Invoice.DOCUMENT_TYPE_FIELD) // params.add(new BasicNameValuePair("type", invoice.getType())); // if ((fieldsScanned & Invoice.GIRO_ACCOUNT_FIELD) == // Invoice.GIRO_ACCOUNT_FIELD) // params.add(new BasicNameValuePair("account", invoice // .getGiroAccount())); // if ((fieldsScanned & Invoice.REFERENCE_FIELD) == // Invoice.REFERENCE_FIELD) // params.add(new BasicNameValuePair("reference", invoice // .getReference())); // // sendFields(params); // // } // if (invoice.isComplete()) { // resultListHandler.setSent(true); // this.scanButton.setText(getString(R.string.scan_state_scan)); // onContentChanged(); // } else if (!paused) { handler.sendEmptyMessageDelayed(R.id.restart_preview, SCAN_DELAY_MS); } onContentChanged(); }
From source file:com.elephant.ediyou.imagecache2.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.// w w w . j a v a2 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.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); // imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setScaleType(ImageView.ScaleType.FIT_XY); // 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.geeker.door.imgcache.ImageDownloader.java
/** * bitmapzho/*ww w . j av a2s . c om*/ * * @param view * @param bitmap */ public void setBitmapByView(View view, Bitmap bitmap) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; imageView.setImageBitmap(bitmap); } else if (view instanceof ImageSwitcher) { ImageSwitcher imageSwitcher = (ImageSwitcher) view; imageSwitcher.setImageDrawable(new BitmapDrawable(bitmap)); } }
From source file:es.uma.lcc.tasks.EncryptionUploaderTask.java
private void displayEncryptedImage(String path) { ImageView imageView = (ImageView) mMainActivity.findViewById(R.id.imageView); imageView.setVisibility(ImageView.VISIBLE); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bmp = BitmapFactory.decodeFile(path, options); int w = options.outWidth; int h = options.outHeight; if (w >= 2048 || h >= 2048) { double factor = (w > h ? 2048.0 / w : 2048.0 / h); imageView.setImageBitmap(Bitmap.createScaledBitmap(bmp, (int) (factor * w), (int) (factor * h), false)); } else {//from w w w .ja v a 2 s.c o m imageView.setImageBitmap(bmp); } }
From source file:com.airad.zhonghan.ui.components.ImageWorker.java
public void loadImage(Object data, ImageView imageView, ProgressBar progressBar) { if (data == null) { return;//from w ww. java 2s.c o m } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); if (progressBar != null) { progressBar.setVisibility(View.INVISIBLE); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, progressBar); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); task.execute(data); if (progressBar != null) { progressBar.setVisibility(View.INVISIBLE); } } }
From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java
/** * In this function (prescribed by Android), we collect all information * about the new vehicle and input it into a vehicle object. * This is then saved./* ww w. j a va 2s . c o m*/ * * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addinventory); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); uController = new UserController(getApplicationContext()); // TODO: Needs to smell more MVCish //vehicleImage = (ImageButton) findViewById(R.id.vehicleImage); gallery = (LinearLayout) findViewById(R.id.addinventorygallery); delete = (Button) findViewById(R.id.delete); vehicleName = (EditText) findViewById(R.id.vehicleField); vehicleQuantity = (EditText) findViewById(R.id.quantityField); vehicleComments = (EditText) findViewById(R.id.commentsField); vehiclePublic = (Switch) findViewById(R.id.ispublic); done = (Button) findViewById(R.id.button); location = (EditText) findViewById(R.id.locationField); vehicle = new Vehicle(); //Assign and display the current location geolocation = new Geolocation(); try { current = geolocation.getCurrentLocation(getApplicationContext(), this); location.setText(current.getPostalCode()); } catch (IllegalArgumentException e) { location.setText("Geolocation cannot be determined."); } /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ categorySpinner = (Spinner) findViewById(R.id.categorySpinner); categorySpinner.setAdapter(new ArrayAdapter<VehicleCategory>(this, android.R.layout.simple_spinner_dropdown_item, VehicleCategory.values())); categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleCategory = (VehicleCategory) categorySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ qualitySpinner = (Spinner) findViewById(R.id.qualitySpinner); qualitySpinner.setAdapter(new ArrayAdapter<VehicleQuality>(this, android.R.layout.simple_spinner_dropdown_item, VehicleQuality.values())); qualitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleQuality = (VehicleQuality) qualitySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); final boolean loadVehicle = getIntent().hasExtra("vehiclePosition"); Vehicle loaded; if (loadVehicle) { position = getIntent().getIntExtra("vehiclePosition", 0); loaded = UserSingleton.getCurrentUser().getInventory().getList().get(position); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first vehicle.setPhotoIds(loaded.getPhotoIds()); vehicleName.setText(loaded.getName()); vehicleQuantity.setText(loaded.getQuantity().toString()); vehicleComments.setText(loaded.getComments()); vehiclePublic.setChecked(loaded.getPublic()); qualitySpinner.setSelection(loaded.getQuality().getPosition()); categorySpinner.setSelection(loaded.getCategory().getPosition()); // TODO: Fix null error issue //location.setText(loaded.getLocation().getPostalCode()); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (UniqueID uid : vehicle.getPhotoIds()) { photos.add(ldm.loadPhoto(uid.getID())); } for (Photo photo : photos) { ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } //default the photo to a new photo if we are not loading a vehicle else { // TODO: Default photo? Here or set in Vehicle? Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); vehicle.deletePhotoArrayList(getApplicationContext()); } LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } /** * This onClick listener implements the function that clicking on the default * image box at the top of the vehicle page will open the camera and allow the * user to take a photo which will be saved directly to the vehicle object */ gallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakePictureIntent(); } }); /** * This onClick listener occurs when someone clicks delete. This will delete the photo * that is initialized in the view. */ delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //vehicle.setPhoto(new Photo(getApplicationContext())); //vehicleImage.setBackground(new BitmapDrawable(getResources(), vehicle.getPhoto().getImage())); vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (Photo photo1 : photos) { ldm.deletePhoto(photo1.getUid().getID()); } photos.clear(); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first if (vehicle.getPhotoIds().size() > 0 && UserSingleton.getDownloadPhotos()) { gallery.removeAllViews(); } for (UniqueID uid : vehicle.getPhotoIds()) { if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } }); /** * This onClick listener occurs after done button is clicked. This would save * the object to inventory -- which then makes it appear in the inventory tab. * * Taken from Oracle Documentation - we found we were required to catch the * possibility that a number might be the wrong format, or not even a number * at all. Accessed November 3, 2015. * * @see <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-">Oracle</a> */ done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // vehicle.setPhoto(vehicleImage); Geolocation geolocation1 = new Geolocation(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); if (vehicleName.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Please enter name", Toast.LENGTH_SHORT).show(); return; } if (vehicleQuantity.getText().toString().equals("0") || vehicleQuantity.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Quantity cannot be 0", Toast.LENGTH_SHORT).show(); return; } vehicle.setName(vehicleName.getText().toString()); vehicle.setCategory(vehicleCategory); vehicle.setQuality(vehicleQuality); vehicle.setLocation(geolocation1.setSpecificLocation(getApplicationContext(), AddInventoryActivity.this, location.getText().toString())); //http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int- //Nov. 3/ 2015 //the error should never occur as we force the user to input a numeric value, but //we are required to catch it anyway try { vehicle.setQuantity(Integer.parseInt(vehicleQuantity.getText().toString())); } catch (NumberFormatException e) { e.printStackTrace(); } vehicle.setComments(vehicleComments.getText().toString()); vehicle.setPublic(vehiclePublic.isChecked()); vehicle.setBelongsTo(UserSingleton.getCurrentUser().getUserName()); for (Photo photo : photos) { vehicle.addPhoto(photo.getUid()); ldm.savePhoto(photo); } //add the vehicle to our current user. if (loadVehicle) { //UserSingleton.getCurrentUser().getInventory().getList().add(position, vehicle); uController.getUserInventoryItems().add(position, vehicle); //UserSingleton.getCurrentUser().getInventory().getList().remove(position+1); uController.getUserInventoryItems().remove(position + 1); } else { //UserSingleton.getCurrentUser().addItem(vehicle); uController.getCurrentUser().addItem(vehicle); } //save the user to ensure all changes are updated uController.saveCurrentUser(); Gson gson = new Gson(); String s = gson.toJson(vehicle); Log.i("SizeOfCar", Integer.toString(s.length())); /* //dont start a new activity if we are editing a vehicle if(!loadVehicle) { Intent intent = new Intent(AddInventoryActivity.this, MainMenu.class); startActivity(intent); }*/ finish(); } }); gallery.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } return true; } }); }
From source file:com.synconset.ImageFetcher.java
public void fetch(Integer id, ImageView imageView, int colWidth, int rotate) { resetPurgeTimer();//w w w . j av a2 s .c o m this.colWidth = colWidth; this.origId = id; Bitmap bitmap = getBitmapFromCache(id); if (bitmap == null) { forceDownload(id, imageView, rotate); } else { cancelPotentialDownload(id, imageView); imageView.setImageBitmap(bitmap); } }
From source file:com.life.wuhan.util.ImageDownloader.java
public void download(String url, ImageView imageView) { resetPurgeTimer();//w ww. j a va2s.c o m Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }
From source file:com.mobicage.rogerthat.GroupDetailActivity.java
private void handleCrop(int resultCode, Intent result) { T.UI();/*www .j av a 2 s. co m*/ if (resultCode == RESULT_OK) { final ImageView newGroupAvatar = ((ImageView) findViewById(R.id.update_group_avatar_img)); Bitmap newAvatar = squeezeImage(Crop.getOutput(result)); if (newAvatar != null) { newGroupAvatar.setImageBitmap(newAvatar); mPhotoSelected = true; } } else if (resultCode == Crop.RESULT_ERROR) { UIUtils.showLongToast(this, Crop.getError(result).getMessage()); } }
From source file:com.secretlisa.lib.utils.BaseImageLoader.java
public void download(String url, ImageView imageView) { resetPurgeTimer();//from w w w . j a v a 2s .co m Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { Log.v(TAG, "bitmap is null,download from web"); forceDownload(url, imageView); } else { Log.v(TAG, "bitmap is not null"); cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }