Example usage for android.widget ImageView setBackgroundDrawable

List of usage examples for android.widget ImageView setBackgroundDrawable

Introduction

In this page you can find the example usage for android.widget ImageView setBackgroundDrawable.

Prototype

@Deprecated
public void setBackgroundDrawable(Drawable background) 

Source Link

Usage

From source file:cn.com.wo.bitmap.ImageWorker.java

public void loadImage(String url, ImageView imageView, boolean isBackground) {
    //      url = Images.getUrl();
    if (url == null || url.trim().length() == 0 || !url.startsWith("http"))
        return;// w w w  . jav a 2 s .  com
    if (ImageFetcher.isDebug)
        Log.i(ImageFetcher.TAG, "loadImage " + url + "; isBg=" + isBackground);
    //    url = "http://58.254.132.169/picture/90755000/copyright/singer/2012032806/23280.jpg";

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(url);
    }

    if (value != null) {
        // Bitmap found in memory cache
        if (isBackground)
            imageView.setBackgroundDrawable(value);
        else
            imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(url, imageView, isBackground)) {
        imageView.setTag(0);
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, 0, isBackground);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap[0], task);
        //          imageView.setImageDrawable(asyncDrawable);

        if (isBackground)
            imageView.setBackgroundDrawable(asyncDrawable);
        else
            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, url);
    }
}

From source file:pum.android.project.tools.displayingbitmaps.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*ww w  . j  a v a  2 s  . c  om*/
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    try {
        ViewGroup viewGroup = (ViewGroup) imageView.getParent();
        if (viewGroup instanceof FrameLayout) {
            FrameLayout parent = (FrameLayout) viewGroup;
            View view;
            if ((view = parent.getChildAt(1)) instanceof ProgressBar)
                parent.removeView(view);
        }
    } catch (Exception e) {
        Log.e(getClass().getSimpleName(), "onPostExecute, progressBar not found", e);
    }

    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:uk.ac.horizon.artcodes.scanner.ScannerActivity.java

private void createSettingsUI(List<DetectorSetting> settings) {
    settingIcons.removeAllViews();//from  w w  w .  j  a  va  2 s.com
    if (settings != null && !settings.isEmpty()) {
        final int padding = getResources().getDimensionPixelSize(R.dimen.setting_padding);
        List<DetectorSetting> settingList = settings;
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            settingList = Lists.reverse(settings);
        }
        for (final DetectorSetting setting : settingList) {
            final ImageView button = new ImageView(this);
            button.setContentDescription(getString(setting.getText()));
            final int[] attrs = new int[] { android.R.attr.selectableItemBackground };
            final TypedArray ta = obtainStyledAttributes(attrs);
            final Drawable drawableFromTheme = ta.getDrawable(0);
            ta.recycle();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                button.setImageResource(setting.getIcon());
                button.setImageTintList(ColorStateList.valueOf(Color.WHITE));
                button.setBackground(drawableFromTheme);
            } else {
                button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE));
                //noinspection deprecation
                button.setBackgroundDrawable(drawableFromTheme);
            }

            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setting.nextValue();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        button.setImageResource(setting.getIcon());
                    } else {
                        button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE));
                    }
                    button.setContentDescription(getString(setting.getText()));
                    textAnimator.setText(setting.getText());
                }
            });
            final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
            params.weight = 1;
            button.setLayoutParams(params);
            settingIcons.addView(button);
            button.setPadding(padding, padding, padding, padding);
        }

    }

    menuAnimator.setViewVisible(settingIcons.getChildCount() > 0);
}

From source file:com.android.mms.rcs.FavoriteDetailAdapter.java

private void initVcardMagView(LinearLayout linearLayout) {
    ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view);
    String fileName = mCursor//from   w w w .  java  2s . c o m
            .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME));
    String vcardFileName = fileName;
    ArrayList<PropertyNode> propList = RcsMessageOpenUtils.openRcsVcardDetail(mContext, vcardFileName);
    Bitmap bitmap = null;
    for (PropertyNode propertyNode : propList) {
        if ("PHOTO".equals(propertyNode.propName)) {
            if (propertyNode.propValue_bytes != null) {
                byte[] bytes = propertyNode.propValue_bytes;
                bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                bitmap = RcsUtils.decodeInSampleSizeBitmap(bitmap);
                break;
            }
        }
    }
    if (bitmap != null) {
        imageView.setBackgroundDrawable(new BitmapDrawable(bitmap));
    } else {
        imageView.setBackgroundResource(R.drawable.ic_attach_vcard);
    }
}

