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.lokiy.widget.BannerView.java

private RadioButton generateRadioButton(int i, int w) {
    RadioButton rb = new RadioButton(getContext());
    rb.setBackgroundResource(mIndicatorId);
    rb.setButtonDrawable(new BitmapDrawable(getResources(), (Bitmap) null));
    rb.setId(i);//from   w  w w . j  a  v a  2 s  .com
    rb.setPadding(0, 0, 0, 0);
    RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(w, w);
    params.leftMargin = w / 2;
    params.rightMargin = w / 2;
    rb.setLayoutParams(params);
    if (i == 0) {
        rb.setChecked(true);
    }
    return rb;
}

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//  ww  w  .  j ava 2s.c o m

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.image.cache.util.ImageWorker.java

public void loadImageCustom(Object data, ImageView imageView) {
    if (data == null) {
        return;//w  w  w. jav a 2  s  .c  om
    }

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (value != null) {
        // Bitmap found in memory cache
        //            imageView.setImageDrawable(value);
        //           Bitmap bmp = ImageHelper.createFramedImage(value, BORDER_THICKNESS);
        //           Drawable d = new BitmapDrawable(mResources, bmp);
        //           imageView.setImageDrawable(d);

        if (BORDER_RADIUS > 0 && COLOR < 0) {
            //               Log.e("IMAGE", "BORDER_RADIUS");
            Bitmap bmp = ImageHelper.getRoundedCornerBitmap3(value, BORDER_RADIUS);
            Drawable d = new BitmapDrawable(mResources, bmp);
            setImageDrawableFrame(imageView, d);
        } else if (BORDER_THICKNESS == -1 && BORDER_RADIUS == -1) {
            //               Log.e("IMAGE", " NO BORDER_THICKNESS - NO BORDER_RADIUS");
            setImageDrawable(imageView, value);
        } else if (BORDER_THICKNESS > 0 && COLOR > 0) {
            //               Log.e("IMAGE", "BORDER_THICKNESS - COLOR");
            Bitmap bmp = ImageHelper.createRoundedFramedImage(value, BORDER_THICKNESS, COLOR);
            Drawable d = new BitmapDrawable(mResources, bmp);
            setImageDrawableFrame(imageView, d);
        } else if (BORDER_THICKNESS > 0) {
            //               Log.e("IMAGE", "BORDER_THICKNESS");
            Bitmap bmp = ImageHelper.createFramedImage(value, BORDER_THICKNESS);
            Drawable d = new BitmapDrawable(mResources, bmp);
            setImageDrawableFrame(imageView, d);
        }

    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // 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.dgnt.dominionCardPicker.view.DynamicListView.java

/**
 * Creates the hover cell with the appropriate bitmap and of appropriate
 * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
 * single time an invalidate call is made.
 *///from ww  w .ja v a2s  .  co  m
private BitmapDrawable getAndAddHoverView(View v) {

    int w = v.getWidth();
    int h = v.getHeight();
    int top = v.getTop();
    int left = v.getLeft();

    Bitmap b = getBitmapWithBorder(v);

    BitmapDrawable drawable = new BitmapDrawable(getResources(), b);

    mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
    mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);

    drawable.setBounds(mHoverCellCurrentBounds);

    return drawable;
}

From source file:com.nerderylabs.android.nerdalert.ui.fragment.MainFragment.java

private void initializeNametag() {
    final EditText nameEditText = (EditText) view.findViewById(R.id.my_name);
    final EditText taglineEditText = (EditText) view.findViewById(R.id.my_tagline);
    final ImageView photoImageView = (ImageView) view.findViewById(R.id.my_photo);

    // restore state
    nameEditText.setText(myInfo.getName());
    taglineEditText.setText(myInfo.getTagline());
    if (myInfo.getBitmap() != null) {
        photoImageView.setImageDrawable(new BitmapDrawable(getResources(), myInfo.getBitmap()));
    } else {//from w w  w  .  jav a2 s .  co  m
        Drawable photo = ContextCompat.getDrawable(getContext(), R.drawable.ic_contact_photo);
        DrawableCompat.setTint(photo, ContextCompat.getColor(getContext(), R.color.color_nametag));
        photoImageView.setImageDrawable(photo);
    }

    // listen for focus change
    View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                persistNametagValues((TextView) v);
            }
        }
    };

    // listen for the done key
    EditText.OnEditorActionListener doneListener = new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                persistNametagValues(v);
            }
            return false;
        }
    };

    // open profile contact card when user's photo is tapped
    ImageView.OnClickListener imageClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setDataAndType(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.CONTENT_ITEM_TYPE);

            // In Android 4.0 (API version 14) and later, a problem in the contacts app causes
            // incorrect navigation.To work around this problem in Android 4.0.3 (API version
            // 15) and later, add the extended data key finishActivityOnSaveCompleted to the
            // intent, with a value of true.
            intent.putExtra("finishActivityOnSaveCompleted", true);

            startActivity(intent);
        }
    };

    nameEditText.setOnEditorActionListener(doneListener);
    taglineEditText.setOnEditorActionListener(doneListener);

    nameEditText.setOnFocusChangeListener(focusListener);
    taglineEditText.setOnFocusChangeListener(focusListener);

    photoImageView.setOnClickListener(imageClickListener);

}

