List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
@Deprecated
public BitmapDrawable(java.io.InputStream is)
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public Drawable GetGraph(String urlString) throws IOException, URISyntaxException { HttpGet httpRequest = new HttpGet(new URL(ZENOSS_INSTANCE + urlString).toURI()); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); final long contentLength = bufHttpEntity.getContentLength(); //Log.e("GetGraph",Long.toString(contentLength)); if (contentLength >= 0) { InputStream is = bufHttpEntity.getContent(); Bitmap bitmap = BitmapFactory.decodeStream(is); /*ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 10, out); // ww w.ja v a2s . co m return new BitmapDrawable(BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())));*/ is.close(); return new BitmapDrawable(bitmap); } else { return null; } }
From source file:androidx.media.widget.VideoView2.java
@SuppressWarnings("deprecation") private void extractAudioMetadata() { if (!mIsMusicMediaType) { return;// www . j av a2s . c o m } mResources = getResources(); mManager = (WindowManager) getContext().getApplicationContext().getSystemService(Context.WINDOW_SERVICE); byte[] album = mRetriever.getEmbeddedPicture(); if (album != null) { Bitmap bitmap = BitmapFactory.decodeByteArray(album, 0, album.length); mMusicAlbumDrawable = new BitmapDrawable(bitmap); // TODO: replace with visualizer Palette.Builder builder = Palette.from(bitmap); builder.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // TODO: add dominant color for default album image. mDominantColor = palette.getDominantColor(0); if (mMusicView != null) { mMusicView.setBackgroundColor(mDominantColor); } } }); } else { mMusicAlbumDrawable = mResources.getDrawable(R.drawable.ic_default_album_image); } String title = mRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (title != null) { mMusicTitleText = title; } else { mMusicTitleText = mResources.getString(R.string.mcv2_music_title_unknown_text); } String artist = mRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); if (artist != null) { mMusicArtistText = artist; } else { mMusicArtistText = mResources.getString(R.string.mcv2_music_artist_unknown_text); } // Send title and artist string to MediaControlView2 MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mMusicTitleText); builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, mMusicArtistText); mMediaSession.setMetadata(builder.build()); // Display Embedded mode as default removeView(mSurfaceView); removeView(mTextureView); inflateMusicView(R.layout.embedded_music); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
public static BitmapDrawable scaleTo(BitmapDrawable bmd, float newSize) { Bitmap bm = bmd.getBitmap();/*from w w w.j ava2s . c o m*/ int width = bm.getWidth(); float scale = (float) (newSize / (float) width); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap bmNew = Bitmap.createBitmap(bm, 0, 0, width, width, matrix, true); return new BitmapDrawable(bmNew); }
From source file:com.amaze.filemanager.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {//from ww w . j a v a 2 s . c om personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); drawerHeaderView.setBackground(new BitmapDrawable(loadedImage)); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } @Override public void onLoadingStarted(String imageUri, View view) { super.onLoadingStarted(imageUri, view); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } }); // setting profile pic ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerProfilePic.setImageBitmap(loadedImage); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } } }
From source file:com.igniva.filemanager.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {//w w w. ja v a2 s. c o m personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { drawerHeaderView.setBackground(new BitmapDrawable(loadedImage)); } else drawerHeaderView.setBackgroundDrawable(new BitmapDrawable(loadedImage)); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent .setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } @Override public void onLoadingStarted(String imageUri, View view) { super.onLoadingStarted(imageUri, view); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent .setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } }); // setting profile pic ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerProfilePic.setImageBitmap(loadedImage); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } } }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {/*w w w .java 2 s . c o m*/ personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic mImageLoader.get(personCover.getUrl(), new ImageLoader.ImageListener() { @Override public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) { drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); if (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { drawerHeaderView.setBackground(new BitmapDrawable(response.getBitmap())); } else drawerHeaderView.setBackgroundDrawable(new BitmapDrawable(response.getBitmap())); } @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this, getString(R.string.no_cover_photo), Toast.LENGTH_LONG) .show(); } }); // setting profile pic mImageLoader.get(stringBuilder.toString(), new ImageLoader.ImageListener() { @Override public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) { drawerProfilePic.setImageBitmap(response.getBitmap()); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this, getString(R.string.no_profile_pic), Toast.LENGTH_LONG) .show(); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor( getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab))); } } }
From source file:self.philbrown.droidQuery.$.java
/** * Includes the given image inside of the selected views. If a view is an `ImageView`, its image * is set. Otherwise, the background image of the view is set. * @param image the bitmap image to include * @return this/*from w w w .j a v a 2 s . com*/ */ public $ image(Bitmap image) { for (View v : views) { if (v instanceof ImageView) { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(image)); } else { v.setBackgroundDrawable(new BitmapDrawable(image)); } } return this; }
From source file:self.philbrown.droidQuery.$.java
/** * For `ImageView`s, this will set the image to the given asset or url. Otherwise, it will set the * background image for the selected views. * @param source asset path, file path (starting with "file://") or URL to image * @param width specifies the output bitmap width * @param height specifies the output bitmap height * @param error if the given source is a file or asset, this receives a droidQuery wrapping the * current context and the {@code Throwable} error. Otherwise, this will receive an * Ajax error.//from w ww . j av a 2 s . c o m * @return this * @see AjaxOptions#error(Function) */ public $ image(final String source, int width, int height, final Function error) { if (source.startsWith("file://")) { try { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.ARGB_8888; if (width >= 0) opt.outWidth = width; if (height >= 0) opt.outHeight = height; Bitmap bitmap = BitmapFactory.decodeFile(source.substring(6), opt); for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } catch (Throwable t) { if (error != null) { error.invoke($.with(context), t); } } } else if (URLUtil.isValidUrl(source)) { AjaxOptions options = new AjaxOptions().url(source).type("GET").dataType("image").context(context) .global(false).redundancy(Redundancy.RESPOND_TO_ALL_LISTENERS).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { Bitmap bitmap = (Bitmap) params[0]; for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } }); if (error != null) { options.error(error); } if (width >= 0) { options.imageWidth(width); } if (height >= 0) { options.imageHeight(height); } $.ajax(options); } else { try { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inSampleSize = 1; opt.inPurgeable = true; opt.inInputShareable = false; if (width >= 0) opt.outWidth = width; if (height >= 0) opt.outHeight = height; Bitmap bitmap = BitmapFactory.decodeStream(context.getAssets().open(source), new Rect(0, 0, 0, 0), opt); for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } catch (Throwable t) { if (error != null) { error.invoke($.with(context), t); } } } return this; }
From source file:com.skytree.epubtest.BookViewActivity.java
private Drawable changeDrawableColor(Drawable drawable, int fromColor, int color) { Bitmap src = ((BitmapDrawable) drawable).getBitmap(); Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true); for (int x = 0; x < bitmap.getWidth(); x++) { for (int y = 0; y < bitmap.getHeight(); y++) { if (colorMatched(bitmap.getPixel(x, y), fromColor, 10)) { bitmap.setPixel(x, y, color); }/*from w w w .ja va 2 s. co m*/ } } return new BitmapDrawable(bitmap); }
From source file:com.xmobileapp.rockplayer.RockPlayer.java
/******************************** * /*from ww w. j a va2 s . c om*/ * set Background * ********************************/ public void setBackground() { try { String bgPath = null; RockOnPreferenceManager settings = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH); Log.i("BG", "BG"); if (settings.getBoolean(PREFS_CUSTOM_BACKGROUND, false)) { Log.i("DBG", "Setting up background"); if (display.getOrientation() == 0) bgPath = FILEX_BACKGROUND_PATH + PREFS_CUSTOM_BACKGROUND_PORTRAIT; else bgPath = FILEX_BACKGROUND_PATH + PREFS_CUSTOM_BACKGROUND_LANDSCAPE; Bitmap bgBitmap = BitmapFactory.decodeStream(new FileInputStream(new File(bgPath))); findViewById(R.id.songfest_container).setBackgroundDrawable(new BitmapDrawable(bgBitmap)); } else if (settings.getBoolean(PREFS_BACKGROUND_BLUR, false)) { Log.i("DBG", "Blurring Background"); System.gc(); /* * Blur&Dim the BG */ // getTheme().applyStyle(arg0, arg1) getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(0, 0, 0, 0))); // Have the system blur any windows behind this one. getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_DITHER, // WindowManager.LayoutParams.FLAG_DITHER); getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND); WindowManager.LayoutParams params = getWindow().getAttributes(); params.dimAmount = 0.625f; getWindow().setAttributes(params); } else { Log.i("DBG", "Clearing out background"); System.gc(); findViewById(R.id.songfest_container).setBackgroundDrawable(null); getWindow().setBackgroundDrawable(null); // Do something } // BitmapFactory.Options opts = new BitmapFactory.Options(); // opts.inJustDecodeBounds = true; // BitmapFactory.decodeFile(bgPath, opts); // int sampling = 1; // TODO::::: // opts.inJustDecodeBounds = false; // Bitmap bgBitmap = null; // if(opts.outHeight/display.getHeight() > opts.outWidth/display.getWidth()){ // int newHeight = (int)Math.round(opts.outHeight*(display.getWidth()/opts.outWidth)); // Bitmap tmpBitmap = Bitmap.createScaledBitmap( // BitmapFactory.decodeStream(new FileInputStream(bgPath), null, opts), // display.getWidth(), // newHeight, // false); // bgBitmap = Bitmap.createBitmap( // tmpBitmap, // 0, // (newHeight-display.getHeight())/2, // display.getWidth(), // display.getHeight(), // null, // false); // } else { // int newWidth = (int)Math.round(opts.outWidth*(display.getHeight()/opts.outHeight)); // Bitmap tmpBitmap = Bitmap.createScaledBitmap( // BitmapFactory.decodeStream(new FileInputStream(bgPath), null, opts), // newWidth, // display.getHeight(), // false); // bgBitmap = Bitmap.createBitmap( // tmpBitmap, // (newWidth-display.getWidth())/2, // 0, // display.getWidth(), // display.getHeight(), // null, // false); // } // findViewById(R.id.songfest_container) // .setBackgroundDrawable(new BitmapDrawable(bgBitmap)); } catch (Exception e) { e.printStackTrace(); } }