From source file:com.c4mprod.utils.ImageDownloader.java

/**
 * Same as download but the image is always downloaded and the cache is not used.
 * Kept private at the moment as its interest is not clear.
 *//*  w w w  .j a va2  s. c om*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            task = new BitmapDownloaderTask(imageView);
            imageView.setBackgroundDrawable((default_img));
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);

            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:org.telegram.ui.Components.StickersAlert.java

private void init(Context context) {
    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);

    containerView = new FrameLayout(context) {

        private int lastNotifyWidth;

        @Override//from ww w .jav a 2 s  .  c o  m
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
                dismiss();
                return true;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return !isDismissed() && super.onTouchEvent(e);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int height = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21) {
                height -= AndroidUtilities.statusBarHeight;
            }
            int contentSize;
            if (stickerSetCovereds != null) {
                contentSize = AndroidUtilities.dp(48 + 8) + AndroidUtilities.dp(60) * stickerSetCovereds.size()
                        + adapter.stickersRowCount * AndroidUtilities.dp(82);
            } else {
                contentSize = AndroidUtilities.dp(48 + 48) + Math.max(3,
                        (stickerSet != null ? (int) Math.ceil(stickerSet.documents.size() / 5.0f) : 0))
                        * AndroidUtilities.dp(82) + backgroundPaddingTop;
            }
            int padding = contentSize < (height / 5 * 3.2) ? 0 : (height / 5 * 2);
            if (padding != 0 && contentSize < height) {
                padding -= (height - contentSize);
            }
            if (padding == 0) {
                padding = backgroundPaddingTop;
            }
            if (stickerSetCovereds != null) {
                padding += AndroidUtilities.dp(8);
            }
            if (gridView.getPaddingTop() != padding) {
                ignoreLayout = true;
                gridView.setPadding(AndroidUtilities.dp(10), padding, AndroidUtilities.dp(10), 0);
                emptyView.setPadding(0, padding, 0, 0);
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            if (lastNotifyWidth != right - left) {
                lastNotifyWidth = right - left;
                if (adapter != null && stickerSetCovereds != null) {
                    adapter.notifyDataSetChanged();
                }
            }
            super.onLayout(changed, left, top, right, bottom);
            updateLayout();
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(),
                    getMeasuredHeight());
            shadowDrawable.draw(canvas);
        }
    };
    containerView.setWillNotDraw(false);
    containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);

    titleTextView = new TextView(context);
    titleTextView.setLines(1);
    titleTextView.setSingleLine(true);
    titleTextView.setTextColor(
            ContextCompat.getColor(context, R.color.primary_text) /*Theme.STICKERS_SHEET_TITLE_TEXT_COLOR*/);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    titleTextView.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    titleTextView.setGravity(Gravity.CENTER_VERTICAL);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    containerView.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
    titleTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    shadow[0] = new View(context);
    shadow[0].setBackgroundResource(R.drawable.header_shadow);
    shadow[0].setAlpha(0.0f);
    shadow[0].setVisibility(View.INVISIBLE);
    shadow[0].setTag(1);
    containerView.addView(shadow[0],
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    gridView = new RecyclerListView(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent event) {
            boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, gridView, 0);
            return super.onInterceptTouchEvent(event) || result;
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    gridView.setTag(14);
    gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 5));
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (stickerSetCovereds != null && adapter.cache.get(position) instanceof Integer
                    || position == adapter.totalItems) {
                return adapter.stickersPerRow;
            }
            return 1;
        }
    });
    gridView.setAdapter(adapter = new GridAdapter(context));
    gridView.setVerticalScrollBarEnabled(false);
    gridView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.left = 0;
            outRect.right = 0;
            outRect.bottom = 0;
            outRect.top = 0;
        }
    });
    gridView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    gridView.setClipToPadding(false);
    gridView.setEnabled(true);
    gridView.setGlowColor(0xfff5f6f7);
    gridView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return StickerPreviewViewer.getInstance().onTouch(event, gridView, 0, stickersOnItemClickListener);
        }
    });
    gridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateLayout();
        }
    });
    stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (stickerSetCovereds != null) {
                TLRPC.StickerSetCovered pack = adapter.positionsToSets.get(position);
                if (pack != null) {
                    dismiss();
                    TLRPC.TL_inputStickerSetID inputStickerSetID = new TLRPC.TL_inputStickerSetID();
                    inputStickerSetID.access_hash = pack.set.access_hash;
                    inputStickerSetID.id = pack.set.id;
                    StickersAlert alert = new StickersAlert(parentActivity, parentFragment, inputStickerSetID,
                            null, null);
                    alert.show();
                }
            } else {
                if (stickerSet == null || position < 0 || position >= stickerSet.documents.size()) {
                    return;
                }
                selectedSticker = stickerSet.documents.get(position);

                boolean set = false;
                for (int a = 0; a < selectedSticker.attributes.size(); a++) {
                    TLRPC.DocumentAttribute attribute = selectedSticker.attributes.get(a);
                    if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
                        if (attribute.alt != null && attribute.alt.length() > 0) {
                            stickerEmojiTextView.setText(Emoji.replaceEmoji(attribute.alt,
                                    stickerEmojiTextView.getPaint().getFontMetricsInt(),
                                    AndroidUtilities.dp(30), false));
                            set = true;
                        }
                        break;
                    }
                }
                if (!set) {
                    stickerEmojiTextView
                            .setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(selectedSticker.id),
                                    stickerEmojiTextView.getPaint().getFontMetricsInt(),
                                    AndroidUtilities.dp(30), false));
                }

                stickerImageView.getImageReceiver().setImage(selectedSticker, null,
                        selectedSticker.thumb.location, null, "webp", true);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) stickerPreviewLayout
                        .getLayoutParams();
                layoutParams.topMargin = scrollOffsetY;
                stickerPreviewLayout.setLayoutParams(layoutParams);
                stickerPreviewLayout.setVisibility(View.VISIBLE);
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(stickerPreviewLayout, "alpha", 0.0f, 1.0f));
                animatorSet.setDuration(200);
                animatorSet.start();
            }
        }
    };
    gridView.setOnItemClickListener(stickersOnItemClickListener);
    containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 48));

    emptyView = new FrameLayout(context) {
        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    containerView.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
    gridView.setEmptyView(emptyView);
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    ProgressBar progressView = new ProgressBar(context);
    emptyView.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    shadow[1] = new View(context);
    shadow[1].setBackgroundResource(R.drawable.header_shadow_reverse);
    containerView.addView(shadow[1],
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));

    pickerBottomLayout = new PickerBottomLayout(context, false);
    containerView.addView(pickerBottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    pickerBottomLayout.cancelButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    pickerBottomLayout.cancelButton.setTextColor(Theme.STICKERS_SHEET_CLOSE_TEXT_COLOR);
    pickerBottomLayout.cancelButton.setText(LocaleController.getString("Close", R.string.Close).toUpperCase());
    pickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
        }
    });
    pickerBottomLayout.doneButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    pickerBottomLayout.doneButtonBadgeTextView.setBackgroundResource(R.drawable.stickercounter);

    stickerPreviewLayout = new FrameLayout(context);
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) != 0) {
        stickerPreviewLayout.setBackgroundColor(
                0x00ffffff & ContextCompat.getColor(context, R.color.card_background) | 0xdf000000);
    } else {
        stickerPreviewLayout.setBackgroundColor(0xdfffffff);
    }
    stickerPreviewLayout.setVisibility(View.GONE);
    stickerPreviewLayout.setSoundEffectsEnabled(false);
    containerView.addView(stickerPreviewLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    stickerPreviewLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hidePreview();
        }
    });

    ImageView closeButton = new ImageView(context);
    closeButton.setImageResource(R.drawable.delete_reply);
    closeButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        closeButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
    }
    stickerPreviewLayout.addView(closeButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hidePreview();
        }
    });

    stickerImageView = new BackupImageView(context);
    stickerImageView.setAspectFit(true);
    stickerPreviewLayout.addView(stickerImageView);

    stickerEmojiTextView = new TextView(context);
    stickerEmojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
    stickerEmojiTextView.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
    stickerPreviewLayout.addView(stickerEmojiTextView);

    previewSendButton = new TextView(context);
    previewSendButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    previewSendButton.setTextColor(Theme.STICKERS_SHEET_SEND_TEXT_COLOR);
    previewSendButton.setGravity(Gravity.CENTER);
    previewSendButton.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    previewSendButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    previewSendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    stickerPreviewLayout.addView(previewSendButton,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
    previewSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            delegate.onStickerSelected(selectedSticker);
            dismiss();
        }
    });

    previewSendButtonShadow = new View(context);
    previewSendButtonShadow.setBackgroundResource(R.drawable.header_shadow_reverse);
    stickerPreviewLayout.addView(previewSendButtonShadow,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    updateFields();
    updateSendButton();
    adapter.notifyDataSetChanged();
}