From source file:com.ifeng.util.imagecache.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 added using/*from ww  w  .j a v  a  2 s.c o  m*/
 * {@link ImageWorker#addImageCache(FragmentManager, ImageCache.ImageCacheParams)}
 * . 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.
 * 
 * @param item
 *            The loadtask of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
final protected void loadImageInternal(BitmapTaskItem item, ImageView imageView) {
    if (item == null || item.mDataSource == null || imageView == null) {
        return;
    }

    // ?
    if (item.mDataSource instanceof String && TextUtils.isEmpty((CharSequence) item.mDataSource)) {
        return;
    }
    // resId?s
    if (item.mDataSource instanceof Integer && (Integer) item.mDataSource == 0) {
        return;
    }

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(item.mDataSource));
    }

    if (value != null) {
        // Bitmap found in memory cache
        // Bug fix by XuWei 2013-09-09
        // Drawable?bug?ViewDrawable??Drawable
        Drawable copyDrawable = new BitmapDrawable(mResources, value.getBitmap());
        imageView.setImageDrawable(copyDrawable);
    } else if (cancelPotentialWork(item.mDataSource, imageView)) {

        byte[] chunk = null;
        if (mLoadingBitmap != null) {
            chunk = mLoadingBitmap.getNinePatchChunk();
        }

        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        if (chunk == null) {
            final AsyncBitmapDrawable asyncBitmapDrawable = new AsyncBitmapDrawable(mResources, mLoadingBitmap,
                    task);
            imageView.setImageDrawable(asyncBitmapDrawable);
        } else {
            final AsyncNinePatchDrawable.NinePatchChunk npc = AsyncNinePatchDrawable.NinePatchChunk
                    .deserialize(chunk);
            final AsyncNinePatchDrawable asyncNinePatchDrawable = new AsyncNinePatchDrawable(mResources,
                    mLoadingBitmap, chunk, npc.mPaddings, null, task);
            imageView.setImageDrawable(asyncNinePatchDrawable);
        }

        // 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(mExecutor, item);
    }
}

From source file:com.android.displayingbitmaps.util.ImageWorker.java

public BitmapDrawable loadDrawableImage(String data) {
    if (data == null) {
        return null;
    }/*from  w  w  w  . ja  v  a2  s . c o  m*/
    BitmapDrawable value = null;
    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
        if (value != null) {
            return value;
        }
    }

    Bitmap bitmap = processBitmap(data);
    ;
    if (bitmap != null) {
        if (Utils.hasHoneycomb()) {
            // Running on Honeycomb or newer, so wrap in a standard BitmapDrawable
            value = new BitmapDrawable(mResources, bitmap);
        } else {
            // Running on Gingerbread or older, so wrap in a RecyclingBitmapDrawable
            // which will recycle automagically
            value = new RecyclingBitmapDrawable(mResources, bitmap);
        }

        if (mImageCache != null) {
            mImageCache.addBitmapToCache(data, value);
        }
    }
    return value;
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

private Drawable createCircleDrawable(RectF circleRect, int color) {
    final Bitmap bitmap = Bitmap.createBitmap(mDrawableSize, mDrawableSize, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);/*from  ww  w  .  j a  v  a2  s  . c  om*/
    paint.setColor(color);

    canvas.drawOval(circleRect, paint);

    return new BitmapDrawable(getResources(), bitmap);
}

From source file:calibrationapp.spectoccular.com.keyboardtolinux.MainActivity.java

private BitmapDrawable toDrawable(int rid) {
    return new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), rid));
}

From source file:com.example.zillowapplication.SlidingTabsBasicFragment.java

public void passImagesToFragment(HashMap<Integer, Bitmap> yearToImageMap) {
    for (Entry<Integer, Bitmap> entry : yearToImageMap.entrySet()) {
        chartHeaders.add(String.format(Constants.CHART_HEADER,
                entry.getKey() + (entry.getKey() > 1 ? " years" : " year")));
        chartImages.add(new BitmapDrawable(getResources(), entry.getValue()));
    }/*w w  w.j a v a2  s.c o  m*/
    //TODO Handle Timeout
}