Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

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

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:com.bitants.wally.fragments.ToplistFragment.java

private void setupAdapter() {
    imagesAdapter.setOnGetViewListener(new RecyclerImagesAdapter.OnGetViewListener() {
        @Override//  w  w  w . j  a  v a2s.  c  om
        public void onBindView(int position) {
            getMoreImagesIfNeeded(position, imagesAdapter.getItemCount());
        }
    });
    imagesAdapter.setOnItemClickListener(new RecyclerImagesAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Image image = (Image) imagesAdapter.getItem(position);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(image.imagePageURL()), view.getContext(),
                    ImageDetailsActivity.class);

            ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumb_image_view);

            Bitmap thumb = null;

            intent.putExtra(ImageDetailsActivity.INTENT_EXTRA_IMAGE, image);

            if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof GlideBitmapDrawable) {
                GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) thumbnailImageView
                        .getDrawable();
                thumb = glideBitmapDrawable.getBitmap();
            } else if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof TransitionDrawable) {
                GlideBitmapDrawable squaringDrawable = (GlideBitmapDrawable) ((TransitionDrawable) thumbnailImageView
                        .getDrawable()).getDrawable(1);
                thumb = squaringDrawable.getBitmap();
            }
            WallyApplication.setBitmapThumb(thumb);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                String transitionNameImage = getString(R.string.transition_image_details);
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                        getActivity(),
                        Pair.create(view.findViewById(R.id.thumb_image_view), transitionNameImage));
                ActivityCompat.startActivityForResult(getActivity(), intent,
                        ImageDetailsActivity.REQUEST_EXTRA_TAG, options.toBundle());

            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0)
                        .toBundle();
                getActivity().startActivityForResult(intent, REQUEST_CODE, bundle);
            } else {
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    });
}

From source file:com.likou.util.NImageLoader.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  w  w.  java2s .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 && NetUtils.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(250);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.mikhaellopez.saveinsta.activity.MainActivity.java

private int getDominantColor(ImageView imageView) {
    int color = 0;
    try {//from   www. ja va2s  .  com
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        String dominantColor = DominantImageColor.getDominantColorOfImage(bitmap);
        color = Color.parseColor(dominantColor);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return color;
}

From source file:com.layer.atlas.AtlasMessageComposer.java

private void addAttachmentMenuItem(AttachmentSender sender) {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    LinearLayout menuLayout = (LinearLayout) mAttachmentMenu.getContentView();

    View menuItem = inflater.inflate(R.layout.atlas_message_composer_attachment_menu_item, menuLayout, false);
    ((TextView) menuItem.findViewById(R.id.title)).setText(sender.getTitle());
    menuItem.setTag(sender);/*from  w  w  w  .j  a  va  2s  .c om*/
    menuItem.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAttachmentMenu.dismiss();
            ((AttachmentSender) v.getTag()).requestSend();
        }
    });
    if (sender.getIcon() != null) {
        ImageView iconView = ((ImageView) menuItem.findViewById(R.id.icon));
        iconView.setColorFilter(getResources().getColor(R.color.atlas_cell_attachment_title),
                PorterDuff.Mode.MULTIPLY);
        iconView.setImageResource(sender.getIcon());
        iconView.setVisibility(VISIBLE);
        Drawable d = DrawableCompat.wrap(iconView.getDrawable());
        DrawableCompat.setTint(d, getResources().getColor(R.color.atlas_icon_enabled));
    }
    menuLayout.addView(menuItem);
}

From source file:com.musenkishi.wally.fragments.RandomImagesFragment.java

private void setupAdapter() {
    imagesAdapter.setOnGetViewListener(new RecyclerImagesAdapter.OnGetViewListener() {
        @Override//from  ww w .  j  a  v a2 s  .c om
        public void onBindView(int position) {
            int defaultNumberOfItemsPerPage = NetworkDataProvider.THUMBS_PER_PAGE;
            boolean shouldLoadMore = position >= imagesAdapter.getItemCount()
                    - (defaultNumberOfItemsPerPage / 2);
            if (shouldLoadMore && !isLoading && imagesAdapter.getItemCount() > 0) {
                getImages(++currentPage, null);
            }
        }
    });
    imagesAdapter.setOnItemClickListener(new RecyclerImagesAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Image image = (Image) imagesAdapter.getItem(position);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(image.imagePageURL()), view.getContext(),
                    ImageDetailsActivity.class);

            ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumb_image_view);

            Bitmap thumb = null;

            intent.putExtra(ImageDetailsActivity.INTENT_EXTRA_IMAGE, image);

            if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof GlideBitmapDrawable) {
                GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) thumbnailImageView
                        .getDrawable();
                thumb = glideBitmapDrawable.getBitmap();
            } else if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof TransitionDrawable) {
                GlideBitmapDrawable squaringDrawable = (GlideBitmapDrawable) ((TransitionDrawable) thumbnailImageView
                        .getDrawable()).getDrawable(1);
                thumb = squaringDrawable.getBitmap();
            }
            WallyApplication.setBitmapThumb(thumb);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0)
                        .toBundle();
                getActivity().startActivityForResult(intent, REQUEST_CODE, bundle);
            } else {
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    });
}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

