Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

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

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.cnm.cnmrc.fragment.RcChannelVolume.java

/**
 * Loading TapPressAnimation <br>/*from   www. java2s  . com*/
 */
private void startLoadingAni(ImageButton view, final ImageView animView) {
    if (view != null) {
        view.post(new Runnable() {
            @Override
            public void run() {
                try {
                    mTapPressAnimation = new AnimationDrawable();
                    mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress01), 60);
                    mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress02), 60);
                    mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress03), 60);
                    mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress04), 60);
                    mTapPressAnimation.setOneShot(true);
                    animView.setImageDrawable(mTapPressAnimation);

                    // API 2.3.4?  ?... ???
                    // animView.setBackgroundResource(R.drawable.anim_tappress);
                    // mTapPressAnimation = (AnimationDrawable)
                    // animView.getBackground();

                    mTapPressDuration = 0;
                    for (int i = 0; i < mTapPressAnimation.getNumberOfFrames(); i++) {
                        mTapPressDuration += mTapPressAnimation.getDuration(i);
                    }

                    animView.setVisibility(View.VISIBLE);

                    // Start the animation (looped playback by default).
                    mTapPressAnimation.start();

                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            mTapPressAnimation.stop();
                            mTapPressAnimation = null;
                            animView.setBackgroundResource(0);
                            animView.setVisibility(View.INVISIBLE);
                            oneClickTapPress = true;
                        }
                    }, mTapPressDuration);
                } catch (Exception e) {
                    e.getStackTrace();
                }

            }
        });
    }

    //view.post(new Starter());
}

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  a  v  a  2 s . c om*/
 */
@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.zhihuigu.sosoOffice.utils.ImageDownloaderUrl.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.
 *//*from  w  ww .jav  a  2  s.com*/
private void forceDownload(String url, File file, String sql, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageResource(resid);
        return;
    }
    Log.i("", imageView.toString() + "-----" + url);
    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, context, resid);
        imageView.setImageDrawable(downloadedDrawable);

        task.execute(url, file, sql);
    }
}

From source file:com.jefftharris.passwdsafe.SyncProviderFilesFragment.java

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

    itsProviderAdapter = new SimpleCursorAdapter(getActivity(), R.layout.sync_provider_file_list_item, null,
            new String[] { PasswdSafeContract.Files.COL_TITLE, PasswdSafeContract.Files.COL_MOD_DATE,
                    PasswdSafeContract.Files.COL_FOLDER },
            new int[] { R.id.title, R.id.mod_date, R.id.folder }, 0);

    itsProviderAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override/*from w  w  w  .j  a va2s.  c  om*/
        public boolean setViewValue(View view, Cursor cursor, int colIdx) {
            switch (colIdx) {
            case PasswdSafeContract.Files.PROJECTION_IDX_MOD_DATE: {
                long modDate = cursor.getLong(colIdx);
                TextView tv = (TextView) view;
                tv.setText(Utils.formatDate(modDate, getActivity()));
                return true;
            }
            case PasswdSafeContract.Files.PROJECTION_IDX_FOLDER: {
                String folder = cursor.getString(colIdx);
                if (TextUtils.isEmpty(folder)) {
                    view.setVisibility(View.GONE);
                } else {
                    view.setVisibility(View.VISIBLE);
                    ((TextView) view).setText(folder);
                }
                return true;
            }
            }
            return false;
        }
    });

    setListAdapter(itsProviderAdapter);

    LoaderManager lm = getLoaderManager();
    lm.initLoader(LOADER_TITLE, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new PasswdCursorLoader(getActivity(), itsProviderUri,
                    PasswdSafeContract.Providers.PROJECTION, null, null, null);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            if (!PasswdCursorLoader.checkResult(loader)) {
                return;
            }
            View view = getView();
            if (view == null) {
                return;
            }
            String str;
            ImageView icon = (ImageView) view.findViewById(R.id.icon);
            if ((cursor != null) && cursor.moveToFirst()) {
                str = PasswdSafeContract.Providers.getDisplayName(cursor);
                String typeStr = cursor.getString(PasswdSafeContract.Providers.PROJECTION_IDX_TYPE);
                try {
                    ProviderType type = ProviderType.valueOf(typeStr);
                    type.setIcon(icon);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Unknown provider type", e);
                }
            } else {
                str = getString(R.string.none);
                icon.setImageDrawable(null);
            }
            TextView tv = (TextView) view.findViewById(R.id.title);
            tv.setText(str);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
        }
    });

    lm.initLoader(LOADER_FILES, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new PasswdCursorLoader(getActivity(), itsFilesUri, PasswdSafeContract.Files.PROJECTION,
                    PasswdSafeContract.Files.NOT_DELETED_SELECTION, null,
                    PasswdSafeContract.Files.TITLE_SORT_ORDER);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            if (PasswdCursorLoader.checkResult(loader)) {
                itsProviderAdapter.swapCursor(cursor);
            }
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            if (PasswdCursorLoader.checkResult(loader)) {
                itsProviderAdapter.swapCursor(null);
            }
        }
    });
}

