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

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:com.facebook.react.views.slider.ReactSlider.java

public void setThumbImage(ReadableMap source) {
    getImage(source, new PictureSubscriber() {
        @Override/*ww w. j  a v  a  2s . c o m*/
        public void doBitmap(Bitmap bitmap) {
            setThumb(new BitmapDrawable(getResources(), bitmap));
        }

        @Override
        public void doDrawable(Drawable drawable) {
            setThumb(drawable);
        }
    });
}

From source file:ca.hoogit.garagepi.Camera.CameraFragment.java

private void handleUpdatingCameraFeed(String frame) {
    if (isAdded()) {
        Log.v(TAG, "handleUpdatingCameraFeed: Updating image view");
        byte[] decoded = Base64.decode(frame, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
        Drawable drawable = new BitmapDrawable(getResources(), bitmap);
        mCameraFeed.setImageDrawable(drawable);
    }/*from  w  w  w .j a  v a  2 s. c  o  m*/
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getDefaultImage(@NonNull Context context, @DrawableRes int res) {
    try {//ww w.jav a 2 s  .co  m
        int color = ColorHelper.getAttributeColor(context, android.R.attr.textColorSecondary);
        int padding = context.getResources().getDimensionPixelSize(R.dimen.default_image_padding);

        Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        Bitmap tintedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() + padding,
                Bitmap.Config.ARGB_8888);
        Canvas tintedCanvas = new Canvas(tintedBitmap);
        int background = ColorHelper.getAttributeColor(context, R.attr.card_background);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setAntiAlias(true);
        tintedCanvas.drawColor(background, PorterDuff.Mode.ADD);
        tintedCanvas.drawBitmap(bitmap, (tintedCanvas.getWidth() - bitmap.getWidth()) / 2,
                (tintedCanvas.getHeight() - bitmap.getHeight()) / 2, paint);
        return new BitmapDrawable(context.getResources(), tintedBitmap);
    } catch (Exception | OutOfMemoryError e) {
        return null;
    }
}

From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Fragment rawFragment = getTargetFragment();
    if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
        throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface");
    }/*from w w w .  j  a v a2 s  .  c  o  m*/

    final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;

    final String key = getArguments().getString(ARG_KEY);
    if (savedInstanceState == null) {
        mPreference = (DialogPreference) fragment.findPreference(key);
        mDialogTitle = mPreference.getDialogTitle();
        mPositiveButtonText = mPreference.getPositiveButtonText();
        mNegativeButtonText = mPreference.getNegativeButtonText();
        mDialogMessage = mPreference.getDialogMessage();
        mDialogLayoutRes = mPreference.getDialogLayoutResource();

        final Drawable icon = mPreference.getDialogIcon();
        if (icon == null || icon instanceof BitmapDrawable) {
            mDialogIcon = (BitmapDrawable) icon;
        } else {
            final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            icon.draw(canvas);
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    } else {
        mDialogTitle = savedInstanceState.getCharSequence(SAVE_STATE_TITLE);
        mPositiveButtonText = savedInstanceState.getCharSequence(SAVE_STATE_POSITIVE_TEXT);
        mNegativeButtonText = savedInstanceState.getCharSequence(SAVE_STATE_NEGATIVE_TEXT);
        mDialogMessage = savedInstanceState.getCharSequence(SAVE_STATE_MESSAGE);
        mDialogLayoutRes = savedInstanceState.getInt(SAVE_STATE_LAYOUT, 0);
        final Bitmap bitmap = savedInstanceState.getParcelable(SAVE_STATE_ICON);
        if (bitmap != null) {
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    }
}

From source file:com.mobicage.rogerthat.NavigationItem.java

public Drawable getFooterIcon(Context context) {
    if (this.faIcon == null) {
        BitmapDrawable image = (BitmapDrawable) context.getResources().getDrawable(this.iconId);
        int w = UIUtils.convertDipToPixels(context, 34);
        Bitmap bitmapResized = Bitmap.createScaledBitmap(image.getBitmap(), w, w, false);
        return new BitmapDrawable(context.getResources(), bitmapResized);
    }/*from   www  . j  ava 2  s  .co  m*/
    return new IconicsDrawable(context, this.faIcon).color(ContextCompat.getColor(context, R.color.mc_white))
            .sizeDp(20);
}

From source file:com.bayapps.android.robophish.ui.tv.CardPresenter.java

private void setCardImage(CardViewHolder cardViewHolder, Bitmap art) {
    if (cardViewHolder.mCardView == null) {
        return;//from  ww w  .  j a v a2  s.c  om
    }
    Drawable artDrawable = null;
    if (art != null) {
        artDrawable = new BitmapDrawable(mContext.getResources(), art);
    } else {
        CharSequence title = cardViewHolder.mCardView.getTitleText();
        if (title != null && title.length() > 0) {
            artDrawable = new TextDrawable(String.valueOf(title.charAt(0)));
        }
    }
    cardViewHolder.mCardView.setMainImage(artDrawable);
}

From source file:co.nerdart.ourss.activity.EntriesListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getActionBar();
    if (actionBar != null)
        actionBar.setDisplayHomeAsUpEnabled(true);

    Intent intent = getIntent();/*from  w ww . j  av  a2 s  . co m*/
    long feedId = intent.getLongExtra(FeedColumns._ID, 0);

    String title = null;
    if (feedId > 0) {
        Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null,
                null);

        if (cursor.moveToFirst()) {
            title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0);
            iconBytes = cursor.getBlob(2);
        }
        cursor.close();
    }

    if (title != null) {
        setTitle(title);
    }

    if (savedInstanceState == null) {
        EntriesListFragment fragment = new EntriesListFragment();
        Bundle args = new Bundle();
        args.putParcelable(EntriesListFragment.ARG_URI, intent.getData());
        fragment.setArguments(args);
        fragment.setHasOptionsMenu(true);
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit();
    }

    if (iconBytes != null && iconBytes.length > 0) {
        int bitmapSizeInDip = UiUtils.dpToPixel(24);
        Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length);
        if (bitmap != null) {
            if (bitmap.getHeight() != bitmapSizeInDip) {
                bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false);
            }

            getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        }
    }

    if (MainActivity.mNotificationManager == null) {
        MainActivity.mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
    }
}