private void setTargetOffsetTopAndBottom(int offset) {
    circle.offsetTopAndBottom(offset);/*  ww w .j a v  a  2s . co  m*/
    currentTargetOffsetTop = circle.getTop();
    int percent = (int) ((currentTargetOffsetTop / distanceToTriggerSync) * 100);
    if (onSwipeListener != null) {
        onSwipeListener.onSwipe(percent, currentTargetOffsetTop);
    }
    ViewCompat.setElevation(circle, percent);
    ImageView imageView = (ImageView) circle;
    ClipDrawable clipDrawable = (ClipDrawable) imageView.getDrawable();

    if (percent < 50) {
        clipDrawable.setLevel(0);
    } else {
        clipDrawable.setLevel((percent - 50) * 2 * 100);
    }
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Assign a note visually and in the project.
 * @param view/*ww  w  .  j a  va 2s  . com*/
 */
private void paintNote(View view) {
    com.getbase.floatingactionbutton.FloatingActionButton ptool = (com.getbase.floatingactionbutton.FloatingActionButton) findViewById(
            R.id.pencilTool);
    ImageView iview = (ImageView) view;
    Drawable notestatus = iview.getDrawable();
    if (pencil) {
        if (notestatus.getConstantState().equals(ContextCompat
                .getDrawable(getApplicationContext(), R.drawable.note_filled).getConstantState())) {

            //blank all other notes in the column
            TableRow parent = (TableRow) iview.getParent();
            TableLayout layoutparent = (TableLayout) parent.getParent();
            int notedrawlen = layoutparent.getChildCount();
            for (int x = 0; x < notedrawlen; x++) {
                TableRow noterow = (TableRow) layoutparent.getChildAt(x);
                for (int i = 0; i < noterow.getChildCount(); i++) {
                    ImageView note = (ImageView) noterow.getChildAt(i);
                    if (note.getTag(R.id.TAG_COLUMN) == iview.getTag(R.id.TAG_COLUMN)) {
                        note.setImageDrawable(
                                ContextCompat.getDrawable(getApplicationContext(), R.drawable.measure_outline));
                        for (int n = 0; n < filledNotes.size(); n++) {
                            int[] comp = filledNotes.get(n);
                            if (comp[0] == (int) note.getTag(R.id.TAG_ROW)
                                    && comp[1] == (int) note.getTag(R.id.TAG_COLUMN)) {
                                filledNotes.remove(n);
                            }
                        }
                    }
                }
            }
            //set the drawable
            iview.setImageDrawable(
                    ContextCompat.getDrawable(getApplicationContext(), R.drawable.measure_outline));
            filledNotes.remove(
                    new int[] { (int) iview.getTag(R.id.TAG_ROW), (int) iview.getTag(R.id.TAG_COLUMN) });

            // set the other notes to rests
            List<Integer> guiSNAPRange = (List<Integer>) iview.getTag(R.id.TAG_GUISNAPRANGE);
            for (int z = guiSNAPRange.get(0); z <= guiSNAPRange.get(guiSNAPRange.size() - 1); z++) {
                theproject.track(trackNum).measure(measureNum).replace(z, new Note(Note.REST, noteSUB));
            }
        } else {
            //blank all other notes in the column
            TableRow parent = (TableRow) iview.getParent();
            TableLayout layoutparent = (TableLayout) parent.getParent();
            int notedrawlen = layoutparent.getChildCount();
            for (int x = 0; x < notedrawlen; x++) {
                TableRow noterow = (TableRow) layoutparent.getChildAt(x);
                for (int i = 0; i < noterow.getChildCount(); i++) {
                    ImageView note = (ImageView) noterow.getChildAt(i);
                    if (note.getTag(R.id.TAG_COLUMN) == iview.getTag(R.id.TAG_COLUMN)) {
                        note.setImageDrawable(
                                ContextCompat.getDrawable(getApplicationContext(), R.drawable.measure_outline));
                        for (int n = 0; n < filledNotes.size(); n++) {
                            int[] comp = filledNotes.get(n);
                            if (comp[0] == (int) note.getTag(R.id.TAG_ROW)
                                    && comp[1] == (int) note.getTag(R.id.TAG_COLUMN)) {
                                filledNotes.remove(n);
                            }
                        }
                    }
                }
            }
            //set the drawable
            iview.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.note_filled));
            filledNotes
                    .add(new int[] { (int) iview.getTag(R.id.TAG_ROW), (int) iview.getTag(R.id.TAG_COLUMN) });

            //set the note in the data structure
            double notetype = stringToNoteDouble((String) iview.getTag(R.id.TAG_NOTE));
            List<Integer> guiSNAPRange = (List<Integer>) iview.getTag(R.id.TAG_GUISNAPRANGE);
            for (int z = guiSNAPRange.get(0); z <= guiSNAPRange.get(guiSNAPRange.size() - 1); z++) {
                theproject.track(trackNum).measure(measureNum).replace(z, new Note(notetype, noteSUB));
            }
        }
    }
}

