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.hunch.ImageManager.java

/**
 * Get the image for a Hunch category. These images are cached into internal storage
 * after the first time they are downloaded. If the image is not present in the cache,
 * it will be downloaded in a background thread then cached, and a placeholder image
 * will be displayed it its place.//from   w ww  .  ja v  a2s.  c o m
 * 
 * @param context Application context (to get to internal storage dir)
 * @param image The ImageView that will display the image
 * @param imgURL The URL to the image.
 */
public void getCategoryImage(final Context context, final ImageView image, final String imgURL) {
    URL url = stringToURL(imgURL);
    Drawable cachedDrawable = getCachedCategoryImage(context, url);

    if (cachedDrawable != null) {
        // the image is in the cache
        image.setImageDrawable(cachedDrawable);
    } else {

        // the image is not in the cache, must download
        downloadCategoryDrawable(url, context, new Callback() {

            @Override
            public void callComplete(Drawable d) {
                image.setImageDrawable(d);
            }
        });

        // set it to the placeholder image for now
        image.setImageResource(Const.CAT_DEFAULT_IMG);
    }

}

From source file:com.ifeng.util.imagecache.ImageWorker.java

/**
 * /*w  w  w .  ja va  2s .  c  om*/
 * 
 * @param imageView
 * @param drawable
 */
public static void setFadeInDrawable(ImageView imageView, Drawable drawable) {
    // Bug fix by XuWei 2013-09-09
    // Drawable?bug?ViewDrawable??Drawable
    Drawable copyDrawable = new BitmapDrawable(imageView.getContext().getResources(),
            ((BitmapDrawable) drawable).getBitmap());

    // Transition drawable with a transparent drawable and the final
    // drawable
    final TransitionDrawable td = new TransitionDrawable(
            new Drawable[] { new ColorDrawable(android.R.color.transparent), copyDrawable });

    imageView.setImageDrawable(td);
    td.startTransition(FADE_IN_TIME);
}

From source file:com.sutromedia.android.core.PhotoActivity.java

private void setImageView(View view, int resourceId, int index, Integer[] licences) {
    ImageView image = (ImageView) view.findViewById(resourceId);
    if (index < licences.length) {
        setVisibility(view, resourceId, true);
        image.setImageResource(getLicenceBitmap(licences[index]));
    } else {/*w w w.ja v a 2 s.  c  o  m*/
        setVisibility(view, resourceId, false);
        image.setImageDrawable(null);
    }
}

From source file:cmu.cconfs.instantMessage.util.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  w  w .jav  a 2s.  com*/
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)) {
        //BEGIN_INCLUDE(execute_background_task)
        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(DUAL_THREAD_EXECUTOR);
        //END_INCLUDE(execute_background_task)
    }
}

From source file:com.cttapp.bby.mytlc.layer8apps.MyTlc.java

/************
 *  PURPOSE: Primary thread that starts everything
 *  ARGUMENTS: <Bundle> savedInstanceState
 *  RETURNS: void//from  w w w  .  ja  v  a 2s  .  c  o m
 *  AUTHOR: Casey Stark <starkca90@gmail.com>, Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com>
 ************/
@Override
public void onCreate(Bundle savedInstanceState) {

    /*************
     * The following try statement makes the app think that the user doesn't
     * have a hard settings button.  This allows the options menu to always be
     * visible
     ************/

    currentMyTLCActivity = this;

    try {
        // Get the configuration of the device
        ViewConfiguration config = ViewConfiguration.get(this);
        // Check if the phone has a hard settings key
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        // If it does...
        if (menuKeyField != null) {
            // Make our app think it doesn't!
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Do nothing
    }

    // Create a new preferences manager
    pf = new Preferences(this);
    // Set the theme of the app
    int logo = applyTheme();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView imgLogo = (ImageView) findViewById(R.id.logo);

    imgLogo.setImageDrawable(getResources().getDrawable(logo));

    txtUsername = (EditText) findViewById(R.id.txtUsername);
    txtUsername.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    txtPassword = (EditText) findViewById(R.id.txtPassword);
    //        remember = (CheckBox) findViewById(R.id.remember);
    results = (TextView) findViewById(R.id.results);

    // Get a reference to our last handler
    final Object handler = getLastCustomNonConfigurationInstance();
    // If the last handler existed
    if (handler != null) {
        // Cast the handler to MyHandler so we can use it
        mHandler = (MyHandler) handler;
    } else {
        // Otherwise create a new handler
        mHandler = new MyHandler();
    }
    // Assign the activity for our handler so it knows the proper reference
    mHandler.setActivity(this);

    // Load all of the users saved options
    checkSavedSettings();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    System.out.println("Saved Shifts:\n" + pf.getJSONString());

    loginButton = (Button) findViewById(R.id.loginButton);
    loginButton.setOnClickListener(this);

    // Show the ads
    //showAds();
}

From source file:com.facebook.samples.loginsample.accountkit.ReverbBodyFragment.java

private void updateIcon(final View view) {

    final View progressSpinner = view.findViewById(R.id.reverb_progress_spinner);
    if (progressSpinner != null) {
        progressSpinner.setVisibility(showProgressSpinner ? View.VISIBLE : View.GONE);
    }//from   ww  w.jav a 2  s  . c om

    final ImageView iconView = (ImageView) view.findViewById(R.id.reverb_icon);
    if (iconView != null) {
        if (iconResourceId > 0) {

            /*
             * Api levels lower than 21 do not support android:tint in xml drawables. Tint can
             * be applied with DrawableCompat
             */
            Drawable icon = getResources().getDrawable(iconResourceId);
            if (iconTintResourceId > 0) {
                icon = DrawableCompat.wrap(icon);
                DrawableCompat.setTint(icon, ContextCompat.getColor(view.getContext(), R.color.reverb_dark));
            }

            iconView.setImageDrawable(icon);
            iconView.setVisibility(View.VISIBLE);
        } else {
            iconView.setVisibility(View.GONE);
        }
    }
}

From source file:com.laer.easycast.ImagePane.java

public void loadBitmap(int resId, ImageView imageView) {
    if (cancelPotentialWork(resId, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(resId, imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(getResources(), mPlaceHolderBitmap, task);
        imageView.setImageDrawable(asyncDrawable);
        task.execute(resId);//from w  w  w.  ja  va  2 s.  co m

    }
}

From source file:com.android.simpleimageloader.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.//from   w  w  w.j  a va  2s.c  o  m
 * 
 * @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, DisplayOptions options) {

    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)) {
        // BEGIN_INCLUDE(execute_background_task)
        final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView, options);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, options.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);
        // END_INCLUDE(execute_background_task)
    }
}

