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.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java

private void handleSelection() {
    if (mUriSavedImage == null) {
        L.bug("PhotoUploadWidget mUriSavedImage was null.. Creating now");
        File image;//from w  ww.  j av a  2s  . c om
        try {
            image = getTmpUploadPhotoLocation();
        } catch (IOException e) {
            L.d(e.getMessage());
            return;
        }
        mUriSavedImage = Uri.fromFile(image);
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    Bitmap bitmap = ImageHelper.getBitmapFromFile(mUriSavedImage.getPath(), options);

    Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap);
    mImagePreview.setImageDrawable(d);

    if (!USER_QUALITY.equals(mQuality)) {
        if (BEST_QUALITY.equals(mQuality) || mQuality == null) {
            IOUtils.compressPicture(mUriSavedImage, 0);
        } else {
            IOUtils.compressPicture(mUriSavedImage, Long.parseLong(mQuality));
        }
    } else {
        pickSizePhoto(mUriSavedImage);
    }
    mPhotoSelected = true;
    mSourceButton.setText(R.string.change_picture);
}

From source file:com.example.mohmurtu.registration.imagesUtil.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//from  w  w  w  . ja va  2s .c o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        System.out.println("Doing some thing here");
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        System.out.println("Bitmap is getting drawable");
        imageView.setImageDrawable(drawable);
    }
}

From source file:angel.zhuoxiu.picker.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//from   w  w  w  .j av  a2s  . co m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.corebase.android.bitmap.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./* ww  w.j  a  v  a2s  .  co m*/
 * 
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        imageView.setBackgroundDrawable(null);
        td.startTransition(FADE_IN_TIME);

    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.linkbubble.util.Util.java

/**
 * Returns a bitmap suitable for the all apps view. Used to convert pre-ICS
 * icon bitmaps that are stored in the database (which were 74x74 pixels at hdpi size)
 * to the proper size (48dp)/*from   ww  w. j av  a 2  s.co  m*/
 */
static Bitmap createIconBitmap(Bitmap icon, Context context) {
    int textureWidth = sIconTextureWidth;
    int textureHeight = sIconTextureHeight;
    int sourceWidth = icon.getWidth();
    int sourceHeight = icon.getHeight();
    if (sourceWidth > textureWidth && sourceHeight > textureHeight) {
        // Icon is bigger than it should be; clip it (solves the GB->ICS migration case)
        return Bitmap.createBitmap(icon, (sourceWidth - textureWidth) / 2, (sourceHeight - textureHeight) / 2,
                textureWidth, textureHeight);
    } else if (sourceWidth == textureWidth && sourceHeight == textureHeight) {
        // Icon is the right size, no need to change it
        return icon;
    } else {
        // Icon is too small, render to a larger bitmap
        final Resources resources = context.getResources();
        return createIconBitmap(new BitmapDrawable(resources, icon), context);
    }
}

From source file:com.cleveroad.audiowidget.AudioWidget.java

