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.android.volley.cache.SimpleImageLoader.java

/**
 * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a
 * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on
 * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent
 * Drawable./*from  w  ww.  j ava2 s  .co m*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources,
        boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageView.setImageBitmap(bitmap);
                        imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (imageView.getDrawable() != null) {
            initialDrawable = imageView.getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        imageView.setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.github.mobile.util.HttpImageGetter.java

@Override
public Drawable getDrawable(String source) {
    Bitmap bitmap = null;/*  w  ww  .ja va 2 s .  c o m*/

    if (!destroyed) {
        File output = null;
        InputStream is = null;
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) new URL(source).openConnection();
            is = connection.getInputStream();
            if (is != null) {
                String mime = connection.getContentType();
                if (mime == null) {
                    mime = URLConnection.guessContentTypeFromName(source);
                }
                if (mime == null) {
                    mime = URLConnection.guessContentTypeFromStream(is);
                }
                if (mime != null && mime.startsWith("image/svg")) {
                    bitmap = ImageUtils.renderSvgToBitmap(context.getResources(), is, width, height);
                } else {
                    boolean isGif = mime != null && mime.startsWith("image/gif");
                    if (!isGif || canLoadGif()) {
                        output = File.createTempFile("image", ".tmp", dir);
                        if (FileUtils.save(output, is)) {
                            if (isGif) {
                                GifDrawable d = new GifDrawable(output);
                                d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                                return d;
                            } else {
                                bitmap = ImageUtils.getBitmap(output, width, height);
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            // fall through to showing the loading bitmap
        } finally {
            if (output != null) {
                output.delete();
            }
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // ignored
                }
            }
            if (connection != null) {
                connection.disconnect();
            }
        }
    }

    synchronized (this) {
        if (destroyed && bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        } else if (bitmap != null) {
            loadedBitmaps.add(new WeakReference<>(bitmap));
        }
    }

    if (bitmap == null) {
        return loading.getDrawable(source);
    }

    BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    return drawable;
}

From source file:com.example.nanchen.aiyaschoolpush.im.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./*from www .jav a 2 s .  c  om*/
 *
 * @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(App.getAppContext().getResources().getColor(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.app.uafeed.activity.HomeActivity.java

private void selectDrawerItem(int position) {
    mCurrentDrawerPos = position;/*from   w  w  w .  jav  a2  s.c  o m*/
    mIcon = null;

    Uri newUri;
    boolean showFeedInfo = true;

    switch (position) {
    case 0:
        newUri = EntryColumns.ALL_ENTRIES_CONTENT_URI;
        break;
    case 1:
        newUri = EntryColumns.FAVORITES_CONTENT_URI;
        break;
    case 2:
        newUri = EntryColumns.SEARCH_URI(mEntriesFragment.getCurrentSearch());
        break;
    default:
        long feedOrGroupId = mDrawerAdapter.getItemId(position);
        if (mDrawerAdapter.isItemAGroup(position)) {
            newUri = EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId);
        } else {
            byte[] iconBytes = mDrawerAdapter.getItemIcon(position);
            Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
            if (bitmap != null) {
                mIcon = new BitmapDrawable(getResources(), bitmap);
            }

            newUri = EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId);
            showFeedInfo = false;
        }
        mTitle = mDrawerAdapter.getItemName(position);
        break;
    }

    if (!newUri.equals(mEntriesFragment.getUri())) {
        mEntriesFragment.setData(newUri, showFeedInfo);
    }

    mDrawerList.setItemChecked(position, true);

    // First open => we open the drawer for you
    if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) {
        PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.openDrawer(mDrawerList);
            } //   500  300
        }, 300);
    }
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

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

    setHasOptionsMenu(false);/* w  w  w. j  a v  a2  s  . co m*/
    //MAIN_ACTIVITY = (MainActivity) getActivity();
    initNoFileLayout();
    SHOW_HIDDEN = sharedPref.getBoolean("showHidden", false);
    COLORISE_ICONS = sharedPref.getBoolean("coloriseIcons", true);
    mFolderBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_grid_folder_new);
    goback = res.getString(R.string.goback);
    folder = new BitmapDrawable(res, mFolderBitmap);
    getSortModes();
    DARK_IMAGE = new BitmapDrawable(res, BitmapFactory.decodeResource(res, R.drawable.ic_doc_image_dark));
    DARK_VIDEO = new BitmapDrawable(res, BitmapFactory.decodeResource(res, R.drawable.ic_doc_video_dark));
    this.setRetainInstance(false);
    HFile f = new HFile(OpenMode.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    MAIN_ACTIVITY.initiatebbar();
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);

    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !IS_LIST) {
        listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
    } else {
        listView.setBackgroundDrawable(null);
    }

    listView.setHasFixedSize(true);
    columns = Integer.parseInt(sharedPref.getString("columns", "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getActivity());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    //View footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);// TODO: 23/5/2017 use or delete
    dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false,
            SHOW_DIVIDERS);
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(Color.parseColor(fabSkin));
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if ((columns == 0 || columns == -1)) {
                        int screen_width = listView.getWidth();
                        int dptopx = Utils.dpToPx(115, getContext());
                        columns = screen_width / dptopx;
                        if (columns == 0 || columns == -1)
                            columns = 3;
                        if (!IS_LIST)
                            mLayoutManagerGrid.setSpanCount(columns);
                    }
                    if (savedInstanceState != null && !IS_LIST)
                        retrieveFromSavedInstance(savedInstanceState);
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });

    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);
    } else {
        if (IS_LIST)
            retrieveFromSavedInstance(savedInstanceState);
    }
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

