List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java
void showBitmap(Bitmap bitmap, boolean isImmediate) { Drawable drawable = new BitmapDrawable(getResources(), bitmap); showDrawable(drawable, isImmediate); }
From source file:com.example.util.ImageUtils.java
/** * // www .ja va2 s .co m */ private static StateListDrawable getMaskDrawable(Context context) { StateListDrawable stateDrawable = new StateListDrawable(); int statePressed = android.R.attr.state_pressed; final Resources res = context.getResources(); stateDrawable.addState(new int[] { statePressed }, new BitmapDrawable(res, BitmapFactory.decodeResource(res, R.drawable.banner_pressed))); return stateDrawable; }
From source file:com.hunch.ImageManager.java
protected Runnable getDownloadTask(final URL url, final Callback callback, final Context context, final CachePolicy... level) { // hander to deal with the image once UI thread has it final Handler imgHandler = new Handler() { @Override/*from w w w . j a v a2s . c o m*/ public void handleMessage(Message msg) { Drawable d = (Drawable) msg.obj; callback.callComplete(d); } }; // the job to grab the image off the network and cache it Runnable task = new Runnable() { @Override public void run() { try { Log.d(Const.TAG, String.format("[%d] fetching image from URI (%s)", Thread.currentThread().getId(), url.toString())); InputStream iStream = ImageManager.this.getInputStream(url); final Bitmap image = BitmapFactory.decodeStream(iStream); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), image); final Message msg = imgHandler.obtainMessage(); msg.obj = drawable; // send off the message with the drawable imgHandler.sendMessage(msg); // then cache the stream cacheBitmap(image, url, context, level); } catch (FileNotFoundException e) { Log.e(Const.TAG, "couldn't get image off network (404 error)"); } catch (IOException e) { Log.e(Const.TAG, "couldn't get image off network"); } } }; return task; }
From source file:com.flym.dennikn.activity.HomeActivity.java
private void selectDrawerItem(int position) { mCurrentDrawerPos = position;/*from www.j av a 2s .com*/ mIcon = null; Uri newUri; boolean showFeedInfo = true; switch (position) { case SEARCH_DRAWER_POSITION: newUri = EntryColumns.SEARCH_URI(mEntriesFragment.getCurrentSearch()); break; case 0: newUri = EntryColumns.ALL_ENTRIES_CONTENT_URI; break; case 1: newUri = EntryColumns.FAVORITES_CONTENT_URI; break; default: long feedOrGroupId = mDrawerAdapter.getItemId(position); if (mDrawerAdapter.isItemAGroup(position)) { newUri = EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId); } else { byte[] iconBytes = mDrawerAdapter.getItemIcon(position); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { mIcon = new BitmapDrawable(getResources(), bitmap); } newUri = EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId); showFeedInfo = false; } mTitle = mDrawerAdapter.getItemName(position); break; } if (!newUri.equals(mEntriesFragment.getUri())) { mEntriesFragment.setData(newUri, showFeedInfo); } mDrawerList.setItemChecked(position, true); // First open => we open the drawer for you if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) { PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false); if (mDrawerLayout != null) { mDrawerLayout.postDelayed(new Runnable() { @Override public void run() { mDrawerLayout.openDrawer(mLeftDrawer); } }, 500); } FeedDataContentProvider.addFeed(this, "https://dennikn.sk/slovensko/feed/", "Slovensko", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/svet/feed/", "Zahrani?ie", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/ekonomika/feed/", "Ekonomika", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/kultura/feed/", "Kultra", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/komentare/feed/", "Komentre", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/veda/feed/", "Veda", true); FeedDataContentProvider.addFeed(this, "https://dennikn.sk/blog/feed/", "Blogy", true); // FeedDataContentProvider.addFeed(this, "https://dennikn.sk/shooty/feed/", "Shooty", true); /* AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.welcome_title) .setItems(new CharSequence[]{getString(R.string.google_news_title), getString(R.string.add_custom_feed)}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 1) { startActivity(new Intent(Intent.ACTION_INSERT).setData(FeedColumns.CONTENT_URI)); } else { startActivity(new Intent(HomeActivity.this, AddGoogleNewsActivity.class)); } } }); builder.show(); */ } // Set title & icon switch (mCurrentDrawerPos) { case SEARCH_DRAWER_POSITION: getSupportActionBar().setTitle(android.R.string.search_go); getSupportActionBar().setIcon(R.drawable.action_search); break; default: getSupportActionBar().setTitle(mTitle); if (mIcon != null) { getSupportActionBar().setIcon(mIcon); } else { getSupportActionBar().setIcon(null); } break; } // Put the good menu invalidateOptionsMenu(); }
From source file:cn.com.caronwer.activity.AuthSecondActivity.java
private void setPicToView(Intent data) { Bundle extras = data.getExtras();/* w ww .j av a2s . co m*/ if (extras != null) { Bitmap bitmap = extras.getParcelable("data"); Drawable drawable = new BitmapDrawable(null, bitmap); //String HeadPortrait = BitmapUtil.getImgStr(bitmap); switch (imgType) { case 0: cardNoImg.setImageDrawable(drawable); cardNoImg.setVisibility(View.VISIBLE); cardNoUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("Sfz", HeadPortrait); // isCardNoImgSuccess = true; break; case 1: drivingLicenseImg.setImageDrawable(drawable); drivingLicenseImg.setVisibility(View.VISIBLE); drivingLicenseUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("Driver", HeadPortrait); // isDrivingLicenseImgSuccess = true; break; case 2: carHeadImg.setImageDrawable(drawable); carHeadImg.setVisibility(View.VISIBLE); carHeadUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("CarFront", HeadPortrait); // isCarHeadImgSuccess = true; break; case 3: carTailImg.setImageDrawable(drawable); carTailImg.setVisibility(View.VISIBLE); carTailUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("CarBack", HeadPortrait); // isCarTailImgSuccess = true; break; case 4: carLeftImg.setImageDrawable(drawable); carLeftImg.setVisibility(View.VISIBLE); carLeftUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("CarLeft", HeadPortrait); // isCarLeftImgSuccess = true; break; case 5: carRightImg.setImageDrawable(drawable); carRightImg.setVisibility(View.VISIBLE); carRightUpload.setVisibility(View.INVISIBLE); // jsonObject.addProperty("CarRight", HeadPortrait); // isCarRightImgSuccess = true; break; } } }
From source file:com.itsherpa.andg.imageloader.ContactImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView./*www. j a v a2 s . c om*/ * * @param imageView * The ImageView to set the bitmap to. * @param bitmap * The new bitmap to set. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(imageView.getDrawable()); } else { imageView.setBackgroundDrawable(imageView.getDrawable()); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPaymentWithoutScan.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("Activity sss1", "sds"); if (requestCode == GALLERY_REQUEST) { if (resultCode == RESULT_OK) { if (data != null) { uri = data.getData();/*from w ww.j a v a 2 s . co m*/ image_path = uri.getPath(); // addNewVehicalFragment.setImagePath(image_path); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; try { // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); options.inSampleSize = calculateInSampleSize(options, 100, 100); options.inJustDecodeBounds = false; Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); car_image.setImageBitmap(image); car_image1.setImageBitmap(image); /* Bitmap bitmap = ((BitmapDrawable)car_image.getDrawable()).getBitmap(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(Environment.getExternalStorageDirectory(),"car.jpg"); FileOutputStream fo; try { fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (IOException e) { e.printStackTrace(); } image_path=destination.getAbsolutePath(); // car_image.setImageBitmap(bitmap); addNewVehicalFragment.setImagePath(image_path);*/ } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (requestCode == CAMERA_REQUEST) { if (resultCode == RESULT_OK) { if (data.hasExtra("data")) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); /* ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(Environment.getExternalStorageDirectory(),"car.jpg"); FileOutputStream fo; try { fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (IOException e) { e.printStackTrace(); } image_path=destination.getAbsolutePath();*/ car_image.setImageBitmap(bitmap); car_image1.setImageBitmap(bitmap); // addNewVehicalFragment.setImagePath(image_path); } else if (data.getExtras() == null) { Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show(); BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath()); //img_view_drivingLicense.setImageDrawable(thumbnail); car_image.setImageDrawable(thumbnail); car_image1.setImageDrawable(thumbnail); } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } }
From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("Activity sss1", "sds"); if (requestCode == GALLERY_REQUEST) { if (resultCode == RESULT_OK) { if (data != null) { uri = data.getData();//from www. j av a2s .c o m image_path = uri.getPath(); addNewVehicalFragment.setImagePath(image_path); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; try { // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); options.inSampleSize = calculateInSampleSize(options, 100, 100); options.inJustDecodeBounds = false; Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); // File mm=new File(image_path); car_image.setImageBitmap(image); car_image1.setImageBitmap(image); Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap(); /* ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(getCacheDir(),"car.jpg"); FileOutputStream fo; try { fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (IOException e) { e.printStackTrace(); } image_path=destination.getAbsolutePath(); // car_image.setImageBitmap(bitmap); addNewVehicalFragment.setImagePath(image_path);*/ } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (requestCode == CAMERA_REQUEST) { if (resultCode == RESULT_OK) { if (data.hasExtra("data")) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(getCacheDir(), "car.jpg"); FileOutputStream fo; try { fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (IOException e) { e.printStackTrace(); } image_path = destination.getAbsolutePath(); car_image.setImageBitmap(bitmap); car_image1.setImageBitmap(bitmap); addNewVehicalFragment.setImagePath(image_path); } else if (data.getExtras() == null) { Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show(); BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath()); //img_view_drivingLicense.setImageDrawable(thumbnail); car_image.setImageDrawable(thumbnail); car_image1.setImageDrawable(thumbnail); } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if (result != null && AddNewVehicalFragment.scanFlag) { AddNewVehicalFragment.scanFlag = false; if (result.getContents() == null) { finish(); Toast.makeText(AddVehicalAndPayment.this, "Cancelled", Toast.LENGTH_LONG).show(); } else { //Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show(); //scan_txt.setText(""+result.getContents()); Log.e("result", result.getContents()); // getVinNumber(result.getContents()); vin_number = result.getContents(); getVinNumber(vin_number); } } } }
From source file:com.flym.dennikn.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);//from w ww .java 2 s.co m byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getSupportActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getSupportActionBar().setIcon(null); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { showSwipeProgress(); // If the service is not started, start it here to avoid an infinite loading if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) { MainApplication.getContext() .startService(new Intent(MainApplication.getContext(), FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); } } else { hideSwipeProgress(); } // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } } }
From source file:com.firefly.sample.castcompanionlibrary.cast.player.VideoCastControllerActivity.java
@SuppressWarnings("deprecation") @Override//from w w w . j av a2 s. c o m public void setImage(Bitmap bitmap) { if (null != bitmap) { if (mPageView instanceof ImageView) { ((ImageView) mPageView).setImageBitmap(bitmap); } else { mPageView.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap)); } } }