From source file:com.brq.wallet.activity.main.AddressFragment.java

private void updateUi() {
    if (!isAdded()) {
        return;//from   ww  w.  j a va  2s  . c om
    }
    if (_mbwManager.getSelectedAccount().isArchived()) {
        return;
    }

    // Update QR code
    QrImageView qrButton = (QrImageView) Preconditions.checkNotNull(_root.findViewById(R.id.ivQR));

    Optional<Address> receivingAddress = getAddress();

    // Update address
    if (receivingAddress.isPresent()) {
        // Set address
        qrButton.setVisibility(View.VISIBLE);
        qrButton.setQrCode(BitcoinUriWithAddress.fromAddress(receivingAddress.get()).toString());
        String[] addressStrings = Utils.stringChopper(receivingAddress.get().toString(), 12);
        ((TextView) _root.findViewById(R.id.tvAddress1)).setText(addressStrings[0]);
        ((TextView) _root.findViewById(R.id.tvAddress2)).setText(addressStrings[1]);
        ((TextView) _root.findViewById(R.id.tvAddress3)).setText(addressStrings[2]);
        if (_showBip44Path && receivingAddress.get() instanceof HdDerivedAddress) {
            HdDerivedAddress hdAdr = (HdDerivedAddress) receivingAddress.get();
            ((TextView) _root.findViewById(R.id.tvAddressPath)).setText(hdAdr.getBip32Path().toString());
        } else {
            ((TextView) _root.findViewById(R.id.tvAddressPath)).setText("");
        }
    } else {
        // No address available
        qrButton.setVisibility(View.INVISIBLE);
        ((TextView) _root.findViewById(R.id.tvAddress1)).setText("");
        ((TextView) _root.findViewById(R.id.tvAddress2)).setText("");
        ((TextView) _root.findViewById(R.id.tvAddress3)).setText("");
        ((TextView) _root.findViewById(R.id.tvAddressPath)).setText("");
    }

    // Show name of bitcoin address according to address book
    TextView tvAddressTitle = (TextView) _root.findViewById(R.id.tvAddressLabel);
    ImageView ivAccountType = (ImageView) _root.findViewById(R.id.ivAccountType);

    String name = _mbwManager.getMetadataStorage().getLabelByAccount(_mbwManager.getSelectedAccount().getId());
    if (name.length() == 0) {
        tvAddressTitle.setVisibility(View.GONE);
        ivAccountType.setVisibility(View.GONE);
    } else {
        tvAddressTitle.setVisibility(View.VISIBLE);
        tvAddressTitle.setText(name);

        // show account type icon next to the name
        Drawable drawableForAccount = Utils.getDrawableForAccount(_mbwManager.getSelectedAccount(), true,
                getResources());
        if (drawableForAccount == null) {
            ivAccountType.setVisibility(View.GONE);
        } else {
            ivAccountType.setImageDrawable(drawableForAccount);
            ivAccountType.setVisibility(View.VISIBLE);
        }
    }

}

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

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.// w w  w .j a  v a  2 s.  co  m
 *
 * @param imageView
 * @param drawable
 */
protected 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.android.beez.loadimage.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*from  w  ww  .  ja v  a  2  s  .com*/
 * 
 * @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.setVisibility(View.VISIBLE);
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.krava.vkmessenger.domain.image.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*from w w  w  .ja  v  a  2s  . 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(imageView.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.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Drop money from the top of the layout to the bottom simulating that a
 * coin or bill is inserted in the moneybox.
 * /*from   ww w. ja  v  a2 s.  c o m*/
 * @param leftMargin
 *            Left side of the coin/bill
 * @param width
 *            Width of the image to slide down
 * @param m
 *            Movement with the value of the money to drop
 */
protected void dropMoney(int leftMargin, int width, Movement m) {
    ImageView money;
    AnimationSet moneyDrop;
    RelativeLayout layout;
    RelativeLayout.LayoutParams lpParams;
    Rect r;
    Activity parent;
    CurrencyValueDef curr;

    parent = getActivity();

    curr = CurrencyManager.getCurrencyDef(Math.abs(m.getAmount()));
    r = curr.getDrawable().getBounds();

    money = new ImageView(parent);
    money.setVisibility(View.INVISIBLE);
    money.setImageDrawable(curr.getDrawable().getConstantState().newDrawable());
    money.setTag(curr);
    money.setId((int) m.getIdMovement());

    layout = findLayout();

    lpParams = new RelativeLayout.LayoutParams(r.width(), r.height());
    lpParams.leftMargin = leftMargin;
    lpParams.rightMargin = layout.getWidth() - (leftMargin + width);
    lpParams.topMargin = 0;
    lpParams.bottomMargin = r.height();

    layout.addView(money, lpParams);

    moneyDrop = createDropAnimation(money, layout, curr);
    money.setVisibility(View.VISIBLE);

    SoundsManager.playMoneySound(curr.getType());
    VibratorManager.vibrateMoneyDrop(curr.getType());

    money.startAnimation(moneyDrop);
}

From source file:com.intuit.qboecoui.feeds.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*from  w  w  w .  jav a  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.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

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