@NonNull
private Controller newController() {
    return new Controller() {

        @Override/*from   ww  w.ja  va2 s  .c o m*/
        public void start() {
            playbackState.start(this);
        }

        @Override
        public void pause() {
            playbackState.pause(this);
        }

        @Override
        public void stop() {
            playbackState.stop(this);
        }

        @Override
        public int duration() {
            return playbackState.duration();
        }

        @Override
        public void duration(int duration) {
            playbackState.duration(duration);
        }

        @Override
        public int position() {
            return playbackState.position();
        }

        @Override
        public void position(int position) {
            playbackState.position(position);
        }

        @Override
        public void onControlsClickListener(@Nullable OnControlsClickListener onControlsClickListener) {
            AudioWidget.this.onControlsClickListener.onControlsClickListener(onControlsClickListener);
        }

        @Override
        public void onWidgetStateChangedListener(
                @Nullable OnWidgetStateChangedListener onWidgetStateChangedListener) {
            AudioWidget.this.onWidgetStateChangedListener = onWidgetStateChangedListener;
        }

        @Override
        public void albumCover(@Nullable Drawable albumCover) {
            expandCollapseWidget.albumCover(albumCover);
            playPauseButton.albumCover(albumCover);
        }

        @Override
        public void albumCoverBitmap(@Nullable Bitmap bitmap) {
            if (bitmap == null) {
                return;
            }
            WeakReference<Drawable> wrDrawable = albumCoverCache.get(bitmap.hashCode());
            if (wrDrawable != null) {
                Drawable drawable = wrDrawable.get();
                if (drawable != null) {
                    expandCollapseWidget.albumCover(drawable);
                    playPauseButton.albumCover(drawable);
                    return;
                }
            }
            Drawable albumCover = new BitmapDrawable(context.getResources(), bitmap);
            expandCollapseWidget.albumCover(albumCover);
            playPauseButton.albumCover(albumCover);
            albumCoverCache.put(bitmap.hashCode(), new WeakReference<>(albumCover));
        }
    };
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

public void onEvent(String html) {
    if ((isRefresh || mContent == null) && html != null) {
        if (StringUtil.startsWith(html, "http")) {
            new ImageLoader(DpApp.getRequestQueue(), new BitmapLruCache()).get(html,
                    new ImageLoader.ImageListener() {
                        public void onErrorResponse(VolleyError paramVolleyError) {
                        }//from ww  w  .ja  va  2s.  co m

                        public void onResponse(ImageContainer container, boolean paramBoolean) {
                            getSupportActionBar()
                                    .setIcon(new BitmapDrawable(getResources(), container.getBitmap()));
                        }
                    });
        } else if (StringUtil.startsWith(html, "<!DOCTYPE")) {
            isRefresh = false;
            mContent = html;
            if (StringUtil.isBlank(html)) {
                AndroidUtil.showToast(DpApp.getContext(), getString(R.string.list_loading_fail));
                finish();
                return;
            }
            mWebView.loadDataWithBaseURL("http://dvdprime.donga.com", html, "text/html", "utf-8", null);
            EventBusProvider.getInstance().post(new Refresh(Refresh.VIEW));
            mPullToRefreshAttacher.setRefreshComplete();
            return;
        } else {
            String[] splitText = StringUtil.split(html, '|');
            getSupportActionBar().setTitle(splitText[1]);
            getSupportActionBar().setSubtitle(splitText[2]);
            if (StringUtil.equals(splitText[0], PrefUtil.getInstance().getString("account_id", null))) {
                modifyMenu.setVisible(true);
                modifyMenu.setEnabled(true);
                deleteMenu.setVisible(true);
                deleteMenu.setEnabled(true);
            }
        }
    }
}

From source file:com.example.android.displayingbitmaps.imageloader.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//from ww w . j  a v a 2 s . c o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(final ImageView imageView, final Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                //                            new ColorDrawable(android.R.color.transparent),
                new BitmapDrawable(mResources, mLoadingBitmap), drawable });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));
        imageView.setBackgroundColor(Color.TRANSPARENT);

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
        imageView.setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private void drawUpdateCount(Activity context, Resources res, ImageView view, boolean flag) {
    DisplayMetrics dm = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap cornerRes = BitmapFactory.decodeResource(res, R.drawable.notify_update);
    Bitmap appBitmapNormal = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_unselect);
    Bitmap appBitmapPressed = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_select);

    StateListDrawable stateDrawable = new StateListDrawable();
    int stateSelected = android.R.attr.state_selected;
    if (flag) {/* ww w  .j  a  va  2s. co m*/
        Bitmap cornerBitmap = drawText(dm, res, cornerRes, mSession.getUpgradeNumber());
        Bitmap newBitmapNormal = drawBitmap(dm, appBitmapNormal, cornerBitmap);
        Bitmap newBitmapPressed = drawBitmap(dm, appBitmapPressed, cornerBitmap);

        stateDrawable.addState(new int[] { -stateSelected }, new BitmapDrawable(res, newBitmapNormal));
        stateDrawable.addState(new int[] { stateSelected }, new BitmapDrawable(res, newBitmapPressed));

        view.setImageDrawable(stateDrawable);
    } else {

        view.setImageResource(R.drawable.main_tab_app_manager_selector);
    }
}

From source file:android.support.asy.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView.//from  w  ww  . j a  v a2  s.  com
 * 
 * @param imageView
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        // imageView.setBackgroundDrawable(new BitmapDrawable(mResources,
        // mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}