From source file:cn.com.wo.bitmap.ImageWorker.java

public void loadImageByIndex(String url, ImageView imageView, int loadingIndex, boolean isBackground) {
    //      url = Images.getUrl();
    if (url == null || url.trim().length() == 0 || !url.startsWith("http"))
        return;//from  www . j  av a  2  s  . c om
    if (ImageFetcher.isDebug)
        Log.i(ImageFetcher.TAG, "loadImage " + url + "; isBg=" + isBackground + "; " + (imageView == null));
    //    url = "http://58.254.132.169/picture/90755000/copyright/singer/2012032806/23280.jpg";

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(url);
    }

    if (value != null) {
        // Bitmap found in memory cache
        if (ImageFetcher.isDebug)
            Log.i(ImageFetcher.TAG, "value is null ?  " + (value == null));
        if (isBackground) {
            imageView.setBackgroundDrawable(null);
            imageView.setBackgroundDrawable(value);
        } else
            imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(url, imageView, isBackground)) {
        if (ImageFetcher.isDebug)
            Log.i(ImageFetcher.TAG, "value is null ?  " + (value == null));
        imageView.setTag(loadingIndex);
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, 0, isBackground);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap[loadingIndex], task);
        //          imageView.setImageDrawable(asyncDrawable);
        if (isBackground) {
            imageView.setBackgroundDrawable(null);
            imageView.setBackgroundDrawable(asyncDrawable);
        } else
            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, url);
    }
}

