Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable BitmapDrawable.

Prototype

@Deprecated
public BitmapDrawable(java.io.InputStream is) 

Source Link

Document

Create a drawable by decoding a bitmap from the given input stream.

Usage

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java

/**
 * Updates activity background./*from  www . j a v  a  2  s .co  m*/
 */
private void updateBackground() {
    try {
        root.setBackgroundDrawable(
                new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(cacheBackgroundFile))));
    } catch (FileNotFoundException fNFEx) {
        Log.e(TAG, fNFEx.getMessage());
        fNFEx.printStackTrace();
    }
}

From source file:com.geeker.door.imgcache.ImageDownloader.java

/**
 * bitmapzho/*  w  ww.j  ava2 s . c o  m*/
 * 
 * @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:com.freerdp.freerdpcore.presentation.SessionActivity.java

@Override
public void OnSettingsChanged(int width, int height, int bpp) {

    if (bpp > 16)
        bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    else// w  w w . j a va2s .  c  o  m
        bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    session.setSurface(new BitmapDrawable(bitmap));

    // check this settings and initial settings - if they are not equal the server doesn't support our settings
    // FIXME: the additional check (settings.getWidth() != width + 1) is for the RDVH bug fix to avoid accidental notifications
    // (refer to android_freerdp.c for more info on this problem)
    BookmarkBase.ScreenSettings settings = session.getBookmark().getActiveScreenSettings();
    if ((settings.getWidth() != width && settings.getWidth() != width + 1) || settings.getHeight() != height
            || settings.getColors() != bpp)
        uiHandler.sendMessage(Message.obtain(null, UIHandler.DISPLAY_TOAST,
                getResources().getText(R.string.info_capabilities_changed)));
}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

private void setPictureToImageView(String pictureName, ImageView imageView) {
    Bitmap picture = null;/*  w ww.j a  v  a 2 s  .  com*/

    try {
        InputStream in = openFileInput(pictureName);
        picture = BitmapFactory.decodeStream(in);
        in.close();

        LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.editable_picture_frame);
        if (picture.getHeight() > picture.getWidth()) {
            Matrix m = new Matrix();
            m.postRotate(-90);
            picture = Bitmap.createBitmap(picture, 0, 0, picture.getWidth(), picture.getHeight(), m, true);
        }
        picture = Bitmap.createScaledBitmap(picture, d.getIntrinsicWidth(), d.getIntrinsicHeight(), true);

        d.setDrawableByLayerId(R.id.picture, new BitmapDrawable(picture));
        imageView.setImageDrawable(d);

        if (!hasPic)
            hasPic = (imageView.getId() == R.id.ImageView_far);

        // WTF ?
        // if (hasPic && (imageView.getId() == R.id.ImageView_far)) {
        // loadZoom();
        // }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.mods.grx.settings.GrxSettingsActivity.java

private void update_nav_header_bg() {
    boolean color_bg = true;
    if (getResources().getBoolean(R.bool.allow_user_panel_header_bg)) {
        String nav_header_file = Common.IconsDir + File.separator
                + getString(R.string.gs_nav_header_bg_image_name);
        File f = new File(nav_header_file);
        if (f.exists()) {
            update_text_panel_header_bg(getString(R.string.gs_image));
            Bitmap bitmap = GrxImageHelper.load_bmp_image(nav_header_file);
            if (bitmap != null) {
                FrameLayout header = (FrameLayout) mSVN.getHeaderView()
                        .findViewById(R.id.navigation_header_container);
                if (header != null) {
                    header.setBackground(new BitmapDrawable(bitmap));
                    color_bg = false;//from w  w  w.j a v a  2 s  .  co m
                }
            }
        } else
            update_text_panel_header_bg(getString(R.string.gs_default));
    }
    if (color_bg) {
        FrameLayout header = (FrameLayout) mSVN.getHeaderView().findViewById(R.id.navigation_header_container);
        if (header != null) {
            TypedArray a = this.getTheme().obtainStyledAttributes(new int[] { R.attr.svn_nav_header_bg });
            if (header != null)
                header.setBackgroundColor(a.getColor(0, 0));
            a.recycle();
        }
    }
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

@Override
public void OnGraphicsResize(int width, int height, int bpp) {
    // replace bitmap
    if (bpp > 16)
        bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    else//from   w  w w . ja v a2s . c om
        bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
    session.setSurface(new BitmapDrawable(bitmap));

    /* since sessionView can only be modified from the UI thread
     * any modifications to it need to be scheduled */
    uiHandler.sendEmptyMessage(UIHandler.GRAPHICS_CHANGED);
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Convenience method for a shiny background for text ads
 *
 * @param rect//from   ww  w  . ja v  a 2s  .c  o  m
 * @param backgroundColor
 * @param mTextColor
 * @return
 */
private BitmapDrawable generateBackgroundDrawable(final Rect rect, final int backgroundColor,
        final int shineColor) {
    try {
        Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawTextBannerBackground(canvas, rect, backgroundColor, shineColor);
        return new BitmapDrawable(bitmap);
    } catch (Throwable t) {
        return null;
    }
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private void updateColor(boolean defaults) {
    Bitmap bm = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas cnv = new Canvas(bm);

    if (defaults) {
        cnv.drawColor(0xFF000000);//from  w  ww .  jav  a2  s.  c  o  m
        setBackground(new BitmapDrawable(bm));
        return;
    }

    String setting = Settings.System.getString(mContext.getContentResolver(), Settings.System.NAV_BAR_COLOR);
    String[] colors = (setting == null || setting.equals("")
            ? ExtendedPropertiesUtils.PARANOID_COLORS_DEFAULTS[ExtendedPropertiesUtils.PARANOID_COLORS_NAVBAR]
            : setting).split(ExtendedPropertiesUtils.PARANOID_STRING_DELIMITER);
    String currentColor = colors[Integer.parseInt(colors[2])];

    cnv.drawColor(new BigInteger(currentColor, 16).intValue());

    TransitionDrawable transition = new TransitionDrawable(
            new Drawable[] { getBackground(), new BitmapDrawable(bm) });
    transition.setCrossFadeEnabled(true);
    setBackground(transition);
    transition.startTransition(1000);
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void setBackground(View v, Bitmap bm) {

    if (bm == null) {
        v.setBackgroundResource(0);//  www  .j a va2s  . c o m
        return;
    }

    int vwidth = v.getWidth();
    int vheight = v.getHeight();
    int bwidth = bm.getWidth();
    int bheight = bm.getHeight();
    float scalex = (float) vwidth / bwidth;
    float scaley = (float) vheight / bheight;
    float scale = Math.max(scalex, scaley) * 1.3f;

    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
    Canvas c = new Canvas(bg);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    ColorMatrix greymatrix = new ColorMatrix();
    greymatrix.setSaturation(0);
    ColorMatrix darkmatrix = new ColorMatrix();
    darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
    greymatrix.postConcat(darkmatrix);
    ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
    paint.setColorFilter(filter);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin
    matrix.postRotate(10);
    matrix.postScale(scale, scale);
    matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center
    c.drawBitmap(bm, matrix, paint);
    v.setBackgroundDrawable(new BitmapDrawable(bg));
}