From source file:com.eamonndunne.londontraffic.view.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 CustomAsyncTask}
 * 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 www . j  a  va 2 s .  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);
    } else if (cancelPotentialWork(data, imageView)) {
        //BEGIN_INCLUDE(execute_background_task)
        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(CustomAsyncTask.DUAL_THREAD_EXECUTOR);
        //END_INCLUDE(execute_background_task)
    }
}

From source file:com.github.michalbednarski.intentslab.browser.RegisteredReceiverInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_component_info, container, false);

    // Find views: header, icon, component name and description
    TextView titleTextView = (TextView) v.findViewById(R.id.title);
    TextView componentTextView = (TextView) v.findViewById(R.id.component);
    ImageView iconView = (ImageView) v.findViewById(R.id.icon);
    TextView descriptionTextView = (TextView) v.findViewById(R.id.description);
    descriptionTextView.setMovementMethod(LinkMovementMethod.getInstance());

    // Fill header
    titleTextView.setText(R.string.registered_receiver);
    componentTextView.setText(mReceiverInfo.processName);
    /*mIconView.setImageDrawable(
        mExtendedComponentInfo.systemComponentInfo.loadIcon(getActivity().getPackageManager())
    );*//*www . j  a  v a 2s. c o  m*/
    iconView.setImageDrawable(null); // TODO

    // Description text
    FormattedTextBuilder text = new FormattedTextBuilder();

    // Description: permission
    boolean hasOverallPermission = false;
    String permission = null;
    try {
        permission = mReceiverInfo.getOverallPermission();
        hasOverallPermission = true;
    } catch (RegisteredReceiverInfo.MixedPermissionsException ignored) {
    }
    if (permission != null) {
        text.appendValue(getString(R.string.permission_required_title), permission, true,
                FormattedTextBuilder.ValueSemantic.PERMISSION);
    }

    // Description: <intent-filter>'s
    text.appendHeader(getString(R.string.intent_filters));
    IntentFilter[] intentFilters = mReceiverInfo.intentFilters;
    for (int i = 0, j = intentFilters.length; i < j; i++) {
        IntentFilter filter = intentFilters[i];
        boolean hasSpecificPermission = !hasOverallPermission && mReceiverInfo.filterPermissions[i] != null;
        if (hasSpecificPermission) {
            text.appendColoured( // TODO: link
                    "\n\n<!-- " + getString(R.string.permission_required_title) + ": "
                            + mReceiverInfo.filterPermissions[i] + " -->",
                    getResources().getColor(R.color.xml_comment));
        }
        text.appendFormattedText(ComponentInfoFragment.dumpIntentFilter(filter, getResources(), true));
        if (hasSpecificPermission) {
            text.appendRaw("\n");
        }
    }

    // Put text in TextView
    descriptionTextView.setText(text.getText());

    // Go to intent editor button
    v.findViewById(R.id.go_to_intent_editor).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getArguments().getBoolean(ComponentInfoFragment.ARG_LAUNCHED_FROM_INTENT_EDITOR, false)) {
                getActivity().finish();
                return;
            }
            startActivity(new Intent(getActivity(), IntentEditorActivity.class)
                    .putExtra(IntentEditorActivity.EXTRA_INTENT, new Intent())
                    .putExtra(IntentEditorActivity.EXTRA_COMPONENT_TYPE, IntentEditorConstants.BROADCAST)
                    .putExtra(IntentEditorActivity.EXTRA_INTENT_FILTERS, mReceiverInfo.intentFilters));
        }
    });

    // Receive broadcast button
    View receiveBroadcastButton = v.findViewById(R.id.receive_broadcast);
    receiveBroadcastButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ReceiveBroadcastService.startReceiving(getActivity(), mReceiverInfo.intentFilters, false);
        }
    });
    receiveBroadcastButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            ReceiveBroadcastService.startReceiving(getActivity(), mReceiverInfo.intentFilters, true);
            return true;
        }
    });
    receiveBroadcastButton.setVisibility(View.VISIBLE);
    receiveBroadcastButton.setEnabled(true);

    return v;
}