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.gh4a.utils.ImageDownloader.java

public void downloadByUrl(String url, ImageView ivImage) {
    resetPurgeTimer();//from w  ww . ja  v a  2  s.c  o  m
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        if (cancelPotentialDownload(url, ivImage)) {
            BitmapDownloaderTask task = new BitmapDownloaderTask(ivImage);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            ivImage.setImageDrawable(downloadedDrawable);
            task.execute(url);
        }
    } else {
        cancelPotentialDownload(url, ivImage);
        ivImage.setImageBitmap(bitmap);
    }
}

From source file:air.com.snagfilms.utils.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   w ww.jav a  2s.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 data
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public void loadImage(Object data, ImageView imageView) {
    if (data == null) {
        return;
    }

    BitmapDrawable value = null;

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

    if (value != null) {
        // Bitmap found in memory cache
        imageView.setImageDrawable(value);
    } 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.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Drop again a movement in the moneybox making an animation.
 * /*from ww w.j ava  2  s.co  m*/
 * @param m
 *            Movement to be dropped.
 */
public void dropAgainMovement(Movement m) {
    ImageView v;
    CurrencyValueDef c;

    // TODO: This doesn't work!!!!!!

    c = CurrencyManager.getCurrencyDef(Math.abs(m.getAmount()));

    v = new ImageView(getActivity());
    v.setLeft(findLayout().getWidth() / 2);
    v.setTop(0);
    v.setImageDrawable(c.getDrawable());
    v.setTag(c);

    dropMoney(v, m);
}

From source file:com.conferenceengineer.android.iosched.util.ImageLoader.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 ww  w.j a v a  2s .  c  o  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 && UIUtils.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(UIUtils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageBitmap(bitmap);
    }
}

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

public void loadImageWithFrame(Object data, ImageView imageView, int thumbThickness) {
    if (data == null) {
        return;//w w w  .ja va  2  s.c  o m
    }

    BitmapDrawable value = null;

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

    if (value != null) {
        // Bitmap found in memory cache
        imageView.setImageDrawable(value);
    } 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.radicaldynamic.groupinform.activities.LauncherActivity.java

private void displaySplash() {
    // Don't show the splash screen if this app appears to be registered
    if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getString(InformOnlineState.DEVICE_ID, null) instanceof String) {
        return;//w  w w. j  a  va 2 s. co  m
    }

    // Fetch the splash screen Drawable
    Drawable image = null;

    try {
        // Attempt to load the configured default splash screen
        // The following code only works in 1.6+
        // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH);
        BitmapDrawable bitImage = new BitmapDrawable(
                FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE);

        if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0
                && bitImage.getIntrinsicWidth() > 0) {
            image = bitImage;
        }
    } catch (Exception e) {
        // TODO: log exception for debugging?
    }

    // TODO: rework
    if (image == null) {
        // no splash provided...
        //            if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) {
        // Show the built-in splash image if the config directory 
        // does not exist. Otherwise, suppress the icon.
        image = getResources().getDrawable(R.drawable.gc_color);
        //            }

        if (image == null)
            return;
    }

    // Create ImageView to hold the Drawable...
    ImageView view = new ImageView(getApplicationContext());

    // Initialise it with Drawable and full-screen layout parameters
    view.setImageDrawable(image);

    int width = getWindowManager().getDefaultDisplay().getWidth();
    int height = getWindowManager().getDefaultDisplay().getHeight();

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0);

    view.setLayoutParams(lp);
    view.setScaleType(ScaleType.CENTER);
    view.setBackgroundColor(Color.WHITE);

    // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured
    FrameLayout layout = new FrameLayout(getApplicationContext());
    layout.addView(view);

    // Create the toast and set the view to be that of the FrameLayout
    mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG);
    mSplashToast.setView(layout);
    mSplashToast.setGravity(Gravity.CENTER, 0, 0);
    mSplashToast.show();
}

From source file:com.android.contacts.activities.ContactDetailActivity.java

/**
 * M:update rcs-e icon//w  w  w  .j  a  v a  2 s  .  co  m
 */
public void updateRCSIcon(long id) {
    ///@ update the rcs-e icon
    LogUtils.i(TAG, "updateRCSIcon,Need to remove the code...");
    ActionBar actionBar = getActionBar();
    Drawable drawable = ExtensionManager.getInstance().getContactDetailExtension().getRCSIcon(id);
    if (drawable != null) {
        View view = LayoutInflater.from(this).inflate(com.android.contacts.R.layout.mtk_action_bar_rcs_icon,
                null);
        ImageView iv = (ImageView) view.findViewById(com.android.contacts.R.id.rcs_icon);
        iv.setImageDrawable(drawable);
        actionBar.setCustomView(view);
    }
}

From source file:com.ez.gallery.ucrop.UCropActivity.java

/**
 * Use {@link #mActiveWidgetColor} for color filter
 *//*  w  w w.j a  va 2 s . co  m*/
private void setupStatesWrapper() {
    ImageView stateScaleImageView = (ImageView) findViewById(R.id.image_view_state_scale);
    ImageView stateRotateImageView = (ImageView) findViewById(R.id.image_view_state_rotate);
    ImageView stateAspectRatioImageView = (ImageView) findViewById(R.id.image_view_state_aspect_ratio);

    stateScaleImageView.setImageDrawable(
            new SelectedStateListDrawable(stateScaleImageView.getDrawable(), mActiveWidgetColor));
    stateRotateImageView.setImageDrawable(
            new SelectedStateListDrawable(stateRotateImageView.getDrawable(), mActiveWidgetColor));
    stateAspectRatioImageView.setImageDrawable(
            new SelectedStateListDrawable(stateAspectRatioImageView.getDrawable(), mActiveWidgetColor));
}

From source file:com.common.app.image.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
 * {@link ImageWorker#addImageCache(android.support.v4.app.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 data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//*from  w  ww .ja va  2s  .c o m*/
public void loadImage(Object data, ImageView imageView) {
    if (data == null) {
        return;
    }

    BitmapDrawable value = null;

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

    if (value != null) {
        // Bitmap found in memory cache
        imageView.setImageDrawable(value);

        //add by fangzhu
        if (onLoadCallBackListenering != null) {
            onLoadCallBackListenering.onPostExecute(value, imageView);
        }

    } else if (cancelPotentialWork(data, imageView)) {

        final BitmapWorkerTask task = new BitmapWorkerTask(data, 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);

    }
}

From source file:com.app.chasebank.contactslist.util.ImageLoader.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView The ImageView to set the bitmap to.
 * @param bitmap The new bitmap to set.//  ww w .j av  a  2 s  .c  o  m
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable to fade from loading bitmap to final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });

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