private View buildResumeRow(RequestCreator handicapIconRequest, String handicapName, AccessibilityStats stats,
        int rowIndex) {

    TableRow row = (TableRow) getLayoutInflater().inflate(com.orange.ocara.R.layout.result_resume_item, null);

    TextView noImpact = (TextView) row.findViewById(com.orange.ocara.R.id.resume_handicap_no_impact);
    TextView annoying = (TextView) row.findViewById(com.orange.ocara.R.id.resume_handicap_annoying);
    TextView blocking = (TextView) row.findViewById(com.orange.ocara.R.id.resume_handicap_blocking);
    TextView doubt = (TextView) row.findViewById(com.orange.ocara.R.id.resume_handicap_doubt);

    noImpact.setText(Integer.toString(stats.getCounter(AccessibilityStats.Type.ACCESSIBLE)));
    annoying.setText(Integer.toString(stats.getCounter(AccessibilityStats.Type.ANNOYING)));
    blocking.setText(Integer.toString(stats.getCounter(AccessibilityStats.Type.BLOCKING)));
    doubt.setText(Integer.toString(stats.getCounter(AccessibilityStats.Type.DOUBT)));

    final TextView handicapType = (TextView) row.findViewById(com.orange.ocara.R.id.resume_handicap_type);
    handicapType.setText(handicapName);/*w w w  .ja v a2  s.  c  o m*/
    if (handicapIconRequest != null) {

        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                handicapType.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(getResources(), bitmap),
                        null, null, null);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }
        };
        final int maxSize = getResources()
                .getDimensionPixelSize(com.orange.ocara.R.dimen.resultResumeHandicapIconSize);
        handicapIconRequest.placeholder(android.R.color.black).resize(maxSize, maxSize).into(target);
    }

    int backGroundColor = (rowIndex % 2 == 0) ? com.orange.ocara.R.color.resultTableColorEven
            : com.orange.ocara.R.color.resultTableColorOdd;
    row.setBackgroundResource(backGroundColor);

    return row;
}

From source file:com.android.incallui.ContactInfoCache.java

/**
 * Implemented for ContactsAsyncHelper.OnImageLoadCompleteListener interface.
 * make sure that the call state is reflected after the image is loaded.
 *//*w  w w  .  j  a v a2  s. c  o m*/
@Override
public void onImageLoadComplete(int token, Drawable photo, Bitmap photoIcon, Object cookie) {
    Log.d(this, "Image load complete with context: ", mContext);
    // TODO: may be nice to update the image view again once the newer one
    // is available on contacts database.

    final String callId = (String) cookie;
    final ContactCacheEntry entry = mInfoMap.get(callId);

    if (entry == null) {
        Log.e(this, "Image Load received for empty search entry.");
        clearCallbacks(callId);
        return;
    }
    Log.d(this, "setting photo for entry: ", entry);

    // Conference call icons are being handled in CallCardPresenter.
    if (photo != null) {
        Log.v(this, "direct drawable: ", photo);
        entry.photo = photo;
    } else if (photoIcon != null) {
        Log.v(this, "photo icon: ", photoIcon);
        entry.photo = new BitmapDrawable(mContext.getResources(), photoIcon);
    } else {
        Log.v(this, "unknown photo");
        entry.photo = null;
    }

    sendImageNotifications(callId, entry);
    clearCallbacks(callId);
}

From source file:com.android.project.imagefetcher.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./*  w  w  w. ja  va  2s  . c o m*/
 * 
 * @param imageView
 * @param bitmap
 */
@SuppressWarnings("deprecation")
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);
    }
}

From source file:com.cnblogs.app.bitmap.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//  www .ja va  2  s  . c o  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.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));

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

From source file: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 a2 s. c  o  m
 *
 * @param imageView
 * @param drawable
 */
@SuppressWarnings("deprecation")
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);
    }
}