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:am.project.x.business.drawables.centerdrawable.CenterDrawableActivity.java

@Override
protected void initializeActivity(@Nullable Bundle savedInstanceState) {
    setSupportActionBar(R.id.cd_toolbar);
    ImageView image = findViewById(R.id.center_iv_rectangle);
    image.setImageDrawable(
            new CenterDrawable(ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
                    ContextCompat.getColor(this, R.color.colorPrimary)));
    image = findViewById(R.id.center_iv_rectangle_e);
    image.setImageDrawable(//from ww  w .ja  v a 2 s.c  o  m
            new CenterDrawable(ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
                    ContextCompat.getColor(this, R.color.colorPrimary), true));
    image = findViewById(R.id.center_iv_rounded_rectangle);
    CenterDrawable cRR = new CenterDrawable(
            ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
            ContextCompat.getColor(this, R.color.colorPrimary), CenterDrawable.SHAPE_ROUNDED_RECTANGLE, false);
    cRR.setCornerRadius(getResources().getDisplayMetrics().density * 10);
    image.setImageDrawable(cRR);
    image = findViewById(R.id.center_iv_rounded_rectangle_e);
    CenterDrawable cRRE = new CenterDrawable(
            ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
            ContextCompat.getColor(this, R.color.colorPrimary), CenterDrawable.SHAPE_ROUNDED_RECTANGLE, true);
    cRRE.setCornerRadius(getResources().getDisplayMetrics().density * 10);
    image.setImageDrawable(cRRE);
    image = findViewById(R.id.center_iv_oval);
    image.setImageDrawable(
            new CenterDrawable(ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
                    ContextCompat.getColor(this, R.color.colorPrimary), CenterDrawable.SHAPE_OVAL, false));
    image = findViewById(R.id.center_iv_oval_e);
    image.setImageDrawable(
            new CenterDrawable(ContextCompat.getDrawable(this, R.drawable.ic_centerdrawable_center),
                    ContextCompat.getColor(this, R.color.colorPrimary), CenterDrawable.SHAPE_OVAL, true));
}

From source file:com.android.volley.cache.plus.ImageLoader.java

/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param imageView The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 *//*from   w  w w  .  j  a  v a 2s .com*/
public static ImageListener getImageListener(final ImageView view, final int defaultImageResId,
        final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageDrawable(response.getBitmap());
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}

From source file:com.android.projectz.teamrocket.thebusapp.adapters.CustomListSettingMain.java

/**
 * adattatore per visualizzare la lista con i determinati parametri:
 * 1.testo/*from   www . j  a va2  s  .  c om*/
 * 2.immagine
 *
 * @param position
 * @param view
 * @param parent
 * @return
 */
@Override
public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView = inflater.inflate(R.layout.list_main, null, true);

    TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
    txtTitle.setText(text[position]);

    Drawable colorImg = null;
    if (SharedPreferencesUtils.getSelectedTheme(context).equals("AppTheme")) {
        colorImg = changeColorOfIcons(imageId[position], R.color.iconLight);
    } else {
        colorImg = changeColorOfIcons(imageId[position], R.color.iconDark);
    }

    ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
    imageView.setImageDrawable(colorImg);

    return rowView;
}

From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java

private static void loadFromRes(final File file, final ImageView icon) {
    Drawable mimeIcon = null;//  w w w . j a  va  2 s .  c om

    if (file != null && file.isDirectory()) {
        String[] files = file.list();
        if (file.canRead() && files != null && files.length > 0)
            mimeIcon = mResources.getDrawable(R.drawable.type_folder);
        else
            mimeIcon = mResources.getDrawable(R.drawable.type_folder_empty);
    } else if (file != null && file.isFile()) {
        final String fileExt = FilenameUtils.getExtension(file.getName());
        mimeIcon = mMimeTypeIconCache.get(fileExt);

        if (mimeIcon == null) {
            final int mimeIconId = MimeTypes.getIconForExt(fileExt);
            if (mimeIconId != 0) {
                mimeIcon = mResources.getDrawable(mimeIconId);
                mMimeTypeIconCache.put(fileExt, mimeIcon);
            }
        }
    }

    if (mimeIcon != null) {
        icon.setImageDrawable(mimeIcon);
    } else {
        // default icon
        icon.setImageResource(R.drawable.type_unknown);
    }
}

From source file:co.uk.rehope.androidapp.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable((Drawable) drawableMap.get(urlString));
    }//www .  j  a va 2  s  .com

    final Handler handler = new Handler() {
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            // TODO : set imageView to a "pending" image
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.vti.managers.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    } else {//  ww w.  j  a  v a 2 s.co m
        Thread thread = new Thread() {
            @Override
            public void run() {
                final Drawable drawable = fetchDrawable(urlString);
                if (!drawableMap.containsKey(urlString)) {
                    drawableMap.put(urlString, drawable);
                }
                if (null != drawable) {
                    imageView.post(new Runnable() {
                        @Override
                        public void run() {
                            imageView.setImageDrawable(drawable);
                        }
                    });
                }

            }
        };
        thread.start();
    }

}

From source file:com.novel.lightnovel.Utils.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//from   ww w  .j  a  v a2 s  .c  o  m
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };
    Thread thread = new Thread() {
        @Override
        public void run() {
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:br.com.agendatech.cadastro.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }/*  w ww  .ja va 2  s.  c o  m*/

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.example.hotspot.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//from  w  w w  .  java  2s  .com

    final Handler handler = new Handler() {
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.social.services.managers.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    } else {/*from  w ww .  ja va 2  s.com*/
        Thread thread = new Thread() {
            @Override
            public void run() {
                final Drawable drawable = fetchDrawable(urlString);
                if (!drawableMap.containsKey(urlString)) {
                    drawableMap.put(urlString, drawable);
                }
                if (null != drawable) {
                    imageView.post(new Runnable() {

                        @Override
                        public void run() {
                            imageView.setImageDrawable(drawable);
                        }
                    });
                }

            }
        };
        thread.start();
    }

}