From source file:com.baseproject.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView.//from   w w w . jav a2 s  . co  m
 * 
 * @param imageView
 * @param bitmap
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        if (imageView.getTag() instanceof String && "no_animation".equals(String.valueOf(imageView.getTag()))) {
            imageView.setImageBitmap(bitmap);
        } else {
            // Transition drawable with a transparent drwabale and the final
            // bitmap
            TransitionDrawable td = new TransitionDrawable(
                    new Drawable[] { new ColorDrawable(android.R.color.transparent),
                            new BitmapDrawable(mContext.getResources(), bitmap) });
            final WeakReference<TransitionDrawable> tdReference = new WeakReference<TransitionDrawable>(td);
            td = null;
            // Set background to loading bitmap
            final BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), mLoadingBitmap);
            if (Build.VERSION.SDK_INT >= 16) {
                imageView.setBackground(bd);
            } else {
                imageView.setBackgroundDrawable(bd);

            }
            if (null != tdReference.get()) {
                imageView.setImageDrawable(tdReference.get());
                tdReference.get().startTransition(FADE_IN_TIME);
            }
        }
    } else {
        imageView.setImageBitmap(bitmap);
    }

}

From source file:com.moki.touch.fragments.views.WebContent.java

private boolean setLogo() {
    final ImageView logoView = (ImageView) rootView.findViewById(R.id.logo);
    boolean shouldListenForLogo = false;
    if (SettingsUtil.getUploadLogo() != null && !SettingsUtil.getUploadLogo().isEmpty()) {
        final Bitmap bitmapLogo = getLogoBitmap();
        if (bitmapLogo == null) {
            shouldListenForLogo = true;/*from w  w w .  jav  a 2 s  . c  o  m*/
        } else {
            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    super.onPostExecute(aVoid);
                    logoView.setImageBitmap(bitmapLogo);
                }
            }.execute();
        }
    } else {
        logoView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.mt_web_logo));
    }
    return shouldListenForLogo;
}

From source file:kuta.adrian.cv.displayingbitmaps.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//from  ww  w .ja  v  a2 s  .c  o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    try {
        ViewGroup viewGroup = (ViewGroup) imageView.getParent();
        if (viewGroup instanceof FrameLayout) {
            FrameLayout parent = (FrameLayout) viewGroup;
            View view;
            if ((view = parent.getChildAt(0)) instanceof ProgressBar)
                parent.removeView(view);
        }
    } catch (Exception e) {
        Log.e(getClass().getSimpleName(), "onPostExecute, progressBar not found", e);
    }

    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(ContextCompat.getColor(imageView.getContext(), android.R.color.transparent)),
                drawable });
        // Set background to loading bitmap
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
        else
            imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));

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