From source file:at.wada811.imageslider.ImageSliderFragment.java

public void setImageBitmap(Bitmap bitmap) {
    mImageSwitcher.setImageDrawable(new BitmapDrawable(getResources(), bitmap));
}

From source file:com.cooltechworks.views.ScratchImageView.java

/**
 * Initialises the paint drawing elements.
 *///from  w  ww.j  av a  2s .com
private void init() {

    mTouchPath = new Path();

    mErasePaint = new Paint();
    mErasePaint.setAntiAlias(true);
    mErasePaint.setDither(true);
    mErasePaint.setColor(0xFFFF0000);
    mErasePaint.setStyle(Paint.Style.STROKE);
    mErasePaint.setStrokeJoin(Paint.Join.BEVEL);
    mErasePaint.setStrokeCap(Paint.Cap.ROUND);
    setStrokeWidth(6);

    mGradientBgPaint = new Paint();

    mErasePath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    Bitmap scratchBitmap;
    if (mCustomScrachView != null) {
        scratchBitmap = ((BitmapDrawable) mCustomScrachView).getBitmap();
    } else {
        scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern);
    }

    mDrawable = new BitmapDrawable(getResources(), scratchBitmap);
    mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

    setEraserMode();

}

From source file:com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.content_browse_activity_layout);

    Helpers.handleActivityEnterFadeTransition(this, ACTIVITY_ENTER_TRANSITION_FADE_DURATION);

    mContentTitle = (TextView) findViewById(R.id.content_detail_title);
    CalligraphyUtils.applyFontToTextView(this, mContentTitle,
            ConfigurationManager.getInstance(this).getTypefacePath(ConfigurationConstants.BOLD_FONT));

    mContentDescription = (TextView) findViewById(R.id.content_detail_description);
    CalligraphyUtils.applyFontToTextView(this, mContentDescription,
            ConfigurationManager.getInstance(this).getTypefacePath(ConfigurationConstants.LIGHT_FONT));

    mContentImage = (ImageView) findViewById(R.id.content_image);

    mContentImage.setImageURI(Uri.EMPTY);

    // Get display/background size
    Display display = getWindowManager().getDefaultDisplay();
    Point windowSize = new Point();
    display.getSize(windowSize);/*from   w  w  w  .  j  ava2  s .  c o  m*/
    int imageWidth = (int) getResources().getDimension(R.dimen.content_image_width);
    int imageHeight = (int) getResources().getDimension(R.dimen.content_image_height);
    int gradientSize = (int) getResources().getDimension(R.dimen.content_image_gradient_size);
    // Create the background
    Bitmap background = BackgroundImageUtils.createBackgroundWithPreviewWindow(windowSize.x, windowSize.y,
            imageWidth, imageHeight, gradientSize,
            ContextCompat.getColor(this, R.color.browse_background_color));
    mBackgroundWithPreview = new BitmapDrawable(getResources(), background);
    // Set the background
    mMainFrame = findViewById(R.id.main_frame);
    mMainFrame.setBackground(mBackgroundWithPreview);
}