From source file:com.bitants.wally.fragments.RandomImagesFragment.java

private void setupAdapter() {
    imagesAdapter.setOnGetViewListener(new RecyclerImagesAdapter.OnGetViewListener() {
        @Override//ww w  .j a  va2 s  .co m
        public void onBindView(int position) {
            int defaultNumberOfItemsPerPage = NetworkDataProvider.THUMBS_PER_PAGE;
            boolean shouldLoadMore = position >= imagesAdapter.getItemCount()
                    - (defaultNumberOfItemsPerPage / 2);
            if (shouldLoadMore && !isLoading && imagesAdapter.getItemCount() > 0) {
                getImages(++currentPage, null);
            }
        }
    });
    imagesAdapter.setOnItemClickListener(new RecyclerImagesAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Image image = (Image) imagesAdapter.getItem(position);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(image.imagePageURL()), view.getContext(),
                    ImageDetailsActivity.class);

            ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumb_image_view);

            Bitmap thumb = null;

            intent.putExtra(ImageDetailsActivity.INTENT_EXTRA_IMAGE, image);

            if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof GlideBitmapDrawable) {
                GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) thumbnailImageView
                        .getDrawable();
                thumb = glideBitmapDrawable.getBitmap();
            } else if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof TransitionDrawable) {
                GlideBitmapDrawable squaringDrawable = (GlideBitmapDrawable) ((TransitionDrawable) thumbnailImageView
                        .getDrawable()).getDrawable(1);
                thumb = squaringDrawable.getBitmap();
            }
            WallyApplication.setBitmapThumb(thumb);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                String transitionNameImage = getString(R.string.transition_image_details);
                ActivityOptionsCompat options = ActivityOptionsCompat
                        .makeSceneTransitionAnimation(getActivity(), android.support.v4.util.Pair
                                .create(view.findViewById(R.id.thumb_image_view), transitionNameImage));
                ActivityCompat.startActivityForResult(getActivity(), intent,
                        ImageDetailsActivity.REQUEST_EXTRA_TAG, options.toBundle());

            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0)
                        .toBundle();
                getActivity().startActivityForResult(intent, REQUEST_CODE, bundle);
            } else {
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    });
}

From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java

private void removeImage(int index) {
    for (int i = index; i < postImageViewIds.length - 1; i++) {
        int nextIndex = i + 1;
        ImageView nowImage = (ImageView) rootView.findViewById(postImageViewIds[i]);
        ImageView nextImage = (ImageView) rootView.findViewById(postImageViewIds[nextIndex]);

        nowImage.setImageDrawable(nextImage.getDrawable());
        nowImage.setTag(nextImage.getTag());
        rootView.findViewById(postImageViewPlusIds[i])
                .setVisibility(rootView.findViewById(postImageViewPlusIds[nextIndex]).getVisibility());
        rootView.findViewById(postImageViewRemoveIds[i])
                .setVisibility(rootView.findViewById(postImageViewRemoveIds[nextIndex]).getVisibility());

        if (nowImage.getTag() == null) {
            nowImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        } else {/*  www .ja  v  a 2 s  . co  m*/
            nowImage.setScaleType(ImageView.ScaleType.FIT_XY);
        }
    }
    int lastIndex = postImageViewIds.length - 1;
    ImageView lastImage = (ImageView) rootView.findViewById(postImageViewIds[lastIndex]);
    lastImage.setImageResource(R.drawable.ic_add_photo);
    lastImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    lastImage.setTag(null);
    rootView.findViewById(postImageViewPlusIds[lastIndex]).setVisibility(View.GONE);
    rootView.findViewById(postImageViewRemoveIds[lastIndex]).setVisibility(View.GONE);

}

From source file:github.madmarty.madsonic.util.ImageLoader.java

@SuppressWarnings("deprecation")
private void setImage(View view, Drawable drawable, boolean crossfade) {
    if (view instanceof TextView) {
        // Cross-fading is not implemented for TextView since it's not in use.  It would be easy to add it, though.
        TextView textView = (TextView) view;
        textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    } else if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        if (crossfade) {

            Drawable existingDrawable = imageView.getDrawable();
            if (existingDrawable == null) {
                Bitmap emptyImage;/*from   www. j  av  a  2s .com*/
                if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
                    emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                } else {
                    emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault,
                            Bitmap.Config.ARGB_8888);
                }
                existingDrawable = new BitmapDrawable(emptyImage);
            } else {
                // Try to get rid of old transitions
                try {
                    TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
                    int layers = tmp.getNumberOfLayers();
                    existingDrawable = tmp.getDrawable(layers - 1);
                } catch (Exception e) {
                    // Do nothing, just means that the drawable is a flat image
                }
            }

            Drawable[] layers = new Drawable[] { existingDrawable, drawable };

            TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(250);
        } else {
            imageView.setImageDrawable(drawable);
        }
    }
}